fix(renderer): improve shortcut hint rendering#1949
fix(renderer): improve shortcut hint rendering#1949janburzinski wants to merge 2 commits intogeneralaction:mainfrom
Conversation
Greptile SummaryThis PR replaces the fragile
Confidence Score: 5/5Safe to merge — changes are purely presentational with no logic regressions. Both files touch only UI rendering: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/renderer/lib/ui/shortcut-hint.tsx | Replaces string-splitting via formatForDisplay with structured parseHotkey — modifiers and main key are rendered as separate Kbd elements with platform-aware symbols and proper fallbacks. |
| src/renderer/lib/ui/kbd.tsx | KbdGroup now fuses child Kbd items into a seamless pill by zeroing the gap and selectively applying rounded corners and padding only to the first/last child. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[ShortcutHint] --> B{hotkey?}
B -- no --> C[return null]
B -- yes --> D[parseHotkey hotkey PLATFORM]
D --> E[parsed.modifiers + parsed.key]
E --> F{IS_MAC?}
F -- yes --> G[MAC_MODIFIER_SYMBOLS glyph wrap in translate-y-px span]
F -- no --> H[STANDARD_MODIFIER_LABELS glyph render plain text]
G --> I[KbdGroup]
H --> I
E --> J[KEY_DISPLAY_SYMBOLS parsed.key]
J --> I
I --> K[CSS: gap-0, first-child rounded-l pl-1 last-child rounded-r pr-1]
Reviews (2): Last reviewed commit: "fix(renderer): address shortcut hint rev..." | Re-trigger Greptile
| {parsed.modifiers.map((modifier, idx) => { | ||
| const glyph = IS_MAC | ||
| ? MAC_MODIFIER_SYMBOLS[modifier] | ||
| : STANDARD_MODIFIER_LABELS[modifier]; | ||
| return ( | ||
| <Kbd key={idx}>{IS_MAC ? <span className="translate-y-px">{glyph}</span> : glyph}</Kbd> | ||
| ); | ||
| })} |
There was a problem hiding this comment.
Using the array index as the React
key for modifier elements is fragile — if modifiers ever reorder, React will diff them incorrectly and potentially keep stale DOM. Each modifier string is already unique within the array (a hotkey can't have duplicate modifiers), so modifier itself is a stable, meaningful key.
| {parsed.modifiers.map((modifier, idx) => { | |
| const glyph = IS_MAC | |
| ? MAC_MODIFIER_SYMBOLS[modifier] | |
| : STANDARD_MODIFIER_LABELS[modifier]; | |
| return ( | |
| <Kbd key={idx}>{IS_MAC ? <span className="translate-y-px">{glyph}</span> : glyph}</Kbd> | |
| ); | |
| })} | |
| {parsed.modifiers.map((modifier) => { | |
| const glyph = IS_MAC | |
| ? MAC_MODIFIER_SYMBOLS[modifier] | |
| : STANDARD_MODIFIER_LABELS[modifier]; | |
| return ( | |
| <Kbd key={modifier}>{IS_MAC ? <span className="translate-y-px">{glyph}</span> : glyph}</Kbd> | |
| ); | |
| })} |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/renderer/lib/ui/shortcut-hint.tsx
Line: 36-43
Comment:
Using the array index as the React `key` for modifier elements is fragile — if modifiers ever reorder, React will diff them incorrectly and potentially keep stale DOM. Each modifier string is already unique within the array (a hotkey can't have duplicate modifiers), so `modifier` itself is a stable, meaningful key.
```suggestion
{parsed.modifiers.map((modifier) => {
const glyph = IS_MAC
? MAC_MODIFIER_SYMBOLS[modifier]
: STANDARD_MODIFIER_LABELS[modifier];
return (
<Kbd key={modifier}>{IS_MAC ? <span className="translate-y-px">{glyph}</span> : glyph}</Kbd>
);
})}
```
How can I resolve this? If you propose a fix, please make it concise.| const glyph = IS_MAC | ||
| ? MAC_MODIFIER_SYMBOLS[modifier] | ||
| : STANDARD_MODIFIER_LABELS[modifier]; |
There was a problem hiding this comment.
glyph has no fallback when a modifier is absent from MAC_MODIFIER_SYMBOLS or STANDARD_MODIFIER_LABELS. If parseHotkey ever surfaces an unexpected modifier name (e.g. 'Mod' before it is resolved, or a future library addition), glyph is undefined and an empty <Kbd> renders in the group. Adding ?? modifier as a last-resort fallback — mirroring what KEY_DISPLAY_SYMBOLS[parsed.key] ?? parsed.key already does for the main key — keeps the output legible instead of blank.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/renderer/lib/ui/shortcut-hint.tsx
Line: 37-39
Comment:
`glyph` has no fallback when a modifier is absent from `MAC_MODIFIER_SYMBOLS` or `STANDARD_MODIFIER_LABELS`. If `parseHotkey` ever surfaces an unexpected modifier name (e.g. `'Mod'` before it is resolved, or a future library addition), `glyph` is `undefined` and an empty `<Kbd>` renders in the group. Adding `?? modifier` as a last-resort fallback — mirroring what `KEY_DISPLAY_SYMBOLS[parsed.key] ?? parsed.key` already does for the main key — keeps the output legible instead of blank.
How can I resolve this? If you propose a fix, please make it concise.|
@greptile |
summary
adjust go back/forward