Skip to content

feat: add keyboard shortcuts to switch between projects - #6834

Open
realitsyourman wants to merge 6 commits into
stablyai:mainfrom
realitsyourman:feat/project-switch-shortcuts
Open

realitsyourman wants to merge 6 commits into
stablyai:mainfrom
realitsyourman:feat/project-switch-shortcuts

Conversation

@realitsyourman

@realitsyourman realitsyourman commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds two remappable keyboard actions to switch directly between projects in the sidebar — project.navigateNext and project.navigatePrevious — mirroring the existing worktree navigation (worktree.navigateUp/Down). A "project" is a top-level sidebar section: a project group when grouped, or a repo when ungrouped. Switching activates that project's most-recently-focused worktree (same focus-recency rule as the Cmd+J palette), routed through the existing activateAndRevealWorktree helper so history and reveal behave exactly like worktree nav.

Both actions ship unbound by default and are remappable in Settings → Shortcuts. Every natural chord is already taken (Cmd+1–9, Cmd+Shift+↑/↓, Cmd/Ctrl+Shift+←/→ from #6135), so rather than claim a conflicting default we register the actions with no binding — happy to set a default (e.g. Cmd+Shift+[ / ]) if maintainers prefer; it's a one-line change. Closes #6674 (Phase 1).

project.selectByIndex (Cmd+number jump) from the issue is intentionally deferred to a follow-up — it needs the main-process digit-index IPC chain, separate from these renderer-only actions.

Screenshots

No visual change by default (both shortcuts ship unbound). New remappable rows appear under Settings → Shortcuts → Global as "Next project" / "Previous project".

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test (full keybinding/shortcut/sidebar regression: 1397 passed; new unit tests for the pure helpers)
  • pnpm build — not run in this environment; pnpm typecheck (3 tsgo projects) passes clean
  • Added high-quality tests: project-navigation.test.ts (9 cases: wrap up/down, no-active default, recency selection, empty→null, order/dedupe/null-skip/input-order) + a registry test asserting both actions ship unbound on all platforms and remap correctly

AI Review Report

Reviewed with an architect agent against the acceptance criteria plus correctness/optimality.

  • Main risks checked: the "project" identity (getGroupKeysForWorktree(...)[0]) being sound for grouped (incl. nested groups), ungrouped repos, and non-repo groupings; exact mirror of navigateWorktree's buildRows args; recency selection on a different project; React hook deps; regression to the existing worktree-nav handler.
  • Flagged (MEDIUM): project cycle order was derived from item rows, so pinned worktrees (emitted at the top of the row stream) could skew the order vs. the visible section headers when ≥2 distinct pinned projects appear in a contradicting pin order.
  • Changed as a result: extracted a pure buildProjectNavigationOrder and now drop the Pinned section's duplicate rows (sectionKey === PINNED_GROUP_KEY) before deriving order, so the cycle follows the visible sections. Each worktree still appears under its real section (the layout is fully expanded), so none are dropped. Added unit coverage for the derivation.
  • Cross-platform: actions ship unbound; platform-aware labels/accelerators are produced by the shared keybinding registry (⌘/⇧ on macOS, Ctrl+/Shift+ elsewhere) exactly like the sibling worktree actions — no hardcoded metaKey. No paths, shell, or Electron platform branches touched. lint:switch-exhaustiveness passes (no exhaustive switch over the action-id union was broken).

Security Audit

Low surface. Renderer-only navigation that reuses existing, already-trusted helpers (buildRows, getGroupKeysForWorktree, orderEmptyQueryWorktrees, activateAndRevealWorktree). No new input handling, no command execution, no path handling, no auth/secrets, and no new IPC (the IPC-bearing project.selectByIndex is deferred). The pure helpers do bounded array/Map work over in-memory sidebar state. No follow-up needed.

Notes

  • Phase 1 scope: next/previous only. project.selectByIndex deferred to a follow-up PR.
  • In non-repo groupings (workspace-status / pr-status / none) the action cycles the active grouping's top-level sections — a faithful mirror of navigateWorktree, which is itself grouping-agnostic. Can guard to groupBy === 'repo' if maintainers want "project" to always mean repo/project-group.
  • Default binding is deliberately omitted; suggest a default in review and I'll wire it.
  • Project order derives from the full projectGroups (same source as navigateWorktree), so the two navigators always agree. Under an active SSH/multi-host filter the nav order can differ slightly from the host-filtered visible layout — pre-existing and shared with worktree nav, considered and non-blocking.

Files: src/shared/keybindings.ts (+ union/definitions), src/shared/keybindings-unassigned-actions.test.ts, src/renderer/src/components/sidebar/worktree-list/navigation/use-keyboard.ts (handler + navigateProject), WorktreeList.tsx / viewport/VirtualizedWorktreeViewport.tsx / viewport/viewport-props.ts (navigation-scope prop plumbing), and new src/renderer/src/components/sidebar/project-navigation.ts (+ test).

Folder workspaces are included in the cycle and activate through activateAndRevealFolderWorkspace. See the readiness verdict comment for the current gate results, Windows proof, and live-app capture.

ELI5

New keyboard shortcuts jump to the next or previous project section in the sidebar, similar to worktree up/down. Focus goes to that project’s most recently used worktree.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8658e395-547d-48a4-81d4-4d961a84720c

📥 Commits

Reviewing files that changed from the base of the PR and between 3d74f5f and 43045ee.

📒 Files selected for processing (8)
  • src/renderer/src/components/sidebar/WorktreeList.tsx
  • src/renderer/src/components/sidebar/project-navigation.test.ts
  • src/renderer/src/components/sidebar/project-navigation.ts
  • src/renderer/src/components/sidebar/worktree-list/navigation/use-keyboard.ts
  • src/renderer/src/components/sidebar/worktree-list/viewport/VirtualizedWorktreeViewport.tsx
  • src/renderer/src/components/sidebar/worktree-list/viewport/viewport-props.ts
  • src/shared/keybindings-unassigned-actions.test.ts
  • src/shared/keybindings.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/renderer/src/components/sidebar/WorktreeList.tsx
  • src/renderer/src/components/sidebar/project-navigation.test.ts
  • src/shared/keybindings.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

Adds project-level sidebar navigation with next and previous keybinding actions. The new navigation model resolves project groups, orders projects and worktrees, removes duplicate host-qualified identities, and selects targets with wrap-around and visit recency. Sidebar keyboard handling activates and reveals worktrees or folder workspaces. The viewport now receives the required navigation data. Tests cover traversal, ordering, grouping, host identity, filtering, cycle handling, and keybinding metadata.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements the required next/previous project actions, ordering, recent-worktree activation, global registration, and platform-aware remapping for [#6674].
Out of Scope Changes check ✅ Passed The changes remain within [#6674], covering navigation logic, keybindings, integration, and tests without unrelated functionality.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Title check ✅ Passed The title clearly summarizes the main change: adding keyboard shortcuts to switch between projects.
Description check ✅ Passed The description clearly covers the change, rationale, linked issue, testing, scope, risks, and deferred work, with only minor template deviations.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3936ddf2-4df8-4a64-821e-aceb18bf2601

📥 Commits

Reviewing files that changed from the base of the PR and between 30fc485 and 958b2952b0d917c7cf05b3f9dc19c753e1de4093.

📒 Files selected for processing (5)
  • src/renderer/src/components/sidebar/WorktreeList.tsx
  • src/renderer/src/components/sidebar/project-navigation.test.ts
  • src/renderer/src/components/sidebar/project-navigation.ts
  • src/shared/keybindings.test.ts
  • src/shared/keybindings.ts

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/components/sidebar/WorktreeList.tsx (1)

2433-2454: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use the same host-filtered project groups for project navigation.

Rendered rows use visibleProjectGroupsForRows, but navigateProject rebuilds order and folder ancestors from unfiltered projectGroups. Under a host filter, a visible child group whose parent is filtered out renders as its own top-level sidebar project, while keyboard navigation can collapse it under the hidden parent key/order.

Proposed fix
 type VirtualizedWorktreeViewportProps = {
   folderWorkspaces: readonly FolderWorkspace[]
   /** Host-filtered folder workspaces, mirroring the rendered rows, for project nav. */
   visibleFolderWorkspacesForRows: readonly FolderWorkspace[]
+  visibleProjectGroupsForRows: readonly ProjectGroup[]
   selectedWorktreeIds: ReadonlySet<string>
   folderWorkspaces,
   visibleFolderWorkspacesForRows,
+  visibleProjectGroupsForRows,
   selectedWorktreeIds,
-        projectGroups,
+        visibleProjectGroupsForRows,
         new Set(),
         new Map(),
       const parentGroupIdById = new Map(
-        projectGroups.map((group) => [group.id, group.parentGroupId ?? null])
+        visibleProjectGroupsForRows.map((group) => [group.id, group.parentGroupId ?? null])
       )
-                projectGroups,
+                visibleProjectGroupsForRows,
                 projectGrouping
       projectGroups,
       projectGrouping,
+      visibleProjectGroupsForRows,
       visibleFolderWorkspacesForRows,
       lastVisitedAtByWorktreeId
         folderWorkspaces={folderWorkspaces}
         visibleFolderWorkspacesForRows={visibleFolderWorkspacesForRows}
+        visibleProjectGroupsForRows={visibleProjectGroupsForRows}
         selectedWorktreeIds={selectedWorktreeIds}

Also applies to: 2470-2479, 2535-2538, 6827-6827


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3248f95b-2a77-4a9e-9611-f88f475624a7

📥 Commits

Reviewing files that changed from the base of the PR and between 958b2952b0d917c7cf05b3f9dc19c753e1de4093 and 2902fae42f8d821b3742aa04fb69a412282f1494.

📒 Files selected for processing (3)
  • src/renderer/src/components/sidebar/WorktreeList.tsx
  • src/renderer/src/components/sidebar/project-navigation.test.ts
  • src/renderer/src/components/sidebar/project-navigation.ts

@AmethystLiang AmethystLiang assigned OrcaWin and unassigned Jinwoo-H Jul 20, 2026
@AmethystLiang
AmethystLiang requested review from OrcaWin and removed request for Jinwoo-H July 20, 2026 18:42
@nwparker nwparker added the enhancement New feature or request label Jul 27, 2026
realitsyourman and others added 3 commits August 23, 2026 16:14
Add remappable project.navigateNext / project.navigatePrevious actions that
cycle to the next/previous top-level sidebar project (project group when
grouped, repo when ungrouped) and activate that project's most-recently-
focused worktree, mirroring the existing worktree navigation.

Both ship unbound by default and are assignable in Settings > Shortcuts;
every natural chord is already taken, so no default is claimed.

Phase 1 of stablyai#6674; project.selectByIndex is deferred to a follow-up.
Folder-workspace-only projects were dropped from the project switch cycle:
navigateProject only processed worktree rows and never passed folder
workspaces to buildRows. Thread the host-filtered folder workspaces through
buildRows and convert folder-workspace rows into navigation entries via
folderWorkspaceToWorktree, so they share the worktree recency/activation id
and dispatch to activateAndRevealFolderWorkspace.

Use the host-filtered folder list (not the raw store list) so navigation
never lands on a workspace hidden by the active host filter; worktrees are
already host-filtered upstream.

Extract resolveTopLevelProjectGroupId as a tested pure helper.

Addresses review feedback on stablyai#6834.
@nwparker
nwparker force-pushed the feat/project-switch-shortcuts branch from 2902fae to 43045ee Compare August 23, 2026 23:25
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nwparker

Copy link
Copy Markdown
Contributor

Readiness verdict: READY (P0: 0, P1: 0, P2: 0 open)

Reviewed at 003eed38759 against the readiness checklist. Renderer-only sidebar navigation + two remappable keybinding actions; no IPC, no persistence, no shell, no network.

Residual issue found and fixed in this pass

selectProjectNavigationTarget degraded into worktree navigation when only one project is visible. With a single top-level section (one repo, or groupBy: 'none' where the only header is ALL_GROUP_KEY), (currentIndex + 1) % 1 wraps back onto the active project, and orderEmptyQueryWorktrees excludes the current workspace — so "Next project" silently switched to a different worktree inside the same project. Now the wrap-onto-self case returns the active workspace (reveal/scroll only). src/renderer/src/components/sidebar/project-navigation.ts + a regression test asserting both directions hold at b1.

Real Windows shortcut behavior — proof

Both actions ship unbound on all three platforms and the platform split is produced entirely by the shared registry — no hardcoded metaKey anywhere in the diff. The renderer resolves the platform at keydown time via getShortcutPlatform() (navigator.userAgent → darwin / win32 / linux), so a Windows build takes the Ctrl branch. Executed assertions:

✓ ships unbound on every platform                                   (win32 / linux / darwin → [])
✓ resolves Mod to Ctrl on win32 and to Cmd on darwin
    Ctrl+Alt+K  → win32  matches   |  Cmd+Alt+K → win32  does NOT match
    Cmd+Alt+K   → darwin matches   |  Ctrl+Alt+K → darwin does NOT match
    Ctrl+Alt+K  → linux  matches
✓ renders Windows labels as Ctrl/Alt, not the mac glyphs
    win32 label : ["Ctrl","Alt","K"]
    linux label : ["Ctrl","Alt","K"]
    darwin label: ["⌘","⌥","K"]

The win32 half of this is committed as a permanent regression test in src/shared/keybindings-unassigned-actions.test.ts (keeps project navigation unassigned until users customize it), which asserts getEffectiveKeybindingsForAction(..., 'win32') === [] and that a Ctrl+Alt chord matches on win32 while the same Mod+ override matches Cmd+Alt on darwin.

Cross-platform checklist items with no surface in this diff: file paths, child processes, shells/PTYs, WSL argv, process enumeration, native modules, line endings.

Live app proof (macOS dev build, real store: 13 repos / 464 worktrees)

New remappable rows render under Settings → Shortcuts → Global, directly beneath "Next worktree", both unbound:

settings-shortcuts-project-rows.png

With Mod+Alt+K / Mod+Alt+J assigned through the normal remap path and groupBy: 'repo', the chord moves the active workspace across project sections and back:

start   test ssh              repo 0c7a6532 (orca)
next#1  main                  repo 1bee363e (projects-orca-repro)
next#2  test ssh              repo 0c7a6532 (orca)
next#3  main                  repo 1bee363e (projects-orca-repro)
prev#1  test ssh              repo 0c7a6532 (orca)
prev#2  main                  repo 1bee363e (projects-orca-repro)

Before (main selected under projects-orca-repro) → after one ⌘⌥K (test ssh selected under orca):

nav-A-projects-orca-repro.png

nav-B-orca.png

Note the target is test ssh, not the project's first row main — the focus-recency rule (orderEmptyQueryWorktrees) picking the most-recently-focused workspace in the destination project. Bindings and groupBy were reset to their defaults afterward.

Checklist coverage

# Area Result
01 SSH / remote / network N/A + verified. No RPC, stream frame, or published content changes → no wire-compat surface. Host identity is respected end to end: order keys on getWorktreeHostIdentity, getActiveProjectKey composes host+id with a bare-id fallback, and orderEmptyQueryWorktrees filters via isPaletteCurrentWorktree (STA-4343 host-aware). Covered by keeps same-id worktrees on different hosts distinct.
02 Crash / cast / retry / unbounded growth Clean. No JSON.parse, no !, no retry loop, no timer. Every allocation is per-keypress and GC'd. All three graph walks are cycle-fenced by a Set: resolveTopLevelProjectGroupId (seen), getGroupKeysForWorktree (visited), buildProjectNavigationOrder (seenProjectKeys). terminates on a cyclic parent chain covers it. Two as unknown as Worktree casts are test-fixture-only.
03 Security / supply chain Clean. No deps, no lockfile change, no shell/eval, no secrets, no network sink, no new IPC.
04 Performance Acceptable. buildSidebarProjectNavigationOrder is O(rows + worktrees + folderWorkspaces) and runs only inside the handler after a bound chord matches — not on render and not on every keystroke. Both actions are unbound by default, so the default-config cost is exactly two keybindingMatchesAction calls per keydown, matching the existing worktree-nav path. The useEffect listener churn from navigateProject's deps mirrors the pre-existing navigateWorktree deps; no new re-render source.
05 Functional correctness Verified (see fix above). Project identity is getGroupKeysForWorktree(...)[0] — outermost project group when grouped, repo:<id> when not, including the missing-group-metadata fallback that buildRows itself renders as top-level. Nav order is derived from the rendered header rows, so it always agrees with the visible layout; the Pinned section is dropped so pin order can't skew the cycle, and duplicate host-scoped headers dedupe. Folder workspaces route through activateAndRevealFolderWorkspace via parseWorkspaceKey, and their activeWorktreeId shape matches getActiveSidebarWorkspaceId. Navigation consumes the same visibleScope.visibleProjectGroupsForRows / visibleFolderWorkspacesForRows the rows are built from, so a host filter can't desync the two. Provider-neutral — no GitHub/GitLab surface touched.
06 Back-compat / data loss Clean. No schema, migration, cache, or persisted-state change. The two new action ids are additive; existing keybindings.json files are unaffected and both actions read as unassigned on upgrade and on rollback (an unknown action id is simply ignored). No mobile-facing surface touched.
07 Cross-platform & remoting Verified — see the Windows section above.

Gates run at 003eed38759

Gate Result
pnpm typecheck (3 tsgo projects) ✅ pass
pnpm lint (oxlint + native/type-aware quality, reliability gates, max-lines ratchet, runtime-electron ratchet, skill guides/manifest, 4× localization verifiers) ✅ pass
project-navigation.test.ts ✅ 20/20
keybindings-unassigned-actions.test.ts ✅ pass
Windows/platform proof above ✅ 3/3
Sidebar + keybindings suites in isolation ✅ pass
Full src/renderer/.../sidebar + src/shared/keybindings in one pool ⚠️ see below
pnpm build not run (unchanged from the original PR note)

The one caveat, stated plainly: running all 277 sidebar test files in a single local vitest pool produced 3, then 11, then 16 failed files across three runs — a different set each time, and every single failure was Error: Test timed out / Hook timed out, zero assertion failures. The affected files (WorktreeCard.*, WorktreeList.lineage*) are untouched by this PR. Re-running the representative failures in isolation: 5 files / 60 tests, all pass in 18s. This is local-machine saturation on heavyweight React component tests, not a regression from this change — CI shards these.

Summary

The change is ready. It adds two remappable, unbound-by-default global actions that cycle the sidebar's top-level project sections and activate each project's most-recently-focused workspace, reusing the existing activateAndRevealWorktree / activateAndRevealFolderWorkspace helpers. Nothing here touches persistence, IPC, the remote wire, Git, or process spawning, so the blast radius is one keydown handler and a pure ordering module.

Reviewing it surfaced exactly one real defect — with a single visible project, "Next project" wrapped onto itself and switched worktrees instead of doing nothing — which is fixed at 003eed38759 with a regression test. Windows behavior is real and proven, not assumed: the actions ship unbound on win32, a Mod+ override resolves to Ctrl there and Cmd on macOS, and the shortcut chips render Ctrl/Alt rather than ⌘/⌥. Live-app capture confirms the shortcut crosses project boundaries in both directions and lands on the recency-correct workspace.

Action required before release: none. The only open item is CI on the shared runner queue, which is external to this change.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Keyboard shortcut to switch directly between projects

4 participants