fix(shortcuts): keep global shortcuts live inside CodeMirror - #1183
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
⌘W does not close the active tab while the CodeMirror editor has focus. The close handler lives in a capture-phase
documentkeydown listener, so CodeMirror never even sees the event — the bug is upstream inside the handler: the workstation-route ⌘G/⌘E/⌘J block does a barereturnwhen the event target is editable, andisEditableElementExtendedexplicitly matches.cm-editor/.cm-content. With editor focus the handler aborts before thecase "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
workstationEditorToolShortcut.ts(same extraction pattern asdigitZeroShortcut): claims only ⌘G/⌘E/⌘J, returnsnullfor them while an editable surface has focus, and never claims any other key. The handler dispatches on the resolver result and falls through onnull, so ⌘W reacheshandleCloseCurrentTab→closeActiveWorkStationTabAtomwith editor focus. ⌘G/⌘E/⌘J behavior while typing is unchanged.case "/"now yields to CodeMirror (.cm-editortarget): the buggy early-return was accidentally protecting CM's ⌘/ toggle-comment (defaultKeymapMod-/), and without this guard the fix would have hijacked it into the model selector.Potential risks
Verification
Verified in a detached worktree at
origin/develop(57c8ffd) containing only this PR's three files (node_modulessymlinked):npx tsc --noEmit --pretty false -p tsconfig.json— exit 0npx 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 eslintover all three files — cleanNot 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.