Fix global shortcuts
This commit is contained in:
parent
2c70040a2b
commit
56a1058539
|
@ -0,0 +1 @@
|
||||||
|
Fix global keyboard shortcuts firing when input is focused (#1876)
|
|
@ -1,6 +1,6 @@
|
||||||
import { DefaultMagicKeysAliasMap, tryOnScopeDispose, useActiveElement, useEventListener } from '@vueuse/core'
|
import { DefaultMagicKeysAliasMap, tryOnScopeDispose, useEventListener } from '@vueuse/core'
|
||||||
import { computed, reactive } from 'vue'
|
|
||||||
import { isEqual, isMatch } from 'lodash-es'
|
import { isEqual, isMatch } from 'lodash-es'
|
||||||
|
import { reactive } from 'vue'
|
||||||
|
|
||||||
type KeyFilter = string | string[]
|
type KeyFilter = string | string[]
|
||||||
|
|
||||||
|
@ -11,12 +11,14 @@ interface Entry {
|
||||||
}
|
}
|
||||||
|
|
||||||
const combinations = reactive(new Map())
|
const combinations = reactive(new Map())
|
||||||
const activeElement = useActiveElement()
|
|
||||||
const bodyIsActive = computed(() => activeElement.value === document.body)
|
|
||||||
|
|
||||||
const current = new Set()
|
const current = new Set()
|
||||||
useEventListener(window, 'keydown', (event) => {
|
useEventListener(window, 'keydown', (event) => {
|
||||||
if (!bodyIsActive.value && !event.key) return
|
if (!event.key) return
|
||||||
|
|
||||||
|
const target = event.target as HTMLElement
|
||||||
|
if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA') return
|
||||||
|
|
||||||
current.add(event.key.toLowerCase())
|
current.add(event.key.toLowerCase())
|
||||||
|
|
||||||
const currentArray = [...current]
|
const currentArray = [...current]
|
||||||
|
@ -29,7 +31,7 @@ useEventListener(window, 'keydown', (event) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
useEventListener(window, 'keyup', (event) => {
|
useEventListener(window, 'keyup', (event) => {
|
||||||
if (!event.key) {
|
if (event.key) {
|
||||||
current.delete(event.key.toLowerCase())
|
current.delete(event.key.toLowerCase())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue