Repository navigation
fix(cmd-j): focus the destination workspace's own terminal after a jump - #10695
Conversation
Selecting a workspace in Cmd+J called the palette's fallback with no preferred target, so it took the first .xterm-helper-textarea in the whole document. Orca keeps every visited worktree mounted and hides inactive ones with display:none, so that first match is routinely the worktree the user just left. Focusing a display:none element is a silent no-op in Chromium, leaving the keyboard on document.body. Resolve the destination's own terminal tab from the store after activation and focus it scoped by data-terminal-tab-id. The helper reports whether it claimed focus so a non-terminal destination keeps the previous behavior. Also covers the two Cmd+J issue-match jump paths, which had no focus call at all, and restores the exact prior element for project/repo reveal, which does not change worktrees. Renames new-workspace-terminal-focus to workspace-activation-terminal-focus since the palette activates existing workspaces, not just new ones. Co-authored-by: Orca <[email protected]>
Two independent reviewers found the same hole: reverting the palette wiring back to an unconditional focusFallbackSurface() — the exact original bug — passed the entire components suite (10,140 tests). happy-dom does not reproduce Chromium's display:none focus no-op, so the regression is invisible to behavioral tests. These use the repo's existing source-boundary pattern instead, which pins which API the handler selects rather than who ended up focused. Kills three mutations that previously survived: - full revert of the worktree-select routing - ignoring the helper's return and always falling back - project-target restoration reverting to the unscoped query
📝 WalkthroughWalkthroughTerminal focus queueing now targets the activated workspace and returns whether focus was scheduled. Worktree jump palette paths use scoped focus with guarded fallback restoration, including existing issue and pull-request matches. Project selection restores the previously focused element. Composer submission and worktree creation flows now use the renamed activation-focus helper, with corresponding tests updated and expanded. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ff69f00b-ba56-47d2-aae6-1dbb4faef7db
📒 Files selected for processing (7)
src/renderer/src/components/WorktreeJumpPalette.tsxsrc/renderer/src/components/cmd-j/palette-activation-focus-routing.test.tssrc/renderer/src/hooks/useComposerState.tssrc/renderer/src/lib/workspace-activation-terminal-focus.test.tssrc/renderer/src/lib/workspace-activation-terminal-focus.tssrc/renderer/src/lib/worktree-creation-flow.test.tssrc/renderer/src/lib/worktree-creation-flow.ts
…mp (stablyai#10695) Co-authored-by: Orca <[email protected]>
Fixes #9939
What's broken
Switch workspace with
Cmd+Jand the keyboard goes nowhere. You have to click the terminal before you can type. @yanghoonkim: "really need it!!!!!!"ELI5
Orca keeps every workspace you've visited alive in the background and just hides the ones you're not looking at. When you jumped to a new workspace, the code said "focus the first terminal you can find on the page" — and the first one it found was usually the workspace you just left, which is now hidden.
Focusing a hidden element in Chromium doesn't throw an error. It doesn't do anything at all. So the keyboard was left attached to nothing, silently.
The fix: ask the store which tab the destination workspace actually restored, and focus that specific tab, instead of grabbing whatever terminal happens to come first in the document.
Root cause
Terminal.tsx:2136-2145gives inactive worktrees thehiddenclass while keeping them mounted.handleSelectWorktreecalledfocusFallbackSurface(), which resolves throughpalette-focus-restore-target.ts:13— a baredocument.querySelector('.xterm-helper-textarea')with no worktree or tab-type scoping at all..focus()on adisplay:noneelement is a silent no-op in Chromium: no error, no focus,activeElementstaysdocument.body.The sibling handlers in the same file already did this correctly —
handleSelectBrowserPagedispatches a scopedrequestBrowserFocus({ pageId }). Only the plain worktree-row path fell through to the unscoped query.Fix proof
Measured in real Chromium (Playwright, Chromium 147) — not happy-dom, which does not replicate the
display:noneno-op and would have shown a false pass:{ "before": { "picked": "background", "activeElementIsBody": true, "focusReachedATerminal": false }, "after": { "picked": "destination", "activeElementIsBody": false, "focusReachedATerminal": true } }Proof of no regressions
src/renderer/src/lib/andsrc/renderer/src/components/cmd-j/pnpm typecheckclean,oxlintcleanworktrees.ts:4509-4745and confirmedsetActiveWorktreecommits via a synchronous Zustandset(), so reading the store immediately after activation is not observing stale state. Both reviewers confirmed this separately.new-workspace-terminal-focus→workspace-activation-terminal-focus) adds only areturnstatement; both existing callers ignore it.Mutation testing
Two independent reviewers (GPT-5.6-sol + Fable) found the helper well-pinned but the call-site wiring completely unpinned — reverting to the original bug passed all 10,140 component tests. happy-dom can't see this class of bug, so the added tests use the repo's existing source-boundary pattern (
feature-interaction-writer-boundaries.test.ts), pinning which API the handler selects rather than who ended up focused.focusFallbackSurface()return false→return trueactiveTabType !== 'terminal'guardactiveWorktreeIdrace guardReview loop: 2 rounds to clean (round 1 GPT + Fable → both NON-BLOCKING with a shared coverage finding; round 2 closed it).
Trade-offs / known limits
Stated plainly rather than claimed away:
Cmd+1..9and nav back/forward have the same bug (useIpcEvents.ts:1416,worktree-activation.ts:729). Out of scope here; worth a follow-up.Cross-platform
No platform-specific code paths. DOM selectors and Zustand state only — no
metaKeyhandling, no filesystem assumptions. SSH and native remote tabs follow the same renderer mount path; web-runtime workspaces with no mirrored tab decline focus rather than claiming it.Perf
No new subscriptions, no polling, no added renders. One
requestAnimationFramereplacing a path that already used two. Strictly one frame earlier.0 regressions / risk.
🤖 Generated with Claude Code
Made with Orca 🐋