refactor: throw if word element is nullish instead of assuming its always there which could cause issues

This commit is contained in:
Miodec 2024-06-11 00:30:57 +02:00
parent eab8eefd4b
commit fb721344a7

View file

@ -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();
}