Skip to content

fix(titlebar): keep terminal focus when toggling a sidebar with the mouse - #46735

Merged
AmoabaKelvin merged 5 commits into
mainfrom
fix/sidebar-toggle-focus
Nov 22, 2026
Merged

AmoabaKelvin merged 5 commits into
mainfrom
fix/sidebar-toggle-focus

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

If you were typing in a terminal and clicked the button that shows or hides the left or right sidebar, your typing stopped reaching the terminal. Now the sidebar opens or closes and you can keep typing. If you were halfway through renaming something inside the sidebar you're closing, the rename still saves.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​52 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​52
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​28 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25

What Changed

  • Before: a mouse click on the left-sidebar toggle, the titlebar's right-sidebar toggle or the right sidebar's own close toggle moved keyboard focus off the terminal. Focus landed on the button, or on the page once the button unmounted.
  • After: those toggles leave focus where it was, the same as the right sidebar's panel tabs since fix(right-sidebar): keep terminal focus when clicking a panel tab #46620. The Windows/Linux titlebar "Application menu" button follows the same rule, so Edit menu commands such as Paste act on the terminal instead of the button.
  • focus-keeping-press.ts gains keepPaneFocusPressProps. A press keeps focus only while focus is in a pane surface: the workbench, the floating terminal panel or Activity's terminal slots, none of which a sidebar or titlebar press can unmount. With focus anywhere else (a sidebar field, a hovercard, a menu) the press takes focus as before, so blur-to-save fields still save. All the sidebar and titlebar chrome changed here uses it, including the right sidebar's panel tabs and More button from fix(right-sidebar): keep terminal focus when clicking a panel tab #46620.

Why

The terminal releases focus on any pointer press outside its pane unless the control carries data-keeps-focus, and Chromium focuses a button on mousedown. The toggles had neither guard. Not taking focus at all fixes this where it starts, so there is nothing to remember and restore afterwards.

Keeping focus on every press would lose a workspace or bot rename typed into the sidebar being closed, because those fields save on blur and React doesn't run onBlur when they unmount. A check for "is focus inside the sidebar being closed" missed fields rendered in portals, such as a rename in a workspace hovercard. Keeping focus only when it's in a pane is safe by construction, because these presses never unmount a pane.

Supersedes #36193 by @MimeLyc, who found the issue and the mouse-press half of the fix. That PR tracked focusin and restored focus after each sidebar transition. Not taking focus in the first place makes that tracking unnecessary.

Linked Issue

Fixes #36184

Visual Proof

Terminal focused, left sidebar toggled closed and open, right sidebar toggled open and closed, all with the mouse, then echo typed-after-sidebar-toggles typed.

Before After
sidebar-toggles-before.png sidebar-toggles-after.png

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

