@@ -25,7 +25,11 @@ function wasModifierPressed(event: KeyboardEvent) {
25
25
}
26
26
27
27
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 ( ) )
29
33
30
34
if ( keyCombination . length === 1 ) {
31
35
return pressedKey . toLowerCase ( ) === keyToMatch . toLowerCase ( )
@@ -50,13 +54,16 @@ function createKeyPredicate(keyFilter: string | string[], pressedKeys: Set<strin
50
54
51
55
const keyOrCode = useKeyOrCode ( event . code , keyFilter )
52
56
57
+ const isKeyUp = event . type === 'keyup'
58
+ const pressedKey = event [ keyOrCode ]
59
+
53
60
// if the keyFilter is an array of multiple keys, we need to check each possible key combination
54
61
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 ) )
56
63
}
57
64
58
65
// 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 )
60
67
}
61
68
}
62
69
@@ -126,7 +133,9 @@ export function useKeyPress(keyFilter: MaybeRefOrGetter<KeyFilter | boolean | nu
126
133
)
127
134
128
135
onKeyStroke (
129
- ( ...args ) => currentFilter ( ...args ) ,
136
+ ( ...args ) => {
137
+ return currentFilter ( ...args )
138
+ } ,
130
139
( e ) => {
131
140
if ( isPressed . value ) {
132
141
const preventAction = ( ! modifierPressed || ( modifierPressed && ! actInsideInputWithModifier . value ) ) && isInputDOMNode ( e )
0 commit comments