Skip to content

Commit

Permalink
fix: find the caret domrect with largest bottom value
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictb committed Aug 19, 2024
1 parent 61da827 commit 7a68bd4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/web/cursorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,19 @@ function scrollCursorIntoView(target: HTMLInputElement) {
return;
}

const caretRect = selection.getRangeAt(0).getClientRects()[0];
const caretRects = selection.getRangeAt(0).getClientRects();

// we'll find the caretRect from the DOMRectList above with the largest bottom value
let caretRect = caretRects[0];
if (caretRect) {
for (let i = 1; i < caretRects.length; i++) {
const ithCaretRect = caretRects[i];
if (ithCaretRect && ithCaretRect.bottom > caretRect.bottom) {
caretRect = ithCaretRect;
}
}
}

const editableRect = target.getBoundingClientRect();

// Adjust for padding and border
Expand Down

0 comments on commit 7a68bd4

Please sign in to comment.