fix(defineShortcuts): support minus - key (#962)

This commit is contained in:
Sylvain Marroufin
2023-11-14 14:24:46 +01:00
committed by GitHub
parent a3046aa256
commit de38afd97b

View File

@@ -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<Shortcut>
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(),