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(settings): release the recorder on unmount + pin the disarm divergence

enes821de394aed3
diff --git a/src/renderer/components/settings/ShortcutRecorderButton.tsx b/src/renderer/components/settings/ShortcutRecorderButton.tsx
index ac8a644b4..36c7bbcc3 100644
--- a/src/renderer/components/settings/ShortcutRecorderButton.tsx
+++ b/src/renderer/components/settings/ShortcutRecorderButton.tsx
@@ -6,10 +6,17 @@
* (so ⌘W/⌘M/⌘0 interception cannot swallow the capture) is Task 5's: `window.nodeTerminal
* .shortcuts` does not exist on `NodeTerminalApi` yet, and that type lives in
* `src/shared/types.ts` — a file this task does not own. An optional-chained call does NOT
- * typecheck against a member the interface never declares, so the two calls are marked below
- * rather than shipped broken.
+ * typecheck against a member the interface never declares, so the three call sites are marked
+ * below rather than shipped broken.
+ *
+ * **That bit is GLOBAL, so it owes an unmount release.** Chromium does not reliably fire `blur`
+ * on a focused element that is REMOVED from the DOM, so closing Settings while the recorder is
+ * armed can skip `onBlur` entirely — leaving the main-process bit set with no component left to
+ * clear it, suppressing ⌘W/⌘M/⌘0 app-wide until the next arm/disarm cycle. `release` (below) is
+ * the teardown both `stop()` and the unmount cleanup run; it touches refs only, so it is stable
+ * and safe to run when the recorder was never armed.
*/
-import { useRef, useState } from 'react'
+import { useCallback, useEffect, useRef, useState } from 'react'
import { COMMANDS_BY_ID, normalizeBindingForCommand, type CommandId } from '@shared/keybindings'
import { isMacPlatform } from '@shared/platform-utils'
import { recordingKeydown, recordingKeyup, type RecordingState } from './shortcutRecording'
@@ -31,11 +38,19 @@ export function ShortcutRecorderButton({
const def = COMMANDS_BY_ID.get(commandId)!
const opts = { isMac, allowHold: def.allowHoldChord === true }
+ // Refs only ⇒ stable with no deps, so the mount-time cleanup below cannot capture stale state,
+ // and idempotent ⇒ running it on an unmount that was never armed is a no-op.
+ const release = useCallback((): void => {
+ stateRef.current = { mods: null }
+ // Task 5 wires the main-process recording bit here: setRecording(false)
+ }, [])
+ // Task 5: setRecording(false) must also be called from this unmount cleanup — see the header.
+ useEffect(() => release, [release])
+
const stop = (): void => {
setCapturing(false)
setHint('')
- stateRef.current = { mods: null }
- // Task 5 wires the main-process recording bit here: setRecording(false)
+ release()
}
const start = (): void => {
stateRef.current = { mods: null }
diff --git a/src/renderer/components/settings/shortcutRecording.test.ts b/src/renderer/components/settings/shortcutRecording.test.ts
index 86c1acbd6..c1a57a4b6 100644
--- a/src/renderer/components/settings/shortcutRecording.test.ts
+++ b/src/renderer/components/settings/shortcutRecording.test.ts
@@ -50,6 +50,16 @@ describe('recordingKeydown', () => {
expect(r.hint).toContain('Super')
}
})
+ // Deliberate divergence from the legacy SpeechSection field, which left modsRef untouched here:
+ // arm Cmd+Alt, release ⌘ while keeping ⌥, add ⇧ — the baseline still committed Cmd+Alt on the
+ // eventual full release, a chord the finished gesture (⌥⇧) could never fire under exact
+ // matching. Losing the primary modifier must DISARM.
+ it('a modifier-only keydown without the primary disarms an armed hold chord', () => {
+ const armed = { mods: { cmd: true, ctrl: false, alt: true, shift: false } }
+ const r = recordingKeydown(armed, e({ altKey: true, shiftKey: true, key: 'Shift' }), HOLD)
+ expect(r.kind).toBe('pending')
+ if (r.kind === 'pending') expect(r.state.mods).toBeNull()
+ })
it('modifier-only keydown without allowHold just previews the requirement', () => {
const r = recordingKeydown({ mods: null }, e({ metaKey: true, key: 'Meta' }), KEYED)
expect(r.kind).toBe('pending')
diff --git a/src/renderer/components/settings/shortcutRecording.ts b/src/renderer/components/settings/shortcutRecording.ts
index bc5c0aa67..8a3c498fe 100644
--- a/src/renderer/components/settings/shortcutRecording.ts
+++ b/src/renderer/components/settings/shortcutRecording.ts
@@ -25,6 +25,18 @@
* has no spelling in this grammar (same rule `captureToShortcut` already applies to keyed
* captures, here extended to the hold path).
*
+ * **Deliberate divergence from the legacy field — losing the primary modifier DISARMS.** When a
+ * modifier-only keydown arrives with the primary modifier NOT pressed, the legacy field showed the
+ * `Hold ⌘…` hint and returned, leaving `modsRef` holding whatever it had armed earlier. That let a
+ * gesture commit a chord the user was no longer making: arm `Cmd+Alt`, release ⌘ while keeping ⌥,
+ * add ⇧ — the ⇧ keydown left `{cmd:true, alt:true}` armed, and the eventual full release committed
+ * `Cmd+Alt` even though the user finished on ⌥⇧. Under exact matching that stored chord then never
+ * fires from the gesture that recorded it. Here the same event clears `mods`, so a hold chord is
+ * only ever committed from a state where the primary was observed down alongside it; the user
+ * simply presses the chord again. (`recordingKeydown` still preserves an armed chord across a
+ * REFUSED KEYED press — see the `captureToShortcut` fall-through below — because that path cannot
+ * lose the primary without a modifier keyup/keydown passing through here first.)
+ *
* Pure: no DOM, no React, no clock. The component owns `RecordingState` in a ref and the caller
* validates the committed combo through `normalizeBindingForCommand` — this module decides only
* what the gesture MEANT, never whether the command accepts it.