@@ -62,15 +62,18 @@ export default function useHotkeys<T extends HTMLElement>(
6262 return
6363 }
6464
65+ let recordedKeys : string [ ] = [ ]
66+ let sequenceTimer : NodeJS . Timeout | undefined
67+
6568 const [ comboHotkeys , sequenceHotkeys ] = parseKeysHookInput ( _keys , memoisedOptions ?. delimiter )
6669 . reduce < [ Hotkey [ ] , Hotkey [ ] ] > ( ( acc , key ) => {
67- const [ _comboHotkey , _sequenceHotkey ] = acc ;
70+ const [ _comboHotkey , _sequenceHotkey ] = acc
6871
6972 const splitKey = memoisedOptions ?. splitKey ?? '+'
7073 const sequenceSplitKey = memoisedOptions ?. sequenceSplitKey ?? '>'
7174
7275 if ( key . includes ( splitKey ) && key . includes ( sequenceSplitKey ) ) {
73- console . warn ( `Hotkey ${ key } contains both ${ splitKey } and ${ sequenceSplitKey } which is not supported.` ) ;
76+ console . warn ( `Hotkey ${ key } contains both ${ splitKey } and ${ sequenceSplitKey } which is not supported.` )
7477 }
7578
7679 const hotkey = parseHotkey (
@@ -87,10 +90,7 @@ export default function useHotkeys<T extends HTMLElement>(
8790 _comboHotkey . push ( hotkey )
8891 }
8992 return [ _comboHotkey , _sequenceHotkey ]
90- } , [ [ ] , [ ] ] ) ;
91-
92- let sequenceRecordedKeys : string [ ] = [ ] ;
93- let sequenceTimer : NodeJS . Timeout | undefined = undefined ;
93+ } , [ [ ] , [ ] ] )
9494
9595 const combinedHotkeys = [ ...comboHotkeys , ...sequenceHotkeys ]
9696
@@ -158,22 +158,22 @@ export default function useHotkeys<T extends HTMLElement>(
158158 if ( ! isHotkeyModifier ( currentKey . toLowerCase ( ) ) ) {
159159 // clear the previous timer
160160 if ( sequenceTimer ) {
161- clearTimeout ( sequenceTimer ) ;
161+ clearTimeout ( sequenceTimer )
162162 }
163163
164164 sequenceTimer = setTimeout ( ( ) => {
165- sequenceRecordedKeys = [ ] ;
166- } , memoisedOptions ?. sequenceTimeoutMs ?? 1000 ) ;
165+ recordedKeys = [ ]
166+ } , memoisedOptions ?. sequenceTimeoutMs ?? 1000 )
167167
168- sequenceRecordedKeys . push ( currentKey ) ;
168+ recordedKeys . push ( currentKey )
169169
170170 for ( const hotkey of sequenceHotkeys ) {
171171 if ( ! hotkey . keys ) {
172172 continue
173173 }
174174
175- if ( sequenceEndsWith ( sequenceRecordedKeys , [ ...hotkey . keys ] ) ) {
176- cbRef . current ( e , hotkey ) ;
175+ if ( sequenceEndsWith ( recordedKeys , [ ...hotkey . keys ] ) ) {
176+ cbRef . current ( e , hotkey )
177177 }
178178 }
179179 }
@@ -226,12 +226,12 @@ export default function useHotkeys<T extends HTMLElement>(
226226 domNode . removeEventListener ( 'keydown' , handleKeyDown , _options ?. eventListenerOptions )
227227
228228 if ( proxy ) {
229- combinedHotkeys . forEach ( proxy . removeHotkey ) ;
229+ combinedHotkeys . forEach ( proxy . removeHotkey )
230230 }
231231
232- sequenceRecordedKeys = [ ] ;
232+ recordedKeys = [ ]
233233 if ( sequenceTimer ) {
234- clearTimeout ( sequenceTimer ) ;
234+ clearTimeout ( sequenceTimer )
235235 }
236236 }
237237 } , [ _keys , memoisedOptions , activeScopes ] )
0 commit comments