tests/e2e/terminal/input/sidebar-chrome-terminal-focus.spec.ts (renamed from the #46620 spec) drives a hidden Electron build on macOS:

  • left toggle, and right toggle with the top and the side activity bar: the terminal stays focused and typed text reaches the shell. All three fail on main.
  • a workspace rename typed in the left sidebar survives collapsing it with the toggle. This fails if the toggle keeps focus unconditionally.

The Application menu button only renders with the Windows/Linux custom titlebar, so it wasn't run here. pnpm check:changed passed.

Performance

None, because this only changes where focus goes on a toggle press: one getElementById or closest lookup per mousedown on these buttons. Nothing runs per render, keystroke or output chunk.

Risk

Renderer focus handling only. It applies on every platform, in remote workspaces and in paired web clients. The riskiest part is the pane selector. A pane surface it misses just behaves as it did before (the press takes focus). It can't lose input, because focus is only kept where these presses can't unmount anything. A plain revert restores the old behaviour.

Level: Low

AI Disclosure

Review

Codex plus a Claude reviewer, three rounds. Round 1 (both reviewers) found that keeping focus unconditionally lost an in-progress sidebar rename; a regression test now covers it. Round 2 found that a region check still lost a rename in a portaled hovercard, so the rule was inverted to "keep focus only in a pane". Round 3 had no P0/P1. Its one P3 (Activity-view terminal slots) is included, and a misplaced doc comment from round 2 is fixed.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Collapsing the left sidebar with its keyboard shortcut during a rename already loses the rename on main. That's older than this change and is left out of it. The titlebar's back/forward buttons change worktree, and "Collapse pane" already refocuses the pane, so those are deliberately unchanged.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

AmoabaKelvin and others added 5 commits November 22, 2026 04:04
…ouse

The left and right sidebar toggles (titlebar and right sidebar header) and
the Windows/Linux application-menu button took focus on mouse press, so the
terminal released keyboard focus and typing went nowhere. They now use the
shared keepFocusPressProps, the same rule as the right sidebar's panel tabs.

Co-authored-by: MimeLyc <[email protected]>
…oggle hides it

Keeping focus on every press meant a rename typed in the left sidebar
unmounted with the sidebar and was lost, since its save runs on blur. Sidebar
toggles and right sidebar panel tabs now keep focus only when it is outside
the region they close or swap; focus inside it moves to the control as before.
…in a pane

A region check missed sidebar fields rendered in portals, such as a rename in
a workspace hovercard. Sidebar and titlebar chrome now keep focus only when it
is in the pane workbench or the floating terminal panel, which these presses
never unmount; focus anywhere else moves to the control as before, so blur
saves still run.
@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Sidebar and titlebar controls now use pane-aware mouse-down handling. When focus is inside a terminal surface, the handler prevents the mouse press from moving focus. End-to-end tests cover left and right sidebar interactions, terminal input, activity-bar positions, and workspace renaming.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to a8915

Clicking sidebar and titlebar controls now keeps keyboard focus in a terminal pane, and still moves focus to the control when it is pressed from elsewhere. No concrete defect or performance regression was found, and the change is small and easy to revert.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the primary change: terminal focus is kept when a sidebar is toggled with the mouse. The changeset adds keepPaneFocusPressProps and applies it to the left sidebar toggle, the titlebar …
Description check Passed The description follows the repository template. It has ELI5, What Changed, Why, Linked Issue (Fixes #36184), Visual Proof with before/after images, Testing with checked items and an e2e test descript…
Linked Issues check Passed Issue #36184 requires that a mouse open/close of the right sidebar not leave the active terminal pane without keyboard focus, and that focus restoration not override an intentional handoff. At the rev…
Out of Scope Changes check Passed All changed files apply one focus rule to sidebar and titlebar chrome. RightSidebarToggle.tsx, RightSidebar.tsx, TitlebarLeftControls.tsx (Windows/Linux Application menu button and left sidebar toggle…
Full details: Title check

Explanation

The title names the primary change: terminal focus is kept when a sidebar is toggled with the mouse. The changeset adds keepPaneFocusPressProps and applies it to the left sidebar toggle, the titlebar right-sidebar toggle, the right sidebar's close toggle, and the activity bar buttons, and the e2e tests cover these toggles. The 'fix(titlebar)' scope is slightly narrow because the sidebar and activity bar components are also changed, but the title still reflects the main change.

Full details: Description check

Explanation

The description follows the repository template. It has ELI5, What Changed, Why, Linked Issue (Fixes #36184), Visual Proof with before/after images, Testing with checked items and an e2e test description, Performance, Risk with level Low, AI Disclosure, Review, Agent skill boundary, Notes, and Checklist. It explains the mechanism and the alternatives considered. The Risk section names the riskiest part and how to revert. Minor gaps: the Application menu button was not runtime-tested, and the Testing section lists platform coverage only as macOS. The AI Disclosure section is empty, though the template marks it as conditional for internal contributors.

Full details: Linked Issues check

Explanation

Issue #36184 requires that a mouse open/close of the right sidebar not leave the active terminal pane without keyboard focus, and that focus restoration not override an intentional handoff. At the reviewed head, keepPaneFocusPressProps (focus-keeping-press.ts) calls preventDefault() on mousedown only when document.activeElement is inside a pane surface ([data-terminal-workbench-container], [data-floating-terminal-panel], [data-activity-terminal-slot-id]). The right-sidebar toggle in RightSidebarToggle.tsx and the sidebar header close button in RightSidebar.tsx spread these props. A press from a terminal therefore never moves focus to the button, so the button cannot unmount and drop focus to BODY. The change does not restore focus programmatically, so it does not override intentional handoffs. The reported reproduction is covered. Tests are added in tests/e2e/terminal/input/sidebar-chrome-terminal-focus.spec.ts for the left toggle, the right toggle with top and side activity bars, and a rename-survives-collapse case. The PR description reports these fail on main. I did not run the e2e tests. Residual behavior: if focus is in a sidebar field when the sidebar closes, focus moves to the button or page as before. This is intended, because blur-to-save fields must save. The issue's reported scenario does not involve that case.

Full details: Out of Scope Changes check

Explanation

All changed files apply one focus rule to sidebar and titlebar chrome. RightSidebarToggle.tsx, RightSidebar.tsx, TitlebarLeftControls.tsx (Windows/Linux Application menu button and left sidebar toggle), and activity-bar-buttons.tsx (panel tabs and More trigger) spread the same props, and focus-keeping-press.ts adds the shared helper. The left sidebar toggle and the Application menu button use the same titlebar mechanism as the right-sidebar toggle in #36184, so they fall within the issue's bug class. The activity-bar change switches from keepFocusPressProps to keepPaneFocusPressProps. The PR description links this to the rename-loss case, where the old rule would take focus from a sidebar field. The e2e spec supports the focus change. Back/forward history buttons and Collapse pane are unchanged. No unrelated file or feature change appears in the summary. The Application menu button was not runtime-tested, as the PR states; this is a verification gap and not a scope issue.

  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9439d5b6-a31b-43b3-aa11-695f68f68101
Commits

Reviewing files that changed from the base of the PR and between 211f46d and a891544.

Files selected for processing: 6

  • src/renderer/src/app-shell/chrome/RightSidebarToggle.tsx
  • src/renderer/src/app-shell/chrome/TitlebarLeftControls.tsx
  • src/renderer/src/components/right-sidebar/RightSidebar.tsx
  • src/renderer/src/components/right-sidebar/activity-bar/activity-bar-buttons.tsx
  • src/renderer/src/lib/overlay-interaction/focus-keeping-press.ts
  • tests/e2e/terminal/input/sidebar-chrome-terminal-focus.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@AmoabaKelvin
AmoabaKelvin merged commit dc2cebc into main Nov 22, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Toggling the right sidebar with the mouse loses active terminal pane focus

1 participant