chore: fix link editor positoning on desktop/web [skip e2e]

This commit is contained in:
Aman Harwara
2023-10-24 20:04:33 +05:30
parent ccc9d705a5
commit 80d9b0c31c

View File

@@ -50,6 +50,7 @@ const FloatingLinkEditor = ({
}, [linkText])
const linkEditorRef = useRef<HTMLDivElement>(null)
const rangeRect = useRef<DOMRect>()
const updateLinkEditorPosition = useCallback(() => {
if (isMobile) {
@@ -66,15 +67,17 @@ const FloatingLinkEditor = ({
const nativeSelection = window.getSelection()
const rootElement = editor.getRootElement()
if (nativeSelection !== null && rootElement !== null && rootElement.contains(nativeSelection.anchorNode)) {
const rangeRect = getDOMRangeRect(nativeSelection, rootElement)
if (nativeSelection !== null && rootElement !== null) {
if (rootElement.contains(nativeSelection.anchorNode)) {
rangeRect.current = getDOMRangeRect(nativeSelection, rootElement)
}
const linkEditorRect = linkEditorElement.getBoundingClientRect()
const rootElementRect = rootElement.getBoundingClientRect()
const calculatedStyles = getPositionedPopoverStyles({
align: 'start',
align: 'center',
side: 'top',
anchorRect: rangeRect,
anchorRect: rangeRect.current,
popoverRect: linkEditorRect,
documentRect: rootElementRect,
offset: 12,
@@ -133,6 +136,10 @@ const FloatingLinkEditor = ({
setEditMode(false)
}
useEffect(() => {
setTimeout(updateLinkEditorPosition)
}, [isEditMode, updateLinkEditorPosition])
return (
<Portal>
<div