Skip to content

feat(sidebar): show Cmd/Ctrl+1-9 index badges on workspace cards - #16083

Open
BinyaminEden wants to merge 2 commits into
stablyai:mainfrom
BinyaminEden:cmd-number-badges
Open

BinyaminEden wants to merge 2 commits into
stablyai:mainfrom
BinyaminEden:cmd-number-badges

Conversation

@BinyaminEden

Copy link
Copy Markdown

What

Hold ⌘ (Ctrl on Windows/Linux) and each of the first nine workspace cards in the sidebar overlays the digit that jumps to it — the way Safari numbers tabs. Release the key, or move focus off the window, and the badges go away.

Before this, workspace.selectByIndex ("Select Workspace 1–9") was invisible: nothing told you which card a given number would land on.

How the numbering stays honest

The jump handler resolves its target from the row order the sidebar publishes through setVisibleWorktreeShortcutTargets. The badges read the row keys out of that same walk (getRenderedWorktreeEntriesInSidebarOrder) instead of a second copy, so a badge can never label a card the chord would not activate. Pinned-row de-duping, folder workspaces, grouping and lineage nesting all follow from that one function.

Badges stay hidden whenever the chord would not act:

  • outside the terminal view — the handler returns early there
  • while Cmd+J is open — the digits address palette rows then
  • when the user has unbound the action

Cross-platform

The armed modifiers come from the user's effective binding, not a hardcoded metaKey: getDigitIndexModifierChords() resolves Mod to Meta on darwin and Control elsewhere, and honours overrides — remap the row to Ctrl+Shift+1 and the badges arm on that chord instead.

A 400 ms hold delay keeps ordinary chords (⌘C, ⌘S) from strobing the sidebar.

Files

File Change
src/shared/keybindings.ts new getDigitIndexModifierChords() + chord equality helper
src/renderer/src/components/sidebar/workspace-index-shortcut-badges.ts hold detection and the row-key → digit map
src/renderer/src/components/sidebar/WorkspaceShortcutIndexBadge.tsx the chip, built on ShortcutKeyCombo with sidebar tokens
worktree-sidebar-row-preference.ts order walk now also reports row keys
item-row.tsx, folder-row.tsx, virtual-row-context.ts, VirtualizedWorktreeViewport.tsx wiring

Test plan

  • pnpm typecheck and pnpm lint pass (lint covers the max-lines ratchet, localization and code-quality audits).
  • vitest src/renderer/src/components/sidebar src/shared/keybindings — 276 files / 2386 tests pass, including two new cases: the row-key entries walk, and the platform/override resolution of the armed modifiers.
  • Full suite: 13 files fail in src/main/claude-accounts, src/main/skills, src/relay (keychain / filesystem / subprocess). Nothing in this diff reaches those areas, but I did not confirm they fail on a clean tree.

Not done: no rendered check in the running app — badge placement (card top-right) and light/dark contrast are reasoned from the tokens, not seen. Worth an eye during review.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SdXFcR11WcqQXiSRo4Jj1G

Hold the workspace.selectByIndex modifiers (Cmd on Mac, Ctrl elsewhere) and
each of the first nine sidebar cards overlays the digit that jumps to it, the
way Safari numbers tabs. Release, or move focus off the window, and they go.

The digits come from getRenderedWorktreeEntriesInSidebarOrder — the same row
walk the sidebar publishes as the shortcut's target cache — so a badge can
never label a card the chord would not activate. Badges stay hidden outside
the terminal view and while Cmd+J owns the digits, matching the handler.

The armed modifiers are read from the user's effective binding rather than
hardcoded, so a remapped or unbound row is reflected. A 400ms hold delay keeps
ordinary chords (Cmd+C, Cmd+S) from strobing the sidebar.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SdXFcR11WcqQXiSRo4Jj1G
@coderabbitai

coderabbitai Bot commented Aug 23, 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: cb97772b-84e2-46dd-a842-a93866f91bb8

📥 Commits

Reviewing files that changed from the base of the PR and between e8fcc41 and bc21b48.

📒 Files selected for processing (2)
  • src/shared/keybindings-digit-index.test.ts
  • src/shared/keybindings.ts

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


📝 Walkthrough

Walkthrough

The change adds platform-aware modifier-chord utilities for workspace digit shortcuts. It preserves sidebar row keys during rendered worktree ordering. New hooks track held shortcut chords and map visible rows to digits 1–9. The virtualized sidebar passes this map through row contexts. Item and folder workspace rows render accessibility-hidden shortcut badges when an index is available. Tests cover modifier resolution and rendered row ordering.

Merge Risk: 🟡 Moderate · up to bc21b

