Skip to content

Commit

Permalink
Fix word and caret shift on Wikipedia (and Poetry) funbox
Browse files Browse the repository at this point in the history
  • Loading branch information
sanidhyas3s committed Aug 24, 2024
1 parent cb7d910 commit 2fb9fcb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
17 changes: 9 additions & 8 deletions frontend/src/ts/controllers/input-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,6 @@ async function handleSpace(): Promise<void> {
) {
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();
Expand Down Expand Up @@ -368,6 +360,15 @@ async function handleSpace(): Promise<void> {
// //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 {
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/ts/test/test-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ export async function addWord(): Promise<void> {
Config.language
);

if (section === false) {
if (section === undefined || section === false) {
Notifications.add(
"Error while getting section. Please try again later",
-1
Expand All @@ -569,15 +569,11 @@ export async function addWord(): Promise<void> {
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);
}
Expand Down

0 comments on commit 2fb9fcb

Please sign in to comment.