feat(desktop): show hotkey shortcuts in preset dropdown#991
Conversation
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughAdds UI rendering of per-preset hotkey shortcuts by introducing a PresetMenuItemShortcut in GroupStrip and exporting PRESET_HOTKEY_IDS from the preset-hotkeys hook; also tweaks a divider style and alignment of the default preset star icon. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/GroupStrip/GroupStrip.tsx`:
- Around line 51-60: PresetMenuItemShortcut currently calls useHotkeyText even
when PRESET_HOTKEY_IDS[index] is undefined for indices >8; change the logic so
you first read const hotkeyId = PRESET_HOTKEY_IDS[index] and if (!hotkeyId)
return null before calling useHotkeyText, then only call const hotkeyText =
useHotkeyText(hotkeyId) and guard the "Unassigned" value after that; also
consider extracting PresetMenuItemShortcut into its own file to follow the
one-component-per-file guideline and import it where needed (references:
PresetMenuItemShortcut, PRESET_HOTKEY_IDS, useHotkeyText, DropdownMenuShortcut).
| function PresetMenuItemShortcut({ index }: { index: number }) { | ||
| const hotkeyId = PRESET_HOTKEY_IDS[index]; | ||
| const hotkeyText = useHotkeyText(hotkeyId); | ||
|
|
||
| if (!hotkeyId || hotkeyText === "Unassigned") { | ||
| return null; | ||
| } | ||
|
|
||
| return <DropdownMenuShortcut>{hotkeyText}</DropdownMenuShortcut>; | ||
| } |
There was a problem hiding this comment.
Guard against out‑of‑range preset indices before calling useHotkeyText.
For presets beyond index 8, PRESET_HOTKEY_IDS[index] is undefined but the hook is still called, which can lead to runtime errors or undefined lookups. Also, consider extracting PresetMenuItemShortcut to its own file to comply with the one‑component‑per‑file guideline. As per coding guidelines, ...
🔧 Proposed fix
-function PresetMenuItemShortcut({ index }: { index: number }) {
- const hotkeyId = PRESET_HOTKEY_IDS[index];
- const hotkeyText = useHotkeyText(hotkeyId);
-
- if (!hotkeyId || hotkeyText === "Unassigned") {
- return null;
- }
-
- return <DropdownMenuShortcut>{hotkeyText}</DropdownMenuShortcut>;
-}
+function PresetMenuItemShortcut({ hotkeyId }: { hotkeyId: HotkeyId }) {
+ const hotkeyText = useHotkeyText(hotkeyId);
+
+ if (hotkeyText === "Unassigned") {
+ return null;
+ }
+
+ return <DropdownMenuShortcut>{hotkeyText}</DropdownMenuShortcut>;
+} {presets.map((preset, index) => {
const presetIcon = getPresetIcon(preset.name, isDark);
+ const presetHotkeyId = PRESET_HOTKEY_IDS[index];
return (
<DropdownMenuItem
key={preset.id}
onClick={() => handleSelectPreset(preset)}
className="gap-2"
>
@@
{preset.isDefault && (
<HiStar className="size-3 text-yellow-500 flex-shrink-0" />
)}
- <PresetMenuItemShortcut index={index} />
+ {presetHotkeyId && (
+ <PresetMenuItemShortcut hotkeyId={presetHotkeyId} />
+ )}
</DropdownMenuItem>
);
})}Also applies to: 260-284
🤖 Prompt for AI Agents
In
`@apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/GroupStrip/GroupStrip.tsx`
around lines 51 - 60, PresetMenuItemShortcut currently calls useHotkeyText even
when PRESET_HOTKEY_IDS[index] is undefined for indices >8; change the logic so
you first read const hotkeyId = PRESET_HOTKEY_IDS[index] and if (!hotkeyId)
return null before calling useHotkeyText, then only call const hotkeyText =
useHotkeyText(hotkeyId) and guard the "Unassigned" value after that; also
consider extracting PresetMenuItemShortcut into its own file to follow the
one-component-per-file guideline and import it where needed (references:
PresetMenuItemShortcut, PRESET_HOTKEY_IDS, useHotkeyText, DropdownMenuShortcut).
Display the bound keyboard shortcut (e.g., ⌘⇧1) next to each preset in the dropdown menu, making it easier for users to discover and remember preset hotkeys.
57bab01 to
744267a
Compare
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
Test plan
Summary by CodeRabbit
New Features
Style
✏️ Tip: You can customize this high-level summary in your review settings.