From a754fc435814bb2a12142125cd11da7489bc0b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ska=C5=82ka?= Date: Thu, 3 Oct 2024 12:19:02 +0200 Subject: [PATCH] Fix getting cursor position y --- src/components/Composer/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Composer/index.tsx b/src/components/Composer/index.tsx index 5e9fa77e6dfc..46c2b01f21af 100755 --- a/src/components/Composer/index.tsx +++ b/src/components/Composer/index.tsx @@ -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 = {