Skip to content

Commit f746d7d

Browse files
committed
chore: code style
1 parent 17e8118 commit f746d7d

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

packages/react-hotkeys-hook/src/lib/parseHotkeys.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ export function parseKeysHookInput(keys: string, delimiter = ','): string[] {
4040
*/
4141
export const sequenceEndsWith = (sequence: string[], subSequence: string[]): boolean => {
4242
if (sequence.length < subSequence.length) {
43-
return false;
43+
return false
4444
}
4545

46-
const endOfSequence = sequence.slice(-subSequence.length);
46+
const endOfSequence = sequence.slice(-subSequence.length)
4747

48-
return subSequence.every((key, index) => key === endOfSequence[index]);
49-
};
48+
return subSequence.every((key, index) => key === endOfSequence[index])
49+
}
5050

5151
export function parseHotkey(
5252
hotkey: string,

packages/react-hotkeys-hook/src/lib/useHotkeys.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)