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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(speech): hold-to-talk — modifier-only chord records while held (v3)
enes24bfc7059983
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex c8dc3891d..7a29143df 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -192,7 +192,7 @@ import {} from '@shared/canvas-publish'import { createCanvasOrder, createReconnectWatch, type CanvasOrder } from '@shared/canvas-order'import { createMutationGuard } from '@shared/canvas-mutations'-import { matchesShortcut } from '@shared/shortcut'+import { chordHeld, isHoldChord, isModifierEventKey, matchesShortcut } from '@shared/shortcut'import { canvasSyncTarget } from './collab-sync'import {@@ -2524,8 +2524,11 @@ export function Canvas() {requireProOr('Remote SSH terminals', () => setRemotePicker(screenPos))}, [])- // ⌘T = new terminal, ⌘⇧C = new default agent, configured dictation shortcut (default ⌘⌥D) =- // toggle dictation (ignored while typing in a field/terminal).+ // ⌘T = new terminal, ⌘⇧C = new default agent, a KEYED dictation shortcut (e.g. "Cmd+Alt+D") =+ // toggle dictation (ignored while typing in a field/terminal). A modifier-only shortcut (the+ // new default, "Cmd+Alt") is hold-to-talk instead — matchesShortcut always returns false for+ // that shape (its `key` is null), so this effect is naturally a no-op for it; see the+ // dedicated hold-mode effect below, which is what fires in that case.useEffect(() => {const onKey = (e: KeyboardEvent) => {if (isKanbanOpen(useProjects.getState().activeProjectId)) return@@ -2550,6 +2553,109 @@ export function Canvas() {return () => window.removeEventListener('keydown', onKey)}, [addTerminal, addAgentNode, toggleDictation])+ // v3 hold-to-talk: active only while the configured dictation shortcut is a modifier-only+ // chord (isHoldChord — the new default, "Cmd+Alt"). Walkie-talkie semantics: the chord held+ // down starts recording immediately (armed on the keydown that completes the exact modifier+ // match — see chordHeld); releasing either chord modifier stops (transcribe → insert) UNLESS+ // the hold was under 400ms, which cancels quietly (an accidental tap, not an intentional+ // hold). Unlike the toggle-mode effect above, this deliberately has NO typing guard — the+ // chord types nothing, so it must fire even while a terminal/input has focus. State lives in+ // plain closures (not React state) so a keystroke never triggers a re-render.+ //+ // Misfire guards: a third, non-modifier key pressed while armed cancels immediately (the user+ // was invoking a real shortcut, e.g. the ⌘⌥D Dock-collision class) — and is never+ // preventDefault()'d, so that shortcut still fires normally. An extra modifier joining the+ // held chord (chordHeld flips false) cancels the same way. Auto-repeat keydowns for an+ // already-armed chord are inert by construction: once armed, a repeat keydown of the same+ // modifier still satisfies chordHeld, so the "misfire" branch's condition is false and it's a+ // no-op. Window blur (app switch) cancels outright.+ useEffect(() => {+ if (!isHoldChord(settings.speech.shortcut)) return++ let armed = false+ let heldSince = 0++ const cancel = (): void => {+ if (!armed) return+ armed = false+ setDictationOpen(false)+ }++ const stop = (): void => {+ if (!armed) return+ armed = false+ setDictationStopSignal((n) => n + 1)+ }++ const onKeyDown = (e: KeyboardEvent): void => {+ if (isKanbanOpen(useProjects.getState().activeProjectId)) return+ const combo = useSettings.getState().settings.speech.shortcut+ if (!isHoldChord(combo)) return++ if (!armed) {+ // Arm only on the keydown that completes the exact chord — not on every keydown while+ // some-but-not-all of it is down (e.g. Cmd alone, before Alt joins).+ if (e.repeat) return+ if (!isModifierEventKey(e.key)) return+ if (!chordHeld(e, combo, isMac)) return+ armed = true+ heldSince = Date.now()+ const sel = nodesRef.current.find(+ (n) => n.selected && (n.type === 'terminal' || n.type === 'chat')+ )+ setDictationTarget(+ sel+ ? {+ kind: sel.type === 'chat' ? 'chat' : 'terminal',+ nodeId: sel.id,+ title: (sel.data.title as string) || 'Untitled'+ }+ : null+ )+ setDictationNonce((n) => n + 1)+ setDictationOpen(true)+ return+ }++ // Already armed: a non-modifier key, or an extra modifier joining the chord, is the+ // misfire guard — cancel without preventDefault so the real shortcut still fires.+ if (!isModifierEventKey(e.key) || !chordHeld(e, combo, isMac)) {+ cancel()+ }+ }++ const onKeyUp = (e: KeyboardEvent): void => {+ if (!armed) return+ const combo = useSettings.getState().settings.speech.shortcut+ // Still fully down (an unrelated key was released) — keep recording.+ if (chordHeld(e, combo, isMac)) return+ const heldMs = Date.now() - heldSince+ if (heldMs < 400) {+ cancel()+ } else {+ stop()+ }+ }++ const onBlur = (): void => {+ cancel()+ }++ window.addEventListener('keydown', onKeyDown)+ window.addEventListener('keyup', onKeyUp)+ window.addEventListener('blur', onBlur)+ return () => {+ window.removeEventListener('keydown', onKeyDown)+ window.removeEventListener('keyup', onKeyUp)+ window.removeEventListener('blur', onBlur)+ // A settings change / project switch mid-hold must not leave a dangling recording.+ if (armed) {+ armed = false+ setDictationOpen(false)+ }+ }+ }, [settings.speech.shortcut])+// "Connect to a host" from the Settings section / tab-menu dialog: they collect the pairing offer// and dispatch it here (a window event, so they need no Canvas reference), and this runs the SAME// relay connect → SAS compare → mount-as-tab flow the dock/palette entry uses (`connectOffer`).diff --git a/src/renderer/components/Dock.tsx b/src/renderer/components/Dock.tsxindex 260e095dc..94b317739 100644--- a/src/renderer/components/Dock.tsx+++ b/src/renderer/components/Dock.tsx@@ -1,6 +1,6 @@import { useState } from 'react'import { AGENT_CONFIG, BUILTIN_AGENT_IDS, type AgentId } from '@shared/agents/config'-import { formatShortcut } from '@shared/shortcut'+import { formatShortcut, isHoldChord } from '@shared/shortcut'import { hintLabel } from '@shared/platform-utils'import { AgentIcon } from '../lib/agentIcons'import { useSettings } from '../state/settings'@@ -188,7 +188,11 @@ export function Dock({</button><buttonclassName={`dock-btn${dictateActive ? ' active' : ''}`}- title={`Dictate (${formatShortcut(dictationShortcut, isMac)})`}+ title={+ isHoldChord(dictationShortcut)+ ? `Dictate (hold ${formatShortcut(dictationShortcut, isMac)})`+ : `Dictate (${formatShortcut(dictationShortcut, isMac)})`+ }onClick={onDictate}><MicIcon />diff --git a/src/renderer/components/ShortcutsPanel.tsx b/src/renderer/components/ShortcutsPanel.tsxindex 7b000ddf8..994795867 100644--- a/src/renderer/components/ShortcutsPanel.tsx+++ b/src/renderer/components/ShortcutsPanel.tsx@@ -1,6 +1,6 @@import { useEffect } from 'react'import { createPortal } from 'react-dom'-import { shortcutKeyParts } from '@shared/shortcut'+import { isHoldChord, shortcutKeyParts } from '@shared/shortcut'import { useSettings } from '../state/settings'const isMac = /Mac/i.test(navigator.platform || navigator.userAgent)@@ -15,9 +15,10 @@ interface Row {label: string}-/** Everything but "Dictate" is fixed; that row's keys depend on `settings.speech.shortcut`, so- * the sections are built at render time instead of module scope. */-function buildSections(dictationKeys: string[]): { title: string; rows: Row[] }[] {+/** Everything but "Dictate" is fixed; that row's keys/label depend on `settings.speech.shortcut`+ * (a modifier-only chord is hold-to-talk — no trailing key badge, so the label spells that out),+ * so the sections are built at render time instead of module scope. */+function buildSections(dictationKeys: string[], dictationLabel: string): { title: string; rows: Row[] }[] {return [{title: 'General',@@ -25,7 +26,7 @@ function buildSections(dictationKeys: string[]): { title: string; rows: Row[] }[{ keys: ['⌘', 'K'], label: 'Command palette' },{ keys: ['⌘', ','], label: 'Settings' },{ keys: ['⌘', '/'], label: 'This shortcuts panel' },- { keys: dictationKeys, label: 'Dictate' },+ { keys: dictationKeys, label: dictationLabel },{ keys: ['⌘', 'Z'], label: 'Undo' },{ keys: ['⌘', '⇧', 'Z'], label: 'Redo' }]@@ -66,7 +67,10 @@ function buildSections(dictationKeys: string[]): { title: string; rows: Row[] }[/** Keyboard shortcuts reference; shown on first launch and via ⌘/ or the ? button. */export function ShortcutsPanel({ onClose }: ShortcutsPanelProps) {const speechShortcut = useSettings((s) => s.settings.speech.shortcut)- const SECTIONS = buildSections(shortcutKeyParts(speechShortcut, isMac))+ const SECTIONS = buildSections(+ shortcutKeyParts(speechShortcut, isMac),+ isHoldChord(speechShortcut) ? 'Dictate (hold)' : 'Dictate'+ )useEffect(() => {const onKey = (e: KeyboardEvent) => {diff --git a/src/renderer/components/settings/sections/SpeechSection.tsx b/src/renderer/components/settings/sections/SpeechSection.tsxindex fbd1d05a2..a79d44d50 100644--- a/src/renderer/components/settings/sections/SpeechSection.tsx+++ b/src/renderer/components/settings/sections/SpeechSection.tsx@@ -1,7 +1,15 @@-import { useCallback, useEffect, useState } from 'react'+import { useCallback, useEffect, useRef, useState } from 'react'import type { SpeechModelInfo } from '@shared/types'import { DEFAULT_SETTINGS } from '@shared/types'-import { captureToShortcut, formatShortcut, type ShortcutKeyEvent } from '@shared/shortcut'+import {+ buildModifierChord,+ captureToShortcut,+ formatShortcut,+ isHoldChord,+ isModifierEventKey,+ type ChordModifiers,+ type ShortcutKeyEvent+} from '@shared/shortcut'import { useSettings } from '../../../state/settings'import { useEntitlement } from '../../../state/entitlement'import { SettingsSection } from '../SettingsSection'@@ -45,9 +53,18 @@ const ROWS = {}const ENTRIES = Object.values(ROWS)-/** Focus -> "Press keys…" -> keydown capture (must include Cmd/Ctrl + a non-modifier key) ->- * saves the canonical combo. Esc cancels; blur cancels; a separate Reset button restores the- * default. Pure combo logic lives in `@shared/shortcut` (parse/match/format/capture). */+/**+ * Focus -> "Press keys…" -> capture -> saves the canonical combo. Two shapes commit+ * differently (v3):+ * - A real key (Cmd/Ctrl + a non-modifier key) commits IMMEDIATELY on keydown, same as before+ * — toggle mode.+ * - Modifier keys only (Cmd/Ctrl [+ Alt] [+ Shift], no other key yet) commit on KEYUP, once+ * every key has been released — hold-to-talk mode. Each modifier keydown along the way+ * remembers the strongest state seen (`modsRef`) and previews it, since the keyup event+ * itself no longer carries that state once everything's up (see `buildModifierChord`'s doc).+ * Esc cancels; blur cancels; a separate Reset button restores the default (`Cmd+Alt`, itself a+ * hold-to-talk chord). Pure combo logic lives in `@shared/shortcut`.+ */function ShortcutCaptureField({value,onChange@@ -57,10 +74,18 @@ function ShortcutCaptureField({}): React.JSX.Element {const [capturing, setCapturing] = useState(false)const [hint, setHint] = useState('')+ const modsRef = useRef<ChordModifiers | null>(null)const stopCapturing = (): void => {setCapturing(false)setHint('')+ modsRef.current = null+ }++ const startCapturing = (): void => {+ modsRef.current = null+ setCapturing(true)+ setHint('')}const onKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>): void => {@@ -70,6 +95,23 @@ function ShortcutCaptureField({stopCapturing()return}++ if (isModifierEventKey(e.key)) {+ // Only modifier keys pressed so far — remember the strongest state for a possible keyUp+ // commit (hold-to-talk) and preview it; still lets the user continue on to press a real+ // key instead (toggle mode) below.+ const primaryPressed = isMac ? e.metaKey : e.ctrlKey+ if (!primaryPressed) {+ setHint(isMac ? `Hold ⌘…` : `Hold Ctrl…`)+ return+ }+ const mods: ChordModifiers = { cmd: true, alt: e.altKey, shift: e.shiftKey }+ modsRef.current = mods+ const preview = buildModifierChord(mods)+ setHint(preview ? `Release now for hold-to-talk (${formatShortcut(preview, isMac)}) — or press a key for toggle` : '')+ return+ }+const evt: ShortcutKeyEvent = {metaKey: e.metaKey,ctrlKey: e.ctrlKey,@@ -86,16 +128,24 @@ function ShortcutCaptureField({stopCapturing()}+ const onKeyUp = (e: React.KeyboardEvent<HTMLButtonElement>): void => {+ if (!capturing || !modsRef.current) return+ const anyModDown = (isMac ? e.metaKey : e.ctrlKey) || e.altKey || e.shiftKey+ if (anyModDown) return // not fully released yet — keep waiting+ const combo = buildModifierChord(modsRef.current)+ if (!combo) return+ onChange(combo)+ stopCapturing()+ }+return (<div className="flex items-center gap-2"><buttontype="button"className="min-w-[140px] cursor-pointer rounded-md border border-border bg-panel-header px-3 py-1.5 text-[13px] font-medium text-text outline-none hover:bg-[rgba(255,255,255,0.06)]"- onClick={() => {- setCapturing(true)- setHint('')- }}+ onClick={startCapturing}onKeyDown={onKeyDown}+ onKeyUp={onKeyUp}onBlur={stopCapturing}>{capturing ? hint || 'Press keys…' : formatShortcut(value, isMac)}@@ -271,7 +321,12 @@ export function SpeechSection({<SearchableRow {...ROWS.shortcut}><FieldRowlabel="Shortcut"- description="Press-to-talk: starts recording immediately, press again to stop and insert. The Dock mic uses the same shortcut."+ description="Press a combo — with a key = toggle (press to start, press again to stop and insert); modifiers only = hold to talk (hold to record, release to stop and insert). The Dock mic uses the same shortcut."+ note={+ isHoldChord(settings.speech.shortcut)+ ? `Currently hold-to-talk: hold ${formatShortcut(settings.speech.shortcut, isMac)}.`+ : `Currently toggle: press ${formatShortcut(settings.speech.shortcut, isMac)}.`+ }control={<ShortcutCaptureField value={settings.speech.shortcut} onChange={setShortcut} />}/></SearchableRow>diff --git a/src/shared/shortcut.test.ts b/src/shared/shortcut.test.tsindex 9fe9ba199..9b2f2e67e 100644--- a/src/shared/shortcut.test.ts+++ b/src/shared/shortcut.test.ts@@ -1,7 +1,11 @@import { describe, expect, it } from 'vitest'import {+ buildModifierChord,captureToShortcut,+ chordHeld,formatShortcut,+ isHoldChord,+ isModifierEventKey,matchesShortcut,parseShortcut,shortcutKeyParts@@ -41,6 +45,19 @@ describe('parseShortcut', () => {key: 'D'})})++ it('parses a modifier-only chord (no trailing key) — the v3 hold-to-talk shape', () => {+ expect(parseShortcut('Cmd+Alt')).toEqual({ cmd: true, alt: true, shift: false, key: null })+ })++ it('parses a modifier-only chord with all three modifiers', () => {+ expect(parseShortcut('Cmd+Alt+Shift')).toEqual({+ cmd: true,+ alt: true,+ shift: true,+ key: null+ })+ })})describe('formatShortcut', () => {@@ -78,6 +95,26 @@ describe('formatShortcut', () => {expect(parseShortcut(combo)).toEqual(parsed)}})++ it('formats a modifier-only chord (Cmd+Alt) on mac with no trailing key badge', () => {+ expect(formatShortcut('Cmd+Alt', true)).toBe('⌘⌥')+ })++ it('formats a modifier-only chord (Cmd+Alt) off mac with no trailing key badge', () => {+ expect(formatShortcut('Cmd+Alt', false)).toBe('Ctrl+Alt')+ })++ it('round-trips a modifier-only chord through parse -> format -> parse', () => {+ for (const combo of ['Cmd+Alt', 'Cmd+Alt+Shift']) {+ const parsed = parseShortcut(combo)+ expect(parsed.key).toBeNull()+ // formatShortcut is a display transform; there's no un-format, but shortcutKeyParts should+ // never emit a stray trailing key badge for a modifier-only chord.+ expect(shortcutKeyParts(combo, true).length).toBe(+ (parsed.cmd ? 1 : 0) + (parsed.alt ? 1 : 0) + (parsed.shift ? 1 : 0)+ )+ }+ })})describe('shortcutKeyParts', () => {@@ -170,6 +207,100 @@ describe('matchesShortcut', () => {matchesShortcut({ ...base, metaKey: true, key: 'F5' }, 'Cmd+F5', true)).toBe(true)})++ it('never matches a modifier-only chord — that shape has no key to check', () => {+ // Even a keydown of a real key while the exact modifiers are held must not match: a+ // modifier-only shortcut is handled by chordHeld, not matchesShortcut.+ expect(matchesShortcut({ ...base, metaKey: true, altKey: true, key: 'd' }, 'Cmd+Alt', true)).toBe(+ false+ )+ })+})++describe('isHoldChord', () => {+ it('is true for a modifier-only combo', () => {+ expect(isHoldChord('Cmd+Alt')).toBe(true)+ expect(isHoldChord('Cmd+Alt+Shift')).toBe(true)+ })++ it('is false for a keyed combo', () => {+ expect(isHoldChord('Cmd+Alt+D')).toBe(false)+ expect(isHoldChord('Cmd+D')).toBe(false)+ })+})++describe('isModifierEventKey', () => {+ it('recognizes modifier key names, case-insensitively', () => {+ expect(isModifierEventKey('Meta')).toBe(true)+ expect(isModifierEventKey('CONTROL')).toBe(true)+ expect(isModifierEventKey('alt')).toBe(true)+ expect(isModifierEventKey('Shift')).toBe(true)+ })++ it('rejects non-modifier keys', () => {+ expect(isModifierEventKey('d')).toBe(false)+ expect(isModifierEventKey('F5')).toBe(false)+ expect(isModifierEventKey('Escape')).toBe(false)+ })+})++describe('chordHeld', () => {+ const base = { metaKey: false, ctrlKey: false, shiftKey: false, altKey: false, key: 'Alt' }++ it('is true when the event modifiers exactly match the chord (mac)', () => {+ expect(chordHeld({ ...base, metaKey: true, altKey: true }, 'Cmd+Alt', true)).toBe(true)+ })++ it('is true when the event modifiers exactly match the chord (non-mac, ctrlKey primary)', () => {+ expect(chordHeld({ ...base, ctrlKey: true, altKey: true }, 'Cmd+Alt', false)).toBe(true)+ })++ it('is false when the primary modifier is missing', () => {+ expect(chordHeld({ ...base, altKey: true }, 'Cmd+Alt', true)).toBe(false)+ })++ it('is false when a required modifier (alt) is missing', () => {+ expect(chordHeld({ ...base, metaKey: true }, 'Cmd+Alt', true)).toBe(false)+ })++ it('is false when an EXTRA modifier is held beyond what the chord requires', () => {+ expect(chordHeld({ ...base, metaKey: true, altKey: true, shiftKey: true }, 'Cmd+Alt', true)).toBe(+ false+ )+ })++ it('is false on the wrong platform primary (ctrlKey standing in for metaKey on mac)', () => {+ expect(chordHeld({ ...base, ctrlKey: true, altKey: true }, 'Cmd+Alt', true)).toBe(false)+ })++ it('ignores e.key entirely — same result regardless of which key the event names', () => {+ expect(chordHeld({ ...base, metaKey: true, altKey: true, key: 'd' }, 'Cmd+Alt', true)).toBe(true)+ })+})++describe('buildModifierChord', () => {+ it('builds a Cmd+Alt combo', () => {+ expect(buildModifierChord({ cmd: true, alt: true, shift: false })).toBe('Cmd+Alt')+ })++ it('builds a Cmd+Alt+Shift combo', () => {+ expect(buildModifierChord({ cmd: true, alt: true, shift: true })).toBe('Cmd+Alt+Shift')+ })++ it('builds a bare Cmd combo', () => {+ expect(buildModifierChord({ cmd: true, alt: false, shift: false })).toBe('Cmd')+ })++ it('returns null when the primary modifier is missing', () => {+ expect(buildModifierChord({ cmd: false, alt: true, shift: true })).toBeNull()+ })++ it('round-trips through parseShortcut', () => {+ const combo = buildModifierChord({ cmd: true, alt: true, shift: false })+ expect(combo).not.toBeNull()+ expect(parseShortcut(combo as string)).toEqual({ cmd: true, alt: true, shift: false, key: null })+ expect(isHoldChord(combo as string)).toBe(true)+ })})describe('captureToShortcut', () => {diff --git a/src/shared/shortcut.ts b/src/shared/shortcut.tsindex 5d1646350..660b7d9e6 100644--- a/src/shared/shortcut.ts+++ b/src/shared/shortcut.ts@@ -2,11 +2,17 @@* Pure keyboard-shortcut parse/match/format helpers, shared by the Canvas listener, the* Settings → Speech capture field, the Dock mic tooltip, and ShortcutsPanel.*- * Canonical string shape: modifier tokens joined by "+", ending in one non-modifier key token,- * e.g. `"Cmd+Shift+D"`, `"Cmd+F5"`. `Cmd` is a PLATFORM-ABSTRACTED primary modifier — it means- * "the primary modifier for this platform": metaKey (⌘) on mac, ctrlKey elsewhere. There is no- * separate literal "Ctrl" token; storing shortcuts in terms of the abstract "Cmd" is what lets- * one stored string match on every platform via `matchesShortcut(e, s, isMac)`.+ * Canonical string shape: modifier tokens joined by "+", optionally ending in one non-modifier+ * key token, e.g. `"Cmd+Shift+D"`, `"Cmd+F5"`, or (v3) a MODIFIER-ONLY chord with no trailing key,+ * e.g. `"Cmd+Alt"`. `Cmd` is a PLATFORM-ABSTRACTED primary modifier — it means "the primary+ * modifier for this platform": metaKey (⌘) on mac, ctrlKey elsewhere. There is no separate literal+ * "Ctrl" token; storing shortcuts in terms of the abstract "Cmd" is what lets one stored string+ * match on every platform via `matchesShortcut(e, s, isMac)`.+ *+ * A modifier-only chord (`key === null`, see `isHoldChord`) means hold-to-talk: the chord is held+ * down to record and released to stop, instead of toggling on a keyed press. `chordHeld` (not+ * `matchesShortcut`, which requires a trailing key) is what the Canvas hold-mode listener uses to+ * test the held modifier state.*/export interface ParsedShortcut {@@ -14,8 +20,9 @@ export interface ParsedShortcut {cmd: booleanshift: booleanalt: boolean- /** Uppercased single char (e.g. "D") or named key (e.g. "F5", "SPACE", "ESCAPE"). */- key: string+ /** Uppercased single char (e.g. "D") or named key (e.g. "F5", "SPACE", "ESCAPE"). `null` means+ * a modifier-only (hold-to-talk) chord — see `isHoldChord`. */+ key: string | null}/** Friendly display labels for named (non single-char) keys. Falls back to title-case. */@@ -42,7 +49,17 @@ function normalizeKey(key: string): string {return key.toUpperCase()}-/** Parse a canonical combo string, e.g. `"Cmd+Shift+D"` -> `{cmd:true, shift:true, alt:false, key:'D'}`. */+/** True when `key` (a raw `e.key`, any case) names a modifier key itself rather than a+ * printable/named key — e.g. `"Meta"`, `"Alt"`, `"Shift"`. Exported so the Settings capture+ * field and the Canvas hold-mode listener can classify a keydown/keyup the same way+ * `captureToShortcut` does internally. */+export function isModifierEventKey(key: string): boolean {+ return MODIFIER_KEYS.has(normalizeKey(key))+}++/** Parse a canonical combo string, e.g. `"Cmd+Shift+D"` -> `{cmd:true, shift:true, alt:false,+ * key:'D'}`; a modifier-only chord, e.g. `"Cmd+Alt"` -> `{cmd:true, shift:false, alt:true,+ * key:null}` (see `isHoldChord`). */export function parseShortcut(s: string): ParsedShortcut {const parts = s.split('+')@@ -52,7 +69,7 @@ export function parseShortcut(s: string): ParsedShortcut {let cmd = falselet shift = falselet alt = false- let key = ''+ let key: string | null = nullfor (const part of parts) {const lower = part.toLowerCase()if (lower === 'cmd' || lower === 'command' || lower === 'ctrl' || lower === 'control') {@@ -68,6 +85,13 @@ export function parseShortcut(s: string): ParsedShortcut {return { cmd, shift, alt, key }}+/** True when `s` is a modifier-only chord (no trailing key) — the v3 hold-to-talk shape. A+ * keyed combo (`"Cmd+Alt+D"`) keeps the existing press-to-talk toggle behavior; the mode is+ * derived from the stored string, not a separate setting. */+export function isHoldChord(s: string): boolean {+ return parseShortcut(s).key === null+}+/** `"D"` -> `"D"`, `"SPACE"` -> `"Space"`, `"F5"` -> `"F5"`, unknown multi-char -> title case. */function keyLabel(key: string): string {if (KEY_LABELS[key]) return KEY_LABELS[key]@@ -76,28 +100,27 @@ function keyLabel(key: string): string {return key.charAt(0) + key.slice(1).toLowerCase()}-/** `"Cmd+Shift+D"` + mac -> `["⌘", "⇧", "D"]`; + non-mac -> `["Ctrl", "Shift", "D"]`. One badge- * per element — used by ShortcutsPanel's `<kbd>` row rendering. */+/** `"Cmd+Shift+D"` + mac -> `["⌘", "⇧", "D"]`; + non-mac -> `["Ctrl", "Shift", "D"]`; a+ * modifier-only chord (`"Cmd+Alt"`) -> `["⌘", "⌥"]` (no trailing key badge). One badge per+ * element — used by ShortcutsPanel's `<kbd>` row rendering. */export function shortcutKeyParts(s: string, isMac: boolean): string[] {const { cmd, shift, alt, key } = parseShortcut(s)- const label = keyLabel(key)+ const parts: string[] = []if (isMac) {- const parts: string[] = []if (cmd) parts.push('⌘')if (alt) parts.push('⌥')if (shift) parts.push('⇧')- parts.push(label)- return parts+ } else {+ if (cmd) parts.push('Ctrl')+ if (alt) parts.push('Alt')+ if (shift) parts.push('Shift')}- const parts: string[] = []- if (cmd) parts.push('Ctrl')- if (alt) parts.push('Alt')- if (shift) parts.push('Shift')- parts.push(label)+ if (key !== null) parts.push(keyLabel(key))return parts}-/** `"Cmd+Shift+D"` + mac -> `"⌘⇧D"`; + non-mac -> `"Ctrl+Shift+D"`. */+/** `"Cmd+Shift+D"` + mac -> `"⌘⇧D"`; + non-mac -> `"Ctrl+Shift+D"`; a modifier-only chord+ * (`"Cmd+Alt"`) -> `"⌘⌥"` / `"Ctrl+Alt"`. */export function formatShortcut(s: string, isMac: boolean): string {const parts = shortcutKeyParts(s, isMac)return isMac ? parts.join('') : parts.join('+')@@ -113,21 +136,40 @@ export interface ShortcutKeyEvent {key: string}-/** Does `e` match the canonical combo `s`? `cmd` in `s` means metaKey on mac, ctrlKey elsewhere. */+/** Does `e` match the canonical combo `s`? `cmd` in `s` means metaKey on mac, ctrlKey elsewhere.+ * For a keyed combo only — a modifier-only chord (`isHoldChord(s)`) never matches here (its+ * `key` is `null`, which no `e.key` ever equals); the Canvas hold-mode listener uses+ * `chordHeld` instead. */export function matchesShortcut(e: ShortcutKeyEvent, s: string, isMac: boolean): boolean {const parsed = parseShortcut(s)const primaryPressed = isMac ? e.metaKey : e.ctrlKeyif (parsed.cmd !== primaryPressed) return falseif (parsed.shift !== e.shiftKey) return falseif (parsed.alt !== e.altKey) return false- return normalizeKey(e.key) === parsed.key+ return parsed.key !== null && normalizeKey(e.key) === parsed.key+}++/** True when `e`'s currently-held modifiers EXACTLY cover `s`'s modifiers (no key check, and no+ * extra modifier beyond what `s` requires). Used by the Canvas hold-mode listener for a+ * modifier-only chord: "is the chord fully down" (arm, on keydown) and "did one of the chord's+ * own modifiers just come up" (release, on keyup — the keyup event's own modifier flags already+ * reflect the key that was just released). An extra modifier held on top of the chord (e.g.+ * Shift added to a `Cmd+Alt` chord) makes this false, which is also the "third key" misfire+ * guard for modifier keys specifically (a non-modifier third key is guarded separately, since+ * this function ignores `e.key` entirely). */+export function chordHeld(e: ShortcutKeyEvent, s: string, isMac: boolean): boolean {+ const parsed = parseShortcut(s)+ const primaryPressed = isMac ? e.metaKey : e.ctrlKey+ return parsed.cmd === primaryPressed && parsed.shift === e.shiftKey && parsed.alt === e.altKey}/*** Build a canonical combo string from a captured keydown, for the Settings capture field.* Requires the platform's primary modifier (Cmd on mac / Ctrl elsewhere) plus a non-modifier* key; returns null while only modifier keys have been pressed so far, or when the primary- * modifier is missing.+ * modifier is missing. (A modifier-only chord is captured separately — see `buildModifierChord`+ * below — because it commits on keyUP once every key is released, by which point the keyup+ * event's own modifier flags are already false and can't be read off it directly.)*/export function captureToShortcut(e: ShortcutKeyEvent, isMac: boolean): string | null {const primaryPressed = isMac ? e.metaKey : e.ctrlKey@@ -140,3 +182,24 @@ export function captureToShortcut(e: ShortcutKeyEvent, isMac: boolean): string |parts.push(key)return parts.join('+')}++/** The modifier state observed while capturing a would-be hold-to-talk chord (see+ * `buildModifierChord`). */+export interface ChordModifiers {+ cmd: boolean+ alt: boolean+ shift: boolean+}++/** `{cmd:true, alt:true, shift:false}` -> `"Cmd+Alt"`; `{cmd:false, ...}` -> `null` (the primary+ * modifier is mandatory, same as `captureToShortcut`). The Settings capture field calls this at+ * keyUp, once every key has been released, using the modifier state it remembered from the last+ * keyDown while only modifier keys had been pressed (`isModifierEventKey`) — the keyup event+ * itself no longer carries that state. */+export function buildModifierChord(mods: ChordModifiers): string | null {+ if (!mods.cmd) return null+ const parts = ['Cmd']+ if (mods.alt) parts.push('Alt')+ if (mods.shift) parts.push('Shift')+ return parts.join('+')+}diff --git a/src/shared/speech.test.ts b/src/shared/speech.test.tsindex a22759809..71b566380 100644--- a/src/shared/speech.test.ts+++ b/src/shared/speech.test.ts@@ -26,7 +26,7 @@ describe('whisper model catalog', () => {engine: 'whisper',model: 'tiny',language: 'auto',- shortcut: 'Cmd+Alt+D'+ shortcut: 'Cmd+Alt'})})})diff --git a/src/shared/types.ts b/src/shared/types.tsindex 31a677a44..b336d82e4 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -489,9 +489,11 @@ export interface SpeechSettings {model: string/** BCP-47-ish hint or 'auto'. */language: string- /** Press-to-talk shortcut, canonical form e.g. "Cmd+Alt+D" (see `shared/shortcut.ts`).- * "Cmd" is platform-abstracted: metaKey on mac, ctrlKey elsewhere. Drives the Canvas- * listener, the Dock mic tooltip, and the ShortcutsPanel row. */+ /** Press-to-talk / hold-to-talk shortcut, canonical form e.g. "Cmd+Alt+D" (keyed = toggle) or+ * "Cmd+Alt" (v3, modifier-only = hold-to-talk — the new DEFAULT); see `shared/shortcut.ts`+ * (`isHoldChord` derives the mode from the string, not a separate setting). "Cmd" is+ * platform-abstracted: metaKey on mac, ctrlKey elsewhere. Drives the Canvas listener, the+ * Dock mic tooltip, and the ShortcutsPanel row. */shortcut: string}@@ -602,7 +604,7 @@ export const DEFAULT_SETTINGS: Settings = {telemetryEnabled: false,phoneAccessEnabled: false,mobilePushEnabled: true,- speech: { engine: 'whisper', model: 'tiny', language: 'auto', shortcut: 'Cmd+Alt+D' },+ speech: { engine: 'whisper', model: 'tiny', language: 'auto', shortcut: 'Cmd+Alt' },}export interface SettingsApi {