Skip to content

Commit ab7acd9

Browse files
KedlingarSkstud5
andauthored
fix(useMagicKeys): correctly clear current pressed keys when releasing Shift (#4731)
Co-authored-by: Skstud5 <skripchenko@rb.asu.ru>
1 parent 94fea43 commit ab7acd9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/core/useMagicKeys/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export function useMagicKeys(options: UseMagicKeysOptions<boolean> = {}): any {
8585
}
8686
const refs: Record<string, any> = useReactive ? reactive(obj) : obj
8787
const metaDeps = new Set<string>()
88+
const shiftDeps = new Set<string>()
8889
const usedKeys = new Set<string>()
8990

9091
function setRefs(key: string, value: boolean) {
@@ -119,7 +120,16 @@ export function useMagicKeys(options: UseMagicKeysOptions<boolean> = {}): any {
119120
usedKeys.add(key)
120121
setRefs(key, value)
121122
}
122-
123+
if (key === 'shift' && !value) {
124+
shiftDeps.forEach((key) => {
125+
current.delete(key)
126+
setRefs(key, false)
127+
})
128+
shiftDeps.clear()
129+
}
130+
else if (typeof e.getModifierState === 'function' && e.getModifierState('Shift') && value) {
131+
[...current, ...values].forEach(key => shiftDeps.add(key))
132+
}
123133
// #1312
124134
// In macOS, keys won't trigger "keyup" event when Meta key is released
125135
// We track it's combination and release manually

0 commit comments

Comments
 (0)