From a1240d3d7e0e9f64667b72f86b6cbd9b76987241 Mon Sep 17 00:00:00 2001 From: Miodec Date: Sun, 21 Dec 2025 11:27:20 +0100 Subject: [PATCH] refactor: clean up zen mode element removal --- frontend/src/ts/test/test-ui.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/frontend/src/ts/test/test-ui.ts b/frontend/src/ts/test/test-ui.ts index f7422084f..4398a2aff 100644 --- a/frontend/src/ts/test/test-ui.ts +++ b/frontend/src/ts/test/test-ui.ts @@ -1814,20 +1814,19 @@ export async function afterTestWordChange( // } else if (direction === "back") { if (Config.mode === "zen") { - const wordsChildren = [...(wordsEl.children ?? [])] as HTMLElement[]; - + // because we need to delete newline, beforenewline and afternewline elements which dont have wordindex attributes + // we need to do this loop thingy and delete all elements after the active word let deleteElements = false; - for (const child of wordsChildren) { - if ( - !deleteElements && - parseInt(child.getAttribute("data-wordindex") ?? "-1", 10) === - TestState.activeWordIndex - ) { - deleteElements = true; - continue; - } + for (const child of wordsEl.children) { if (deleteElements) { child.remove(); + continue; + } + const attr = child.getAttribute("data-wordindex"); + if (attr === null) continue; + const wordIndex = parseInt(attr, 10); + if (wordIndex === TestState.activeWordIndex) { + deleteElements = true; } } }