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
fix(terminal): keep ctrl+digit shortcuts from leaking into the PTY
Mina Sameh2f928a4b8d08
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 996ef0f73..8796a9a5e 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -307,6 +307,10 @@ const isMac = /Mac/i.test(navigator.platform || navigator.userAgent)const GRID = 24+/** Cmd/Ctrl+1-9 "jump to Nth project" shortcut key match — hoisted so the keydown handler+ * doesn't re-allocate a regex literal on every keystroke. */+const DIGIT_SHORTCUT_RE = /^Digit[1-9]$/+/** The empty opaque set (glyphgrid), shared so the render-time compute allocates nothing on the* overwhelmingly common "nothing overlaps / layer off" path. */const EMPTY_OPAQUE: string[] = []@@ -4615,6 +4619,22 @@ export function Canvas() {[goToNode])+ // ---- project (tab) actions ----+ // Declared here (ahead of the keydown effect below, rather than near the other project+ // actions further down) so the Cmd/Ctrl+digit shortcut can list it as a dependency without+ // a TDZ violation: `useCallback`/`const` bindings are not hoisted like function declarations,+ // so referencing switchProject in that effect's deps array before this point would throw+ // "used before its declaration".+ const switchProject = useCallback(+ (id: string) => {+ if (id === useProjects.getState().activeProjectId) return+ commitActiveToStore()+ useProjects.getState().setActive(id)+ void writeDisk()+ },+ [commitActiveToStore, writeDisk]+ )+// Cmd/Ctrl+K toggles the command palette; Cmd/Ctrl+, opens settings.useEffect(() => {const onKey = (e: KeyboardEvent) => {@@ -4641,7 +4661,7 @@ export function Canvas() {} else if ((e.metaKey || e.ctrlKey) && e.key === '/') {e.preventDefault()setShortcutsOpen((v) => !v)- } else if ((e.metaKey || e.ctrlKey) && !e.shiftKey && /^Digit[1-9]$/.test(e.code)) {+ } else if ((e.metaKey || e.ctrlKey) && !e.shiftKey && DIGIT_SHORTCUT_RE.test(e.code)) {const n = Number(e.code.slice(5))const { projects, activeProjectId } = useProjects.getState()const targetId = projectIdAtIndex(projects, n)@@ -4659,7 +4679,7 @@ export function Canvas() {}window.addEventListener('keydown', onKey)return () => window.removeEventListener('keydown', onKey)- }, [toggleSessionsPin])+ }, [toggleSessionsPin, switchProject])// Apply the accent color as a CSS variable.useEffect(() => {@@ -5273,17 +5293,6 @@ export function Canvas() {[markDirty])- // ---- project (tab) actions ----- const switchProject = useCallback(- (id: string) => {- if (id === useProjects.getState().activeProjectId) return- commitActiveToStore()- useProjects.getState().setActive(id)- void writeDisk()- },- [commitActiveToStore, writeDisk]- )-// Focus a node by id (notification click): select + center it; if it lives in another// project, switch there first and let the project-load effect finish the focus.const focusNodeById = useCallback(diff --git a/src/renderer/terminal/terminal-config.ts b/src/renderer/terminal/terminal-config.tsindex dfc97831a..be3d04178 100644--- a/src/renderer/terminal/terminal-config.ts+++ b/src/renderer/terminal/terminal-config.ts@@ -716,6 +716,9 @@ export const SHIFT_ENTER_SEQ = '\x1b\r'export type TerminalKeyAction = CopyKeyAction | 'shift-enter'+/** Matches the Cmd/Ctrl+Digit[1-9] "jump to Nth project" shortcut's key code. */+const DIGIT_SHORTCUT_RE = /^Digit[1-9]$/+/** Superset of `copyKeyAction` used by the terminal's custom key handler. */export function terminalKeyAction(e: CopyShortcutEvent, hasSelection: boolean): TerminalKeyAction {if (@@ -727,5 +730,13 @@ export function terminalKeyAction(e: CopyShortcutEvent, hasSelection: boolean):!e.altKey)return 'shift-enter'+ // Ctrl+Digit[1-9] is the "jump to Nth project" shortcut (Canvas.tsx). On macOS this is Cmd,+ // which xterm already ignores — but on Linux/Windows the Ctrl variant maps to real terminal+ // control codes (Ctrl+2..Ctrl+8 = ^@, ^[, ^\, ^], ^^, ^_), so xterm must be told to swallow it+ // BEFORE it writes the control byte to the PTY. The bubble-phase keydown listener in Canvas.tsx+ // runs `preventDefault()` too late for that — this handler is xterm's own, invoked first via+ // `attachCustomKeyEventHandler`. No meta check needed: Cmd never reaches here as ctrlKey.+ if (e.type === 'keydown' && e.ctrlKey && !e.metaKey && !e.altKey && DIGIT_SHORTCUT_RE.test(e.code))+ return 'swallow'return copyKeyAction(e, hasSelection)}