From 5d006304528374d2562aa0d6646a53ee65f76f11 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 30 Jul 2025 14:26:51 +0300 Subject: [PATCH] refactor(hotkeys): simplify normalization --- apps/client/src/services/shortcuts.ts | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/apps/client/src/services/shortcuts.ts b/apps/client/src/services/shortcuts.ts index a4bfa2909..09d533ad5 100644 --- a/apps/client/src/services/shortcuts.ts +++ b/apps/client/src/services/shortcuts.ts @@ -101,11 +101,14 @@ function matchesShortcut(e: KeyboardEvent, shortcut: string): boolean { } function keyMatches(e: KeyboardEvent, key: string): boolean { - // Handle special key mappings + // Handle special key mappings and aliases const keyMap: { [key: string]: string[] } = { 'return': ['Enter'], + 'enter': ['Enter'], // alias for return 'del': ['Delete'], + 'delete': ['Delete'], // alias for del 'esc': ['Escape'], + 'escape': ['Escape'], // alias for esc 'space': [' ', 'Space'], 'tab': ['Tab'], 'backspace': ['Backspace'], @@ -135,32 +138,14 @@ function keyMatches(e: KeyboardEvent, key: string): boolean { } /** - * Normalize to a consistent format for our custom shortcut parser + * Simple normalization - just lowercase and trim whitespace */ function normalizeShortcut(shortcut: string): string { if (!shortcut) { return shortcut; } - return shortcut - .toLowerCase() - .trim() - .replace(/\s+/g, '') // Remove any spaces - .replace("enter", "return") - .replace("delete", "del") - .replace("escape", "esc") - // Normalize modifier order: ctrl, alt, shift, meta, then key - .split('+') - .sort((a, b) => { - const order = ['ctrl', 'control', 'alt', 'shift', 'meta', 'cmd', 'command']; - const aIndex = order.indexOf(a); - const bIndex = order.indexOf(b); - if (aIndex === -1 && bIndex === -1) return 0; - if (aIndex === -1) return 1; - if (bIndex === -1) return -1; - return aIndex - bIndex; - }) - .join('+'); + return shortcut.toLowerCase().trim().replace(/\s+/g, ''); } export default {