Skip to content

Commit

Permalink
Fix getting cursor position y
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Oct 3, 2024
1 parent 7899bc8 commit a754fc4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/Composer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ function Composer(
if (shouldCalculateCaretPosition && isRendered && sel) {
const range = sel.getRangeAt(0).cloneRange();
range.collapse(true);
const rect = range.getClientRects()[0];
const currentElement = (range.startContainer.nodeType === Node.TEXT_NODE ? range.startContainer.parentElement : range.startContainer) as HTMLElement;
const rect = currentElement.getClientRects()[0];
const containerRect = textInput.current?.getBoundingClientRect();

let x = 0;
let y = 0;
if (rect && containerRect) {
x = rect.left - containerRect.left;
y = rect.top - containerRect.top - rect.height / 2 + (textInput?.current?.scrollTop ?? 0);
y = rect.top - containerRect.top + (textInput?.current?.scrollTop ?? 0) - rect.height / 2;
}

const selectionValue = {
Expand Down

0 comments on commit a754fc4

Please sign in to comment.