Skip to content

Commit b021237

Browse files
committed
only last leading .afterNewline element pushes .words to right
1 parent 550eb61 commit b021237

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,27 +967,32 @@ export function scrollTape(): void {
967967
let widthToHide = 0;
968968
let wordsToHideCount = 0;
969969
let leadingNewLine = 0;
970+
let lastAfterNewLineElement = undefined;
970971
const linesWidths: number[] = [];
971972
const toHide: HTMLElement[] = [];
972973

973974
// remove leading `.newline` and `.afterNewline` elements
974975
for (const child of wordsChildrenArr) {
975976
if (child.classList.contains("word")) {
977+
// only last leading `.afterNewline` element pushes `.word`s to right
978+
if (lastAfterNewLineElement) {
979+
widthToHide += parseInt(lastAfterNewLineElement.style.marginLeft);
980+
}
976981
break;
977982
} else if (child.classList.contains("newline")) {
978983
toHide.push(child);
979984
} else if (child.classList.contains("afterNewline")) {
980985
toHide.push(child);
981-
widthToHide += parseInt(child.style.marginLeft);
982986
leadingNewLine = 1;
987+
lastAfterNewLineElement = child;
983988
}
984989
}
985990
// get last element to loop over
986991
const activeWordIndex = wordsChildrenArr.indexOf(activeWordEl);
987992
const newLinesBeforeActiveWord = wordsChildrenArr
988993
.slice(0, activeWordIndex)
989994
.filter((child) => child.classList.contains("afterNewline")).length;
990-
// the second .afterNewline after active word is visible during line jump
995+
// the second `.afterNewline` after active word is visible during line jump
991996
let lastVisibleAfterNewline = afterNewLineEls[
992997
newLinesBeforeActiveWord + 1
993998
] as HTMLElement | undefined;

0 commit comments

Comments
 (0)