aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTamion <[email protected]>2024-11-19 00:01:21 +0100
committerGitHub <[email protected]>2024-11-19 00:01:21 +0100
commitbbfafc1cc575631407bb6e27d971b86fa30d18f7 (patch)
treebcf6ddda0ad4cc564c851871de661e690b471f34
parentdea95a243cf147818b0ee19fd17957e033518eb9 (diff)
downloadmonkeytype-bbfafc1cc575631407bb6e27d971b86fa30d18f7.tar.gz
monkeytype-bbfafc1cc575631407bb6e27d971b86fa30d18f7.zip
impr(read ahead): show words after correcting typo with backspace (@notTamion) (#6006)
-rw-r--r--backend/src/constants/funbox-list.ts6
-rw-r--r--frontend/src/ts/controllers/input-controller.ts6
-rw-r--r--frontend/src/ts/test/funbox/funbox.ts32
-rw-r--r--frontend/src/ts/utils/json-data.ts2
-rw-r--r--frontend/static/funbox/read_ahead.css4
-rw-r--r--frontend/static/funbox/read_ahead_easy.css2
-rw-r--r--frontend/static/funbox/read_ahead_hard.css9
7 files changed, 51 insertions, 10 deletions
diff --git a/backend/src/constants/funbox-list.ts b/backend/src/constants/funbox-list.ts
index 61b88a139..6ee0bb06a 100644
--- a/backend/src/constants/funbox-list.ts
+++ b/backend/src/constants/funbox-list.ts
@@ -205,7 +205,7 @@ const FunboxList: FunboxMetadata[] = [
frontendForcedConfig: {
highlightMode: ["letter", "off"],
},
- frontendFunctions: ["applyCSS", "rememberSettings"],
+ frontendFunctions: ["applyCSS", "rememberSettings", "handleKeydown"],
name: "read_ahead_easy",
},
{
@@ -215,7 +215,7 @@ const FunboxList: FunboxMetadata[] = [
frontendForcedConfig: {
highlightMode: ["letter", "off"],
},
- frontendFunctions: ["applyCSS", "rememberSettings"],
+ frontendFunctions: ["applyCSS", "rememberSettings", "handleKeydown"],
name: "read_ahead",
},
{
@@ -225,7 +225,7 @@ const FunboxList: FunboxMetadata[] = [
frontendForcedConfig: {
highlightMode: ["letter", "off"],
},
- frontendFunctions: ["applyCSS", "rememberSettings"],
+ frontendFunctions: ["applyCSS", "rememberSettings", "handleKeydown"],
name: "read_ahead_hard",
},
{
diff --git a/frontend/src/ts/controllers/input-controller.ts b/frontend/src/ts/controllers/input-controller.ts
index 951f04817..5acdae853 100644
--- a/frontend/src/ts/controllers/input-controller.ts
+++ b/frontend/src/ts/controllers/input-controller.ts
@@ -907,6 +907,12 @@ $(document).on("keydown", async (event) => {
return;
}
+ FunboxList.get(Config.funbox).forEach((value) => {
+ if (value.functions?.handleKeydown) {
+ void value.functions?.handleKeydown(event);
+ }
+ });
+
//autofocus
const wordsFocused: boolean = $("#wordsInput").is(":focus");
const pageTestActive: boolean = ActivePage.get() === "test";
diff --git a/frontend/src/ts/test/funbox/funbox.ts b/frontend/src/ts/test/funbox/funbox.ts
index fff8f111b..3974bc5d8 100644
--- a/frontend/src/ts/test/funbox/funbox.ts
+++ b/frontend/src/ts/test/funbox/funbox.ts
@@ -379,22 +379,54 @@ FunboxList.setFunboxFunctions("specials", {
},
});
+async function readAheadHandleKeydown(
+ event: JQuery.KeyDownEvent<Document, undefined, Document, Document>
+): Promise<void> {
+ const inputCurrentChar = (TestInput.input.current ?? "").slice(-1);
+ const wordCurrentChar = TestWords.words
+ .getCurrent()
+ .slice(TestInput.input.current.length - 1, TestInput.input.current.length);
+ const isCorrect = inputCurrentChar === wordCurrentChar;
+
+ if (
+ event.key == "Backspace" &&
+ !isCorrect &&
+ (TestInput.input.current != "" ||
+ TestInput.input.history[TestWords.words.currentIndex - 1] !=
+ TestWords.words.get(TestWords.words.currentIndex - 1) ||
+ Config.freedomMode)
+ ) {
+ $("#words").addClass("read_ahead_disabled");
+ } else if (event.key == " ") {
+ $("#words").removeClass("read_ahead_disabled");
+ }
+}
+
FunboxList.setFunboxFunctions("read_ahead_easy", {
rememberSettings(): void {
save("highlightMode", Config.highlightMode, UpdateConfig.setHighlightMode);
},
+ async handleKeydown(event): Promise<void> {
+ await readAheadHandleKeydown(event);
+ },
});
FunboxList.setFunboxFunctions("read_ahead", {
rememberSettings(): void {
save("highlightMode", Config.highlightMode, UpdateConfig.setHighlightMode);
},
+ async handleKeydown(event): Promise<void> {
+ await readAheadHandleKeydown(event);
+ },
});
FunboxList.setFunboxFunctions("read_ahead_hard", {
rememberSettings(): void {
save("highlightMode", Config.highlightMode, UpdateConfig.setHighlightMode);
},
+ async handleKeydown(event): Promise<void> {
+ await readAheadHandleKeydown(event);
+ },
});
FunboxList.setFunboxFunctions("memory", {
diff --git a/frontend/src/ts/utils/json-data.ts b/frontend/src/ts/utils/json-data.ts
index 79909d5c4..93580bf61 100644
--- a/frontend/src/ts/utils/json-data.ts
+++ b/frontend/src/ts/utils/json-data.ts
@@ -362,7 +362,7 @@ export type FunboxFunctions = {
event: JQuery.KeyDownEvent<Document, null, Document, Document>
) => Promise<boolean>;
handleKeydown?: (
- event: JQuery.KeyDownEvent<Document, null, Document, Document>
+ event: JQuery.KeyDownEvent<Document, undefined, Document, Document>
) => Promise<void>;
getResultContent?: () => string;
start?: () => void;
diff --git a/frontend/static/funbox/read_ahead.css b/frontend/static/funbox/read_ahead.css
index 984d50b05..be5620758 100644
--- a/frontend/static/funbox/read_ahead.css
+++ b/frontend/static/funbox/read_ahead.css
@@ -1,5 +1,5 @@
-#words .word.active:nth-of-type(n + 2),
-#words .word.active:nth-of-type(n + 2) + .word {
+#words:not(.read_ahead_disabled) .word.active:nth-of-type(n + 2),
+#words:not(.read_ahead_disabled) .word.active:nth-of-type(n + 2) + .word {
--untyped-letter-color: transparent;
--untyped-letter-animation: none;
}
diff --git a/frontend/static/funbox/read_ahead_easy.css b/frontend/static/funbox/read_ahead_easy.css
index 95f265f05..67215f5f6 100644
--- a/frontend/static/funbox/read_ahead_easy.css
+++ b/frontend/static/funbox/read_ahead_easy.css
@@ -1,4 +1,4 @@
-#words .word.active:nth-of-type(n + 2) {
+#words:not(.read_ahead_disabled) .word.active:nth-of-type(n + 2) {
--untyped-letter-color: transparent;
--untyped-letter-animation: none;
}
diff --git a/frontend/static/funbox/read_ahead_hard.css b/frontend/static/funbox/read_ahead_hard.css
index 903400ea7..df37d119b 100644
--- a/frontend/static/funbox/read_ahead_hard.css
+++ b/frontend/static/funbox/read_ahead_hard.css
@@ -1,6 +1,9 @@
-#words .word.active:nth-of-type(n + 2),
-#words .word.active:nth-of-type(n + 2) + .word,
-#words .word.active:nth-of-type(n + 2) + .word + .word {
+#words:not(.read_ahead_disabled) .word.active:nth-of-type(n + 2),
+#words:not(.read_ahead_disabled) .word.active:nth-of-type(n + 2) + .word,
+#words:not(.read_ahead_disabled)
+ .word.active:nth-of-type(n + 2)
+ + .word
+ + .word {
--untyped-letter-color: transparent;
--untyped-letter-animation: none;
}