From f125d1f0930d84549b7afb6bc355136526c2acdb Mon Sep 17 00:00:00 2001 From: Ramon Mi Date: Sat, 21 Mar 2026 19:49:24 +0800 Subject: [PATCH] Fix view popup caret behavior in editable fields fixes: https://forums.zotero.org/discussion/122693/abnormal-cursor-indicator-position-in-pdf-reader --- .../view-popup/common/view-popup.js | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/common/components/view-popup/common/view-popup.js b/src/common/components/view-popup/common/view-popup.js index 205693719..7274df1f4 100644 --- a/src/common/components/view-popup/common/view-popup.js +++ b/src/common/components/view-popup/common/view-popup.js @@ -4,6 +4,7 @@ import cx from 'classnames'; // TODO: Resizing window doesn't properly reposition annotation popup on x axis, in EPUB view function ViewPopup({ id, rect, className, uniqueRef, padding, children, onRender }) { const [popupPosition, setPopupPosition] = useState(null); + const [disableTransformForCaret, setDisableTransformForCaret] = useState(false); const containerRef = useRef(); const xrect = useRef(); @@ -136,11 +137,42 @@ function ViewPopup({ id, rect, className, uniqueRef, padding, children, onRender pointerClass['page-popup-' + pos.current.side + '-center'] = true; } + function isTextEditableTarget(target) { + return !!target?.closest?.('div[contenteditable="true"], input, textarea'); + } + + function handleFocusCapture(event) { + if (isTextEditableTarget(event.target)) { + setDisableTransformForCaret(true); + } + } + + function handleBlurCapture(event) { + let stillInsidePopup = containerRef.current?.contains(event.relatedTarget); + if (!stillInsidePopup) { + setDisableTransformForCaret(false); + } + } + + let style = {}; + if (pos.current) { + style = disableTransformForCaret + ? { + left: pos.current.left, top: pos.current.top + } + : { + transform: `translate(${pos.current.left}px, ${pos.current.top}px)` + }; + + } + return (
{children}