mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-25 09:20:36 +01:00
fix(defineShortcuts): allow extra keys to be combined with shift (#4456)
This commit is contained in:
committed by
GitHub
parent
d7aefa53b2
commit
772631cde9
@@ -36,6 +36,8 @@ interface Shortcut {
|
|||||||
|
|
||||||
const chainedShortcutRegex = /^[^-]+.*-.*[^-]+$/
|
const chainedShortcutRegex = /^[^-]+.*-.*[^-]+$/
|
||||||
const combinedShortcutRegex = /^[^_]+.*_.*[^_]+$/
|
const combinedShortcutRegex = /^[^_]+.*_.*[^_]+$/
|
||||||
|
// keyboard keys which can be combined with Shift modifier (in addition to alphabet keys)
|
||||||
|
const shiftableKeys = ['arrowleft', 'arrowright', 'arrowup', 'arrowright', 'tab', 'escape', 'enter', 'backspace']
|
||||||
|
|
||||||
export function extractShortcuts(items: any[] | any[][]) {
|
export function extractShortcuts(items: any[] | any[][]) {
|
||||||
const shortcuts: Record<string, Handler> = {}
|
const shortcuts: Record<string, Handler> = {}
|
||||||
@@ -76,7 +78,8 @@ export function defineShortcuts(config: MaybeRef<ShortcutsConfig>, options: Shor
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const alphabeticalKey = /^[a-z]{1}$/i.test(e.key)
|
const alphabetKey = /^[a-z]{1}$/i.test(e.key)
|
||||||
|
const shiftableKey = shiftableKeys.includes(e.key.toLowerCase())
|
||||||
|
|
||||||
let chainedKey
|
let chainedKey
|
||||||
chainedInputs.value.push(e.key)
|
chainedInputs.value.push(e.key)
|
||||||
@@ -109,9 +112,9 @@ export function defineShortcuts(config: MaybeRef<ShortcutsConfig>, options: Shor
|
|||||||
if (e.ctrlKey !== shortcut.ctrlKey) {
|
if (e.ctrlKey !== shortcut.ctrlKey) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// shift modifier is only checked in combination with alphabetical keys
|
// shift modifier is only checked in combination with alphabet keys and some extra keys
|
||||||
// (shift with non-alphabetical keys would change the key)
|
// (shift with special characters would change the key)
|
||||||
if (alphabeticalKey && e.shiftKey !== shortcut.shiftKey) {
|
if ((alphabetKey || shiftableKey) && e.shiftKey !== shortcut.shiftKey) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// alt modifier changes the combined key anyways
|
// alt modifier changes the combined key anyways
|
||||||
|
|||||||
Reference in New Issue
Block a user