Skip to content

Commit

Permalink
refactor: await addWord if the test is out of words
Browse files Browse the repository at this point in the history
fixes #5630 by not always awaiting
closes #5819
  • Loading branch information
Miodec committed Aug 28, 2024
1 parent 13eab07 commit 7b4a789
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions frontend/src/ts/controllers/input-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ import * as KeymapEvent from "../observables/keymap-event";
import { IgnoredKeys } from "../constants/ignored-keys";
import { ModifierKeys } from "../constants/modifier-keys";
import { navigate } from "./route-controller";
import * as Loader from "../elements/loader";

let dontInsertSpace = false;
let correctShiftUsed = true;
let isKoCompiling = false;
let isBackspace: boolean;
let incorrectShiftsInARow = 0;
let awaitingNextWord = false;

const wordsInput = document.getElementById("wordsInput") as HTMLInputElement;
const koInputVisual = document.getElementById("koInputVisual") as HTMLElement;
Expand Down Expand Up @@ -283,10 +285,8 @@ async function handleSpace(): Promise<void> {
}
}

if (
TestLogic.areAllTestWordsGenerated() &&
TestWords.words.currentIndex === TestWords.words.length
) {
const isLastWord = TestWords.words.currentIndex === TestWords.words.length;
if (TestLogic.areAllTestWordsGenerated() && isLastWord) {
void TestLogic.finish();
return;
}
Expand Down Expand Up @@ -326,7 +326,15 @@ async function handleSpace(): Promise<void> {
Config.mode === "custom" ||
Config.mode === "quote"
) {
await TestLogic.addWord();
if (isLastWord) {
awaitingNextWord = true;
Loader.show();
await TestLogic.addWord();
Loader.hide();
awaitingNextWord = false;
} else {
void TestLogic.addWord();
}
}
TestUI.setActiveWordElementIndex(TestUI.activeWordElementIndex + 1);
TestUI.updateActiveElement();
Expand Down Expand Up @@ -882,7 +890,8 @@ $("#wordsInput").on("keydown", (event) => {
!leaderboardsVisible &&
!popupVisible &&
!TestUI.resultVisible &&
event.key !== "Enter";
event.key !== "Enter" &&
!awaitingNextWord;

if (!allowTyping) {
event.preventDefault();
Expand Down Expand Up @@ -918,7 +927,8 @@ $(document).on("keydown", async (event) => {
!leaderboardsVisible &&
!popupVisible &&
!TestUI.resultVisible &&
(wordsFocused || event.key !== "Enter");
(wordsFocused || event.key !== "Enter") &&
!awaitingNextWord;

if (
allowTyping &&
Expand Down

0 comments on commit 7b4a789

Please sign in to comment.