Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions frontend/src/ts/elements/caret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,21 @@ export class Caret {
isDirectionReversed: boolean;
}): { left: number; top: number; width: number } {
const letters = options.word?.qsa("letter");
let letter;
if (!letters?.length || !(letter = letters[options.letterIndex])) {
// maybe we should return null here instead of throwing

if (letters.length === 0) {
throw new Error(
"Caret getTargetPositionAndWidth: no letters found in word",
);
}

let letter = letters[options.letterIndex] ?? letters[letters.length - 1];

if (!letter) {
throw new Error(
`Caret getTargetPositionAndWidth: letter not found for index ${options.letterIndex}`,
);
}

if (caretDebug) {
if (this.id === "paceCaret") {
for (const l of document.querySelectorAll(".word letter")) {
Expand Down
Loading