Repository navigation
feat(web): add shift+t keyboard shortcut for theme toggle - #331
Conversation
|
@SinghAstra is attempting to deploy a commit to the MagicAPI Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan includes up to 1 review per rolling hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe theme-toggle command now registers ChangesTheme Toggle Shortcut
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized keyboard-shortcut change adds and documents theme toggling with a unit test; no actionable merge-blocking risk remains in the supplied evidence. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai review |
|
imshashank
left a comment
There was a problem hiding this comment.
Thanks for picking this up unprompted. #130 had sat for a week and you found it and fixed it without being asked, which is exactly the contribution pattern I want, and the shape of the change is right: one binding, one doc update, one test.
There is one real problem, and it is not quite the one Greptile described.
Shift+D is already taken, and the theme toggle wins
apps/web/src/features/issues/issue-properties.tsx:107 already binds shift+d to the due date menu, and the UI advertises it: <PropertyRow label="Due date" shortcut="shift+d">.
Greptile said the theme shortcut would not reliably fire on issue pages. I checked against the real registry and it is the other way round, which is worse. Both entries register at priority: 0. The issue one passes scope: 'issues' but no priority, so it falls back to HOTKEY_PRIORITY.global. In beats() the two are identical on all three tiebreakers: one step each, same priority, one shift each. So beats returns false, selectMatch keeps whichever it saw first, and that is the command palette's entry, because the palette mounts with the shell before any issue page exists.
I ran it against HotkeyRegistry and selectMatch directly rather than reasoning about it:
WINNER: Switch theme / palette-theme
So after this change, pressing Shift+D on an issue detail page toggles the theme and the due date menu no longer opens. An existing, advertised, documented shortcut stops working, and nothing in the test suite notices.
Suggested fix
Use shift+t. I inventoried every binding in the app and it is free:
useHotkey: ] a alt+shift+f alt+v escape f i j k l m p s shift+d shift+e shift+f shift+j shift+k
palette: ? [ g a g d g i g m g p g r g s g t g v
aliases: up down shift+up shift+down
It is mnemonic for theme, it does not collide, and g t is a two step sequence so it does not interfere. Swap the binding, update the docs row, and this is done.
If you would rather keep shift+d for the theme, that is a bigger conversation: it would mean deliberately taking a key off the issue surface and rebinding due date, and I would want that argued on its own rather than as a side effect.
Smaller things
Three minor items inline. None of them are blocking on their own.
Once the binding changes, this is a quick approve from me. Sorry you waited a day on it, the answer turned out to be one word.
| label: context.dark ? 'Switch to light theme' : 'Switch to dark theme', | ||
| section: 'View', | ||
| icon: context.dark ? Sun : Moon, | ||
| binding: 'shift+d', |
There was a problem hiding this comment.
This is the collision. issue-properties.tsx:107 already registers shift+d for the due date menu, and issue-properties.tsx:277 advertises it in the UI as the due date shortcut.
Both register at HOTKEY_PRIORITY.global, because the issue one sets scope: 'issues' but never sets priority, and scope does not participate in beats(). With equal step count, equal priority and equal shift specificity, beats() returns false and selectMatch keeps the first entry it encountered. The palette registers on shell mount, before any issue page, so the theme command wins and the due date shortcut silently stops opening its menu.
I confirmed this against the real HotkeyRegistry rather than reading it off the rules: registering both and calling selectMatch returns Switch theme / palette-theme.
shift+t is free and mnemonic. Changing this one line and the docs row fixes it.
Worth noting for future work: the registry silently resolves a tie rather than complaining about it, which is how this got past review. A duplicate binding check in the registry, or a test that asserts no two advertised entries share a binding, would catch the next one automatically. That is out of scope here, and I will open an issue for it.
| const commands = buildCommands(context); | ||
| const themeCommand = commands.find((cmd) => cmd.id === 'view:theme'); | ||
| expect(themeCommand).toBeDefined(); | ||
| expect(themeCommand?.binding).toBe('shift+d'); |
There was a problem hiding this comment.
This asserts the metadata rather than the behaviour, so it passes whether or not the shortcut actually works. It would have passed unchanged with the collision in place, which is the definition of a test that cannot fail for the thing it is meant to protect.
What would earn its keep: build a HotkeyRegistry, register the palette command alongside a scope: 'issues' entry on the same key, and assert selectMatch picks the one you intend. That is the assertion that breaks the day somebody adds a third shift+t.
The fixture construction here is good, and CommandContext being explicit rather than cast is the right instinct.
|
|
||
| The theme toggle has no key of its own. Run it from the command palette. | ||
| | <kbd>]</kbd> | Toggle the right panel | | ||
| | <kbd>Shift</kbd> <kbd>D</kbd> | Switch between light and dark theme | |
There was a problem hiding this comment.
Two things in this file.
The row is correct once the binding moves, so it just needs Shift T instead.
More importantly, this file now contradicts itself. Line 149, in the "Adding one" section, uses useHotkey('shift+d', duplicateIssue, ...) as the worked example for registering a shortcut. So the same document tells a reader that Shift+D is the theme toggle and, thirty lines later, that it is duplicate issue. Whichever key this lands on, please pick a key for that example that is not bound to anything real, so the example cannot go stale again.
Also a stray edit: line 119 picked up two trailing spaces after Toggle the right panel. Worth dropping before merge, since trailing whitespace in a table cell is invisible in review and shows up in the next diff that touches the line.
|
Opened #332 for the underlying gap, since the registry resolving a tie silently is what let this through review rather than anything you did. Tagged |
Binds shift+d to the view:theme command to allow toggling light and dark mode without opening the command palette. Updates shortcut documentation and adds a unit test asserting the binding. Closes Noveum#130
458130a to
4ef6d85
Compare
|
Pushed the fix!
Good catch on selectMatch! I see you opened #332 for the underlying architecture fix, so I kept this PR strictly to the Theme toggle shortcut to stay in scope. |
imshashank
left a comment
There was a problem hiding this comment.
All three addressed, and the docs example fix is the one I care most about: moving that snippet to shift+z means the worked example is no longer describing a key that is really bound to something else, so it cannot drift into a real conflict again. I checked shift+z against the full binding inventory and it is free.
Verified locally: shift+t does not collide with anything, apps/web typechecks clean, and tests/lib/navigation.test.ts is 6 pass 0 fail.
On my second comment, the one asking for a registry level test rather than a metadata assertion: you have effectively answered it in #334 by testing the registry directly, which is the better place for it. Keeping the metadata assertion here is fine, since what this PR owns is the choice of key rather than the resolution behaviour.
Thanks for turning this around quickly, and for finding the issue yourself in the first place.
|
Green now. The Merging this. Thanks for the fix and for the follow up in #334. |
Resolves #130. I noticed this issue had been open without a linked PR for a week, so I went ahead and put the fix together to help clear out the backlog!
Binds shift+d to the view:theme command in navigation.ts.
Updates the View table in docs/keyboard-shortcuts.md.
Adds a unit test in navigation.test.ts asserting the binding.
bun test apps/web/tests/lib/navigation.test.ts is fully green.
Greptile Summary
The PR adds a global Shift+T shortcut for toggling the theme and keeps its test coverage and keyboard-shortcut documentation aligned.
shift+ton the existingview:themecommand.Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
shift+tbinding to the existing theme command.Reviews (4): Last reviewed commit: "Merge branch 'main' into feat/130-theme-..." | Re-trigger Greptile
Context used: