From de38afd97b7bfd9af2619a17a42f27177abfec7e Mon Sep 17 00:00:00 2001 From: Sylvain Marroufin Date: Tue, 14 Nov 2023 14:24:46 +0100 Subject: [PATCH] fix(defineShortcuts): support minus `-` key (#962) --- src/runtime/composables/defineShortcuts.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/runtime/composables/defineShortcuts.ts b/src/runtime/composables/defineShortcuts.ts index bea77adf..30d892b3 100644 --- a/src/runtime/composables/defineShortcuts.ts +++ b/src/runtime/composables/defineShortcuts.ts @@ -32,6 +32,9 @@ interface Shortcut { // keyCode?: number } +const chainedShortcutRegex = /^[^-]+.*-.*[^-]+$/ +const combinedShortcutRegex = /^[^_]+.*_.*[^_]+$/ + export const defineShortcuts = (config: ShortcutsConfig, options: ShortcutsOptions = {}) => { const { macOS, usingInput } = useShortcuts() @@ -98,12 +101,15 @@ export const defineShortcuts = (config: ShortcutsConfig, options: ShortcutsOptio // Parse key and modifiers let shortcut: Partial - if (key.includes('-') && key.includes('_')) { - console.trace('[Shortcut] Invalid key') - return null + if (key.includes('-') && key !== '-' && !key.match(chainedShortcutRegex)?.length) { + console.trace(`[Shortcut] Invalid key: "${key}"`) } - const chained = key.includes('-') + if (key.includes('_') && key !== '_' && !key.match(combinedShortcutRegex)?.length) { + console.trace(`[Shortcut] Invalid key: "${key}"`) + } + + const chained = key.includes('-') && key !== '-' if (chained) { shortcut = { key: key.toLowerCase(),