Skip to content

Commit 772631c

Browse files
authored
fix(defineShortcuts): allow extra keys to be combined with shift (#4456)
1 parent d7aefa5 commit 772631c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/runtime/composables/defineShortcuts.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ interface Shortcut {
3636

3737
const chainedShortcutRegex = /^[^-]+.*-.*[^-]+$/
3838
const combinedShortcutRegex = /^[^_]+.*_.*[^_]+$/
39+
// keyboard keys which can be combined with Shift modifier (in addition to alphabet keys)
40+
const shiftableKeys = ['arrowleft', 'arrowright', 'arrowup', 'arrowright', 'tab', 'escape', 'enter', 'backspace']
3941

4042
export function extractShortcuts(items: any[] | any[][]) {
4143
const shortcuts: Record<string, Handler> = {}
@@ -76,7 +78,8 @@ export function defineShortcuts(config: MaybeRef<ShortcutsConfig>, options: Shor
7678
return
7779
}
7880

79-
const alphabeticalKey = /^[a-z]{1}$/i.test(e.key)
81+
const alphabetKey = /^[a-z]{1}$/i.test(e.key)
82+
const shiftableKey = shiftableKeys.includes(e.key.toLowerCase())
8083

8184
let chainedKey
8285
chainedInputs.value.push(e.key)
@@ -109,9 +112,9 @@ export function defineShortcuts(config: MaybeRef<ShortcutsConfig>, options: Shor
109112
if (e.ctrlKey !== shortcut.ctrlKey) {
110113
continue
111114
}
112-
// shift modifier is only checked in combination with alphabetical keys
113-
// (shift with non-alphabetical keys would change the key)
114-
if (alphabeticalKey && e.shiftKey !== shortcut.shiftKey) {
115+
// shift modifier is only checked in combination with alphabet keys and some extra keys
116+
// (shift with special characters would change the key)
117+
if ((alphabetKey || shiftableKey) && e.shiftKey !== shortcut.shiftKey) {
115118
continue
116119
}
117120
// alt modifier changes the combined key anyways

0 commit comments

Comments
 (0)