feat(sidebar): add ⌘B shortcut to collapse/expand sidebar by waleedlatif1 · Pull Request #5047 · simstudioai/sim
Summary
- Added
⌘B(Ctrl+B on Windows) global shortcut to collapse/expand the workspace sidebar - Registered as a first-class entry in the central command registry (
collapse-sidebar,Mod+B) - Surfaced the shortcut in the collapse button's tooltip via the existing
Tooltip.Shortcut, platform-aware (⌘ vs Ctrl)
Type of Change
- New feature
Testing
Tested manually — ⌘B toggles the sidebar from anywhere in the workspace; tooltip shows the shortcut.
Checklist
- Code follows project style guidelines
- Self-reviewed my changes
- Tests added/updated and passing
- No new warnings introduced
- I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
The latest updates on your projects. Learn more about Vercel for GitHub.
PR Summary
Low Risk
UI-only keyboard shortcut and tooltip wiring; no auth, data, or API changes. Mod+B may overlap with browser bold in some contexts, but the command is disabled in editable fields.
Overview
Adds a workspace-wide Mod+B (collapse-sidebar) global command that toggles sidebar collapse via the existing sidebar store, with allowInEditable: false so it does not fire while typing in inputs.
Introduces formatCommandShortcut in the command registry so tooltip labels stay aligned with registered bindings (macOS symbols vs Ctrl+ labels elsewhere). The collapse control and collapsed Expand sidebar affordance show that shortcut through Tooltip.Shortcut.
SidebarTooltip gains an optional shortcut prop for the same pattern on the collapse button.
Reviewed by Cursor Bugbot for commit 97d8c98. Configure here.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 64d4dd0. Configure here.
Greptile Summary
This PR wires up a ⌘B / Ctrl+B global shortcut to toggle the workspace sidebar. The shortcut is registered as collapse-sidebar in the central command registry with allowInEditable: false (preventing conflicts with native bold in text editors), and a new formatCommandShortcut helper derives the display string from the registry so tooltips can never drift from the bound key.
commands-utils.ts: Adds thecollapse-sidebarcommand definition andformatCommandShortcut, which tokenises anyMod+…shortcut string and renders platform-correct symbols (⌘BvsCtrl+B).sidebar.tsx: Registers the command handler, computescollapseShortcutonce per render, and passes it to both the collapse-buttonSidebarTooltipand theWorkspaceHeaderexpand affordance.workspace-header.tsx: The collapsed-state expand button is now wrapped in aTooltip.Roottree and accepts an optionalexpandShortcutprop, completing the discoverability story for both sidebar states.
Confidence Score: 5/5
Safe to merge — the change is additive, touches only sidebar toggling and tooltip display, and correctly guards the shortcut from editable surfaces.
All three files make narrow, well-scoped additions: the new command entry, a pure helper function, and two tooltip wrappers. The allowInEditable: false guard prevents any input/textarea interference. The formatCommandShortcut helper derives its output directly from the registry, eliminating tooltip/binding drift. No state management, data paths, or API routes are affected.
No files require special attention.
Important Files Changed
| Filename | Overview |
|---|---|
| apps/sim/app/workspace/[workspaceId]/utils/commands-utils.ts | Adds collapse-sidebar command definition with allowInEditable: false and a new formatCommandShortcut helper that derives display strings from the registry — no drift risk, correct tokenisation for Mod+B. |
| apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx | Wraps the collapsed-state expand button in Tooltip.Root/Trigger/Content with an optional expandShortcut prop; falls back gracefully to plain text when the prop is absent. |
| apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx | Registers the collapse-sidebar global command, derives collapseShortcut via formatCommandShortcut, and threads it through both the collapse-button SidebarTooltip and the WorkspaceHeader expand affordance. |
Sequence Diagram
sequenceDiagram
participant User
participant GlobalCommandsProvider
participant SidebarStore
participant Sidebar
participant WorkspaceHeader
User->>GlobalCommandsProvider: keydown ⌘B / Ctrl+B
Note over GlobalCommandsProvider: allowInEditable: false<br/>skips inputs/textareas
GlobalCommandsProvider->>SidebarStore: toggleCollapsed()
SidebarStore-->>Sidebar: isCollapsed state change
alt Sidebar expanding (was collapsed)
Sidebar->>WorkspaceHeader: "isCollapsed=false"
WorkspaceHeader-->>User: Full sidebar visible, collapse tooltip shows ⌘B
else Sidebar collapsing (was open)
Sidebar->>WorkspaceHeader: "isCollapsed=true, expandShortcut=⌘B"
WorkspaceHeader-->>User: Collapsed expand button, tooltip shows ⌘B
end
Reviews (4): Last reviewed commit: "improvement(sidebar): address review — s..." | Re-trigger Greptile
Greptile Summary
This PR registers ⌘B / Ctrl+B as a global shortcut to collapse/expand the workspace sidebar, wires it through the central COMMAND_DEFINITIONS registry, and surfaces a platform-aware key hint in the collapse button's tooltip via Tooltip.Shortcut.
collapse-sidebaris added toCOMMAND_DEFINITIONSwithshortcut: 'Mod+B'andallowInEditable: true; the sidebar registers a handler that callstoggleCollapsed().SidebarTooltipgains an optionalshortcutprop that switches from a plain<p>to aTooltip.Shortcutwhen provided; the collapse button passesisMac ? '⌘B' : 'Ctrl+B'.- The shortcut hint is only surfaced on the collapse button (sidebar open state); the expand path in
WorkspaceHeaderdoes not carry the hint, leaving a discoverability gap for users who first see the collapsed sidebar.
Confidence Score: 4/5
Safe to merge; the changes are small and self-contained, with no effect on data or auth. The main practical risk is Mod+B being intercepted in text inputs/contenteditable elements, which could break bold formatting if rich-text editors exist in the workspace.
The implementation is clean and consistent with how other global shortcuts are wired. The allowInEditable: true on Mod+B is the one decision that could cause unexpected behavior: the capture-phase listener calls preventDefault() unconditionally, so any future (or existing) rich-text editor would silently lose its bold shortcut. The tooltip string is also hardcoded rather than derived from the registry, which is a minor drift risk. Neither concern is blocking, but the allowInEditable choice is worth deliberate confirmation from the team.
commands-utils.ts — specifically the allowInEditable: true decision for collapse-sidebar deserves a second look before merging.
Important Files Changed
| Filename | Overview |
|---|---|
| apps/sim/app/workspace/[workspaceId]/utils/commands-utils.ts | Adds collapse-sidebar to the CommandId union and registers it with shortcut Mod+B and allowInEditable: true. The choice of Mod+B (Bold) with allowInEditable: true is the one aspect worth scrutinising given the capture-phase interceptor in the provider. |
| apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx | Wires the collapse-sidebar global command to toggleCollapsed(), adds an optional shortcut prop to SidebarTooltip, and surfaces the platform-aware key hint on the collapse button. Hardcoded display string doesn't derive from COMMAND_DEFINITIONS, creating a potential drift risk. |
Sequence Diagram
sequenceDiagram
participant User
participant GlobalCommandsProvider
participant Sidebar
User->>GlobalCommandsProvider: keydown ⌘B / Ctrl+B (capture phase)
GlobalCommandsProvider->>GlobalCommandsProvider: matchesShortcut("collapse-sidebar")
GlobalCommandsProvider->>GlobalCommandsProvider: e.preventDefault() + e.stopPropagation()
GlobalCommandsProvider->>Sidebar: handler() → toggleCollapsed()
Sidebar->>Sidebar: isCollapsed state flipped
Note over User,Sidebar: Tooltip path (sidebar expanded)
User->>Sidebar: hover collapse button
Sidebar->>User: SidebarTooltip shows "Collapse sidebar ⌘B"
Reviews (2): Last reviewed commit: "feat(sidebar): add ⌘B shortcut to collap..." | Re-trigger Greptile
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 97d8c98. Configure here.
