chore: fix link button

This commit is contained in:
Aman Harwara
2023-10-24 20:50:37 +05:30
parent d9381f592f
commit c6764b7e92
2 changed files with 29 additions and 23 deletions

View File

@@ -57,13 +57,6 @@ const FloatingLinkEditor = ({
return return
} }
const linkEditorElement = linkEditorRef.current
if (!linkEditorElement) {
setTimeout(updateLinkEditorPosition)
return
}
const nativeSelection = window.getSelection() const nativeSelection = window.getSelection()
const rootElement = editor.getRootElement() const rootElement = editor.getRootElement()
@@ -71,6 +64,19 @@ const FloatingLinkEditor = ({
if (rootElement.contains(nativeSelection.anchorNode)) { if (rootElement.contains(nativeSelection.anchorNode)) {
rangeRect.current = getDOMRangeRect(nativeSelection, rootElement) rangeRect.current = getDOMRangeRect(nativeSelection, rootElement)
} }
}
const linkEditorElement = linkEditorRef.current
if (!linkEditorElement) {
setTimeout(updateLinkEditorPosition)
return
}
if (!rootElement) {
return
}
const linkEditorRect = linkEditorElement.getBoundingClientRect() const linkEditorRect = linkEditorElement.getBoundingClientRect()
const rootElementRect = rootElement.getBoundingClientRect() const rootElementRect = rootElement.getBoundingClientRect()
@@ -89,7 +95,6 @@ const FloatingLinkEditor = ({
}) })
linkEditorElement.style.opacity = '1' linkEditorElement.style.opacity = '1'
} }
}
}, [editor, isMobile]) }, [editor, isMobile])
useElementResize(linkEditorRef.current, updateLinkEditorPosition) useElementResize(linkEditorRef.current, updateLinkEditorPosition)

View File

@@ -267,6 +267,7 @@ const ToolbarPlugin = () => {
return activeEditor.dispatchCommand(TOGGLE_LINK_COMMAND, null) return activeEditor.dispatchCommand(TOGGLE_LINK_COMMAND, null)
} else if (typeof payload === 'string') { } else if (typeof payload === 'string') {
const dispatched = activeEditor.dispatchCommand(TOGGLE_LINK_COMMAND, payload) const dispatched = activeEditor.dispatchCommand(TOGGLE_LINK_COMMAND, payload)
setIsLink(true)
setLinkUrl(payload) setLinkUrl(payload)
setIsLinkEditMode(true) setIsLinkEditMode(true)
return dispatched return dispatched