From 2fb9fcb956ac6ab8705cc1a9b726c0ca583abd2a Mon Sep 17 00:00:00 2001 From: sanidhyas3s Date: Sun, 25 Aug 2024 02:30:11 +0530 Subject: [PATCH] Fix word and caret shift on Wikipedia (and Poetry) funbox --- frontend/src/ts/controllers/input-controller.ts | 17 +++++++++-------- frontend/src/ts/test/test-logic.ts | 8 ++------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/frontend/src/ts/controllers/input-controller.ts b/frontend/src/ts/controllers/input-controller.ts index 0a2715ab75bf..f91e47fa7c7d 100644 --- a/frontend/src/ts/controllers/input-controller.ts +++ b/frontend/src/ts/controllers/input-controller.ts @@ -320,14 +320,6 @@ async function handleSpace(): Promise { ) { TimerProgress.update(); } - if ( - Config.mode === "time" || - Config.mode === "words" || - Config.mode === "custom" || - Config.mode === "quote" - ) { - await TestLogic.addWord(); - } TestUI.setCurrentWordElementIndex(TestUI.currentWordElementIndex + 1); TestUI.updateActiveElement(); void Caret.updatePosition(); @@ -368,6 +360,15 @@ async function handleSpace(): Promise { // //send a tab event using jquery // $("#wordsInput").trigger($.Event("keydown", { key: "Tab", code: "Tab" })); // } + // await for addWord should not hold other actions within this function hence should be called last + if ( + Config.mode === "time" || + Config.mode === "words" || + Config.mode === "custom" || + Config.mode === "quote" + ) { + await TestLogic.addWord(); + } } function isCharCorrect(char: string, charIndex: number): boolean { diff --git a/frontend/src/ts/test/test-logic.ts b/frontend/src/ts/test/test-logic.ts index 4d238d9c49cc..59871ec5b7b8 100644 --- a/frontend/src/ts/test/test-logic.ts +++ b/frontend/src/ts/test/test-logic.ts @@ -559,7 +559,7 @@ export async function addWord(): Promise { Config.language ); - if (section === false) { + if (section === undefined || section === false) { Notifications.add( "Error while getting section. Please try again later", -1 @@ -569,15 +569,11 @@ export async function addWord(): Promise { return; } - if (section === undefined) return; - - let wordCount = 0; for (let i = 0; i < section.words.length; i++) { const word = section.words[i] as string; - if (wordCount >= Config.words && Config.mode === "words") { + if (i >= Config.words && Config.mode === "words") { break; } - wordCount++; TestWords.words.push(word, i); TestUI.addWord(word); }