Skip to content

Commit f6421e7

Browse files
committed
fix: uncaught throw when trying to find newline key element
1 parent 9309c0c commit f6421e7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

frontend/src/ts/elements/keymap.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ const stenoKeys: LayoutObject = {
6161
},
6262
};
6363

64-
function findKeyElements(char: string): ElementsWithUtils {
64+
function findKeyElements(char: string): ElementsWithUtils | null {
65+
if (char === "\n") return null;
66+
6567
if (char === " ") {
6668
return keymap.qsa(".keySpace");
6769
}
@@ -87,6 +89,8 @@ function highlightKey(currentKey: string): void {
8789
}
8890

8991
const $target = findKeyElements(currentKey);
92+
if ($target === null || $target.length === 0) return;
93+
9094
$target.addClass("activeKey");
9195
} catch (e) {
9296
if (e instanceof Error) {
@@ -100,7 +104,7 @@ async function flashKey(key: string, correct?: boolean): Promise<void> {
100104
if (key === undefined) return;
101105
requestDebouncedAnimationFrame(`keymap.flashKey.${key}`, async () => {
102106
const elements = findKeyElements(key);
103-
if (elements.length === 0) return;
107+
if (elements === null || elements.length === 0) return;
104108

105109
const themecolors = await ThemeColors.getAll();
106110

0 commit comments

Comments
 (0)