The new badges can advertise a custom Shift+digit workspace shortcut that does not activate on macOS, potentially misleading users and preventing the indicated workspace from being selected. Merge readiness is moderate until this is corrected or explicitly accepted.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the implementation and testing, but it omits required ELI5, Linked Issue, Visual Proof, and checklist sections. Add the missing template sections, link the issue, attach before-and-after visual proof, and complete the required checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: Cmd/Ctrl+1–9 badges on workspace cards in the sidebar.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 00e1f61d-f2b2-45aa-9181-0f76e57a75d9

📥 Commits

Reviewing files that changed from the base of the PR and between c3a1694 and e8fcc41.

📒 Files selected for processing (10)
  • src/renderer/src/components/sidebar/WorkspaceShortcutIndexBadge.tsx
  • src/renderer/src/components/sidebar/workspace-index-shortcut-badges.ts
  • src/renderer/src/components/sidebar/worktree-list/rows/folder-row.tsx
  • src/renderer/src/components/sidebar/worktree-list/rows/item-row.tsx
  • src/renderer/src/components/sidebar/worktree-list/viewport/VirtualizedWorktreeViewport.tsx
  • src/renderer/src/components/sidebar/worktree-list/viewport/virtual-row-context.ts
  • src/renderer/src/components/sidebar/worktree-sidebar-row-preference.test.ts
  • src/renderer/src/components/sidebar/worktree-sidebar-row-preference.ts
  • src/shared/keybindings-digit-index.test.ts
  • src/shared/keybindings.ts

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

Comment thread src/shared/keybindings.ts Resolved
canonicalizeDigitIndexBinding accepts a bare "1" — the settings UI rejects it,
but a hand-edited keybindings.json reaches getDigitIndexModifierChords with no
modifier at all. The resulting empty chord matched every ordinary keystroke, so
the badges would appear mid-typing and stay until a modifier or a blur.

Skip empty chords. Also drop the Shift+digit example from the test: macOS
reports '!' rather than '1' for Shift+1, so matchKeybindingDigitIndex cannot
match a Shift binding today and this must not claim it can.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SdXFcR11WcqQXiSRo4Jj1G
@luw2007

luw2007 commented Sep 8, 2026

Copy link
Copy Markdown

Strong support for this interaction. I hit a real discoverability problem with Select Workspace 1–9: pinned workspaces are visually prominent at the top of the sidebar, but there is currently no reliable way to tell which visible cards own the number shortcuts. Showing the effective digits only while the configured modifier chord is held is lightweight and makes the existing behavior learnable without adding permanent sidebar noise.

The strongest invariant here is the one this PR is built around: the badge and activation target must come from the same rendered-row walk, including grouping, collapsed sections, folder workspaces, and sidebar-open/closed behavior. That is consistent with #9497 / #10693.

One pinned-row detail seems worth making explicit before merge: when showPinnedWorktreesInGroups creates two rendered copies, I would expect the first visible occurrence—the card in the Pinned section—to own the digit, with the natural-group duplicate de-duplicated. Otherwise users can see a pinned card above workspace 1 that owns no number, which breaks the spatial “count cards top-to-bottom” model. This should not block the core badge UX; it is exactly the sort of ambiguity the badges help expose.

The branch currently reports conflicts with main; a rebase appears to be the remaining prerequisite for review.

@luw2007

luw2007 commented Sep 10, 2026

Copy link
Copy Markdown

Follow-up to my pinned-row note above: I implemented the pinned-first shortcut behavior downstream and found an important coupling in the current API. getRenderedWorktreesInSidebarOrder() also supplies renderedWorktreeIdentities for Shift-click range selection. Changing that shared function to first-visible/pinned-first makes a Shift-click on the natural-group duplicate calculate its range from the pinned-section copy, selecting unrelated rows between the two positions.

So this PR does not currently introduce that regression—its getRenderedWorktreeEntriesInSidebarOrder() still uses getPreferredWorktreeRows() and therefore labels the natural copy. But if the pinned-first behavior requested in #7198 / my earlier comment is added while rebasing, it should use a separate shortcut-specific row walk rather than changing the selection ordering function.

Suggested split:

  • getRenderedWorktreesInSidebarOrder(rows, policy): retain natural-row preference for multi-selection/range selection.
  • getShortcutWorktreeEntriesInSidebarOrder(rows): scan rendered rows top-to-bottom, first host-qualified identity wins; use this for setVisibleWorktreeShortcutTargets, closed-sidebar shortcut reconstruction, and this PR's badge rowKey -> digit map.

That preserves both invariants: the Pinned card owns the earliest visible digit, while Shift-clicking its natural-group duplicate uses the natural row position. A focused regression should anchor after the natural duplicate, Shift-click that duplicate, and assert that rows between the Pinned section and natural group are not selected.

The PR is still CONFLICTING / DIRTY, so this separation can be folded into the required rebase.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants