Skip to content

Commit 2e2fa9a

Browse files
committed
fix(core): allow using + as a key in key combinations (#1693)
* fix(core): allow using `+` as a key in key combinations Signed-off-by: braks <[email protected]> * chore(changeset): add Signed-off-by: braks <[email protected]> * chore(core): cleanup Signed-off-by: braks <[email protected]> --------- Signed-off-by: braks <[email protected]>
1 parent 129d543 commit 2e2fa9a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

.changeset/selfish-falcons-run.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/core": patch
3+
---
4+
5+
Allow using the `+` key in key combinations

packages/core/src/composables/useKeyPress.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ function wasModifierPressed(event: KeyboardEvent) {
2525
}
2626

2727
function isKeyMatch(pressedKey: string, keyToMatch: string, pressedKeys: Set<string>, isKeyUp: boolean) {
28-
const keyCombination = keyToMatch.split('+').map((k) => k.trim().toLowerCase())
28+
const keyCombination = keyToMatch
29+
.replace('+', '\n')
30+
.replace('\n\n', '\n+')
31+
.split('\n')
32+
.map((k) => k.trim().toLowerCase())
2933

3034
if (keyCombination.length === 1) {
3135
return pressedKey.toLowerCase() === keyToMatch.toLowerCase()
@@ -50,13 +54,16 @@ function createKeyPredicate(keyFilter: string | string[], pressedKeys: Set<strin
5054

5155
const keyOrCode = useKeyOrCode(event.code, keyFilter)
5256

57+
const isKeyUp = event.type === 'keyup'
58+
const pressedKey = event[keyOrCode]
59+
5360
// if the keyFilter is an array of multiple keys, we need to check each possible key combination
5461
if (Array.isArray(keyFilter)) {
55-
return keyFilter.some((key) => isKeyMatch(event[keyOrCode], key, pressedKeys, event.type === 'keyup'))
62+
return keyFilter.some((key) => isKeyMatch(pressedKey, key, pressedKeys, isKeyUp))
5663
}
5764

5865
// if the keyFilter is a string, we need to check if the key matches the string
59-
return isKeyMatch(event[keyOrCode], keyFilter, pressedKeys, event.type === 'keyup')
66+
return isKeyMatch(pressedKey, keyFilter, pressedKeys, isKeyUp)
6067
}
6168
}
6269

@@ -126,7 +133,9 @@ export function useKeyPress(keyFilter: MaybeRefOrGetter<KeyFilter | boolean | nu
126133
)
127134

128135
onKeyStroke(
129-
(...args) => currentFilter(...args),
136+
(...args) => {
137+
return currentFilter(...args)
138+
},
130139
(e) => {
131140
if (isPressed.value) {
132141
const preventAction = (!modifierPressed || (modifierPressed && !actInsideInputWithModifier.value)) && isInputDOMNode(e)

0 commit comments

Comments
 (0)