diff options
| author | Anwarul Islam <anwaarulislaam@gmail.com> | 2025-07-18 06:22:49 +0600 |
|---|---|---|
| committer | Anwarul Islam <anwaarulislaam@gmail.com> | 2025-07-18 06:22:49 +0600 |
| commit | c391eb861683cb6aa3b98a83b2b9eda2c0ca9e7e (patch) | |
| tree | 16da06df1c0f782bcf40fcaf167d8eb525073d91 /apps/web/src/components | |
| parent | f5d221feec01c835b7c2e7e2a29cdae312f514c1 (diff) | |
| download | opencut-c391eb861683cb6aa3b98a83b2b9eda2c0ca9e7e.tar.gz | |
Refactor keyboard shortcuts to use uppercase keys for display and update KeyBadge functionality
Diffstat (limited to 'apps/web/src/components')
| -rw-r--r-- | apps/web/src/components/keyboard-shortcuts-help.tsx | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/apps/web/src/components/keyboard-shortcuts-help.tsx b/apps/web/src/components/keyboard-shortcuts-help.tsx index e883da14..a33ba666 100644 --- a/apps/web/src/components/keyboard-shortcuts-help.tsx +++ b/apps/web/src/components/keyboard-shortcuts-help.tsx @@ -1,5 +1,7 @@ "use client"; +import { useKeyboardShortcuts } from "@/hooks/use-keyboard-shortcuts"; +import { Keyboard } from "lucide-react"; import { useState } from "react"; import { Button } from "./ui/button"; import { @@ -10,38 +12,33 @@ import { DialogTitle, DialogTrigger, } from "./ui/dialog"; -import { Badge } from "./ui/badge"; -import { Keyboard } from "lucide-react"; -import { useKeyboardShortcuts } from "@/hooks/use-keyboard-shortcuts"; +import { getPlatformSpecialKey } from "@/lib/utils"; -const KeyBadge = ({ keyName }: { keyName: string }) => { - // Replace common key names with symbols or friendly names - return keyName - .replace("Cmd", "⌘") - .replace("Shift", "Shift") - .replace("ArrowLeft", "Arrow Left") - .replace("ArrowRight", "Arrow Right") - .replace("ArrowUp", "Arrow Up") - .replace("ArrowDown", "Arrow Down") - .replace("←", "◀") - .replace("→", "▶") - .replace("Space", "Space"); +const modifier: { + [key: string]: string; +} = { + Shift: "Shift", + Alt: "Alt", + ArrowLeft: "←", + ArrowRight: "→", + ArrowUp: "↑", + ArrowDown: "↓", + Space: "Space", }; +function getKeyWithModifier(key: string) { + if (key === "Ctrl") return getPlatformSpecialKey(); + return modifier[key] || key; +} + 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) - ) { + key.includes("Cmd") && + shortcut.keys.includes(key.replace("Cmd", "Ctrl")) + ) return false; - } return true; }); @@ -60,7 +57,7 @@ const ShortcutItem = ({ shortcut }: { shortcut: any }) => { <div className="flex items-center"> {key.split("+").map((keyPart: string, partIndex: number) => ( <kbd key={partIndex} className="shortcut-key"> - <KeyBadge keyName={keyPart} /> + {getKeyWithModifier(keyPart)} </kbd> ))} </div> |
