Skip to content

fix: sort numbered graph-switch shortcuts alphabetically - #824

Open
mvanhorn wants to merge 2 commits into
team-reflect:masterfrom
mvanhorn:fix/816-graph-switch-shortcuts
Open

fix: sort numbered graph-switch shortcuts alphabetically#824
mvanhorn wants to merge 2 commits into
team-reflect:masterfrom
mvanhorn:fix/816-graph-switch-shortcuts

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jul 15, 2026

Copy link
Copy Markdown

Summary

Command+1 through Command+9 now switch to graphs sorted alphabetically by graph name instead of following the most-recently-used ordering, so a given number maps to a predictable graph.

Why this matters

#816 reported that Command+1 / Command+2 graph switching behaved unpredictably. The shortcuts indexed into the graph list in MRU order, so every switch reordered the list and the number-to-graph mapping changed on each use. Pressing Command+2 twice could land on two different graphs.

What changed

  • Numbered graph slots are now ordered alphabetically by graph name (case-insensitive, root path as tiebreak) via sortGraphsByName in app-commands.ts, applied in app-shortcuts.ts.
  • Active-graph and out-of-range selections remain no-ops.
  • Regression coverage for the alphabetical ordering (app-commands.test.ts).

Testing

Targeted Vitest for the changed command module: 36 passed. Typecheck + oxlint clean.

Note

There is a separate, pre-existing collision between the Meta+digit graph shortcuts and the Meowdown heading shortcuts. That is out of scope for this fix and left unchanged; happy to file or address it separately if useful.

Closes #816

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The change adds alphabetical, case-insensitive ordering for recent graphs with root-path tie-breaking, tests the ordering helper, and updates graph-switching shortcuts to use the resulting graph-root order.

Changes

Alphabetical graph shortcut ordering

Layer / File(s) Summary
Graph order helper and tests
apps/desktop/src/lib/commands/app-commands.ts, apps/desktop/src/lib/commands/app-commands.test.ts
sortGraphsByName returns graph roots sorted by name, ignoring recency, with case-insensitive comparison and root-path tie-breaking; tests cover these cases.
Shortcut graph selection
apps/desktop/src/routing/app-shortcuts.ts
The shortcuts hook stores the sorted graph-root order and switches using the selected root, skipping missing or already-active graphs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The change makes graph-switch shortcuts choose a stable order and no-op on the active graph, matching the bug fix goals in #816.
Out of Scope Changes check ✅ Passed The edits are limited to the shortcut ordering fix and its tests, with no unrelated code paths introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: numbered graph-switch shortcuts are now sorted alphabetically.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@maccman

maccman commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Shall we just sort graphs alphabetically?

Per review: instead of keeping numbered graph slots (Cmd+1..9) in first-seen
order, sort them alphabetically by graph name so a given number maps to a
predictable graph. Case-insensitive with the root path as a stable tiebreak.
This also drops the first-seen reconciliation bookkeeping.
@mvanhorn

Copy link
Copy Markdown
Author

Good call - switched to sorting alphabetically by graph name in 166f923, so Cmd+1 maps to the alphabetically-first graph and so on. More predictable than first-seen order, and it let me drop the stable-order reconciliation entirely (net simpler). Tests + typecheck green. I'll update the PR title/description to match the alphabetical approach.

@mvanhorn mvanhorn changed the title fix: keep numbered graph-switch shortcuts in a stable order fix: sort numbered graph-switch shortcuts alphabetically Jul 15, 2026
@ocavue

ocavue commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Update: the repo reflect-open now only has one long-lived branch master. All open pull requests should target master instead of next now.

@mvanhorn
mvanhorn changed the base branch from next to master July 17, 2026 17:53
@mvanhorn

Copy link
Copy Markdown
Author

Thanks for the heads-up @ocavue — retargeted this PR to master.

Copilot AI 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.

Pull request overview

This PR makes Cmd+1 through Cmd+9 graph-switch shortcuts deterministic by mapping shortcut slots to graphs ordered alphabetically (case-insensitive) by graph name instead of MRU recents ordering, addressing the unpredictability described in #816.

Changes:

  • Added sortGraphsByName helper to compute stable alphabetical ordering for recent graphs (root path tiebreak).
  • Updated app shortcut handling to use the sorted ordering for numbered graph switching.
  • Added regression tests for the new sorting behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
apps/desktop/src/routing/app-shortcuts.ts Switches numbered graph shortcut selection from MRU order to alphabetical graph-name order via sortGraphsByName.
apps/desktop/src/lib/commands/app-commands.ts Introduces sortGraphsByName helper used to derive stable Cmd+1..9 graph slot ordering.
apps/desktop/src/lib/commands/app-commands.test.ts Adds unit tests verifying alphabetical, case-insensitive sorting with root-path tiebreak.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

generationRef.current = graph?.generation ?? null
graphRootRef.current = graph?.root ?? null
recentsRef.current = recents
graphOrderRef.current = sortGraphsByName(recents)
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.

Bug: Command+1 and Command+2 shortcuts to switch between graphs don't seem to work properly

4 participants