Skip to content

Commit d6c1766

Browse files
committed
refactor: await word addition, call some UI functions after word addition
1 parent faf7efa commit d6c1766

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function backspaceToPrevious(): void {
176176
Replay.addReplayEvent("backWord");
177177
}
178178

179-
function handleSpace(): void {
179+
async function handleSpace(): Promise<void> {
180180
if (!TestState.isActive) return;
181181

182182
if (TestInput.input.current === "") return;
@@ -224,10 +224,7 @@ function handleSpace(): void {
224224
PaceCaret.handleSpace(true, currentWord);
225225
TestInput.input.pushHistory();
226226
TestWords.words.increaseCurrentIndex();
227-
TestUI.setCurrentWordElementIndex(TestUI.currentWordElementIndex + 1);
228-
TestUI.updateActiveElement();
229227
Funbox.toggleScript(TestWords.words.getCurrent());
230-
void Caret.updatePosition();
231228
TestInput.incrementKeypressCount();
232229
TestInput.pushKeypressWord(TestWords.words.currentIndex);
233230
if (!nospace) {
@@ -273,10 +270,7 @@ function handleSpace(): void {
273270
TestInput.input.pushHistory();
274271
TestUI.highlightBadWord(TestUI.currentWordElementIndex, !Config.blindMode);
275272
TestWords.words.increaseCurrentIndex();
276-
TestUI.setCurrentWordElementIndex(TestUI.currentWordElementIndex + 1);
277-
TestUI.updateActiveElement();
278273
Funbox.toggleScript(TestWords.words.getCurrent());
279-
void Caret.updatePosition();
280274
TestInput.incrementKeypressCount();
281275
TestInput.pushKeypressWord(TestWords.words.currentIndex);
282276
Replay.addReplayEvent("submitErrorWord");
@@ -369,8 +363,11 @@ function handleSpace(): void {
369363
Config.mode === "custom" ||
370364
Config.mode === "quote"
371365
) {
372-
void TestLogic.addWord();
366+
await TestLogic.addWord();
373367
}
368+
TestUI.setCurrentWordElementIndex(TestUI.currentWordElementIndex + 1);
369+
TestUI.updateActiveElement();
370+
void Caret.updatePosition();
374371
}
375372

376373
function isCharCorrect(char: string, charIndex: number): boolean {
@@ -502,7 +499,7 @@ function handleChar(
502499

503500
if (char !== "\n" && char !== "\t" && /\s/.test(char)) {
504501
if (nospace) return;
505-
handleSpace();
502+
void handleSpace();
506503

507504
//insert space for expert and master or strict space,
508505
//or for stop on error set to word,
@@ -762,7 +759,7 @@ function handleChar(
762759
TestInput.input.current.length === TestWords.words.getCurrent().length) ||
763760
(char === "\n" && thisCharCorrect)
764761
) {
765-
handleSpace();
762+
void handleSpace();
766763
}
767764

768765
const currentWord = TestWords.words.getCurrent();

0 commit comments

Comments
 (0)