From 1ca1cbc8965a804bac6fdd365c4be7bcf670d8d4 Mon Sep 17 00:00:00 2001 From: sadkodev Date: Fri, 17 Jul 2026 14:49:00 -0400 Subject: [PATCH] refactor(keyboard): deduplicate opacity binding handler Collapse the duplicated Digit/Numpad opacity bindings into a single OPACITY_CODES array with one shared run handler. Digit value is extracted via code.slice(-1), which works for both Digit0-9 and Numpad0-9. --- src/app/shell/keyboard/registry.ts | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/app/shell/keyboard/registry.ts b/src/app/shell/keyboard/registry.ts index 69f907f46..506e8eb00 100644 --- a/src/app/shell/keyboard/registry.ts +++ b/src/app/shell/keyboard/registry.ts @@ -36,27 +36,20 @@ function commandShortcuts(...commands: EditorCommandId[]): ShortcutDefinition[] }) } -const OPACITY_DIGITS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] +const OPACITY_CODES = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].flatMap((d) => [ + `Digit${d}`, + `Numpad${d}` +]) function opacityBindings(): ShortcutDefinition[] { - return OPACITY_DIGITS.flatMap((digit) => [ - { - id: `opacity-Digit${digit}`, - keys: `Digit${digit}`, - run: ({ keyEvent, actions }: KeyboardShortcutRunOptions) => { - if (keyEvent.metaKey || keyEvent.ctrlKey || keyEvent.altKey || keyEvent.shiftKey) return - actions.opacityDigit(digit) - } - }, - { - id: `opacity-Numpad${digit}`, - keys: `Numpad${digit}`, - run: ({ keyEvent, actions }: KeyboardShortcutRunOptions) => { - if (keyEvent.metaKey || keyEvent.ctrlKey || keyEvent.altKey || keyEvent.shiftKey) return - actions.opacityDigit(digit) - } + return OPACITY_CODES.map((code) => ({ + id: `opacity-${code}`, + keys: code, + run: ({ keyEvent, actions }: KeyboardShortcutRunOptions) => { + if (keyEvent.metaKey || keyEvent.ctrlKey || keyEvent.altKey || keyEvent.shiftKey) return + actions.opacityDigit(code.slice(-1)) } - ]) + })) } function shouldIgnoreShortcut(event: KeyboardEvent, options: KeyboardShortcutOptions) {