diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-04-20 11:31:17 +0200 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-04-20 11:31:17 +0200 |
| commit | 3e89d2998588f8e35c524e523ba2ee853f0f6475 (patch) | |
| tree | 57221f96c1259b3b07e3ddf8c1adefc502b9d8eb /apps/web/src/hooks/use-keyboard-shortcuts-help.ts | |
| parent | 729d10592f4e802f91c555c309ff3ba4b119f843 (diff) | |
| download | opencut-3e89d2998588f8e35c524e523ba2ee853f0f6475.tar.gz | |
refactor: restructure files to their domains, new preview overlay system, and dep graph
Diffstat (limited to 'apps/web/src/hooks/use-keyboard-shortcuts-help.ts')
| -rw-r--r-- | apps/web/src/hooks/use-keyboard-shortcuts-help.ts | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/apps/web/src/hooks/use-keyboard-shortcuts-help.ts b/apps/web/src/hooks/use-keyboard-shortcuts-help.ts deleted file mode 100644 index 9a2f6cf5..00000000 --- a/apps/web/src/hooks/use-keyboard-shortcuts-help.ts +++ /dev/null @@ -1,83 +0,0 @@ -"use client"; - -import { useMemo } from "react"; -import { useKeybindingsStore } from "@/stores/keybindings-store"; -import { ACTIONS, type TActionWithOptionalArgs } from "@/lib/actions"; -import { - getPlatformAlternateKey, - getPlatformSpecialKey, -} from "@/utils/platform"; - -export interface KeyboardShortcut { - id: string; - keys: string[]; - description: string; - category: string; - action: TActionWithOptionalArgs; - icon?: React.ReactNode; -} - -function formatKey({ key }: { key: string }): string { - return key - .replace("ctrl", getPlatformSpecialKey()) - .replace("alt", getPlatformAlternateKey()) - .replace("shift", "Shift") - .replace("left", "←") - .replace("right", "→") - .replace("up", "↑") - .replace("down", "↓") - .replace("space", "Space") - .replace("home", "Home") - .replace("enter", "Enter") - .replace("end", "End") - .replace("delete", "Delete") - .replace("backspace", "Backspace") - .replace("-", "+"); -} - -export function useKeyboardShortcutsHelp() { - const { keybindings } = useKeybindingsStore(); - - const shortcuts = useMemo(() => { - const result: KeyboardShortcut[] = []; - const actionToKeys: Partial<Record<TActionWithOptionalArgs, string[]>> = {}; - - for (const [key, action] of Object.entries(keybindings) as Array< - [string, TActionWithOptionalArgs | undefined] - >) { - if (action) { - if (!actionToKeys[action]) { - actionToKeys[action] = []; - } - actionToKeys[action].push(formatKey({ key })); - } - } - - for (const [action, keys] of Object.entries(actionToKeys) as Array< - [TActionWithOptionalArgs, string[]] - >) { - const actionDef = ACTIONS[action]; - if (!actionDef) { - continue; - } - result.push({ - id: action, - keys, - description: actionDef.description, - category: actionDef.category, - action, - }); - } - - return result.sort((a, b) => { - if (a.category !== b.category) { - return a.category.localeCompare(b.category); - } - return a.description.localeCompare(b.description); - }); - }, [keybindings]); - - return { - shortcuts, - }; -} |
