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(shortcut): filter closed projects from index, align ctrl-digit guards, add swallow tests

Mina Sameha262dff3f004
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 8796a9a5e..3948e9220 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -4661,10 +4661,18 @@ 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_SHORTCUT_RE.test(e.code)) {
+ } 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, n)
+ const targetId = projectIdAtIndex(
+ projects.filter((p) => !p.closed),
+ n
+ )
if (targetId && targetId !== activeProjectId) {
e.preventDefault()
switchProject(targetId)
diff --git a/src/renderer/terminal/terminal-config.test.ts b/src/renderer/terminal/terminal-config.test.ts
index 92cc7ccfe..6d98dfd04 100644
--- a/src/renderer/terminal/terminal-config.test.ts
+++ b/src/renderer/terminal/terminal-config.test.ts
@@ -530,6 +530,41 @@ describe('terminalKeyAction', () => {
it('exports the ESC+CR sequence', () => {
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(
+ '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')
+ })
+
+ 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('passes a Ctrl+Digit1 keyup through (only keydown swallows)', () => {
+ expect(
+ terminalKeyAction(ev({ key: '1', code: 'Digit1', ctrlKey: true, type: 'keyup' }), false)
+ ).toBe('pass')
+ })
})
describe('seedPaint', () => {
diff --git a/src/renderer/terminal/terminal-config.ts b/src/renderer/terminal/terminal-config.ts
index be3d04178..534493881 100644
--- a/src/renderer/terminal/terminal-config.ts
+++ b/src/renderer/terminal/terminal-config.ts
@@ -736,7 +736,14 @@ export function terminalKeyAction(e: CopyShortcutEvent, hasSelection: boolean):
// 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))
+ if (
+ e.type === 'keydown' &&
+ e.ctrlKey &&
+ !e.metaKey &&
+ !e.altKey &&
+ !e.shiftKey &&
+ DIGIT_SHORTCUT_RE.test(e.code)
+ )
return 'swallow'
return copyKeyAction(e, hasSelection)
}