Repository navigation
feat(shortcuts): add Ctrl+PageDown/Up to cycle terminal tabs only - #1094
Conversation
Closes stablyai#988. Adds 'Next/Previous terminal tab' shortcut bound to Ctrl+PageDown / Ctrl+PageUp. Cycles through terminal tabs in the active worktree, skipping editor and browser tabs (the existing Cmd/Ctrl+Shift+]/[ chord still cycles all tab types). Mirrors the existing handleSwitchTab plumbing: - new handleSwitchTerminalTab in ipc-tab-switch.ts that filters getActiveTabNavOrder to entries where type === 'terminal' - new ui:switchTerminalTab IPC channel (preload + api-types + useIpcEvents) - direct keydown handler in Terminal.tsx (xterm focus path) - before-input-event re-fire in browser-guest-ui.ts (browser webview focus path) - discoverable entries in ShortcutsPane.tsx Chord choice per the issue's analysis: Ctrl+PageDown/Up matches Windows Terminal convention, is currently unused in Orca, and clears the src/shared/window-shortcut-policy.ts:40-51 Alt rejection. The handler explicitly guards !metaKey && !altKey so macOS Cmd+PageDown (the OS desktop-switch chord) is not intercepted.
Address codex review: the Terminal.tsx handler for Ctrl+PageDown/Up matched on shifted variants too, which would steal Ctrl+Shift+PageUp/Down from focused terminal/editor consumers. Add !e.shiftKey to the guard, matching the unshifted predicate already in browser-guest-ui.ts and the chord advertised in ShortcutsPane.
Address codex review (round 2). The 'no-op when terminalTabs.length <= 1' guard skipped the legitimate case of 'one terminal exists, but an editor or browser is currently focused' - the chord did nothing instead of jumping to that single terminal, defeating the whole point of the shortcut. Narrow the no-op to the only true case: zero terminals, or the only terminal already focused. Add tests for both edges.
preventDefault on the window-capture listener does not block xterm's own keydown listener, which translates Ctrl+PageUp/PageDown into \e[5~ / \e[6~ and writes them to the shell (and trips the terminal activity indicator). Stop propagation so the event never reaches the focused terminal. Co-authored-by: Orca <[email protected]>
There was a problem hiding this comment.
Approving. One fix needed during manual testing (already pushed to this branch as fea28635), plus a design suggestion for a follow-up PR.
Fix pushed: Ctrl+PageUp/Down was leaking ^[[5~/^[[6~ into focused xterm
Repro: open 2+ terminal tabs, focus one, press Ctrl+PageDown. The tab switch works, but the previously-focused shell also receives the PageUp/PageDown xterm escape sequence (5~ / 6~ visible in the prompt), and the "terminal activity" bell lights up on every terminal cycled through.
Root cause: the window-capture keydown handler calls e.preventDefault(), but xterm.js attaches its own keydown listener on the terminal's textarea that translates Ctrl+PageUp/PageDown into those escape sequences before writing them to the PTY. preventDefault() on the window-capture listener does not stop xterm's listener on a descendant node — we also need to stop propagation.
This doesn't hit the existing Cmd/Ctrl+Shift+]/[ path because xterm ignores Meta-modified keys by default, so the bug is specific to this PR's chord.
Applied in fea28635 — adds e.stopPropagation() and e.stopImmediatePropagation() alongside preventDefault() in the Terminal.tsx handler. Verified locally that this stops the escape-sequence leak and the bell-on-cycle side effect.
Everything else in the PR looks good — clean scope, good tests, comments call out the "why" correctly.
Follow-up worth considering (separate PR)
Prior art (VS Code terminalActions.ts:528-562) suggests a broader improvement: make Cmd/Ctrl+Shift+]/[ smart-scoped — cycle within the current tab's type (terminal→terminals, editor→editors, browser→browsers) instead of across all types. Almost every "next tab" press in practice means "next tab of the kind I'm looking at." Filed as #1100 so this PR can stay narrow.
|
And thanks for getting this one in too. |
…default (#1281) * feat(shortcuts): cycle Cmd/Ctrl+Shift+]/[ within current tab type by default Extract a shared getNextTabWithinActiveType selector into a new tab-type-cycle.ts helper and route both useTerminalShortcuts.ts and ipc-tab-switch.ts through it. Cmd/Ctrl+Shift+]/[ now cycles within the active tab's type (terminal cycles only terminals, editor cycles only editor tabs, browser cycles only browser tabs). Ctrl+PageDown/Up remains the dedicated terminal-only chord (PR #1094) regardless of focus. useTerminalShortcuts gains optional activeBrowserTabId and onActivateBrowserTab parameters so browser tabs can dispatch through the same path. The default behavior matches VS Code's TerminalContextKeys.focus-gated cycling and Superset's per-scope chord registry referenced in the issue. Adds tab-type-cycle.test.ts covering single-type, mixed-type, and single-tab no-op cases. ipc-tab-switch.test.ts updated to assert same-type cycling under the new selector. Closes #1100 * fix(shortcuts): use direction-aware fallback when active tab is missing When the active tab id is not present in the same-type subset (e.g. during hydration when an editor is active and Cmd+Shift+]/[ targets terminals), findIndex returns -1 and the previous modulo math made backward navigation land on the second-to-last tab instead of the last. Branch on the -1 case to return the last tab for direction=-1 and the first tab for direction=+1, so both directions are predictable. Adds a regression test covering 3 terminal tabs with no active match. * feat(shortcuts): add Cmd/Ctrl+Alt+[/] to cycle across all tab types Adds an "all types" variant of the tab cycle chord so users can page through every tab in the active group regardless of type (terminal / editor / browser), complementing the type-scoped Cmd/Ctrl+Shift+[/]. - Wires the chord through the main-window keydown handler, the browser guest shortcut forwarder, and a new ui:switchTabAcrossAllTypes IPC channel - Factors getNextTabAcrossAllTypes alongside getNextTabWithinActiveType and shares the ipc-tab-switch dispatch logic via resolveCycleContext and applyNextTab helpers to avoid drift between the two chords - Narrows useTerminalShortcuts activeTabType to 'terminal' | 'editor' (the hook's unifiedTabs never contains browsers) and drops the unsound TypeCyclableTab cast - Updates ShortcutsPane to list the new chord and expands tests Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Jinjing <[email protected]> Co-authored-by: Orca <[email protected]>
…ablyai#1094) Co-authored-by: Orca <[email protected]> Co-authored-by: Matt Van Horn <[email protected]> Co-authored-by: Jinjing <[email protected]>
…default (stablyai#1281) * feat(shortcuts): cycle Cmd/Ctrl+Shift+]/[ within current tab type by default Extract a shared getNextTabWithinActiveType selector into a new tab-type-cycle.ts helper and route both useTerminalShortcuts.ts and ipc-tab-switch.ts through it. Cmd/Ctrl+Shift+]/[ now cycles within the active tab's type (terminal cycles only terminals, editor cycles only editor tabs, browser cycles only browser tabs). Ctrl+PageDown/Up remains the dedicated terminal-only chord (PR stablyai#1094) regardless of focus. useTerminalShortcuts gains optional activeBrowserTabId and onActivateBrowserTab parameters so browser tabs can dispatch through the same path. The default behavior matches VS Code's TerminalContextKeys.focus-gated cycling and Superset's per-scope chord registry referenced in the issue. Adds tab-type-cycle.test.ts covering single-type, mixed-type, and single-tab no-op cases. ipc-tab-switch.test.ts updated to assert same-type cycling under the new selector. Closes stablyai#1100 * fix(shortcuts): use direction-aware fallback when active tab is missing When the active tab id is not present in the same-type subset (e.g. during hydration when an editor is active and Cmd+Shift+]/[ targets terminals), findIndex returns -1 and the previous modulo math made backward navigation land on the second-to-last tab instead of the last. Branch on the -1 case to return the last tab for direction=-1 and the first tab for direction=+1, so both directions are predictable. Adds a regression test covering 3 terminal tabs with no active match. * feat(shortcuts): add Cmd/Ctrl+Alt+[/] to cycle across all tab types Adds an "all types" variant of the tab cycle chord so users can page through every tab in the active group regardless of type (terminal / editor / browser), complementing the type-scoped Cmd/Ctrl+Shift+[/]. - Wires the chord through the main-window keydown handler, the browser guest shortcut forwarder, and a new ui:switchTabAcrossAllTypes IPC channel - Factors getNextTabAcrossAllTypes alongside getNextTabWithinActiveType and shares the ipc-tab-switch dispatch logic via resolveCycleContext and applyNextTab helpers to avoid drift between the two chords - Narrows useTerminalShortcuts activeTabType to 'terminal' | 'editor' (the hook's unifiedTabs never contains browsers) and drops the unsound TypeCyclableTab cast - Updates ShortcutsPane to list the new chord and expands tests Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Jinjing <[email protected]> Co-authored-by: Orca <[email protected]>
Summary
Closes #988.
Adds a terminal-only tab cycle shortcut:
Ctrl+PageDown(next terminal) /Ctrl+PageUp(previous terminal). FiltersgetActiveTabNavOrderto entries wheretype === 'terminal', so editor and browser tabs in between are skipped. The existingCmd/Ctrl+Shift+]/[chord still cycles all tab types.The chord choice follows the issue's analysis at
src/shared/window-shortcut-policy.ts:40-51:Ctrl+PageDown/Upmatches Windows Terminal convention, is currently unused, and clears the documented Alt-rejection policy. The renderer-side handler explicitly guards!metaKey && !altKey && !shiftKeyso:Cmd+PageUp/Down(OS desktop-switch) is not stolenCtrl+Shift+PageUp/Downstays available for terminal/editor consumersbrowser-guest-ui.tsScreenshots
Code change (handler logic + chord wiring across the five existing switchTab plumbing points):
Visible result: with terminals and other tabs interleaved,
Ctrl+PageDownjumps directly between terminals. From editor or browser focus, the chord jumps to the nearest forward terminal - including the case where exactly one terminal exists (the chord still jumps to it; only no-ops when zero terminals exist or the only terminal is already focused).Testing
pnpm lint(2 pre-existing warnings inuseDiffCommentDecorator.tsx, 0 errors)pnpm typecheck(all three configs)pnpm test(240 files, 2719 tests pass)pnpm buildsrc/renderer/src/hooks/ipc-tab-switch.test.tswith 7 cases:useIpcEvents.test.tsandbrowser-manager.test.tsfor the new IPC channel + browser-webview re-fireAI Review Report
Implementation by Codex (gpt-5.3-codex, medium reasoning). Two review passes via
codex review:Ctrl+Shift+PageUp/Downfrom focused terminal/editor consumers. Added!e.shiftKeyto the renderer guard so it matches the unshifted predicate already inbrowser-guest-ui.ts.terminalTabs.length <= 1early return was too aggressive: with one terminal and an editor/browser focused, the chord would no-op instead of jumping to that one terminal - defeating the whole point of the shortcut. Narrowed the no-op to two cases: zero terminals, or the only terminal already focused. Added two tests for the edge.Self-review then verified: the
Cmd/Ctrl+Shift+]/[plumbing is unchanged, the new IPC channel name follows the existingui:switchTabconvention, the browser-guest forwarding is gated by the same modifier check as the renderer-side handler, and theShortcutsPaneentries appear under the existing Tabs group with platform-aware key labels.Happy to switch to
Cmd/Ctrl+Alt+]/[(option 2 from the issue) if you would prefer to keep terminal-tab cycling under the existingCmd/Ctrl+Alt+...carve-out namespace - it's a one-line change in three places.This contribution was developed with AI assistance.