From b4d8145f2adb981b462a4581bdf3bf96bc32e3d9 Mon Sep 17 00:00:00 2001 From: cashmere Date: Mon, 27 Jul 2026 00:26:31 +0200 Subject: fix: restore missing keybinding validation guards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit persistence.ts imported isActionWithOptionalArgs and isShortcutKey, neither of which existed at runtime — loading persisted custom keybindings would crash. Adds actions/guards.ts (excluding required-args actions per TActionArgsMap) and isShortcutKey in keybinding.ts; the nine previously dead persistence tests now pass. --- apps/web/src/actions/keybinding.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'apps/web/src/actions/keybinding.ts') diff --git a/apps/web/src/actions/keybinding.ts b/apps/web/src/actions/keybinding.ts index aeec2fd6..a71b7e98 100644 --- a/apps/web/src/actions/keybinding.ts +++ b/apps/web/src/actions/keybinding.ts @@ -32,6 +32,26 @@ export function isKey(value: string): value is Key { return KEY_SET.has(value); } +const MODIFIER_KEYS: readonly ModifierKeys[] = [ + "ctrl", + "alt", + "shift", + "ctrl+shift", + "alt+shift", + "ctrl+alt", + "ctrl+alt+shift", +]; + +export function isShortcutKey(value: string): value is ShortcutKey { + if (isKey(value)) { + return true; + } + const parts = value.split("+"); + const key = parts.at(-1) ?? ""; + const modifiers = parts.slice(0, -1).join("+"); + return (MODIFIER_KEYS as readonly string[]).includes(modifiers) && isKey(key); +} + export type ModifierBasedShortcutKey = `${ModifierKeys}+${Key}`; // Singular keybindings (these will be disabled when an input-ish area has been focused) export type SingleCharacterShortcutKey = `${Key}`; -- cgit v1.3.1