Skip to content

Commit

Permalink
fix(useMagicKeys): only clean up used keys, close #1793
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jul 8, 2022
1 parent 67e1f29 commit 3c85db4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/core/useMagicKeys/index.ts
Expand Up @@ -84,6 +84,7 @@ export function useMagicKeys(options: UseMagicKeysOptions<boolean> = {}): any {
const obj = { toJSON() { return {} }, current }
const refs: Record<string, any> = useReactive ? reactive(obj) : obj
const metaDeps = new Set<string>()
const usedKeys = new Set<string>()

function setRefs(key: string, value: boolean) {
if (key in refs) {
Expand All @@ -95,7 +96,7 @@ export function useMagicKeys(options: UseMagicKeysOptions<boolean> = {}): any {
}

function reset() {
for (const key of Object.keys(refs)) {
for (const key of usedKeys) {
if (useReactive)
refs[key] = false
else
Expand All @@ -116,8 +117,10 @@ export function useMagicKeys(options: UseMagicKeysOptions<boolean> = {}): any {
current.delete(e.code)
}

for (const key of values)
for (const key of values) {
usedKeys.add(key)
setRefs(key, value)
}

// #1312
// In macOS, keys won't trigger "keyup" event when Meta key is released
Expand Down

0 comments on commit 3c85db4

Please sign in to comment.