Skip to content

Commit 02fcad4

Browse files
committed
fix(caret): incorrect vertical position if word wrapped to the next line
1 parent 2908331 commit 02fcad4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

frontend/src/ts/test/caret.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export async function updatePosition(noAnim = false): Promise<void> {
177177
if (!currentWordNodeList?.length) return;
178178

179179
const currentLetter = currentWordNodeList[inputLen];
180+
const lastInputLetter = currentWordNodeList[inputLen - 1];
180181
const lastWordLetter = currentWordNodeList[wordLen - 1];
181182

182183
const currentLanguage = await JSONData.getCurrentLanguage(Config.language);
@@ -187,11 +188,15 @@ export async function updatePosition(noAnim = false): Promise<void> {
187188
// so is offsetTop (for same line letters)
188189
const letterHeight =
189190
(safeNumber(currentLetter?.offsetHeight) ?? 0) ||
191+
(safeNumber(lastInputLetter?.offsetHeight) ?? 0) ||
190192
(safeNumber(lastWordLetter?.offsetHeight) ?? 0) ||
191193
Config.fontSize * convertRemToPixels(1);
192194

193195
const letterPosTop =
194-
currentLetter?.offsetTop ?? lastWordLetter?.offsetTop ?? 0;
196+
currentLetter?.offsetTop ??
197+
lastInputLetter?.offsetTop ??
198+
lastWordLetter?.offsetTop ??
199+
0;
195200
const diff = letterHeight - caretHeight;
196201
let newTop = activeWordEl.offsetTop + letterPosTop + diff / 2;
197202
if (Config.caretStyle === "underline") {

0 commit comments

Comments
 (0)