Skip to content

Commit 13b75f4

Browse files
Leonabcd123Miodec
andauthored
feat(test): add indicate typos both (@Leonabcd123) (#7072)
### Description Added a "both" option to indicate typos that keeps the replace functionality, and makes the below functionality show the correct instead of the incorrect letters. We just check whether the mode is `both` when deciding whether to pass `input` to `createHintsHtml` or to pass `currentWord`. All functionality of replace and below is kept by just adding or operators to check whether indicateTypos is `both` OR replace/below. Implementing #7024 --------- Co-authored-by: Jack <[email protected]>
1 parent e1e1bfb commit 13b75f4

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

frontend/src/html/pages/settings.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,16 @@
538538
</button>
539539
</div>
540540
<div class="text">
541-
Shows typos that you've made. Below shows what you typed below the
542-
letters and replace will replace the letters with the ones you typed.
541+
Shows typos that you've made. "Below" shows what you typed below the
542+
letters, "replace" will replace the letters with the ones you typed and
543+
"both" will do the same as replace and below, but it will show the
544+
correct letters below your mistakes.
543545
</div>
544546
<div class="buttons">
545547
<button data-config-value="off">off</button>
546548
<button data-config-value="below">below</button>
547549
<button data-config-value="replace">replace</button>
550+
<button data-config-value="both">both</button>
548551
</div>
549552
</div>
550553
<div class="section" data-config-name="hideExtraLetters">

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,11 @@ async function handleChar(
691691
!TestUI.lineTransition
692692
// TestInput.input.current.length > 1
693693
) {
694-
if (Config.mode === "zen" || Config.indicateTypos === "replace") {
694+
if (
695+
Config.mode === "zen" ||
696+
Config.indicateTypos === "replace" ||
697+
Config.indicateTypos === "both"
698+
) {
695699
if (!Config.showAllLines) void TestUI.lineJump(activeWordTopBeforeJump);
696700
} else {
697701
TestInput.input.current = TestInput.input.current.slice(0, -1);

frontend/src/ts/test/test-ui.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ async function updateHintsPosition(): Promise<void> {
331331
if (
332332
ActivePage.get() !== "test" ||
333333
TestState.resultVisible ||
334-
Config.indicateTypos !== "below"
334+
(Config.indicateTypos !== "below" && Config.indicateTypos !== "both")
335335
)
336336
return;
337337

@@ -436,7 +436,7 @@ function updateWordWrapperClasses(): void {
436436
$("#wordsWrapper").removeClass("blind");
437437
}
438438

439-
if (Config.indicateTypos === "below") {
439+
if (Config.indicateTypos === "below" || Config.indicateTypos === "both") {
440440
$("#words").addClass("indicateTyposBelow");
441441
$("#wordsWrapper").addClass("indicateTyposBelow");
442442
} else {
@@ -791,7 +791,7 @@ export async function updateActiveWordLetters(
791791
!(containsKorean && !correctSoFar)
792792
) {
793793
ret += `<letter class="dead">${
794-
Config.indicateTypos === "replace"
794+
Config.indicateTypos === "replace" || Config.indicateTypos === "both"
795795
? inputChars[i] === " "
796796
? "_"
797797
: inputChars[i]
@@ -806,13 +806,16 @@ export async function updateActiveWordLetters(
806806
} else {
807807
ret +=
808808
`<letter class="incorrect ${tabChar}${nlChar}">` +
809-
(Config.indicateTypos === "replace"
809+
(Config.indicateTypos === "replace" || Config.indicateTypos === "both"
810810
? inputChars[i] === " "
811811
? "_"
812812
: inputChars[i]
813813
: currentLetter) +
814814
"</letter>";
815-
if (Config.indicateTypos === "below") {
815+
if (
816+
Config.indicateTypos === "below" ||
817+
Config.indicateTypos === "both"
818+
) {
816819
const lastBlock = hintIndices[hintIndices.length - 1];
817820
if (lastBlock && lastBlock[lastBlock.length - 1] === i - 1)
818821
lastBlock.push(i);
@@ -839,7 +842,12 @@ export async function updateActiveWordLetters(
839842

840843
if (hintIndices?.length) {
841844
const activeWordLetters = activeWord.querySelectorAll("letter");
842-
const hintsHtml = createHintsHtml(hintIndices, activeWordLetters, input);
845+
let hintsHtml;
846+
if (Config.indicateTypos === "both") {
847+
hintsHtml = createHintsHtml(hintIndices, activeWordLetters, currentWord);
848+
} else {
849+
hintsHtml = createHintsHtml(hintIndices, activeWordLetters, input);
850+
}
843851
activeWord.insertAdjacentHTML("beforeend", hintsHtml);
844852
const hintElements = activeWord.getElementsByTagName("hint");
845853
await joinOverlappingHints(hintIndices, activeWordLetters, hintElements);

packages/schemas/src/configs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export type CaretStyle = z.infer<typeof CaretStyleSchema>;
5050
export const ConfidenceModeSchema = z.enum(["off", "on", "max"]);
5151
export type ConfidenceMode = z.infer<typeof ConfidenceModeSchema>;
5252

53-
export const IndicateTyposSchema = z.enum(["off", "below", "replace"]);
53+
export const IndicateTyposSchema = z.enum(["off", "below", "replace", "both"]);
5454
export type IndicateTypos = z.infer<typeof IndicateTyposSchema>;
5555

5656
export const TimerStyleSchema = z.enum(["off", "bar", "text", "mini"]);

0 commit comments

Comments
 (0)