Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(keybindings): skip speech.dictation in the resolver + close the review's doc and test gaps

enes9d4e54087f63
diff --git a/src/main/keydown-intercept.test.ts b/src/main/keydown-intercept.test.ts
index bc9ce6ee4..18ebed969 100644
--- a/src/main/keydown-intercept.test.ts
+++ b/src/main/keydown-intercept.test.ts
@@ -260,12 +260,24 @@ describe('binding-driven intercept', () => {
// Alt-only chord is a valid binding per the registry's rules, this intercept is its only
// dispatcher (the chord never reaches the renderer — the page does not see a claimed key), so a
// `meta || control` gate above the matchers would make the remap dead everywhere with no error.
- it('an Alt-only remap fires, and the bare key still does not', () => {
- const alt = resolveInterceptBindings({ 'node.toggleMarkdown': ['Alt+M'] }, true)
- expect(keydownIntercept(input({ alt: true, key: 'm', code: 'KeyM' }), alt, true)).toEqual({
+ // Pressed with **isMac: false** on purpose: `Alt+M` is a Windows/Linux chord. macOS composes
+ // Option+letter into a character (⌥M reports `key: 'µ'`), so this exact remap could not fire
+ // there whatever this module did — mac's stake in the gate is Alt+non-letter (F-keys, arrows).
+ it('an Alt-only remap fires off-mac, and the bare key still does not', () => {
+ const alt = resolveInterceptBindings({ 'node.toggleMarkdown': ['Alt+M'] }, false)
+ expect(keydownIntercept(input({ alt: true, key: 'm', code: 'KeyM' }), alt, false)).toEqual({
action: 'toggle-markdown'
})
- expect(keydownIntercept(input({ key: 'm', code: 'KeyM' }), alt, true)).toBeNull()
+ expect(keydownIntercept(input({ key: 'm', code: 'KeyM' }), alt, false)).toBeNull()
+ })
+
+ // The mac half of the same gate, on a key macOS does NOT compose: ⌥F5 stays `key: 'F5'`.
+ it('a mac Alt+non-letter remap fires (what Option composition leaves reachable there)', () => {
+ const alt = resolveInterceptBindings({ 'node.toggleMarkdown': ['Alt+F5'] }, true)
+ expect(keydownIntercept(input({ alt: true, key: 'F5', code: 'F5' }), alt, true)).toEqual({
+ action: 'toggle-markdown'
+ })
+ expect(keydownIntercept(input({ key: 'F5', code: 'F5' }), alt, true)).toBeNull()
})
it('garbage overrides fall back to defaults', () => {
diff --git a/src/main/keydown-intercept.ts b/src/main/keydown-intercept.ts
index 56b657d33..787b584c8 100644
--- a/src/main/keydown-intercept.ts
+++ b/src/main/keydown-intercept.ts
@@ -108,9 +108,13 @@ function toShortcutEvent(input: KeydownInterceptInput): {
* **Every branch owns its own modifier requirement, and must.** The old shared guard was
* `type !== 'keyDown' || !(input.meta || input.control)`, which is exactly the check standing
* between these branches and ordinary typing — `m`, `w` and `0` are all characters a user types.
- * It could not survive user-remappable bindings: `Alt+M` is a VALID binding per the registry's
+ * It could not survive user-remappable bindings: an Alt-only chord is VALID per the registry's
* rules, and this module is its ONLY dispatcher (a chord we claim never reaches the renderer),
* so a primary-modifier gate above the matchers would make such a remap silently dead everywhere.
+ * Who that actually buys something for: **Windows/Linux Alt chords** (`Alt+M`, `Alt+W` — plain
+ * letter combos there), and on **macOS the Alt+non-letter ones** (`Alt+F5`, `Alt+ArrowUp`). It is
+ * NOT mac Option+letter: macOS composes those into a character, so ⌥M arrives as `key: 'µ'` and an
+ * `Alt+M` binding could never match there whatever this gate did.
* So the two remappable chords are matched EXACTLY (all four modifier flags, `matchesShortcut`),
* which is a modifier requirement per binding, and the hardcoded `Digit0` branch below carries
* the `meta || control` test it used to inherit. `keydown-intercept.test.ts` presses each of them
diff --git a/src/renderer/canvas/canvas-wiring.test.tsx b/src/renderer/canvas/canvas-wiring.test.tsx
index 64ac3d07c..f04404e49 100644
--- a/src/renderer/canvas/canvas-wiring.test.tsx
+++ b/src/renderer/canvas/canvas-wiring.test.tsx
@@ -96,6 +96,20 @@ describe('the zoom chords go through their guarded decision, on both routes', ()
})
})
+describe('the trailing gestures are handed to the dispatcher', () => {
+ // The checks above read the gesture BODIES, which is one hop short: `zoomGesture` can be
+ // perfectly wired internally and simply never reach `dispatchGlobalKeydown`. Deleting
+ // `zoom: zoomGesture,` from the gestures object keeps every assertion in this file — and in
+ // globalKeybindings.test.ts, which supplies its own fakes — green while Shift+1 and the
+ // keydown ⌘0 route quietly stop moving the camera. Same shape for the other two: the project
+ // jump and the file-reference copy have no other call site either.
+ it('wires zoom, projectJump and copy into the dispatcher deps', () => {
+ expect(CANVAS_SRC).toContain('zoom: zoomGesture')
+ expect(CANVAS_SRC).toContain('projectJump: projectJumpGesture')
+ expect(CANVAS_SRC).toContain('copy: copyGesture')
+ })
+})
+
describe('the end-session confirm describes both things it does', () => {
// `closeSession` stops the tmux session AND deletes the canvas node. The wording is inherited
// from the sessions sidebar, where deleting the node is the obvious intent — but the
diff --git a/src/renderer/lib/globalKeybindings.test.ts b/src/renderer/lib/globalKeybindings.test.ts
index 957ca446f..bcf79b64e 100644
--- a/src/renderer/lib/globalKeybindings.test.ts
+++ b/src/renderer/lib/globalKeybindings.test.ts
@@ -103,6 +103,28 @@ describe('dispatchGlobalKeydown', () => {
expect(dispatchGlobalKeydown(ev({ key: '!' , shiftKey: true }), deps({ gestures: g }))).toBe(false)
expect(order).toEqual(['zoom', 'jump', 'copy'])
})
+ it('the kanban board blocks the keyed-dictation gesture entirely', () => {
+ // The gate is `!typing && !terminal && !kanbanOpen`. Dropping the kanban half leaves a
+ // dictation overlay firing over the board with nothing on screen that asked for it — and
+ // the board is exactly where the canvas-only-shortcut discipline says gestures go quiet.
+ const dictation = vi.fn(() => true)
+ const g = { keyedDictation: dictation, zoom: noGesture, projectJump: noGesture, copy: noGesture }
+ const d = deps({ kanbanOpen: () => true, gestures: g })
+ expect(dispatchGlobalKeydown(ev({ metaKey: true, altKey: true, key: 'd' }), d)).toBe(false)
+ expect(dictation).not.toHaveBeenCalled()
+ })
+ it('a claiming trailing gesture short-circuits: the later ones never run', () => {
+ // The `if (...) return true` chain, not a run-them-all fan-out. Turning any of the three
+ // into an unconditional call would let one chord be interpreted twice (zoom AND jump).
+ const zoom = vi.fn(() => true)
+ const projectJump = vi.fn(() => true)
+ const copy = vi.fn(() => true)
+ const g = { keyedDictation: noGesture, zoom, projectJump, copy }
+ expect(dispatchGlobalKeydown(ev({ shiftKey: true, key: '!' }), deps({ gestures: g }))).toBe(true)
+ expect(zoom).toHaveBeenCalledTimes(1)
+ expect(projectJump).not.toHaveBeenCalled()
+ expect(copy).not.toHaveBeenCalled()
+ })
it('overrides reroute dispatch', () => {
const fit = vi.fn(() => true)
const d = deps({
diff --git a/src/renderer/lib/keyContext.ts b/src/renderer/lib/keyContext.ts
index 1bcc52eb5..1cce5771e 100644
--- a/src/renderer/lib/keyContext.ts
+++ b/src/renderer/lib/keyContext.ts
@@ -2,6 +2,16 @@
* One shared answer to "who owns this keystroke's focus" for the global-keybinding
* dispatcher. Replaces the three inline `tagName` guards the Canvas keydown effects carried
* (which disagreed about contentEditable and counted xterm's hidden textarea as typing).
+ *
+ * **This is not the codebase's only "in terminal" notion, and the difference is the point.**
+ * `presenceKeys.ts` (`closest(TYPING_ZONES)`, `.xterm` among them) and the copy gesture
+ * (inline `closest('.monaco-editor, .xterm')`) both ask an ANCESTRY question, because they are
+ * about a "/" keystroke or a mouse selection landing somewhere inside a terminal REGION, which
+ * the `.xterm` wrapper answers and this module's class check would not.
+ * DISPATCH asks a different question: who receives this keystroke. Whenever xterm owns the
+ * keyboard the focused element IS the helper textarea, so the class check here is exact — and it
+ * is what keeps `terminal` and `typing` disjoint (an ancestry check would report BOTH, and
+ * `typing` wins, making every terminal-scope command unreachable).
*/
import type { KeyDispatchContext } from '@shared/keybindings'
diff --git a/src/shared/keybindings.test.ts b/src/shared/keybindings.test.ts
index ccb9afdf9..43ef01773 100644
--- a/src/shared/keybindings.test.ts
+++ b/src/shared/keybindings.test.ts
@@ -367,6 +367,15 @@ describe('resolveCommandForKeyEvent', () => {
expect(resolveCommandForKeyEvent(ev({ metaKey: true, key: 'Enter' }), ctx(), {}, true))
.toBeNull()
})
+ it('never resolves speech.dictation — even a hand-edited KEYED override', () => {
+ // The registry row is display-only; dictation dispatches from its own listeners reading
+ // settings.speech.shortcut, so nothing here would ever handle it. Without the resolver skip
+ // this override RESOLVES, finds no handler, and the chord is spent — the trailing gestures
+ // (zoom / projectJump / copy) never see it, so a `Cmd+0` override kills zoom-to-100%.
+ // Passed straight in, bypassing sanitize: this is exactly the hand-edited settings.json case.
+ const o = { 'speech.dictation': ['Cmd+0'] }
+ expect(resolveCommandForKeyEvent(ev({ metaKey: true, key: '0' }), ctx(), o, true)).toBeNull()
+ })
it('terminal focus admits terminal scope over a canvas command sharing the chord', () => {
// Cmd+F sits on terminal.find; a canvas-scope override claims the same chord. The
// terminal-focus gate drops canvas.fitAll before its bindings are ever read — this
diff --git a/src/shared/keybindings.ts b/src/shared/keybindings.ts
index 4606501de..516de04e7 100644
--- a/src/shared/keybindings.ts
+++ b/src/shared/keybindings.ts
@@ -353,6 +353,13 @@ export function resolveCommandForKeyEvent(
// scm commands dispatch from their own focused composer (local onKeyDown), never from
// the window listener — resolving them here would fire Commit with no composer focused.
if (def.scope === 'scm') continue
+ // speech.dictation dispatches from its own dedicated listeners (the keyed gesture and the
+ // hold-mode effect, both reading settings.speech.shortcut), never from the registry — its
+ // row here is display-only, for ShortcutsPanel and the Settings section. A hand-edited KEYED
+ // override would otherwise RESOLVE, find no handler, and spend the chord: the dispatcher's
+ // claim protocol stops a resolved command from reaching the trailing gestures, so
+ // `{"speech.dictation": ["Cmd+0"]}` would silently kill zoom-to-100%.
+ if (def.id === 'speech.dictation') continue
if (ctx.typing && !def.allowWhileTyping) continue
if (ctx.terminal && !(def.scope === 'terminal' || def.allowInTerminal)) continue
if (!ctx.terminal && def.scope === 'terminal') continue
diff --git a/src/shared/shortcut.ts b/src/shared/shortcut.ts
index 89166f093..5cf82bcc6 100644
--- a/src/shared/shortcut.ts
+++ b/src/shared/shortcut.ts
@@ -71,15 +71,17 @@ export function isModifierEventKey(key: string): boolean {
return MODIFIER_KEYS.has(normalizeKey(key))
}
-/** Parse a canonical combo string, e.g. `"Cmd+Shift+D"` -> `{cmd:true, ctrl:false, shift:true,
- * alt:false, key:'D'}`; a modifier-only chord, e.g. `"Cmd+Alt"` -> `{cmd:true, ctrl:false,
- * shift:false, alt:true, key:null}` (see `isHoldChord`). `Ctrl`/`Control` set the LITERAL `ctrl`
- * field — they are no longer a spelling of the abstract `Cmd`. */
// Memo: dispatch re-parses every candidate binding on every keydown once the registry sits on
// a window listener; distinct binding strings are few, so a small frozen-value cache removes
-// the hot-path cost for every consumer at once.
+// the hot-path cost for every consumer at once. The returned object's IDENTITY is stable only
+// until the size-cap clear below — never key a Map/WeakMap or a React dep array off a
+// `ParsedShortcut`; compare its fields, or the string it came from.
const parseCache = new Map<string, ParsedShortcut>()
+/** Parse a canonical combo string, e.g. `"Cmd+Shift+D"` -> `{cmd:true, ctrl:false, shift:true,
+ * alt:false, key:'D'}`; a modifier-only chord, e.g. `"Cmd+Alt"` -> `{cmd:true, ctrl:false,
+ * shift:false, alt:true, key:null}` (see `isHoldChord`). `Ctrl`/`Control` set the LITERAL `ctrl`
+ * field — they are no longer a spelling of the abstract `Cmd`. */
export function parseShortcut(s: string): ParsedShortcut {
const hit = parseCache.get(s)
if (hit) return hit