Skip to content

feat(shortcuts): add Ctrl+PageDown/Up to cycle terminal tabs only - #1094

Merged
AmethystLiang merged 4 commits into
stablyai:mainfrom
mvanhorn:feat/988-cycle-terminal-tabs-shortcut
Apr 26, 2026
Merged

AmethystLiang merged 4 commits into
stablyai:mainfrom
mvanhorn:feat/988-cycle-terminal-tabs-shortcut

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

Closes #988.

Adds a terminal-only tab cycle shortcut: Ctrl+PageDown (next terminal) / Ctrl+PageUp (previous terminal). Filters getActiveTabNavOrder to entries where type === 'terminal', so editor and browser tabs in between are skipped. The existing Cmd/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/Up matches Windows Terminal convention, is currently unused, and clears the documented Alt-rejection policy. The renderer-side handler explicitly guards !metaKey && !altKey && !shiftKey so:

  • macOS Cmd+PageUp/Down (OS desktop-switch) is not stolen
  • Ctrl+Shift+PageUp/Down stays available for terminal/editor consumers
  • behavior matches the unshifted predicate in browser-guest-ui.ts

Screenshots

Code change (handler logic + chord wiring across the five existing switchTab plumbing points):

Code change

Visible result: with terminals and other tabs interleaved, Ctrl+PageDown jumps 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 in useDiffCommentDecorator.tsx, 0 errors)
  • pnpm typecheck (all three configs)
  • pnpm test (240 files, 2719 tests pass)
  • pnpm build
  • Added src/renderer/src/hooks/ipc-tab-switch.test.ts with 7 cases:
    • skip non-terminal tabs when switching forward
    • wrap from last terminal to first
    • return false when no terminal tabs
    • return false when only terminal is already active
    • jump to first terminal when an editor is active
    • jump from editor to the only terminal (1 terminal, non-terminal focused)
    • return false when only one terminal and it is the active tab
  • Updated useIpcEvents.test.ts and browser-manager.test.ts for the new IPC channel + browser-webview re-fire

AI Review Report

Implementation by Codex (gpt-5.3-codex, medium reasoning). Two review passes via codex review:

  1. Round 1 caught that the renderer-side handler matched on shifted variants too, which would have stolen Ctrl+Shift+PageUp/Down from focused terminal/editor consumers. Added !e.shiftKey to the renderer guard so it matches the unshifted predicate already in browser-guest-ui.ts.
  2. Round 2 caught that the original terminalTabs.length <= 1 early 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 existing ui:switchTab convention, the browser-guest forwarding is gated by the same modifier check as the renderer-side handler, and the ShortcutsPane entries 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 existing Cmd/Ctrl+Alt+... carve-out namespace - it's a one-line change in three places.

This contribution was developed with AI assistance.

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]>

@AmethystLiang AmethystLiang left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@AmethystLiang

Copy link
Copy Markdown
Contributor

Filed the smart-scoped Cmd/Ctrl+Shift+]/[ follow-up as #1100. Keeping it out of this PR so the #988 work stays narrow and additive.

@nwparker nwparker added the size/m Medium PR (≤600 added lines, ≤25 files) label Apr 26, 2026
@AmethystLiang
AmethystLiang merged commit 555ab95 into stablyai:main Apr 26, 2026
2 of 3 checks passed
@mvanhorn

Copy link
Copy Markdown
Contributor Author

And thanks for getting this one in too.

AmethystLiang added a commit that referenced this pull request May 4, 2026
…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]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m Medium PR (≤600 added lines, ≤25 files)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Keyboard shortcut to cycle only through terminal tabs in the active workspace

3 participants