diff --git a/.changeset/selfish-falcons-run.md b/.changeset/selfish-falcons-run.md new file mode 100644 index 000000000..ee0a9fadc --- /dev/null +++ b/.changeset/selfish-falcons-run.md @@ -0,0 +1,5 @@ +--- +"@vue-flow/core": patch +--- + +Allow using the `+` key in key combinations diff --git a/packages/core/src/composables/useKeyPress.ts b/packages/core/src/composables/useKeyPress.ts index 02cd4e8fe..e3c7602c8 100644 --- a/packages/core/src/composables/useKeyPress.ts +++ b/packages/core/src/composables/useKeyPress.ts @@ -25,7 +25,11 @@ function wasModifierPressed(event: KeyboardEvent) { } function isKeyMatch(pressedKey: string, keyToMatch: string, pressedKeys: Set, isKeyUp: boolean) { - const keyCombination = keyToMatch.split('+').map((k) => k.trim().toLowerCase()) + const keyCombination = keyToMatch + .replace('+', '\n') + .replace('\n\n', '\n+') + .split('\n') + .map((k) => k.trim().toLowerCase()) if (keyCombination.length === 1) { return pressedKey.toLowerCase() === keyToMatch.toLowerCase() @@ -50,13 +54,16 @@ function createKeyPredicate(keyFilter: string | string[], pressedKeys: Set isKeyMatch(event[keyOrCode], key, pressedKeys, event.type === 'keyup')) + return keyFilter.some((key) => isKeyMatch(pressedKey, key, pressedKeys, isKeyUp)) } // if the keyFilter is a string, we need to check if the key matches the string - return isKeyMatch(event[keyOrCode], keyFilter, pressedKeys, event.type === 'keyup') + return isKeyMatch(pressedKey, keyFilter, pressedKeys, isKeyUp) } } @@ -126,7 +133,9 @@ export function useKeyPress(keyFilter: MaybeRefOrGetter currentFilter(...args), + (...args) => { + return currentFilter(...args) + }, (e) => { if (isPressed.value) { const preventAction = (!modifierPressed || (modifierPressed && !actInsideInputWithModifier.value)) && isInputDOMNode(e)