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
}
const linkEditorElement = linkEditorRef.current
if (!linkEditorElement) {
setTimeout(updateLinkEditorPosition)
return
}
const nativeSelection = window.getSelection()
const rootElement = editor.getRootElement()
@@ -71,24 +64,36 @@ const FloatingLinkEditor = ({
if (rootElement.contains(nativeSelection.anchorNode)) {
rangeRect.current = getDOMRangeRect(nativeSelection, rootElement)
}
const linkEditorRect = linkEditorElement.getBoundingClientRect()
const rootElementRect = rootElement.getBoundingClientRect()
}
const calculatedStyles = getPositionedPopoverStyles({
align: 'center',
side: 'top',
anchorRect: rangeRect.current,
popoverRect: linkEditorRect,
documentRect: rootElementRect,
offset: 12,
maxHeightFunction: () => 'none',
const linkEditorElement = linkEditorRef.current
if (!linkEditorElement) {
setTimeout(updateLinkEditorPosition)
return
}
if (!rootElement) {
return
}
const linkEditorRect = linkEditorElement.getBoundingClientRect()
const rootElementRect = rootElement.getBoundingClientRect()
const calculatedStyles = getPositionedPopoverStyles({
align: 'center',
side: 'top',
anchorRect: rangeRect.current,
popoverRect: linkEditorRect,
documentRect: rootElementRect,
offset: 12,
maxHeightFunction: () => 'none',
})
if (calculatedStyles) {
Object.entries(calculatedStyles).forEach(([key, value]) => {
linkEditorElement.style.setProperty(key, value)
})
if (calculatedStyles) {
Object.entries(calculatedStyles).forEach(([key, value]) => {
linkEditorElement.style.setProperty(key, value)
})
linkEditorElement.style.opacity = '1'
}
linkEditorElement.style.opacity = '1'
}
}, [editor, isMobile])

View File

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