Skip to content

fix(shortcuts): keep global shortcuts live inside CodeMirror - #1183

Merged
Harry19081 merged 1 commit into
developfrom
fix/codemirror-global-shortcuts
Sep 1, 2026
Merged

fix(shortcuts): keep global shortcuts live inside CodeMirror#1183
Harry19081 merged 1 commit into
developfrom
fix/codemirror-global-shortcuts

Conversation

@Chloe-JY

@Chloe-JY Chloe-JY commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Problem

⌘W does not close the active tab while the CodeMirror editor has focus. The close handler lives in a capture-phase document keydown listener, so CodeMirror never even sees the event — the bug is upstream inside the handler: the workstation-route ⌘G/⌘E/⌘J block does a bare return when the event target is editable, and isEditableElementExtended explicitly matches .cm-editor/.cm-content. With editor focus the handler aborts before the case "w" branch — and also silently kills ⌘1/⌘2/⌘3 station switch, ⌘N, ⌘T, ⌘,, ⌘P, and zoom.

The editable guard itself is legitimate (⌘G is find-next in CM's searchKeymap); it was just scoped to the whole handler instead of the three chords it protects.

Solution

  • New pure resolver workstationEditorToolShortcut.ts (same extraction pattern as digitZeroShortcut): claims only ⌘G/⌘E/⌘J, returns null for them while an editable surface has focus, and never claims any other key. The handler dispatches on the resolver result and falls through on null, so ⌘W reaches handleCloseCurrentTabcloseActiveWorkStationTabAtom with editor focus. ⌘G/⌘E/⌘J behavior while typing is unchanged.
  • case "/" now yields to CodeMirror (.cm-editor target): the buggy early-return was accidentally protecting CM's ⌘/ toggle-comment (defaultKeymap Mod-/), and without this guard the fix would have hijacked it into the model selector.

Potential risks

  • Previously-dead shortcuts now work with editor focus: ⌘1/⌘2/⌘3, ⌘N, ⌘P, ⇧⌘F search sidebar, ⇧⌘M maximize (the last shadows CM's rarely-used lint-panel binding). This matches how these shortcuts already behave in every other editable surface (e.g. chat input on non-workstation routes). ⌘A, ⌘F, and ⌘K keep their existing per-case editable guards.
  • The full keydown handler is not unit-testable in this node-env vitest suite (hence the pure-resolver extraction); the handler restructuring itself is covered by typecheck + review only. No E2E was run and the change was not exercised in the running Tauri app.
  • Keyboard-only change, nothing visual — no screenshots.

Verification

Verified in a detached worktree at origin/develop (57c8ffd) containing only this PR's three files (node_modules symlinked):

  • npx tsc --noEmit --pretty false -p tsconfig.json — exit 0
  • npx vitest run --config config/vitest.config.ts src/hooks/navigation/useGlobalShortcuts/__tests__/workstationEditorToolShortcut.test.ts — 3 tests pass, including the regression contract ("never claims foreign keys, regardless of focus")
  • npx eslint over all three files — clean

Not run: E2E; manual ⌘W check in the running app. The commit was built with git plumbing from a live shared checkout, so git hooks did not run and the Pre-commit hook ran. trailer is absent — typecheck/lint/tests above were run manually instead.

@Harry19081
Harry19081 merged commit cc88214 into develop Sep 1, 2026
6 checks passed
@Harry19081 Harry19081 added bug Something isn't working workstation Workstation, editor, source control, LSP, or status bar frontend-ui Frontend UI, design system, accessibility, layout, or theming labels Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working frontend-ui Frontend UI, design system, accessibility, layout, or theming workstation Workstation, editor, source control, LSP, or status bar

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants