impr(read ahead): show words after correcting typo with backspace (@notTamion) (#6006)

This commit is contained in:
Tamion 2024-11-19 00:01:21 +01:00 committed by GitHub
parent dea95a243c
commit bbfafc1cc5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 51 additions and 10 deletions

View file

@ -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",
},
{

View file

@ -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";

View file

@ -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", {

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}