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.

feat(keybindings): Ctrl+Tab / Ctrl+Shift+Tab cycle project tabs

review6a27f38de48c
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index f84574c90..514e50528 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -325,6 +325,7 @@ import {
waitingBeforeRestart
} from '../lib/nextNeedingYou'
import { liveProjectJumpTarget, projectJumpDigit } from '../lib/projectJump'
+import { adjacentProjectId } from '../lib/projectCycle'
import {
liveZoomShortcutAction,
liveZoomShortcutContext,
@@ -10531,6 +10532,26 @@ export function Canvas() {
return true
}, [switchProject])
+ // `project.next` / `project.prev` (Ctrl+Tab / Ctrl+Shift+Tab): Chrome-style cycling through the
+ // OPEN project tabs, wrapping at both ends. With the global swimlane kanban up it scrolls to
+ // the neighbouring swimlane instead, the same substitution the ⌘1-9 jump makes above.
+ const cycleProject = useCallback((dir: 1 | -1): boolean => {
+ const { projects, activeProjectId: current } = useProjects.getState()
+ const globalKanban = isGlobalKanbanOpen()
+ const from = globalKanban
+ ? useViewMode.getState().highlightedSwimlaneId ?? current
+ : current
+ const targetId = adjacentProjectId(projects, from, dir)
+ if (!targetId) return false
+ if (globalKanban) {
+ useViewMode.getState().setHighlightedSwimlaneId(targetId)
+ window.dispatchEvent(new CustomEvent('nodeterm:swimlane-jump', { detail: { projectId: targetId } }))
+ return true
+ }
+ switchProject(targetId)
+ return true
+ }, [switchProject])
+
const copyGesture = useCallback((e: GlobalKeyEvent): boolean => {
if (!((e.metaKey || e.ctrlKey) && !e.shiftKey && e.key.toLowerCase() === 'c')) return false
// Native text selection wins (markdown, editor and terminal keep their normal copy path).
@@ -10865,6 +10886,8 @@ export function Canvas() {
'panel.sourceControl': () => { setScOpen((v) => !v); return true },
'panel.sessions': () => { toggleSessionsPin(); return true },
'app.reopenLastClosed': reopenLastClosedCommand,
+ 'project.next': () => cycleProject(1),
+ 'project.prev': () => cycleProject(-1),
'canvas.undo': () => { undo(); return true },
'canvas.redo': () => { redo(); return true },
'canvas.goBack': () => { goBack(); return true },
diff --git a/src/renderer/lib/projectCycle.test.ts b/src/renderer/lib/projectCycle.test.ts
new file mode 100644
index 000000000..05d76c4ab
--- /dev/null
+++ b/src/renderer/lib/projectCycle.test.ts
@@ -0,0 +1,30 @@
+import { describe, expect, it } from 'vitest'
+import { adjacentProjectId } from './projectCycle'
+
+const P = [{ id: 'a' }, { id: 'b', closed: true }, { id: 'c' }, { id: 'd' }]
+
+describe('adjacentProjectId', () => {
+ it('steps forward and backward in tab order, skipping closed projects', () => {
+ expect(adjacentProjectId(P, 'a', 1)).toBe('c')
+ expect(adjacentProjectId(P, 'c', -1)).toBe('a')
+ expect(adjacentProjectId(P, 'c', 1)).toBe('d')
+ })
+
+ it('wraps at both ends', () => {
+ expect(adjacentProjectId(P, 'd', 1)).toBe('a')
+ expect(adjacentProjectId(P, 'a', -1)).toBe('d')
+ })
+
+ it('has nowhere to go with a single open project, or none', () => {
+ expect(adjacentProjectId([{ id: 'a' }, { id: 'b', closed: true }], 'a', 1)).toBeNull()
+ expect(adjacentProjectId([{ id: 'a' }], 'a', -1)).toBeNull()
+ expect(adjacentProjectId([], null, 1)).toBeNull()
+ expect(adjacentProjectId([{ id: 'b', closed: true }], 'b', 1)).toBeNull()
+ })
+
+ it('enters the strip from the matching end when the active id is not an open tab', () => {
+ expect(adjacentProjectId(P, null, 1)).toBe('a')
+ expect(adjacentProjectId(P, 'b', -1)).toBe('d')
+ expect(adjacentProjectId(P, 'gone', 1)).toBe('a')
+ })
+})
diff --git a/src/renderer/lib/projectCycle.ts b/src/renderer/lib/projectCycle.ts
new file mode 100644
index 000000000..76896d91d
--- /dev/null
+++ b/src/renderer/lib/projectCycle.ts
@@ -0,0 +1,23 @@
+/**
+ * PURE. The open project one step from `activeId` in tab-strip order (= store array order, with
+ * `closed` projects skipped because they have no tab), wrapping at both ends like a browser's
+ * Ctrl+Tab. Null means "nowhere to go": fewer than two open projects — the caller then leaves
+ * the key alone instead of claiming a chord it does nothing with.
+ *
+ * An `activeId` that is not an open tab (welcome screen, or the active project was just closed)
+ * enters the strip from the matching end: forward lands on the first tab, backward on the last.
+ */
+export function adjacentProjectId(
+ projects: readonly { id: string; closed?: boolean }[],
+ activeId: string | null | undefined,
+ dir: 1 | -1
+): string | null {
+ const open = projects.filter((p) => !p.closed)
+ const at = open.findIndex((p) => p.id === activeId)
+ if (at === -1) {
+ if (open.length === 0) return null
+ return (dir === 1 ? open[0] : open[open.length - 1]).id
+ }
+ if (open.length < 2) return null
+ return open[(at + dir + open.length) % open.length].id
+}
diff --git a/src/shared/keybindings.test.ts b/src/shared/keybindings.test.ts
index 33543f54c..ba3e9d184 100644
--- a/src/shared/keybindings.test.ts
+++ b/src/shared/keybindings.test.ts
@@ -92,6 +92,11 @@ describe('registry invariants', () => {
darwin: ['Cmd+Shift+L'], other: ['Cmd+Shift+L'], allowInTerminal: true },
{ id: 'app.reopenLastClosed', title: 'Reopen last closed', group: 'General', scope: 'app',
darwin: ['Cmd+Shift+T'], other: ['Cmd+Shift+T'], allowInTerminal: true },
+ { id: 'project.next', title: 'Next project tab', group: 'General', scope: 'app',
+ darwin: ['Ctrl+Tab'], other: ['Ctrl+Tab'], allowInTerminal: true, allowWhileTyping: true },
+ { id: 'project.prev', title: 'Previous project tab', group: 'General', scope: 'app',
+ darwin: ['Ctrl+Shift+Tab'], other: ['Ctrl+Shift+Tab'], allowInTerminal: true,
+ allowWhileTyping: true },
{ id: 'canvas.undo', title: 'Undo', group: 'Canvas', scope: 'canvas',
darwin: ['Cmd+Z'], other: ['Cmd+Z'] },
{ id: 'canvas.redo', title: 'Redo', group: 'Canvas', scope: 'canvas',
@@ -538,6 +543,22 @@ const ctx = (
})
describe('resolveCommandForKeyEvent', () => {
+ it('resolves Ctrl+Tab / Ctrl+Shift+Tab to the project-tab cycle from any focus, on both platforms', () => {
+ for (const isMac of [true, false]) {
+ for (const c of [ctx(), ctx({ terminal: true }), ctx({ typing: true }), ctx({ kanbanOpen: true })]) {
+ expect(resolveCommandForKeyEvent(ev({ ctrlKey: true, key: 'Tab' }), c, {}, isMac))
+ .toBe('project.next')
+ expect(resolveCommandForKeyEvent(ev({ ctrlKey: true, shiftKey: true, key: 'Tab' }), c, {}, isMac))
+ .toBe('project.prev')
+ }
+ }
+ // A bare Tab stays focus traversal, and terminal-first hands the chord back to the pane.
+ expect(resolveCommandForKeyEvent(ev({ key: 'Tab' }), ctx(), {}, true)).toBeNull()
+ expect(resolveCommandForKeyEvent(
+ ev({ ctrlKey: true, key: 'Tab' }), ctx({ terminal: true, terminalFirst: true }), {}, true
+ )).toBeNull()
+ })
+
it('matches a default app chord', () => {
expect(resolveCommandForKeyEvent(ev({ metaKey: true, key: 'k' }), ctx(), {}, true))
.toBe('app.commandPalette')
diff --git a/src/shared/keybindings.ts b/src/shared/keybindings.ts
index 0bd798f94..a9e468b3d 100644
--- a/src/shared/keybindings.ts
+++ b/src/shared/keybindings.ts
@@ -58,6 +58,8 @@ export type CommandId =
| 'panel.sourceControl'
| 'panel.sessions'
| 'app.reopenLastClosed'
+ | 'project.next'
+ | 'project.prev'
| 'canvas.undo'
| 'canvas.redo'
| 'canvas.goBack'
@@ -149,6 +151,16 @@ export const COMMAND_DEFINITIONS: readonly CommandDefinition[] = [
defaultBindings: both('Cmd+Shift+L'), allowInTerminal: true },
{ id: 'app.reopenLastClosed', title: 'Reopen last closed', group: 'General', scope: 'app',
defaultBindings: both('Cmd+Shift+T'), allowInTerminal: true },
+ // Chrome's tab-cycling chords, on the project tab strip. `Ctrl` is the LITERAL Control key on
+ // every platform (mac included — ⌘Tab is the OS app switcher), which is also what Chrome uses.
+ // allowWhileTyping + allowInTerminal: like the browser's, it switches from wherever focus is —
+ // Ctrl+Tab types nothing in an input and xterm has no use for it. A browser reserves both
+ // chords for its own tabs and never delivers them to the page, so in the Server Edition these
+ // only fire once rebound.
+ { id: 'project.next', title: 'Next project tab', group: 'General', scope: 'app',
+ defaultBindings: both('Ctrl+Tab'), allowInTerminal: true, allowWhileTyping: true },
+ { id: 'project.prev', title: 'Previous project tab', group: 'General', scope: 'app',
+ defaultBindings: both('Ctrl+Shift+Tab'), allowInTerminal: true, allowWhileTyping: true },
// Canvas — inert while the kanban board is open (scope 'canvas'), blocked while typing.
{ id: 'canvas.undo', title: 'Undo', group: 'Canvas', scope: 'canvas',