mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-30 11:47:55 +01:00
fix(defineShortcuts): support minus - key (#962)
This commit is contained in:
committed by
GitHub
parent
a3046aa256
commit
de38afd97b
@@ -32,6 +32,9 @@ interface Shortcut {
|
|||||||
// keyCode?: number
|
// keyCode?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const chainedShortcutRegex = /^[^-]+.*-.*[^-]+$/
|
||||||
|
const combinedShortcutRegex = /^[^_]+.*_.*[^_]+$/
|
||||||
|
|
||||||
export const defineShortcuts = (config: ShortcutsConfig, options: ShortcutsOptions = {}) => {
|
export const defineShortcuts = (config: ShortcutsConfig, options: ShortcutsOptions = {}) => {
|
||||||
const { macOS, usingInput } = useShortcuts()
|
const { macOS, usingInput } = useShortcuts()
|
||||||
|
|
||||||
@@ -98,12 +101,15 @@ export const defineShortcuts = (config: ShortcutsConfig, options: ShortcutsOptio
|
|||||||
// Parse key and modifiers
|
// Parse key and modifiers
|
||||||
let shortcut: Partial<Shortcut>
|
let shortcut: Partial<Shortcut>
|
||||||
|
|
||||||
if (key.includes('-') && key.includes('_')) {
|
if (key.includes('-') && key !== '-' && !key.match(chainedShortcutRegex)?.length) {
|
||||||
console.trace('[Shortcut] Invalid key')
|
console.trace(`[Shortcut] Invalid key: "${key}"`)
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
if (chained) {
|
||||||
shortcut = {
|
shortcut = {
|
||||||
key: key.toLowerCase(),
|
key: key.toLowerCase(),
|
||||||
|
|||||||
Reference in New Issue
Block a user