Skip to content

Commit 9cdbb38

Browse files
cursoragentmsukkari
andcommitted
fix: show Ctrl instead of ⌘ on non-Mac keyboards in keyboard shortcut hints
The KeyboardShortcutHint component now detects the user's platform and displays 'Ctrl' instead of '⌘' for Windows/Linux users. This fixes the issue where the Reference Guide hint (and other keyboard shortcut hints) incorrectly showed Mac-specific keyboard symbols on non-Mac platforms. Co-authored-by: michael <michael@sourcebot.dev>
1 parent 326bb91 commit 9cdbb38

1 file changed

Lines changed: 32 additions & 15 deletions

File tree

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
1-
import { cn } from '@/lib/utils'
2-
import React from 'react'
1+
'use client';
2+
3+
import { cn, IS_MAC } from '@/lib/utils'
4+
import React, { useMemo } from 'react'
35

46
interface KeyboardShortcutHintProps {
57
shortcut: string
68
label?: string
79
className?: string
810
}
911

12+
/**
13+
* Converts Mac-specific keyboard shortcuts to platform-appropriate shortcuts.
14+
* On Mac: displays the shortcut as-is (e.g., "⌘")
15+
* On Windows/Linux: replaces "⌘" with "Ctrl"
16+
*/
17+
function getPlatformShortcut(shortcut: string): string {
18+
if (IS_MAC) {
19+
return shortcut;
20+
}
21+
// Replace Mac Command key symbol with Ctrl for non-Mac platforms
22+
return shortcut.replace(//g, 'Ctrl');
23+
}
24+
1025
export function KeyboardShortcutHint({ shortcut, label, className }: KeyboardShortcutHintProps) {
11-
return (
12-
<div className={cn("inline-flex items-center", className)} aria-label={label || `Keyboard shortcut: ${shortcut}`}>
13-
<kbd
14-
className="px-2 py-1 font-semibold font-sans border rounded-md"
15-
style={{
16-
fontSize: "0.65rem",
17-
lineHeight: "0.875rem",
18-
}}
19-
>
20-
{shortcut}
21-
</kbd>
22-
</div>
23-
)
26+
const platformShortcut = useMemo(() => getPlatformShortcut(shortcut), [shortcut]);
27+
28+
return (
29+
<div className={cn("inline-flex items-center", className)} aria-label={label || `Keyboard shortcut: ${platformShortcut}`}>
30+
<kbd
31+
className="px-2 py-1 font-semibold font-sans border rounded-md"
32+
style={{
33+
fontSize: "0.65rem",
34+
lineHeight: "0.875rem",
35+
}}
36+
>
37+
{platformShortcut}
38+
</kbd>
39+
</div>
40+
)
2441
}

0 commit comments

Comments
 (0)