more shortcut fixes

This commit is contained in:
Maze Winther
2025-07-16 16:05:30 +02:00
parent 5483db83de
commit 0c086e3c24
2 changed files with 54 additions and 23 deletions
@@ -15,22 +15,44 @@ import { Keyboard } from "lucide-react";
import { useKeyboardShortcuts } from "@/hooks/use-keyboard-shortcuts"; import { useKeyboardShortcuts } from "@/hooks/use-keyboard-shortcuts";
const KeyBadge = ({ keyName }: { keyName: string }) => { const KeyBadge = ({ keyName }: { keyName: string }) => {
// Replace common key names with symbols // Replace common key names with symbols or friendly names
const displayKey = keyName const displayKey = keyName
.replace("Cmd", "⌘") .replace("Cmd", "⌘")
.replace("Shift", "") .replace("Shift", "Shift")
.replace("ArrowLeft", "Arrow Left")
.replace("ArrowRight", "Arrow Right")
.replace("ArrowUp", "Arrow Up")
.replace("ArrowDown", "Arrow Down")
.replace("←", "◀") .replace("←", "◀")
.replace("→", "▶") .replace("→", "▶")
.replace("Space", "Space"); .replace("Space", "Space");
return ( return (
<Badge variant="secondary" className="font-mono text-xs px-2 py-1"> <Badge variant="secondary" className="font-mono text-xs px-1 py-1">
{displayKey} {displayKey}
</Badge> </Badge>
); );
}; };
const ShortcutItem = ({ shortcut }: { shortcut: any }) => ( const ShortcutItem = ({ shortcut }: { shortcut: any }) => {
// Filter out lowercase duplicates for display - if both "j" and "J" exist, only show "J"
const displayKeys = shortcut.keys.filter((key: string) => {
const lowerKey = key.toLowerCase();
const upperKey = key.toUpperCase();
// If this is a lowercase letter and the uppercase version exists, skip it
if (
key === lowerKey &&
key !== upperKey &&
shortcut.keys.includes(upperKey)
) {
return false;
}
return true;
});
return (
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
{shortcut.icon && ( {shortcut.icon && (
@@ -39,17 +61,27 @@ const ShortcutItem = ({ shortcut }: { shortcut: any }) => (
<span className="text-sm">{shortcut.description}</span> <span className="text-sm">{shortcut.description}</span>
</div> </div>
<div className="flex items-center gap-1"> <div className="flex items-center gap-1">
{shortcut.keys.map((key: string, index: number) => ( {displayKeys.map((key: string, index: number) => (
<div key={index} className="flex items-center gap-1"> <div key={index} className="flex items-center gap-1">
<KeyBadge keyName={key} /> <div className="flex items-center">
{index < shortcut.keys.length - 1 && ( {key.split("+").map((keyPart: string, partIndex: number) => (
<div key={partIndex} className="flex items-center gap-1">
<KeyBadge keyName={keyPart} />
{partIndex < key.split("+").length - 1 && (
<span className="text-xs text-muted-foreground">+</span> <span className="text-xs text-muted-foreground">+</span>
)} )}
</div> </div>
))} ))}
</div> </div>
{index < displayKeys.length - 1 && (
<span className="text-xs text-muted-foreground">or</span>
)}
</div>
))}
</div>
</div> </div>
); );
};
export const KeyboardShortcutsHelp = () => { export const KeyboardShortcutsHelp = () => {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
@@ -15,7 +15,6 @@ export interface KeyboardShortcut {
enabled?: boolean; enabled?: boolean;
requiresSelection?: boolean; requiresSelection?: boolean;
icon?: React.ReactNode; icon?: React.ReactNode;
displayKeys?: string[]; // Keys to show in help (defaults to keys if not provided)
} }
interface UseKeyboardShortcutsOptions { interface UseKeyboardShortcutsOptions {