Skip to content

Commit bbfafc1

Browse files
authored
impr(read ahead): show words after correcting typo with backspace (@notTamion) (monkeytypegame#6006)
1 parent dea95a2 commit bbfafc1

File tree

7 files changed

+51
-10
lines changed

7 files changed

+51
-10
lines changed

backend/src/constants/funbox-list.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ const FunboxList: FunboxMetadata[] = [
205205
frontendForcedConfig: {
206206
highlightMode: ["letter", "off"],
207207
},
208-
frontendFunctions: ["applyCSS", "rememberSettings"],
208+
frontendFunctions: ["applyCSS", "rememberSettings", "handleKeydown"],
209209
name: "read_ahead_easy",
210210
},
211211
{
@@ -215,7 +215,7 @@ const FunboxList: FunboxMetadata[] = [
215215
frontendForcedConfig: {
216216
highlightMode: ["letter", "off"],
217217
},
218-
frontendFunctions: ["applyCSS", "rememberSettings"],
218+
frontendFunctions: ["applyCSS", "rememberSettings", "handleKeydown"],
219219
name: "read_ahead",
220220
},
221221
{
@@ -225,7 +225,7 @@ const FunboxList: FunboxMetadata[] = [
225225
frontendForcedConfig: {
226226
highlightMode: ["letter", "off"],
227227
},
228-
frontendFunctions: ["applyCSS", "rememberSettings"],
228+
frontendFunctions: ["applyCSS", "rememberSettings", "handleKeydown"],
229229
name: "read_ahead_hard",
230230
},
231231
{

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,12 @@ $(document).on("keydown", async (event) => {
907907
return;
908908
}
909909

910+
FunboxList.get(Config.funbox).forEach((value) => {
911+
if (value.functions?.handleKeydown) {
912+
void value.functions?.handleKeydown(event);
913+
}
914+
});
915+
910916
//autofocus
911917
const wordsFocused: boolean = $("#wordsInput").is(":focus");
912918
const pageTestActive: boolean = ActivePage.get() === "test";

frontend/src/ts/test/funbox/funbox.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,22 +379,54 @@ FunboxList.setFunboxFunctions("specials", {
379379
},
380380
});
381381

382+
async function readAheadHandleKeydown(
383+
event: JQuery.KeyDownEvent<Document, undefined, Document, Document>
384+
): Promise<void> {
385+
const inputCurrentChar = (TestInput.input.current ?? "").slice(-1);
386+
const wordCurrentChar = TestWords.words
387+
.getCurrent()
388+
.slice(TestInput.input.current.length - 1, TestInput.input.current.length);
389+
const isCorrect = inputCurrentChar === wordCurrentChar;
390+
391+
if (
392+
event.key == "Backspace" &&
393+
!isCorrect &&
394+
(TestInput.input.current != "" ||
395+
TestInput.input.history[TestWords.words.currentIndex - 1] !=
396+
TestWords.words.get(TestWords.words.currentIndex - 1) ||
397+
Config.freedomMode)
398+
) {
399+
$("#words").addClass("read_ahead_disabled");
400+
} else if (event.key == " ") {
401+
$("#words").removeClass("read_ahead_disabled");
402+
}
403+
}
404+
382405
FunboxList.setFunboxFunctions("read_ahead_easy", {
383406
rememberSettings(): void {
384407
save("highlightMode", Config.highlightMode, UpdateConfig.setHighlightMode);
385408
},
409+
async handleKeydown(event): Promise<void> {
410+
await readAheadHandleKeydown(event);
411+
},
386412
});
387413

388414
FunboxList.setFunboxFunctions("read_ahead", {
389415
rememberSettings(): void {
390416
save("highlightMode", Config.highlightMode, UpdateConfig.setHighlightMode);
391417
},
418+
async handleKeydown(event): Promise<void> {
419+
await readAheadHandleKeydown(event);
420+
},
392421
});
393422

394423
FunboxList.setFunboxFunctions("read_ahead_hard", {
395424
rememberSettings(): void {
396425
save("highlightMode", Config.highlightMode, UpdateConfig.setHighlightMode);
397426
},
427+
async handleKeydown(event): Promise<void> {
428+
await readAheadHandleKeydown(event);
429+
},
398430
});
399431

400432
FunboxList.setFunboxFunctions("memory", {

frontend/src/ts/utils/json-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ export type FunboxFunctions = {
362362
event: JQuery.KeyDownEvent<Document, null, Document, Document>
363363
) => Promise<boolean>;
364364
handleKeydown?: (
365-
event: JQuery.KeyDownEvent<Document, null, Document, Document>
365+
event: JQuery.KeyDownEvent<Document, undefined, Document, Document>
366366
) => Promise<void>;
367367
getResultContent?: () => string;
368368
start?: () => void;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#words .word.active:nth-of-type(n + 2),
2-
#words .word.active:nth-of-type(n + 2) + .word {
1+
#words:not(.read_ahead_disabled) .word.active:nth-of-type(n + 2),
2+
#words:not(.read_ahead_disabled) .word.active:nth-of-type(n + 2) + .word {
33
--untyped-letter-color: transparent;
44
--untyped-letter-animation: none;
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#words .word.active:nth-of-type(n + 2) {
1+
#words:not(.read_ahead_disabled) .word.active:nth-of-type(n + 2) {
22
--untyped-letter-color: transparent;
33
--untyped-letter-animation: none;
44
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
#words .word.active:nth-of-type(n + 2),
2-
#words .word.active:nth-of-type(n + 2) + .word,
3-
#words .word.active:nth-of-type(n + 2) + .word + .word {
1+
#words:not(.read_ahead_disabled) .word.active:nth-of-type(n + 2),
2+
#words:not(.read_ahead_disabled) .word.active:nth-of-type(n + 2) + .word,
3+
#words:not(.read_ahead_disabled)
4+
.word.active:nth-of-type(n + 2)
5+
+ .word
6+
+ .word {
47
--untyped-letter-color: transparent;
58
--untyped-letter-animation: none;
69
}

0 commit comments

Comments
 (0)