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(shortcut): the app only owns Cmd/Ctrl+1-9 when it can act on it
Claude Codeda04e905a779
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 3948e9220..21fc25c85 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -126,7 +126,7 @@ import { WorktreeDialog } from '../components/WorktreeDialog'import { NotifyConsentDialog } from '../components/NotifyConsentDialog'import { SessionsSidebar } from '../components/SessionsSidebar'import type { SessionNodeInput } from '../lib/sessionList'-import { projectIdAtIndex } from '../lib/sessionList'+import { liveProjectJumpTarget, projectJumpDigit } from '../lib/projectJump'import { UsageIndicator } from '../components/UsageIndicator'import { PresenceLayer } from '../components/PresenceLayer'import { Facepile } from '../components/Facepile'@@ -307,10 +307,6 @@ 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[] = []@@ -4661,19 +4657,13 @@ export function Canvas() {} else if ((e.metaKey || e.ctrlKey) && e.key === '/') {e.preventDefault()setShortcutsOpen((v) => !v)- } else if (- (e.metaKey || e.ctrlKey) &&- !e.shiftKey &&- !e.altKey &&- DIGIT_SHORTCUT_RE.test(e.code)- ) {- const n = Number(e.code.slice(5))- const { projects, activeProjectId } = useProjects.getState()- const targetId = projectIdAtIndex(- projects.filter((p) => !p.closed),- n- )- if (targetId && targetId !== activeProjectId) {+ } else if (projectJumpDigit(e) !== null) {+ // Cmd/Ctrl+1-9 jumps to the Nth project — but only when the app actually owns the key+ // (desktop shell, and the digit addresses an open project). `liveProjectJumpTarget`+ // is the same decision the terminals' swallow asks, so the two can't disagree; a null+ // target leaves the key to whatever has focus. `switchProject` no-ops on the active id.+ const targetId = liveProjectJumpTarget(e)+ if (targetId) {e.preventDefault()switchProject(targetId)}diff --git a/src/renderer/components/ShortcutsPanel.tsx b/src/renderer/components/ShortcutsPanel.tsxindex 7929a1047..b3a289f71 100644--- a/src/renderer/components/ShortcutsPanel.tsx+++ b/src/renderer/components/ShortcutsPanel.tsx@@ -1,6 +1,7 @@import { useEffect } from 'react'import { createPortal } from 'react-dom'import { isHoldChord, shortcutKeyParts } from '@shared/shortcut'+import { isBrowserRuntime } from '../bridge/runtime'import { useSettings } from '../state/settings'const isMac = /Mac/i.test(navigator.platform || navigator.userAgent)@@ -26,7 +27,9 @@ function buildSections(dictationKeys: string[], dictationLabel: string): { title{ keys: ['⌘', 'K'], label: 'Command palette' },{ keys: ['⌘', ','], label: 'Settings' },{ keys: ['⌘', '/'], label: 'This shortcuts panel' },- { keys: ['⌘', '1-9'], label: 'Jump to project' },+ // Desktop only: browsers own Cmd/Ctrl+1-9 for tab switching and a page cannot take it+ // back, so listing it in the Server Edition would promise a shortcut that never fires.+ ...(isBrowserRuntime() ? [] : [{ keys: ['⌘', '1-9'], label: 'Jump to project' }]),{ keys: dictationKeys, label: dictationLabel },{ keys: ['⌘', 'Z'], label: 'Undo' },{ keys: ['⌘', '⇧', 'Z'], label: 'Redo' }diff --git a/src/renderer/components/kanban/ModalTerminal.tsx b/src/renderer/components/kanban/ModalTerminal.tsxindex c4a73bd2e..bf0459d65 100644--- a/src/renderer/components/kanban/ModalTerminal.tsx+++ b/src/renderer/components/kanban/ModalTerminal.tsx@@ -5,6 +5,7 @@ import { SearchAddon } from '@xterm/addon-search'import { reportsOwnCopy } from '@shared/agents/config'import type { AgentId } from '@shared/agents/config'import { readsClaudeTranscript } from '../../lib/transcriptGates'+import { liveProjectJumpTarget } from '../../lib/projectJump'import { FindBar } from '../FindBar'import { useAgentStatus } from '../../state/agentStatus'import { useProjects } from '../../state/projects'@@ -185,8 +186,11 @@ export function ModalTerminal({ nodeId, spawn, searchOpen, onCloseSearch }: Moda// the xterm selection (a canvas can't be DOM-copied), and Shift+Enter → ESC+CR (`SHIFT_ENTER_SEQ`)// so agent CLIs insert a newline instead of submitting. A copy chord is always swallowed (else// Ctrl+Shift+C would fall through to the pty as \x03/SIGINT); plain Ctrl+C is left alone.+ // MIRROR TerminalNode: Cmd/Ctrl+1-9 (jump to the Nth project) is swallowed here, before xterm+ // turns Ctrl+2..Ctrl+8 into control bytes — but only when the app owns the key (desktop shell,+ // digit addressing an open project), which `liveProjectJumpTarget` decides for both surfaces.term.attachCustomKeyEventHandler((e) => {- const action = terminalKeyAction(e, term.hasSelection())+ const action = terminalKeyAction(e, term.hasSelection(), liveProjectJumpTarget(e) !== null)if (action === 'pass') return truee.preventDefault()if (action === 'copy') window.nodeTerminal.clipboard.writeText(term.getSelection())diff --git a/src/renderer/lib/projectJump.browser.test.ts b/src/renderer/lib/projectJump.browser.test.tsnew file mode 100644index 000000000..46ddf2951--- /dev/null+++ b/src/renderer/lib/projectJump.browser.test.ts@@ -0,0 +1,48 @@+import { describe, it, expect, beforeAll } from "vitest";+import type { Project } from "@shared/types";+import { markBrowserRuntime } from "../bridge/runtime";+import { useProjects } from "../state/projects";+import { liveProjectJumpTarget, type ProjectJumpEvent } from "./projectJump";++// The BROWSER half of the live binding, in its own file because `markBrowserRuntime` is the boot+// switch the WS bridge flips once and never unflips; vitest isolates module state per test file.+//+// REGRESSION GUARD (review #1): Chrome, Firefox and Safari all reserve Ctrl+1-9 (Cmd+1-9 on macOS)+// for tab switching and a page cannot `preventDefault()` them. In the Server Edition the switch+// therefore cannot happen — and without this gate the terminals would still swallow Ctrl+2..Ctrl+8+// (^@ ^[ ^\ ^] ^^ ^_) out of the pty for no benefit at all. Delete the `isBrowserRuntime()` check+// in `liveProjectJumpTarget` and this file fails.++function project(id: string): Project {+ return {+ id,+ name: id,+ color: "#888",+ viewport: { x: 0, y: 0, zoom: 1 },+ nodes: [],+ };+}++const chord: ProjectJumpEvent = {+ type: "keydown",+ code: "Digit1",+ metaKey: false,+ ctrlKey: true,+ altKey: false,+ shiftKey: false,+};++describe("liveProjectJumpTarget (Server Edition / browser tab)", () => {+ beforeAll(() => {+ useProjects.setState({ projects: [project("p1"), project("p2")] });+ markBrowserRuntime();+ });++ it("never claims the chord, even when the digit addresses an open project", () => {+ expect(liveProjectJumpTarget(chord)).toBeNull();+ expect(liveProjectJumpTarget({ ...chord, code: "Digit2" })).toBeNull();+ expect(+ liveProjectJumpTarget({ ...chord, ctrlKey: false, metaKey: true }),+ ).toBeNull();+ });+});diff --git a/src/renderer/lib/projectJump.live.test.ts b/src/renderer/lib/projectJump.live.test.tsnew file mode 100644index 000000000..da524c4d4--- /dev/null+++ b/src/renderer/lib/projectJump.live.test.ts@@ -0,0 +1,60 @@+import { describe, it, expect, beforeEach } from "vitest";+import type { Project } from "@shared/types";+import { useProjects } from "../state/projects";+import { liveProjectJumpTarget, type ProjectJumpEvent } from "./projectJump";++// The DESKTOP half of the live binding (the browser half needs its own file — markBrowserRuntime+// is a one-way boot switch, and vitest isolates module state per file). Under Electron the flag is+// never set, which is exactly the state this file runs in.++function project(id: string, closed?: boolean): Project {+ return {+ id,+ name: id,+ color: "#888",+ viewport: { x: 0, y: 0, zoom: 1 },+ nodes: [],+ ...(closed ? { closed: true } : {}),+ };+}++function ev(code: string): ProjectJumpEvent {+ return {+ type: "keydown",+ code,+ metaKey: false,+ ctrlKey: true,+ altKey: false,+ shiftKey: false,+ };+}++describe("liveProjectJumpTarget (desktop shell)", () => {+ beforeEach(() => {+ useProjects.setState({+ projects: [project("p1"), project("p2"), project("p3")],+ });+ });++ it("resolves a digit that addresses an open project", () => {+ expect(liveProjectJumpTarget(ev("Digit2"))).toBe("p2");+ });++ it("answers null for a digit past the end — the terminals must not swallow that key", () => {+ expect(liveProjectJumpTarget(ev("Digit4"))).toBeNull();+ });++ it("reads the project list live, so closing a project narrows the addressable range", () => {+ useProjects.setState({+ projects: [project("p1"), project("p2", true), project("p3")],+ });+ expect(liveProjectJumpTarget(ev("Digit2"))).toBe("p3");+ expect(liveProjectJumpTarget(ev("Digit3"))).toBeNull();+ });++ it("is null for a non-chord keydown", () => {+ expect(+ liveProjectJumpTarget({ ...ev("Digit1"), ctrlKey: false }),+ ).toBeNull();+ });+});diff --git a/src/renderer/lib/projectJump.test.ts b/src/renderer/lib/projectJump.test.tsnew file mode 100644index 000000000..494413307--- /dev/null+++ b/src/renderer/lib/projectJump.test.ts@@ -0,0 +1,96 @@+import { describe, it, expect } from "vitest";+import {+ projectJumpDigit,+ projectJumpTarget,+ type ProjectJumpEvent,+} from "./projectJump";++function ev(over: Partial<ProjectJumpEvent> = {}): ProjectJumpEvent {+ return {+ type: "keydown",+ code: "Digit1",+ metaKey: false,+ ctrlKey: true,+ altKey: false,+ shiftKey: false,+ ...over,+ };+}++const THREE = [{ id: "p1" }, { id: "p2" }, { id: "p3" }];+const desktop = (projects: { id: string; closed?: boolean }[] = THREE) => ({+ browser: false,+ projects,+});++describe("projectJumpDigit", () => {+ it("reads the 1-9 digit off the physical key code, under either primary modifier", () => {+ expect(projectJumpDigit(ev({ code: "Digit1" }))).toBe(1);+ expect(projectJumpDigit(ev({ code: "Digit9" }))).toBe(9);+ expect(+ projectJumpDigit(ev({ code: "Digit4", ctrlKey: false, metaKey: true })),+ ).toBe(4);+ });++ it("is not the chord without a primary modifier, or on Digit0", () => {+ expect(projectJumpDigit(ev({ ctrlKey: false }))).toBeNull();+ expect(projectJumpDigit(ev({ code: "Digit0" }))).toBeNull();+ expect(projectJumpDigit(ev({ code: "KeyA" }))).toBeNull();+ });++ it("leaves AltGr (ctrl+alt) and shifted digits alone", () => {+ // AltGr reports as ctrl+alt on Linux/Windows and types a real character on non-US layouts.+ expect(projectJumpDigit(ev({ altKey: true }))).toBeNull();+ expect(projectJumpDigit(ev({ shiftKey: true }))).toBeNull();+ });++ it("only fires on keydown", () => {+ expect(projectJumpDigit(ev({ type: "keyup" }))).toBeNull();+ });+});++describe("projectJumpTarget", () => {+ it("resolves the digit against the open projects, in store order", () => {+ expect(projectJumpTarget(ev({ code: "Digit1" }), desktop())).toBe("p1");+ expect(projectJumpTarget(ev({ code: "Digit3" }), desktop())).toBe("p3");+ });++ it("skips closed projects, matching what the tab bar shows", () => {+ const list = [{ id: "p1" }, { id: "p2", closed: true }, { id: "p3" }];+ expect(projectJumpTarget(ev({ code: "Digit2" }), desktop(list))).toBe("p3");+ expect(projectJumpTarget(ev({ code: "Digit3" }), desktop(list))).toBeNull();+ });++ // REGRESSION GUARD (review #2): the terminal's swallow asks this same function, so a digit that+ // addresses nothing must answer null — otherwise Ctrl+5 with three projects open would be eaten+ // and vim would silently lose ^^ / ^] and friends (Ctrl+2..Ctrl+8 are real control codes).+ it("is null for a digit past the end of the list — the key belongs to the pty", () => {+ expect(projectJumpTarget(ev({ code: "Digit5" }), desktop())).toBeNull();+ expect(projectJumpTarget(ev({ code: "Digit9" }), desktop())).toBeNull();+ expect(projectJumpTarget(ev({ code: "Digit1" }), desktop([]))).toBeNull();+ expect(+ projectJumpTarget(+ ev({ code: "Digit1" }),+ desktop([{ id: "p1", closed: true }]),+ ),+ ).toBeNull();+ });++ // REGRESSION GUARD (review #1): Chrome/Firefox/Safari own Ctrl+1-9 (Cmd+1-9 on macOS) for tab+ // switching and a page cannot preventDefault it, so the Server Edition can neither perform the+ // switch nor justify swallowing the key.+ it("is null in a browser tab, even for a digit that would resolve on the desktop", () => {+ expect(+ projectJumpTarget(ev({ code: "Digit1" }), {+ browser: true,+ projects: THREE,+ }),+ ).toBeNull();+ expect(+ projectJumpTarget(ev({ code: "Digit3" }), {+ browser: true,+ projects: THREE,+ }),+ ).toBeNull();+ });+});diff --git a/src/renderer/lib/projectJump.ts b/src/renderer/lib/projectJump.tsnew file mode 100644index 000000000..7d3dcb4b0--- /dev/null+++ b/src/renderer/lib/projectJump.ts@@ -0,0 +1,92 @@+import { isBrowserRuntime } from "../bridge/runtime";+import { useProjects } from "../state/projects";+import { projectIdAtIndex } from "./sessionList";++/**+ * The Cmd/Ctrl+1-9 "jump to the Nth project" chord — ONE decision, shared by the three places+ * that must agree about it: the Canvas keydown handler (which performs the switch), and the two+ * xterm key handlers (canvas `TerminalNode` + kanban `ModalTerminal`) that have to swallow the+ * key BEFORE xterm writes a control byte to the pty. Keeping the matcher in one module is+ * deliberate: a copy of it in each place is a rule that drifts.+ *+ * Two facts make the answer narrower than "is this the chord":+ *+ * 1. **Desktop only.** Chrome, Firefox and Safari all own Ctrl+1-9 (Cmd+1-9 on macOS) for tab+ * switching, and a page CANNOT `preventDefault()` them. So in the Server Edition the switch+ * can never happen — and swallowing the key there would strip the terminal's control codes+ * for exactly zero benefit. The whole feature is therefore gated on the shell.+ * 2. **Only when the digit addresses an open project.** Ctrl+2..Ctrl+8 are real, daily-use+ * terminal control codes (`^@ ^[ ^\ ^] ^^ ^_` — vim's `^]` jump-to-tag and `^^` alternate-file+ * live there). Pressing Ctrl+5 with three projects open must reach the pty untouched, because+ * the app is not going to do anything with it. So the swallow mirrors the handler's decision+ * rather than claiming the whole digit row.+ *+ * Matching is on `e.code` (the physical digit), not `e.key`: on a French AZERTY the unshifted+ * digit row prints letters, and the shortcut is positional. `@shared/shortcut` (parseShortcut /+ * matchesShortcut) was considered and does not fit — it matches ONE named key off `e.key`, while+ * this is a family of nine matched positionally; bending it to do both would make the settings+ * capture field's contract fuzzier for no gain here.+ */+export interface ProjectJumpEvent {+ type: string;+ code: string;+ metaKey: boolean;+ ctrlKey: boolean;+ altKey: boolean;+ shiftKey: boolean;+}++export interface ProjectJumpContext {+ /** True in a browser tab (Server Edition) — see rule 1 above. */+ browser: boolean;+ /** Project list in store order; `closed` ones are hidden from the tab bar and not addressable. */+ projects: readonly { id: string; closed?: boolean }[];+}++const DIGIT_CODE_RE = /^Digit[1-9]$/;++/**+ * The 1-9 digit this keydown addresses, or null when it is not the chord at all.+ *+ * Accepts EITHER modifier (`meta || ctrl`) on every platform, so a mac user's Ctrl+3 jumps too —+ * and, more importantly, so the swallow covers exactly the set the handler acts on. Alt is+ * excluded because AltGr reports as ctrl+alt and must keep typing a real character on non-US+ * layouts; Shift is excluded because a shifted digit is a punctuation key.+ */+export function projectJumpDigit(e: ProjectJumpEvent): number | null {+ if (e.type !== "keydown") return null;+ if (!e.metaKey && !e.ctrlKey) return null;+ if (e.altKey || e.shiftKey) return null;+ if (!DIGIT_CODE_RE.test(e.code)) return null;+ return Number(e.code.slice(5));+}++/**+ * PURE. The project id this chord resolves to, or null when the app does not own the key —+ * either because it is not the chord, or the shell is a browser tab, or the digit addresses no+ * open project. Null means "leave the key alone": no `preventDefault`, no swallow.+ */+export function projectJumpTarget(+ e: ProjectJumpEvent,+ ctx: ProjectJumpContext,+): string | null {+ if (ctx.browser) return null;+ const digit = projectJumpDigit(e);+ if (digit === null) return null;+ return projectIdAtIndex(+ ctx.projects.filter((p) => !p.closed),+ digit,+ );+}++/**+ * `projectJumpTarget` bound to the live shell + project store. The cheap key-shape test runs+ * first so an ordinary keystroke never reaches into the store.+ */+export function liveProjectJumpTarget(e: ProjectJumpEvent): string | null {+ if (projectJumpDigit(e) === null) return null;+ return projectJumpTarget(e, {+ browser: isBrowserRuntime(),+ projects: useProjects.getState().projects,+ });+}diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex 9877c261d..43e405e5b 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -102,6 +102,7 @@ import { ContextMeter } from '../components/ContextMeter'import { isZoomModifierHeld } from '../lib/zoomModifier'import { isHidden } from '../lib/ui-visibility'import { readsClaudeTranscript } from '../lib/transcriptGates'+import { liveProjectJumpTarget } from '../lib/projectJump'import { useSettings } from '../state/settings'import { useAgentStatus, inferInterruptAfterSettle } from '../state/agentStatus'import type { ClientId } from '@shared/presence'@@ -1896,8 +1897,11 @@ export function TerminalNode({// NOT preventable by a page — hence Ctrl+Insert, which no browser reserves.// Shift+Enter is also intercepted here: xterm would send a plain \r (submit), so we remap it to// ESC+CR (`SHIFT_ENTER_SEQ`) — agent CLIs read that as "insert newline" (see terminal-config.ts).+ // Cmd/Ctrl+1-9 (jump to the Nth project) must be swallowed before xterm turns Ctrl+2..Ctrl+8+ // into control bytes — but ONLY when the app owns the key: desktop shell, digit addressing an+ // open project. `liveProjectJumpTarget` is the same decision Canvas's handler makes.term.attachCustomKeyEventHandler((e) => {- const action = terminalKeyAction(e, term.hasSelection())+ const action = terminalKeyAction(e, term.hasSelection(), liveProjectJumpTarget(e) !== null)if (action === 'pass') return truee.preventDefault()if (action === 'copy') window.nodeTerminal.clipboard.writeText(term.getSelection())diff --git a/src/renderer/terminal/terminal-config.test.ts b/src/renderer/terminal/terminal-config.test.tsindex 6d98dfd04..b46117d1f 100644--- a/src/renderer/terminal/terminal-config.test.ts+++ b/src/renderer/terminal/terminal-config.test.ts@@ -531,39 +531,33 @@ describe('terminalKeyAction', () => {expect(SHIFT_ENTER_SEQ).toBe('\x1b\r')})- it('swallows Ctrl+Digit[1-9] keydown so the PTY never sees the jump-to-project chord', () => {- expect(terminalKeyAction(ev({ key: '1', code: 'Digit1', ctrlKey: true }), false)).toBe(+ // The jump-to-project chord: WHICH events are the chord is decided once, in lib/projectJump.ts+ // (and tested there — layout, AltGr, keyup, digit range). This module only obeys the answer.+ it('swallows the jump-to-project chord so the PTY never sees the control byte', () => {+ expect(terminalKeyAction(ev({ key: '1', code: 'Digit1', ctrlKey: true }), false, true)).toBe('swallow')- expect(terminalKeyAction(ev({ key: '9', code: 'Digit9', ctrlKey: true }), false)).toBe(- 'swallow'- )- })-- it('passes Cmd+Digit1 through (meta without ctrl never reaches the PTY as a control code)', () => {- expect(terminalKeyAction(ev({ key: '1', code: 'Digit1', metaKey: true }), false)).toBe('pass')- })-- it('passes Ctrl+Alt+Digit1 through (AltGr on non-US layouts types a real character)', () => {- expect(- terminalKeyAction(ev({ key: '1', code: 'Digit1', ctrlKey: true, altKey: true }), false)- ).toBe('pass')})- it('passes Ctrl+Shift+Digit1 through (matches Canvas.tsx rejecting shifted digit chords)', () => {- expect(- terminalKeyAction(ev({ key: '1', code: 'Digit1', ctrlKey: true, shiftKey: true }), false)- ).toBe('pass')+ // REGRESSION GUARD (review #2): the swallow follows the caller's resolution, so a digit that+ // addresses no open project keeps reaching the pty — Ctrl+2..Ctrl+8 are ^@ ^[ ^\ ^] ^^ ^_, and+ // vim's ^] (jump to tag) and ^^ (alternate file) are daily-use keys.+ it('passes the same chord through when the app does not own it', () => {+ expect(terminalKeyAction(ev({ key: '1', code: 'Digit1', ctrlKey: true }), false, false)).toBe(+ 'pass'+ )+ expect(terminalKeyAction(ev({ key: '5', code: 'Digit5', ctrlKey: true }), false, false)).toBe(+ 'pass'+ )})- it('passes Ctrl+Digit0 through (0 is out of the addressable 1-9 range)', () => {- expect(terminalKeyAction(ev({ key: '0', code: 'Digit0', ctrlKey: true }), false)).toBe('pass')+ it('defaults to not swallowing — the pre-feature behavior, byte for byte', () => {+ expect(terminalKeyAction(ev({ key: '1', code: 'Digit1', ctrlKey: true }), false)).toBe('pass')})- it('passes a Ctrl+Digit1 keyup through (only keydown swallows)', () => {- expect(- terminalKeyAction(ev({ key: '1', code: 'Digit1', ctrlKey: true, type: 'keyup' }), false)- ).toBe('pass')+ it('never lets the jump swallow shadow a copy chord', () => {+ // Cmd+C with a selection still copies; the digit flag only ever applies to a digit keydown.+ expect(terminalKeyAction(ev({ metaKey: true }), true, false)).toBe('copy')})})diff --git a/src/renderer/terminal/terminal-config.ts b/src/renderer/terminal/terminal-config.tsindex 534493881..7fb232edf 100644--- a/src/renderer/terminal/terminal-config.ts+++ b/src/renderer/terminal/terminal-config.ts@@ -716,11 +716,25 @@ 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 {+/**+ * Superset of `copyKeyAction` used by the terminal's custom key handler.+ *+ * `ownsProjectJump` is the Cmd/Ctrl+1-9 "jump to the Nth project" decision, made by the caller+ * (`liveProjectJumpTarget` in `lib/projectJump.ts`) and passed in — this module deliberately does+ * NOT re-derive it. There is exactly one matcher for that chord, because it has to agree with the+ * Canvas handler that performs the switch. When it is true the key must be swallowed HERE: xterm's+ * own handler runs first (via `attachCustomKeyEventHandler`), and by the time Canvas's bubble-phase+ * listener calls `preventDefault()` the control byte has already gone to the pty (on Linux/Windows+ * Ctrl+2..Ctrl+8 are `^@ ^[ ^\ ^] ^^ ^_`).+ *+ * It defaults to `false` = never swallow = the byte-identical pre-feature behavior, which is also+ * what the Server Edition wants: browsers reserve the chord, so nothing there can act on it.+ */+export function terminalKeyAction(+ e: CopyShortcutEvent,+ hasSelection: boolean,+ ownsProjectJump = false+): TerminalKeyAction {if (e.type === 'keydown' &&e.key === 'Enter' &&@@ -730,20 +744,6 @@ 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 &&- !e.shiftKey &&- DIGIT_SHORTCUT_RE.test(e.code)- )- return 'swallow'+ if (ownsProjectJump) return 'swallow'return copyKeyAction(e, hasSelection)}