Skip to content

Commit d29e792

Browse files
committed
fix(caret): incorrect width calculation in zen mode
1 parent 115b0d7 commit d29e792

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

frontend/src/ts/test/caret.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function getTargetPositionLeft(
5151
fullWidthCaret: boolean,
5252
isLanguageRightToLeft: boolean,
5353
activeWordElement: HTMLElement,
54-
underscoreAdded: boolean,
54+
activeWordEmpty: boolean,
5555
currentWordNodeList: NodeListOf<Element>,
5656
fullWidthCaretWidth: number,
5757
wordLen: number,
@@ -101,7 +101,7 @@ function getTargetPositionLeft(
101101
}
102102
}
103103
result = activeWordElement.offsetLeft + positionOffsetToWord;
104-
if (underscoreAdded && isLanguageRightToLeft)
104+
if (activeWordEmpty && isLanguageRightToLeft)
105105
result += activeWordElement.offsetWidth;
106106
} else {
107107
const wordsWrapperWidth =
@@ -140,13 +140,10 @@ export async function updatePosition(noAnim = false): Promise<void> {
140140
const inputLen = splitIntoCharacters(TestInput.input.current).length;
141141
if (Config.mode === "zen") wordLen = inputLen;
142142
const activeWordEl = document?.querySelector("#words .active") as HTMLElement;
143-
//insert temporary character so the caret will work in zen mode
144-
const activeWordEmpty = activeWordEl?.children.length === 0;
145-
if (activeWordEmpty) {
146-
activeWordEl.insertAdjacentHTML(
147-
"beforeend",
148-
'<letter style="opacity: 0;">_</letter>'
149-
);
143+
let activeWordEmpty = false;
144+
if (Config.mode === "zen") {
145+
wordLen = inputLen;
146+
if (inputLen === 0) activeWordEmpty = true;
150147
}
151148

152149
const currentWordNodeList = activeWordEl?.querySelectorAll("letter");
@@ -254,9 +251,6 @@ export async function updatePosition(noAnim = false): Promise<void> {
254251
});
255252
}
256253
}
257-
if (activeWordEmpty) {
258-
activeWordEl?.replaceChildren();
259-
}
260254
}
261255

262256
export function show(noAnim = false): void {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ export function showWords(): void {
423423
}
424424

425425
export function appendEmptyWordElement(): void {
426-
$("#words").append("<div class='word'><letter>ㅤ</letter></div>");
426+
$("#words").append(
427+
"<div class='word'><letter class='invisible'>_</letter></div>"
428+
);
427429
}
428430

429431
const posUpdateLangList = ["japanese", "chinese", "korean"];
@@ -766,7 +768,7 @@ export async function updateActiveWordLetters(
766768
}
767769
}
768770
if (TestInput.input.current === "") {
769-
ret += `<letter>ㅤ</letter>`;
771+
ret += `<letter class='invisible'>_</letter>`;
770772
}
771773
} else {
772774
let correctSoFar = false;

0 commit comments

Comments
 (0)