Skip to content

feat(shortcuts): cycle Cmd/Ctrl+Shift+]/[ within current tab type by default - #1281

Merged
AmethystLiang merged 4 commits into
stablyai:mainfrom
tmchow:feat/1100-tab-cycle-within-type
May 4, 2026
Merged

AmethystLiang merged 4 commits into
stablyai:mainfrom
tmchow:feat/1100-tab-cycle-within-type

Conversation

@tmchow

@tmchow tmchow commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes Cmd/Ctrl+Shift+] and Cmd/Ctrl+Shift+[ cycle within the active tab's type by default - terminal-focused chord cycles only terminals, editor-focused cycles only editor tabs, browser-focused cycles only browser tabs. Mirrors VS Code's Cmd+Shift+] mac behavior (gated on TerminalContextKeys.focus) and Superset's per-scope chord pattern referenced in the issue. The dedicated Ctrl+PageDown / Ctrl+PageUp chord shipped in #1094 stays terminal-only regardless of focus.

The cycling logic is extracted into a shared getNextTabWithinActiveType helper at src/renderer/src/components/terminal/tab-type-cycle.ts so both useTerminalShortcuts.ts (the in-pane chord) and ipc-tab-switch.ts (the broader IPC chord path) can route through one selector. useTerminalShortcuts gains optional activeBrowserTabId and onActivateBrowserTab parameters so browser tabs participate in the same path. When the active tab id is missing from the same-type subset (e.g. hydration race when an editor is active and the chord targets terminals), the helper falls back direction-aware: forward yields the first tab, backward yields the last. Browser-tab activation under the IPC path now also calls activateTab(next.tabId) so split-pane browser layouts re-render to the cycled tab, matching the editor branch.

Screenshots

No visual change to render. The behavior change is keyboard-handler logic: which tab gets focus on chord press.

Testing

  • pnpm lint (oxlint, 0 warnings, 0 errors)
  • pnpm typecheck (typecheck covers node + cli + web tsc)
  • pnpm test src/renderer (1269 / 1269 passed; new tab-type-cycle.test.ts covers single-type cycling, mixed-type no-op, single-tab no-op, group-tab disambiguation, and direction-aware fallback when the active id is stale)
  • pnpm build is unrelated to renderer logic and was not exercised here; pnpm test outside the renderer fails on this branch the same way it fails on main (better-sqlite3 ABI mismatch in main-process orchestration tests)
  • Added high-quality tests that would catch regressions: tests use real TypeCyclableTab shapes with mixed types and assert the exact returned tab, not implementation internals

AI Review Report

Reviewed in two passes against the existing chord and IPC paths:

  • Cross-platform: chord uses event.code === 'BracketRight' / 'BracketLeft' which is platform-symmetric (mac, Linux, Windows produce the same code on the same physical key). Confirmed by inspecting the existing in-source Why: comment that already explained this. No new platform branches added.
  • Sibling chord (Ctrl+PageDown / Ctrl+PageUp, terminal-only via handleSwitchTerminalTab from PR feat(shortcuts): add Ctrl+PageDown/Up to cycle terminal tabs only #1094) is dispatched separately and untouched. Confirmed by reading both branches in ipc-tab-switch.ts after the change.
  • Edge case found in Round 1: when findIndex returns -1 (active id missing from the same-type subset), backward navigation on 3+ same-type tabs landed on the second-to-last tab instead of the last. Fixed with a direction-aware fallback: -1 returns the last tab, +1 returns the first. New test added.
  • Edge case found in Round 2: in split browser layouts, the browser branch only called setActiveBrowserTab(next.id) while the editor branch called both setActiveFile and activateTab(next.tabId). The split pane is rendered from the owning group's activeTabId, so without the activateTab call the visible pane could fail to re-render to the cycled tab. Brought the browser branch in line with the editor branch.

Security Audit

No security-relevant surfaces. The change is renderer-only keyboard event handling and tab-state cycling. No input handling, command execution, path resolution, auth, secrets, or IPC privilege boundaries touched. Browser-tab cycling already runs inside the existing same-origin Electron renderer; no new cross-origin or sandbox boundary work.

Notes

The default-flip is the issue's recommended approach (the alternatives section explicitly rejects a tabCycleScope setting). If a maintainer prefers an opt-in instead, the helper's signature is already well-isolated for that variant: gate the call on a settings boolean and fall back to the previous cross-type rotation when off. Happy to repackage.

Closes #1100

Compound Engineering

tmchow added 2 commits April 30, 2026 01:12
…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
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.
@AmethystLiang

Copy link
Copy Markdown
Contributor

Thx for the PR. Reviewing it and will get it in today's release

@nwparker
nwparker requested a review from AmethystLiang May 2, 2026 01:54
@AmethystLiang

Copy link
Copy Markdown
Contributor

sorry got delayed on this... tmr!

@tmchow

tmchow commented May 2, 2026

Copy link
Copy Markdown
Contributor Author

sorry got delayed on this... tmr!

you tease

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

Copy link
Copy Markdown
Contributor

Pushed a follow-up commit adding Cmd/Ctrl+Alt+[/] as a companion chord that cycles across every visible tab in the active group regardless of type (terminal / editor / browser) — an escape hatch to the pre-scope "cycle through everything" behavior without needing a settings toggle.

Summary of the addition:

  • New ui:switchTabAcrossAllTypes IPC channel + preload binding
  • New getNextTabAcrossAllTypes util alongside the existing getNextTabWithinActiveType
  • Handled in the main-window keydown path (Terminal.tsx), the browser-guest shortcut forwarder (browser-guest-ui.ts), and exposed in the Shortcuts pane
  • Refactored ipc-tab-switch.ts to share setup/dispatch via resolveCycleContext and applyNextTab helpers so the two chords can't drift
  • Narrowed useTerminalShortcuts activeTabType to 'terminal' | 'editor' and dropped an unsound TypeCyclableTab cast (unifiedTabs never contains browsers)
  • Expanded tests for the new chord and the across-type cycle util

@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.

LGTM — tested locally, the new all-types cycle chord works as expected.

@AmethystLiang
AmethystLiang merged commit 201685b into stablyai:main May 4, 2026
@AmethystLiang

Copy link
Copy Markdown
Contributor

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make Cmd/Ctrl+Shift+]/[ cycle within the current tab type by default

2 participants