mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-11-09 13:44:29 +08:00
refactor: throw if word element is nullish instead of assuming its always there which could cause issues
This commit is contained in:
parent
eab8eefd4b
commit
fb721344a7
1 changed files with 16 additions and 14 deletions
|
|
@ -233,20 +233,22 @@ export function updateActiveElement(
|
|||
}
|
||||
active.classList.remove("active");
|
||||
}
|
||||
try {
|
||||
const activeWord = document.querySelectorAll("#words .word")[
|
||||
currentWordElementIndex
|
||||
] as Element;
|
||||
activeWord.classList.add("active");
|
||||
activeWord.classList.remove("error");
|
||||
activeWordTop = (document.querySelector("#words .active") as HTMLElement)
|
||||
.offsetTop;
|
||||
if (Config.highlightMode === "word") {
|
||||
activeWord.querySelectorAll("letter").forEach((e) => {
|
||||
e.classList.add("correct");
|
||||
});
|
||||
}
|
||||
} catch (e) {}
|
||||
const activeWord =
|
||||
document.querySelectorAll("#words .word")[currentWordElementIndex];
|
||||
|
||||
if (activeWord == undefined) {
|
||||
throw new Error("activeWord is undefined - can't update active element");
|
||||
}
|
||||
|
||||
activeWord.classList.add("active");
|
||||
activeWord.classList.remove("error");
|
||||
activeWordTop = (document.querySelector("#words .active") as HTMLElement)
|
||||
.offsetTop;
|
||||
if (Config.highlightMode === "word") {
|
||||
activeWord.querySelectorAll("letter").forEach((e) => {
|
||||
e.classList.add("correct");
|
||||
});
|
||||
}
|
||||
if (!initial && shouldUpdateWordsInputPosition()) {
|
||||
void updateWordsInputPosition();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue