chore: super note link popup changes [skip e2e]

This commit is contained in:
Aman Harwara
2024-05-12 21:25:05 +05:30
parent ec1c0a041c
commit 73e6a598e9
2 changed files with 15 additions and 4 deletions

View File

@@ -32,6 +32,10 @@ const LinkViewer = ({ isMobile, editor, linkNode, setIsEditingLink }: Props) =>
return [linkUrl, isAutoLink]
}, [editor, linkNode])
const linkNodeDOM = useMemo(() => {
return editor.getElementByKey(linkNode.getKey())
}, [editor, linkNode])
const rangeRect = useRef<DOMRect>()
const updateLinkEditorPosition = useCallback(() => {
if (isMobile) {
@@ -58,13 +62,18 @@ const LinkViewer = ({ isMobile, editor, linkNode, setIsEditingLink }: Props) =>
return
}
if (!linkNodeDOM) {
return
}
const linkEditorRect = linkEditorElement.getBoundingClientRect()
const rootElementRect = rootElement.getBoundingClientRect()
const linkNodeRect = linkNodeDOM.getBoundingClientRect()
const calculatedStyles = getPositionedPopoverStyles({
align: 'center',
side: 'top',
anchorRect: rangeRect.current,
anchorRect: linkNodeRect,
popoverRect: linkEditorRect,
documentRect: rootElementRect,
offset: 12,
@@ -77,7 +86,7 @@ const LinkViewer = ({ isMobile, editor, linkNode, setIsEditingLink }: Props) =>
})
linkEditorElement.style.opacity = '1'
}
}, [editor, isMobile])
}, [editor, isMobile, linkNodeDOM])
useElementResize(linkViewerRef.current, updateLinkEditorPosition)

View File

@@ -313,6 +313,8 @@ const ToolbarPlugin = () => {
}
const anchorNode = selection.anchor.getNode()
const focusNode = selection.focus.getNode()
const isAnchorSameAsFocus = anchorNode === focusNode
let element =
anchorNode.getKey() === 'root'
? anchorNode
@@ -342,9 +344,9 @@ const ToolbarPlugin = () => {
const node = getSelectedNode(selection)
const parent = node.getParent()
setIsEditingLink(false)
if ($isLinkNode(node)) {
if ($isLinkNode(node) && isAnchorSameAsFocus) {
setLinkNode(node)
} else if ($isLinkNode(parent)) {
} else if ($isLinkNode(parent) && isAnchorSameAsFocus) {
setLinkNode(parent)
} else {
setLinkNode(null)