Skip to content

fix(ui): focus previous panel after close - #2196

Merged
Xuepoo merged 1 commit into
mainfrom
carryctx/ctx-1300
Oct 17, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
carryctx/ctx-1300

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Priority: P1 | Area: ui | Labels: fix, P1, area:ui | Milestone: v0.1.0 | RFC: OQ-036 | Task: CTX-1300

Summary

  • focus the previous tiled Panel after closing the focused Panel
  • use stable depth-first leaf order with wraparound from the first leaf to the last survivor
  • set focus before layout-closing so primary PTY ownership follows the selected survivor
  • preserve whole-window close, workspace-prune, floating, pinned, and zoom paths

Verification

  • independent review: APPROVE
  • cargo fmt --all -- --check
  • git diff --check
  • cargo test -p bitty-terminal --bin bitty chrome_close_view_focuses_previous_leaf --locked
  • cargo test -p bitty-terminal --bin bitty chrome_close_view_wraps_first_leaf_focus --locked

@coderabbitai

coderabbitai Bot commented Oct 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 48 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 44d1bb71-dca1-46e4-a9db-2164d78d422f
📥 Commits

Reviewing files that changed from the base of the PR and between aceb327 and 7483c7d.

📒 Files selected for processing: 1
  • crates/bitty-terminal/src/chrome_keys.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Xuepoo Xuepoo added the fix Bug fix label Oct 17, 2026
@Xuepoo Xuepoo added this to the v0.1.0 milestone Oct 17, 2026
@Xuepoo Xuepoo added P1 Priority: high area:ui Area: UI / layout labels Oct 17, 2026

@Xuepoo Xuepoo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review — APPROVE

Reviewer: separate agent (hermes guard delegate), verdict recorded via comment (single GitHub identity cannot self-approve).
Scope: commit 7483c7d — crates/bitty-terminal/src/chrome_keys.rs, 1 file, +70/-0.

Checks run (exact):

  1. git show 7483c7d4 --stat → 1 file changed, only chrome_keys.rs.
  2. git show 7483c7d4 -- crates/bitty-terminal/src/chrome_keys.rs
  3. git log --oneline -3 7483c7d4
  4. rg -n 'leaf_order|predecessor|previous.*leaf|close_view' crates/bitty-terminal/src/chrome_keys.rs
  5. rg -n 'fn close_view|fn leaf|close_view_focuses_previous_leaf|wraps_first_leaf' crates/bitty-terminal/src/chrome_keys.rs

Findings:

  • previous_leaf_after_close (chrome_keys.rs:620) returns leaf_ids[position - 1] as predecessor and wraps only when position == 0 (.rev().find(|id| *id != focused)) — no off-by-one; focused can never be returned.
  • Focus is set before the layout close: self.runtime.set_focus(previous) inside the if close_focused_leaf(...) arm ahead of the set_layout install (chrome_keys.rs:1566-1571), so primary ownership re-homes to the same survivor.
  • Scope is exactly one file; whole-window close / workspace-prune / floating / pinned / zoom arms (lines 1442/1514/1535) untouched.
  • Regression tests are present and meaningful: chrome_close_view_focuses_previous_leaf_in_stable_order (5252) and chrome_close_view_wraps_first_leaf_focus_to_last_survivor (5278) assert concrete leaf_ids() / focused_view() / primary_view() after a real apply_chrome_action(ChromeAction::CloseView).
  • MSRV 1.85 OK (plain if let, no let-chain); no hardcoded host/env literals.

Caveat: the reviewer's checkout was not at head, so the two tests were not executed in the review run; approval rests on the committed diff plus fully green CI on head SHA 7483c7d (Quality gates 1/2, MSRV, Windows, macOS, Linux X11/Wayland, Supply chain, Analyze, CodeQL all pass).

@Xuepoo
Xuepoo merged commit 3b7c7a4 into main Oct 17, 2026
17 checks passed
@Xuepoo
Xuepoo deleted the carryctx/ctx-1300 branch October 17, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ui Area: UI / layout fix Bug fix P1 Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant