Skip to content

Commit

Permalink
fix: link dialog button in FF
Browse files Browse the repository at this point in the history
Fixes #135
  • Loading branch information
petyosi committed Oct 23, 2023
1 parent 8d8de50 commit 47f3027
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/plugins/link-dialog/LinkDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ export const LinkDialog: React.FC = () => {
data-visible={linkDialogState.type === 'edit'}
className={styles.linkDialogAnchor}
style={{
top: theRect?.top,
left: theRect?.left,
width: theRect?.width,
height: theRect?.height
top: `${theRect?.top ?? 0}px`,
left: `${theRect?.left ?? 0}px`,
width: `${theRect?.width ?? 0}px`,
height: `${theRect?.height ?? 0}px`
}}
/>

Expand Down
51 changes: 27 additions & 24 deletions src/plugins/link-dialog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,32 @@ const linkDialogSystem = system(
r.o.filter(([, selection]) => $isRangeSelection(selection))
),
([, selection, editor]) => {
editor?.getEditorState().read(() => {
const node = getLinkNodeInSelection(selection)
const rectangle = getSelectionRectangle(editor)!
if (node) {
r.pub(linkDialogState, {
type: 'edit',
initialUrl: node.getURL(),
initialTitle: node.getTitle() || '',
url: node.getURL(),
title: node.getTitle() || '',
linkNodeKey: node.getKey(),
rectangle
})
} else {
r.pub(linkDialogState, {
type: 'edit',
initialUrl: '',
initialTitle: '',
title: '',
url: '',
linkNodeKey: '',
rectangle
})
}
editor?.focus(() => {
editor?.getEditorState().read(() => {
const node = getLinkNodeInSelection(selection)
const rectangle = getSelectionRectangle(editor)!
if (node) {
r.pub(linkDialogState, {
type: 'edit',
initialUrl: node.getURL(),
initialTitle: node.getTitle() || '',
url: node.getURL(),
title: node.getTitle() || '',
linkNodeKey: node.getKey(),
rectangle
})
} else {
r.pub(linkDialogState, {
type: 'edit',
initialUrl: '',
initialTitle: '',
title: '',
url: '',
linkNodeKey: '',
rectangle
})
}
})
})
}
)
Expand Down Expand Up @@ -137,6 +139,7 @@ const linkDialogSystem = system(
if ($isRangeSelection(selection) && (getLinkNodeInSelection(selection) || !selection.isCollapsed())) {
r.pub(openLinkEditDialog, true)
event.stopPropagation()
event.preventDefault()
return true
} else {
return false
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/toolbar/components/CreateLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import { linkDialogPluginHooks } from '../../link-dialog'
export const CreateLink = () => {
const openLinkDialog = linkDialogPluginHooks.usePublisher('openLinkEditDialog')
return (
<ButtonWithTooltip title="Create link" onClick={(_) => openLinkDialog(true)}>
<ButtonWithTooltip
title="Create link"
onClick={(_) => {
openLinkDialog(true)
}}
>
<LinkIcon />
</ButtonWithTooltip>
)
Expand Down
8 changes: 4 additions & 4 deletions src/utils/lexicalHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export function getSelectionRectangle(editor: LexicalEditor) {
}

return {
top: rect.top,
left: rect.left,
width: rect.width,
height: rect.height
top: Math.round(rect.top),
left: Math.round(rect.left),
width: Math.round(rect.width),
height: Math.round(rect.height)
}
} else if (!activeElement || activeElement.className !== 'link-input') {
return null
Expand Down

0 comments on commit 47f3027

Please sign in to comment.