Skip to content

Commit faf7efa

Browse files
committed
refactor: move test finish/fail logic, add all words generated check
1 parent 148fa1e commit faf7efa

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

frontend/src/ts/controllers/input-controller.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,6 @@ function handleSpace(): void {
234234
void Sound.playClick();
235235
}
236236
Replay.addReplayEvent("submitCorrectWord");
237-
if (TestWords.words.currentIndex === TestWords.words.length) {
238-
//submitted last word (checking this in case the test doesnt stop automatically on correct last keypress)
239-
void TestLogic.finish();
240-
return;
241-
}
242237
} else {
243238
if (!nospace) {
244239
if (Config.playSoundOnError === "off" || Config.blindMode) {
@@ -284,15 +279,22 @@ function handleSpace(): void {
284279
void Caret.updatePosition();
285280
TestInput.incrementKeypressCount();
286281
TestInput.pushKeypressWord(TestWords.words.currentIndex);
287-
if (Config.difficulty === "expert" || Config.difficulty === "master") {
282+
Replay.addReplayEvent("submitErrorWord");
283+
}
284+
285+
if (
286+
TestLogic.areAllTestWordsGenerated() &&
287+
TestWords.words.currentIndex === TestWords.words.length
288+
) {
289+
if (
290+
!isWordCorrect &&
291+
(Config.difficulty === "expert" || Config.difficulty === "master")
292+
) {
288293
TestLogic.fail("difficulty");
289-
return;
290-
} else if (TestWords.words.currentIndex === TestWords.words.length) {
291-
//submitted last word that is incorrect
294+
} else {
292295
void TestLogic.finish();
293-
return;
294296
}
295-
Replay.addReplayEvent("submitErrorWord");
297+
return;
296298
}
297299

298300
let wordLength: number;

0 commit comments

Comments
 (0)