Skip to content

feat(shortcuts): make Select Tab/Workspace 1–9 remappable - #5789

Merged
nwparker merged 2 commits into
mainfrom
nwparker/sta-590-feature-remappable-keyboard-shortcuts-fo
Jun 19, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/sta-590-feature-remappable-keyboard-shortcuts-fo

Conversation

@nwparker

@nwparker nwparker commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #5741

What

Exposes Select Tab 1–9 and Select Workspace 1–9 as remappable shortcuts in Settings → Shortcuts. Previously both chords were hardcoded in window-shortcut-policy.ts and had no entry in the Shortcuts UI, so there was no way to remap them (the original ask in #5741: "I'd like to swap them, but there's no way to remap those shortcuts today").

Approach

Each range is modeled as a single remappable row (matching the cmux "Select Surface 1…9" reference in the issue), not 18 per-digit rows. The stored chord is a representative whose digit is canonicalized to 1, but it fires for any of 1–9. This makes the headline use case — swapping the tab/workspace modifiers — a 2-rebind operation instead of 18.

  • New registry actions tab.selectByIndex and workspace.selectByIndex in src/shared/keybindings.ts, with a digit-agnostic matcher (matchKeybindingDigitIndex) and digit canonicalization wired into the shared validation chokepoints (capture, save, and on-disk keybindings.json parsing).
  • window-shortcut-policy.ts now resolves these via the registry (honoring user overrides + the terminal-shortcut policy), replacing the hardcoded digit blocks.
  • The two actions intentionally share no conflictGroup (they live in different scopes), so swapping their modifiers is never blocked as a false conflict; runtime stays deterministic because the workspace range is checked first.
  • ShortcutBindingRow renders the representative chord's trailing cap as the full 1–9 range.

Defaults reproduce existing behavior exactly:

macOS Windows/Linux
Select Workspace 1–9 ⌘1–9 Ctrl+1–9
Select Tab 1–9 ⌃1–9 Alt+1–9

Testing

  • Full unit suite: 18,4xx passed, 0 failed (incl. new coverage for default ranges per platform, custom/swapped bindings, digit canonicalization, conflict behavior, and terminal-context gating).
  • Typecheck (node/web/cli), oxlint + switch-exhaustiveness, and localization checks all pass.
  • Verified live in a dev Electron build — both rows render with correct labels, and recording a chord persists the canonicalized override. Screenshot in a comment below.

Made with Orca 🐋


Open in Stage

Expose Select Tab 1-9 and Select Workspace 1-9 as single remappable rows in
Settings -> Shortcuts. Previously both chords were hardcoded in
window-shortcut-policy.ts and absent from the Shortcuts UI.

Each is modeled as one ranged action whose stored chord is a representative
(digit canonicalized to 1) that fires for any of 1-9, mirroring the cmux
single-row UX. Defaults reproduce existing behavior (mac: tab Ctrl+1-9,
workspace Cmd+1-9; win/linux: tab Alt+1-9, workspace Ctrl+1-9). Swapping the
two modifiers - the headline use case - works without a false conflict.

Co-authored-by: Orca <[email protected]>
@ghost

ghost commented Jun 19, 2026 •

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 6 individual chapters for you:

Title
1 Define digit-index action IDs and types
2 Implement digit-index normalization and matching logic
3 Register remappable actions with default bindings
4 Refactor shortcut policy to use registry
5 Update UI to display digit ranges
6 Verify digit-index logic and policy changes
Open in Stage

Chapters generated by Stage for commit 5b8f7b4 on Jun 19, 2026 9:29am UTC.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

An error occurred during the review process. Please try again later.

📝 Walkthrough

Walkthrough

Two new keybinding action IDs—workspace.selectByIndex and tab.selectByIndex—are added to the KeybindingActionId union and registered in KEYBINDING_DEFINITIONS with platform-specific Mod+1 representative defaults. A digit-index registry (DIGIT_INDEX_ACTION_IDS, isDigitIndexActionId) is introduced, with normalization and capture logic that canonicalizes any modifier+digit(1–9) chord to a digit-1 representative. A new matchKeybindingDigitIndex function rewrites candidate bindings to the pressed digit at runtime and returns a 0-based index. resolveWindowShortcutAction in the window shortcut policy is refactored to use this matcher with workspace-first precedence, replacing removed implicit digit-gating helpers. getWindowShortcutActionId and windowShortcutActionCapturesTerminal are updated accordingly. The settings UI ShortcutBindingRow gains a toDigitRangeKeys helper to render digit-index bindings as a 1–9 range. Tests are added for all new behaviors.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description covers the what/why, approach, testing, and defaults. However, it lacks required template sections: Screenshots, AI Review Report, Security Audit, and explicit cross-platform verification checklist. Add Screenshots section (or 'No visual change' if applicable), AI Review Report with cross-platform checks, Security Audit section, and Notes on platform-specific behavior per the template.
Docstring Coverage ⚠️ Warning Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: making Select Tab/Workspace 1–9 shortcuts remappable, which aligns with the primary objective of the changeset.
Linked Issues check ✅ Passed The PR successfully implements the key requirements from #5741: exposing Select Tab/Workspace 1–9 as remappable shortcuts in the Shortcuts UI, matching the cmux reference implementation approach with single-row digit ranges.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing remappable digit-index keybindings: keybinding definitions, normalization/validation, UI rendering, and window-shortcut policy. No unrelated refactoring or scope creep detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@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

🧹 Nitpick comments (1)
src/shared/window-shortcut-policy.test.ts (1)

107-145: ⚡ Quick win

Move this new digit-index coverage out of the max-lines-disabled file.

The assertions look good, but this separable block grows a file that already relies on the max-lines disable at Line 1. Please move the digit-index policy cases into a focused companion test file instead. As per coding guidelines, “Never add a max-lines disable comment ... Split the file, extract focused modules, move fixtures/builders into named files, or otherwise reduce the counted lines instead.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fb766487-8492-4628-8cfa-d0a5f5a5a5a5

📥 Commits

Reviewing files that changed from the base of the PR and between b5b018c and aee7ef9.

📒 Files selected for processing (5)
  • src/renderer/src/components/settings/ShortcutBindingRow.tsx
  • src/shared/keybindings.test.ts
  • src/shared/keybindings.ts
  • src/shared/window-shortcut-policy.test.ts
  • src/shared/window-shortcut-policy.ts

Comment thread src/shared/keybindings.ts
Comment on lines 1323 to +1340
export function normalizeKeybindingListForAction(
actionId: KeybindingActionId,
input: string
): KeybindingValidationResult | string[] {
return normalizeKeybindingListWithOptions(input, normalizeOptionsForAction(actionId))
return finalizeDigitIndexBindings(
actionId,
normalizeKeybindingListWithOptions(input, normalizeOptionsForAction(actionId))
)
}

export function normalizeKeybindingArrayForAction(
actionId: KeybindingActionId,
input: readonly string[]
): KeybindingValidationResult | string[] {
return normalizeKeybindingArrayWithOptions(input, normalizeOptionsForAction(actionId))
return finalizeDigitIndexBindings(
actionId,
normalizeKeybindingArrayWithOptions(input, normalizeOptionsForAction(actionId))
)

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Canonicalize digit-index overrides at the effective-binding boundary.

These helpers canonicalize explicit normalization calls, but effective override arrays can still flow through the generic override path before matchKeybindingDigitIndex, settings display, and conflict detection consume them. A persisted/programmatic override like ['Ctrl+5'] would fire for Ctrl+1–Ctrl+9, while other consumers may still display/key it as Ctrl+5. Consider ensuring getEffectiveKeybindingsForAction also applies digit-index canonicalization for these action ids.

@nwparker

nwparker commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Verified in a dev Electron build

Settings → Shortcuts now lists both ranges as single, inline-remappable rows — Select Workspace 1–9 (⌘1–9, under Global) and Select Tab 1–9 (⌃1–9, under Tab Navigation) — as the linked issue requests. Recording a new chord persists the canonicalized override; the defaults shown here reproduce today's behavior.

Select Tab / Select Workspace 1–9 as remappable rows in Settings → Shortcuts

- Canonicalize digit-index overrides in getEffectiveKeybindingsForAction so
  display/conflict detection stay consistent regardless of stored digit.
- Use a shared DIGIT_INDEX_KEY_PATTERN regex instead of string comparison.
- Document that extra modifiers (e.g. Shift) are allowed on digit-index chords
  and that the matcher honors terminal-context gating.
- Clarify the workspace-first precedence comment.
- Add tests: Shift modifier, physical-code fallback matching, both ranges disabled.

Co-authored-by: Orca <[email protected]>
@nwparker
nwparker merged commit d855c69 into main Jun 19, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
)

* feat(shortcuts): make Select Tab/Workspace 1-9 remappable (stablyai#5741)

Expose Select Tab 1-9 and Select Workspace 1-9 as single remappable rows in
Settings -> Shortcuts. Previously both chords were hardcoded in
window-shortcut-policy.ts and absent from the Shortcuts UI.

Each is modeled as one ranged action whose stored chord is a representative
(digit canonicalized to 1) that fires for any of 1-9, mirroring the cmux
single-row UX. Defaults reproduce existing behavior (mac: tab Ctrl+1-9,
workspace Cmd+1-9; win/linux: tab Alt+1-9, workspace Ctrl+1-9). Swapping the
two modifiers - the headline use case - works without a false conflict.

Co-authored-by: Orca <[email protected]>

* refactor(shortcuts): tighten digit-index review nits

- Canonicalize digit-index overrides in getEffectiveKeybindingsForAction so
  display/conflict detection stay consistent regardless of stored digit.
- Use a shared DIGIT_INDEX_KEY_PATTERN regex instead of string comparison.
- Document that extra modifiers (e.g. Shift) are allowed on digit-index chords
  and that the matcher honors terminal-context gating.
- Clarify the workspace-first precedence comment.
- Add tests: Shift modifier, physical-code fallback matching, both ranges disabled.

Co-authored-by: Orca <[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.

[Feature]: Remappable keyboard shortcuts for Select Tab 1–9 and Select Workspace 1–9

1 participant