Skip to content

Commit a1240d3

Browse files
committed
refactor: clean up zen mode element removal
1 parent 16b4ec8 commit a1240d3

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

frontend/src/ts/test/test-ui.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,20 +1814,19 @@ export async function afterTestWordChange(
18141814
//
18151815
} else if (direction === "back") {
18161816
if (Config.mode === "zen") {
1817-
const wordsChildren = [...(wordsEl.children ?? [])] as HTMLElement[];
1818-
1817+
// because we need to delete newline, beforenewline and afternewline elements which dont have wordindex attributes
1818+
// we need to do this loop thingy and delete all elements after the active word
18191819
let deleteElements = false;
1820-
for (const child of wordsChildren) {
1821-
if (
1822-
!deleteElements &&
1823-
parseInt(child.getAttribute("data-wordindex") ?? "-1", 10) ===
1824-
TestState.activeWordIndex
1825-
) {
1826-
deleteElements = true;
1827-
continue;
1828-
}
1820+
for (const child of wordsEl.children) {
18291821
if (deleteElements) {
18301822
child.remove();
1823+
continue;
1824+
}
1825+
const attr = child.getAttribute("data-wordindex");
1826+
if (attr === null) continue;
1827+
const wordIndex = parseInt(attr, 10);
1828+
if (wordIndex === TestState.activeWordIndex) {
1829+
deleteElements = true;
18311830
}
18321831
}
18331832
}

0 commit comments

Comments
 (0)