chore: super note link popup changes [skip e2e]
This commit is contained in:
@@ -32,6 +32,10 @@ const LinkViewer = ({ isMobile, editor, linkNode, setIsEditingLink }: Props) =>
|
|||||||
return [linkUrl, isAutoLink]
|
return [linkUrl, isAutoLink]
|
||||||
}, [editor, linkNode])
|
}, [editor, linkNode])
|
||||||
|
|
||||||
|
const linkNodeDOM = useMemo(() => {
|
||||||
|
return editor.getElementByKey(linkNode.getKey())
|
||||||
|
}, [editor, linkNode])
|
||||||
|
|
||||||
const rangeRect = useRef<DOMRect>()
|
const rangeRect = useRef<DOMRect>()
|
||||||
const updateLinkEditorPosition = useCallback(() => {
|
const updateLinkEditorPosition = useCallback(() => {
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
@@ -58,13 +62,18 @@ const LinkViewer = ({ isMobile, editor, linkNode, setIsEditingLink }: Props) =>
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!linkNodeDOM) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const linkEditorRect = linkEditorElement.getBoundingClientRect()
|
const linkEditorRect = linkEditorElement.getBoundingClientRect()
|
||||||
const rootElementRect = rootElement.getBoundingClientRect()
|
const rootElementRect = rootElement.getBoundingClientRect()
|
||||||
|
const linkNodeRect = linkNodeDOM.getBoundingClientRect()
|
||||||
|
|
||||||
const calculatedStyles = getPositionedPopoverStyles({
|
const calculatedStyles = getPositionedPopoverStyles({
|
||||||
align: 'center',
|
align: 'center',
|
||||||
side: 'top',
|
side: 'top',
|
||||||
anchorRect: rangeRect.current,
|
anchorRect: linkNodeRect,
|
||||||
popoverRect: linkEditorRect,
|
popoverRect: linkEditorRect,
|
||||||
documentRect: rootElementRect,
|
documentRect: rootElementRect,
|
||||||
offset: 12,
|
offset: 12,
|
||||||
@@ -77,7 +86,7 @@ const LinkViewer = ({ isMobile, editor, linkNode, setIsEditingLink }: Props) =>
|
|||||||
})
|
})
|
||||||
linkEditorElement.style.opacity = '1'
|
linkEditorElement.style.opacity = '1'
|
||||||
}
|
}
|
||||||
}, [editor, isMobile])
|
}, [editor, isMobile, linkNodeDOM])
|
||||||
|
|
||||||
useElementResize(linkViewerRef.current, updateLinkEditorPosition)
|
useElementResize(linkViewerRef.current, updateLinkEditorPosition)
|
||||||
|
|
||||||
|
|||||||
@@ -313,6 +313,8 @@ const ToolbarPlugin = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const anchorNode = selection.anchor.getNode()
|
const anchorNode = selection.anchor.getNode()
|
||||||
|
const focusNode = selection.focus.getNode()
|
||||||
|
const isAnchorSameAsFocus = anchorNode === focusNode
|
||||||
let element =
|
let element =
|
||||||
anchorNode.getKey() === 'root'
|
anchorNode.getKey() === 'root'
|
||||||
? anchorNode
|
? anchorNode
|
||||||
@@ -342,9 +344,9 @@ const ToolbarPlugin = () => {
|
|||||||
const node = getSelectedNode(selection)
|
const node = getSelectedNode(selection)
|
||||||
const parent = node.getParent()
|
const parent = node.getParent()
|
||||||
setIsEditingLink(false)
|
setIsEditingLink(false)
|
||||||
if ($isLinkNode(node)) {
|
if ($isLinkNode(node) && isAnchorSameAsFocus) {
|
||||||
setLinkNode(node)
|
setLinkNode(node)
|
||||||
} else if ($isLinkNode(parent)) {
|
} else if ($isLinkNode(parent) && isAnchorSameAsFocus) {
|
||||||
setLinkNode(parent)
|
setLinkNode(parent)
|
||||||
} else {
|
} else {
|
||||||
setLinkNode(null)
|
setLinkNode(null)
|
||||||
|
|||||||
Reference in New Issue
Block a user