Skip to content

Commit

Permalink
fix(defineShortcuts): support minus - key (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
smarroufin committed Nov 14, 2023
1 parent a3046aa commit de38afd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/runtime/composables/defineShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ interface Shortcut {
// keyCode?: number
}

const chainedShortcutRegex = /^[^-]+.*-.*[^-]+$/
const combinedShortcutRegex = /^[^_]+.*_.*[^_]+$/

export const defineShortcuts = (config: ShortcutsConfig, options: ShortcutsOptions = {}) => {
const { macOS, usingInput } = useShortcuts()

Expand Down Expand Up @@ -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}"`)
}

if (key.includes('_') && key !== '_' && !key.match(combinedShortcutRegex)?.length) {
console.trace(`[Shortcut] Invalid key: "${key}"`)
}

const chained = key.includes('-')
const chained = key.includes('-') && key !== '-'
if (chained) {
shortcut = {
key: key.toLowerCase(),
Expand Down

1 comment on commit de38afd

@vercel
Copy link

@vercel vercel bot commented on de38afd Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-git-dev-nuxt-js.vercel.app
ui.nuxt.com
ui-nuxt-js.vercel.app

Please sign in to comment.