Skip to content

Commit 6af3b19

Browse files
committed
fix delay in generating words
1 parent e053c56 commit 6af3b19

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

frontend/src/ts/test/caret.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ function getTargetPositionLeft(
116116
if (letterOuterWidth > 0) lastPositiveLetterWidth = letterOuterWidth;
117117
}
118118
// if current letter has zero width move the caret to previous positive width letter
119-
if ($(currentWordNodeList[inputLen] as Element).outerWidth(true) === 0) {
119+
if ($(currentWordNodeList[inputLen] as Element).outerWidth(true) === 0)
120120
currentWordWidth -= lastPositiveLetterWidth;
121-
}
122121
if (isLanguageRightToLeft) currentWordWidth *= -1;
123122
result += currentWordWidth;
124123
}

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

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ export async function scrollTape(): Promise<void> {
938938
document.getElementById("wordsWrapper") as HTMLElement
939939
).offsetWidth;
940940
const words = document.getElementById("words") as HTMLElement;
941-
const wordElements = words.querySelectorAll(".word");
941+
const wordElements = words.getElementsByClassName("word");
942942

943943
let fullWordsWidth = 0;
944944
let widthToHide = 0;
@@ -958,13 +958,22 @@ export async function scrollTape(): Promise<void> {
958958
widthToHide += wordOuterWidth;
959959
}
960960
}
961+
if (toHide.length > 0) {
962+
currentWordElementIndex -= toHide.length;
963+
toHide.forEach((e) => e.remove());
964+
fullWordsWidth -= widthToHide;
965+
if (isLanguageRTL) widthToHide *= -1;
966+
const currentMargin = parseInt($(words).css("margin-left"), 10);
967+
words.style.marginLeft = `${currentMargin + widthToHide}px`;
968+
}
969+
const inputLength = TestInput.input.current.length;
961970
let currentWordWidth = 0;
962-
if (Config.tapeMode === "letter" && TestInput.input.current.length > 0) {
971+
if (Config.tapeMode === "letter" && inputLength > 0) {
963972
const letters =
964973
wordElements[currentWordElementIndex]?.querySelectorAll("letter");
965974
if (!letters) return;
966975
let lastPositiveLetterWidth = 0;
967-
for (let i = 0; i < TestInput.input.current.length; i++) {
976+
for (let i = 0; i < inputLength; i++) {
968977
const letter = letters[i] as HTMLElement;
969978
if (
970979
(Config.blindMode || Config.hideExtraLetters) &&
@@ -977,10 +986,7 @@ export async function scrollTape(): Promise<void> {
977986
if (letterOuterWidth > 0) lastPositiveLetterWidth = letterOuterWidth;
978987
}
979988
// if current letter has zero width move the tape to previous positive width letter
980-
if (
981-
$(letters[TestInput.input.current.length] as Element).outerWidth(true) ===
982-
0
983-
)
989+
if ($(letters[inputLength] as Element).outerWidth(true) === 0)
984990
currentWordWidth -= lastPositiveLetterWidth;
985991
}
986992

@@ -1000,17 +1006,7 @@ export async function scrollTape(): Promise<void> {
10001006
{
10011007
marginLeft: newMargin,
10021008
},
1003-
{
1004-
duration: SlowTimer.get() ? 0 : 125,
1005-
complete: () => {
1006-
if (!toHide.length) return;
1007-
currentWordElementIndex -= toHide.length;
1008-
toHide.forEach((e) => e.remove());
1009-
fullWordsWidth -= widthToHide;
1010-
if (isLanguageRTL) widthToHide *= -1;
1011-
words.style.marginLeft = `${newMargin + widthToHide}px`;
1012-
},
1013-
}
1009+
SlowTimer.get() ? 0 : 125
10141010
);
10151011
} else {
10161012
words.style.marginLeft = `${newMargin}px`;

0 commit comments

Comments
 (0)