fix: convert special keys to valid Electron accelerators

Maps KeyboardEvent.key values (e.g., "ArrowDown", " ") to their
Electron accelerator equivalents (e.g., "Down", "Space") to prevent
global shortcut registration failures.
This commit is contained in:
Yauheni Bandziukevich
2026-05-28 22:11:38 +02:00
parent f1a8552046
commit d86c17407a
+23 -1
View File
@@ -5,12 +5,34 @@ import { SHORTCUTS_FILE } from "./ipc/handlers";
const DEFAULT_OPEN_APP_BINDING: ShortcutBinding = { key: "o", ctrl: true, shift: true };
// Maps KeyboardEvent.key values to Electron accelerator key names
const KEY_TO_ACCELERATOR: Record<string, string> = {
" ": "Space",
"+": "Plus",
"-": "numsub",
"*": "nummult",
"/": "numdiv",
arrowup: "Up",
arrowdown: "Down",
arrowleft: "Left",
arrowright: "Right",
escape: "Escape",
enter: "Return",
backspace: "Backspace",
delete: "Delete",
tab: "Tab",
};
function bindingToAccelerator(binding: ShortcutBinding): string {
const parts: string[] = [];
if (binding.ctrl) parts.push("CommandOrControl");
if (binding.shift) parts.push("Shift");
if (binding.alt) parts.push("Alt");
parts.push(binding.key.toUpperCase());
const keyLower = binding.key.toLowerCase();
const acceleratorKey = KEY_TO_ACCELERATOR[keyLower] ?? binding.key.toUpperCase();
parts.push(acceleratorKey);
return parts.join("+");
}