Skip to content

Commit f4f4057

Browse files
committed
fix(zen mode): newline not working
1 parent dfa716a commit f4f4057

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

frontend/src/ts/input/handlers/before-insert-text.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ export function onBeforeInsertText(data: string): boolean {
5151
return true;
5252
}
5353

54-
//only allow newlines if the test has newlines
55-
if (data === "\n" && !TestWords.hasNewline) {
54+
//only allow newlines if the test has newlines or in zen mode
55+
if (data === "\n" && !TestWords.hasNewline && Config.mode !== "zen") {
5656
return true;
5757
}
5858

frontend/src/ts/input/handlers/insert-text.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export async function onInsertText(options: OnInsertTextParams): Promise<void> {
217217
const result = await goToNextWord({
218218
correctInsert: correct,
219219
isCompositionEnding: isCompositionEnding === true,
220+
zenNewline: charIsNewline && Config.mode === "zen",
220221
});
221222
lastBurst = result.lastBurst;
222223
increasedWordIndex = result.increasedWordIndex;

frontend/src/ts/input/helpers/word-navigation.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type GoToNextWordParams = {
2121
correctInsert: boolean;
2222
// this is used to tell test ui to update the word before moving to the next word (in case of a composition that ends with a space)
2323
isCompositionEnding: boolean;
24+
zenNewline?: boolean;
2425
};
2526

2627
type GoToNextWordReturn = {
@@ -31,13 +32,18 @@ type GoToNextWordReturn = {
3132
export async function goToNextWord({
3233
correctInsert,
3334
isCompositionEnding,
35+
zenNewline,
3436
}: GoToNextWordParams): Promise<GoToNextWordReturn> {
3537
const ret = {
3638
increasedWordIndex: false,
3739
lastBurst: 0,
3840
};
3941

40-
TestUI.beforeTestWordChange("forward", correctInsert, isCompositionEnding);
42+
TestUI.beforeTestWordChange(
43+
"forward",
44+
correctInsert,
45+
isCompositionEnding || zenNewline === true
46+
);
4147

4248
if (correctInsert) {
4349
Replay.addReplayEvent("submitCorrectWord");

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,24 @@ export async function afterTestWordChange(
17661766
}
17671767
} else if (direction === "back") {
17681768
if (Config.mode === "zen") {
1769-
getWordElement(TestState.activeWordIndex + 1)?.remove();
1769+
const wordsChildren = [
1770+
...(document.querySelector("#words")?.children ?? []),
1771+
] as HTMLElement[];
1772+
1773+
let deleteElements = false;
1774+
for (const child of wordsChildren) {
1775+
if (
1776+
!deleteElements &&
1777+
parseInt(child.getAttribute("data-wordindex") ?? "-1", 10) ===
1778+
TestState.activeWordIndex
1779+
) {
1780+
deleteElements = true;
1781+
continue;
1782+
}
1783+
if (deleteElements) {
1784+
child.remove();
1785+
}
1786+
}
17701787
}
17711788
}
17721789
}

0 commit comments

Comments
 (0)