Refactor keyboard shortcuts to use uppercase keys for display and update KeyBadge functionality

This commit is contained in:
Anwarul Islam
2025-07-18 06:22:49 +06:00
parent f5d221feec
commit c391eb8616
2 changed files with 31 additions and 34 deletions
@@ -1,5 +1,7 @@
"use client"; "use client";
import { useKeyboardShortcuts } from "@/hooks/use-keyboard-shortcuts";
import { Keyboard } from "lucide-react";
import { useState } from "react"; import { useState } from "react";
import { Button } from "./ui/button"; import { Button } from "./ui/button";
import { import {
@@ -10,38 +12,33 @@ import {
DialogTitle, DialogTitle,
DialogTrigger, DialogTrigger,
} from "./ui/dialog"; } from "./ui/dialog";
import { Badge } from "./ui/badge"; import { getPlatformSpecialKey } from "@/lib/utils";
import { Keyboard } from "lucide-react";
import { useKeyboardShortcuts } from "@/hooks/use-keyboard-shortcuts";
const KeyBadge = ({ keyName }: { keyName: string }) => { const modifier: {
// Replace common key names with symbols or friendly names [key: string]: string;
return keyName } = {
.replace("Cmd", "⌘") Shift: "Shift",
.replace("Shift", "Shift") Alt: "Alt",
.replace("ArrowLeft", "Arrow Left") ArrowLeft: "←",
.replace("ArrowRight", "Arrow Right") ArrowRight: "→",
.replace("ArrowUp", "Arrow Up") ArrowUp: "↑",
.replace("ArrowDown", "Arrow Down") ArrowDown: "↓",
.replace("←", "◀") Space: "Space",
.replace("→", "▶")
.replace("Space", "Space");
}; };
function getKeyWithModifier(key: string) {
if (key === "Ctrl") return getPlatformSpecialKey();
return modifier[key] || key;
}
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" // Filter out lowercase duplicates for display - if both "j" and "J" exist, only show "J"
const displayKeys = shortcut.keys.filter((key: string) => { 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 ( if (
key === lowerKey && key.includes("Cmd") &&
key !== upperKey && shortcut.keys.includes(key.replace("Cmd", "Ctrl"))
shortcut.keys.includes(upperKey) )
) {
return false; return false;
}
return true; return true;
}); });
@@ -60,7 +57,7 @@ const ShortcutItem = ({ shortcut }: { shortcut: any }) => {
<div className="flex items-center"> <div className="flex items-center">
{key.split("+").map((keyPart: string, partIndex: number) => ( {key.split("+").map((keyPart: string, partIndex: number) => (
<kbd key={partIndex} className="shortcut-key"> <kbd key={partIndex} className="shortcut-key">
<KeyBadge keyName={keyPart} /> {getKeyWithModifier(keyPart)}
</kbd> </kbd>
))} ))}
</div> </div>
+9 -9
View File
@@ -70,7 +70,7 @@ export const useKeyboardShortcuts = (
}, },
{ {
id: "rewind", id: "rewind",
keys: ["j", "J"], keys: ["J"],
description: "Rewind 1 second", description: "Rewind 1 second",
category: "Playback", category: "Playback",
action: () => { action: () => {
@@ -79,7 +79,7 @@ export const useKeyboardShortcuts = (
}, },
{ {
id: "play-pause-alt", id: "play-pause-alt",
keys: ["k", "K"], keys: ["K"],
description: "Play/Pause (alternative)", description: "Play/Pause (alternative)",
category: "Playback", category: "Playback",
action: () => { action: () => {
@@ -88,7 +88,7 @@ export const useKeyboardShortcuts = (
}, },
{ {
id: "fast-forward", id: "fast-forward",
keys: ["l", "L"], keys: ["L"],
description: "Fast forward 1 second", description: "Fast forward 1 second",
category: "Playback", category: "Playback",
action: () => { action: () => {
@@ -157,7 +157,7 @@ export const useKeyboardShortcuts = (
// Editing // Editing
{ {
id: "split-element", id: "split-element",
keys: ["s", "S"], keys: ["S"],
description: "Split element at playhead", description: "Split element at playhead",
category: "Editing", category: "Editing",
requiresSelection: true, requiresSelection: true,
@@ -206,7 +206,7 @@ export const useKeyboardShortcuts = (
}, },
{ {
id: "toggle-snapping", id: "toggle-snapping",
keys: ["n", "N"], keys: ["N"],
description: "Toggle snapping", description: "Toggle snapping",
category: "Editing", category: "Editing",
action: () => { action: () => {
@@ -217,7 +217,7 @@ export const useKeyboardShortcuts = (
// Selection & Organization // Selection & Organization
{ {
id: "select-all", id: "select-all",
keys: ["Cmd+a", "Ctrl+a"], keys: ["Cmd+A", "Ctrl+A"],
description: "Select all elements", description: "Select all elements",
category: "Selection", category: "Selection",
action: () => { action: () => {
@@ -232,7 +232,7 @@ export const useKeyboardShortcuts = (
}, },
{ {
id: "duplicate-element", id: "duplicate-element",
keys: ["Cmd+d", "Ctrl+d"], keys: ["Cmd+D", "Ctrl+D"],
description: "Duplicate selected element", description: "Duplicate selected element",
category: "Selection", category: "Selection",
requiresSelection: true, requiresSelection: true,
@@ -264,7 +264,7 @@ export const useKeyboardShortcuts = (
// History // History
{ {
id: "undo", id: "undo",
keys: ["Cmd+z", "Ctrl+z"], keys: ["Cmd+Z", "Ctrl+Z"],
description: "Undo", description: "Undo",
category: "History", category: "History",
action: () => { action: () => {
@@ -273,7 +273,7 @@ export const useKeyboardShortcuts = (
}, },
{ {
id: "redo", id: "redo",
keys: ["Cmd+Shift+z", "Ctrl+Shift+z", "Cmd+y", "Ctrl+y"], keys: ["Cmd+Shift+Z", "Ctrl+Shift+Z", "Cmd+Y", "Ctrl+Y"],
description: "Redo", description: "Redo",
category: "History", category: "History",
action: () => { action: () => {