diff --git a/src/renderer/lib/ui/kbd.tsx b/src/renderer/lib/ui/kbd.tsx index 4cbc392b9..b57a97640 100644 --- a/src/renderer/lib/ui/kbd.tsx +++ b/src/renderer/lib/ui/kbd.tsx @@ -17,7 +17,10 @@ function KbdGroup({ className, ...props }: React.ComponentProps<'div'>) { return ( [data-slot=kbd]]:min-w-0 [&>[data-slot=kbd]]:rounded-none [&>[data-slot=kbd]]:px-0 [&>[data-slot=kbd]:first-child]:rounded-l-sm [&>[data-slot=kbd]:first-child]:pl-1 [&>[data-slot=kbd]:last-child]:rounded-r-sm [&>[data-slot=kbd]:last-child]:pr-1', + className + )} {...props} /> ); diff --git a/src/renderer/lib/ui/shortcut-hint.tsx b/src/renderer/lib/ui/shortcut-hint.tsx index 1e035cb76..8a4f56d69 100644 --- a/src/renderer/lib/ui/shortcut-hint.tsx +++ b/src/renderer/lib/ui/shortcut-hint.tsx @@ -1,10 +1,17 @@ -import { formatForDisplay } from '@tanstack/react-hotkeys'; +import { + detectPlatform, + KEY_DISPLAY_SYMBOLS, + MAC_MODIFIER_SYMBOLS, + parseHotkey, + STANDARD_MODIFIER_LABELS, +} from '@tanstack/react-hotkeys'; import React from 'react'; import { useAppSettingsKey } from '@renderer/features/settings/use-app-settings-key'; import { getEffectiveHotkey, type ShortcutSettingsKey, } from '@renderer/lib/hooks/useKeyboardShortcuts'; +import { cn } from '@renderer/utils/utils'; import { Kbd, KbdGroup } from './kbd'; interface ShortcutHintProps { @@ -12,19 +19,31 @@ interface ShortcutHintProps { className?: string; } +const PLATFORM = detectPlatform(); +const IS_MAC = PLATFORM === 'mac'; + export const ShortcutHint: React.FC = ({ settingsKey, className }) => { const { value: keyboard } = useAppSettingsKey('keyboard'); const hotkey = getEffectiveHotkey(settingsKey, keyboard); - const display = hotkey ? formatForDisplay(hotkey) : ''; - if (!display) return null; + if (!hotkey) return null; + + const parsed = parseHotkey(hotkey, PLATFORM); return ( - + - {display.split('+').map((key, _) => ( - {key.trim()} - ))} + {parsed.modifiers.map((modifier) => { + const glyph = IS_MAC + ? (MAC_MODIFIER_SYMBOLS[modifier] ?? modifier) + : (STANDARD_MODIFIER_LABELS[modifier] ?? modifier); + return ( + + {IS_MAC ? {glyph} : glyph} + + ); + })} + {KEY_DISPLAY_SYMBOLS[parsed.key] ?? parsed.key} );