diff options
| author | Maze Winther <mazewinther@gmail.com> | 2025-07-20 16:36:21 +0200 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2025-07-20 16:36:21 +0200 |
| commit | ba3da43728bc051aa033dc7b45042b0f0f788e63 (patch) | |
| tree | 6039c0ddd5b19c7ecbcfbc6635e2495d85bd948b /apps/web/src/hooks/use-keybinding-conflicts.ts | |
| parent | afa8f426fbe8617980d848cdda977f2ab47b5e4e (diff) | |
| parent | baaf773b809674c07b4ab17ae3098abd768050ab (diff) | |
| download | opencut-ba3da43728bc051aa033dc7b45042b0f0f788e63.tar.gz | |
Merge branch 'staging'
Diffstat (limited to 'apps/web/src/hooks/use-keybinding-conflicts.ts')
| -rw-r--r-- | apps/web/src/hooks/use-keybinding-conflicts.ts | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/apps/web/src/hooks/use-keybinding-conflicts.ts b/apps/web/src/hooks/use-keybinding-conflicts.ts index 0720982e..cc5dd340 100644 --- a/apps/web/src/hooks/use-keybinding-conflicts.ts +++ b/apps/web/src/hooks/use-keybinding-conflicts.ts @@ -5,55 +5,55 @@ import { useKeybindingsStore } from "@/stores/keybindings-store"; import { ActionWithOptionalArgs } from "@/constants/actions"; export interface KeybindingConflictInfo { - key: string; - actions: ActionWithOptionalArgs[]; - isConflict: boolean; + key: string; + actions: ActionWithOptionalArgs[]; + isConflict: boolean; } export const useKeybindingConflicts = () => { - const { keybindings } = useKeybindingsStore(); + const { keybindings } = useKeybindingsStore(); - const conflicts = useMemo(() => { - const keyToActions: Record<string, ActionWithOptionalArgs[]> = {}; - const conflictList: KeybindingConflictInfo[] = []; + const conflicts = useMemo(() => { + const keyToActions: Record<string, ActionWithOptionalArgs[]> = {}; + const conflictList: KeybindingConflictInfo[] = []; - // Group actions by key - Object.entries(keybindings).forEach(([key, action]) => { - if (!keyToActions[key]) { - keyToActions[key] = []; - } - keyToActions[key].push(action); - }); + // Group actions by key + Object.entries(keybindings).forEach(([key, action]) => { + if (!keyToActions[key]) { + keyToActions[key] = []; + } + keyToActions[key].push(action); + }); - // Find conflicts - Object.entries(keyToActions).forEach(([key, actions]) => { - const uniqueActions = [...new Set(actions)]; - conflictList.push({ - key, - actions: uniqueActions, - isConflict: uniqueActions.length > 1, - }); - }); + // Find conflicts + Object.entries(keyToActions).forEach(([key, actions]) => { + const uniqueActions = [...new Set(actions)]; + conflictList.push({ + key, + actions: uniqueActions, + isConflict: uniqueActions.length > 1, + }); + }); - return conflictList.filter((item) => item.isConflict); - }, [keybindings]); + return conflictList.filter((item) => item.isConflict); + }, [keybindings]); - const hasConflicts = conflicts.length > 0; + const hasConflicts = conflicts.length > 0; - const getConflictsForKey = (key: string): KeybindingConflictInfo | null => { - return conflicts.find((conflict) => conflict.key === key) || null; - }; + const getConflictsForKey = (key: string): KeybindingConflictInfo | null => { + return conflicts.find((conflict) => conflict.key === key) || null; + }; - const getConflictsForAction = ( - action: ActionWithOptionalArgs, - ): KeybindingConflictInfo[] => { - return conflicts.filter((conflict) => conflict.actions.includes(action)); - }; + const getConflictsForAction = ( + action: ActionWithOptionalArgs + ): KeybindingConflictInfo[] => { + return conflicts.filter((conflict) => conflict.actions.includes(action)); + }; - return { - conflicts, - hasConflicts, - getConflictsForKey, - getConflictsForAction, - }; + return { + conflicts, + hasConflicts, + getConflictsForKey, + getConflictsForAction, + }; }; |
