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.
This commit is contained in:
sadkodev 2026-07-17 14:49:00 -04:00
parent b5de980632
commit 1ca1cbc896
No known key found for this signature in database
GPG key ID: C0AAF1AFD0AE9C4E

View file

@ -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) {