Skip to content

Commit ee02bee

Browse files
authored
fix(wordsInput): prevent automatic scrolling when focusing #wordsInput (@nadalaba) (#6724)
fix #6723
1 parent 14cf7b0 commit ee02bee

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

frontend/src/ts/test/test-logic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export function restart(options = {} as RestartOptions): void {
310310
async () => {
311311
$("#result").addClass("hidden");
312312
$("#typingTest").css("opacity", 0).removeClass("hidden");
313-
$("#wordsInput").val(" ");
313+
$("#wordsInput").css({ left: 0 }).val(" ");
314314

315315
if (Config.language.startsWith("korean")) {
316316
koInputVisual.innerText = " ";

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,7 @@ function updateWordWrapperClasses(): void {
438438

439439
updateWordsWidth();
440440
updateWordsWrapperHeight(true);
441-
updateWordsMargin();
442-
setTimeout(() => {
443-
void updateWordsInputPosition(true);
444-
}, 250);
441+
updateWordsMargin(updateWordsInputPosition, [true]);
445442
}
446443

447444
export function showWords(): void {
@@ -637,9 +634,16 @@ export function updateWordsWrapperHeight(force = false): void {
637634
outOfFocusEl.style.maxHeight = wordHeight * 3 + "px";
638635
}
639636

640-
function updateWordsMargin(): void {
637+
function updateWordsMargin<T extends unknown[]>(
638+
afterCompleteFn: (...args: T) => void,
639+
args: T
640+
): void {
641+
const afterComplete = (): void => {
642+
afterCompleteFn(...args);
643+
void updateHintsPositionDebounced();
644+
};
641645
if (Config.tapeMode !== "off") {
642-
void scrollTape(true, updateHintsPositionDebounced);
646+
void scrollTape(true, afterComplete);
643647
} else {
644648
const wordsEl = document.getElementById("words") as HTMLElement;
645649
const afterNewlineEls =
@@ -653,7 +657,7 @@ function updateWordsMargin(): void {
653657
{
654658
duration: SlowTimer.get() ? 0 : 125,
655659
queue: "leftMargin",
656-
complete: updateHintsPositionDebounced,
660+
complete: afterComplete,
657661
}
658662
);
659663
jqWords.dequeue("leftMargin");
@@ -665,7 +669,7 @@ function updateWordsMargin(): void {
665669
for (const afterNewline of afterNewlineEls) {
666670
afterNewline.style.marginLeft = `0`;
667671
}
668-
void updateHintsPositionDebounced();
672+
afterComplete();
669673
}
670674
}
671675
}

0 commit comments

Comments
 (0)