mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-12-27 18:38:37 +08:00
refactor: clean up zen mode element removal
This commit is contained in:
parent
16b4ec88af
commit
a1240d3d7e
1 changed files with 10 additions and 11 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue