Repository navigation
fix(titlebar): keep terminal focus when toggling a sidebar with the mouse - #46735
Conversation
…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.
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
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.
What Changed
focus-keeping-press.tsgainskeepPaneFocusPressProps. 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
onBlurwhen 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
focusinand 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-togglestyped.Testing
tests/e2e/terminal/input/sidebar-chrome-terminal-focus.spec.ts(renamed from the #46620 spec) drives a hidden Electron build on macOS:The Application menu button only renders with the Windows/Linux custom titlebar, so it wasn't run here.
pnpm check:changedpassed.Performance
None, because this only changes where focus goes on a toggle press: one
getElementByIdorclosestlookup 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
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)