Skip to content

Commit 00fbfb0

Browse files
authored
fix: caret error on incorrect final word (@Positiveoo1) (#8191)
Closes #8180 !nuf
1 parent 3ca07c6 commit 00fbfb0

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

frontend/src/ts/elements/caret.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,21 @@ export class Caret {
395395
isDirectionReversed: boolean;
396396
}): { left: number; top: number; width: number } {
397397
const letters = options.word?.qsa("letter");
398-
let letter;
399-
if (!letters?.length || !(letter = letters[options.letterIndex])) {
400-
// maybe we should return null here instead of throwing
398+
399+
if (letters.length === 0) {
401400
throw new Error(
402401
"Caret getTargetPositionAndWidth: no letters found in word",
403402
);
404403
}
405404

405+
let letter = letters[options.letterIndex] ?? letters[letters.length - 1];
406+
407+
if (!letter) {
408+
throw new Error(
409+
`Caret getTargetPositionAndWidth: letter not found for index ${options.letterIndex}`,
410+
);
411+
}
412+
406413
if (caretDebug) {
407414
if (this.id === "paceCaret") {
408415
for (const l of document.querySelectorAll(".word letter")) {

0 commit comments

Comments
 (0)