Skip to content

Commit

Permalink
fix: creation of link without selection
Browse files Browse the repository at this point in the history
Fixes #442
  • Loading branch information
petyosi committed May 9, 2024
1 parent 00fefd2 commit 1d1fc66
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/plugins/link-dialog/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $isLinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link'
import { $createLinkNode, $isLinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link'
import {
$createTextNode,
$getSelection,
Expand Down Expand Up @@ -157,17 +157,18 @@ export const linkDialogState$ = Cell<InactiveLinkDialog | PreviewLinkDialog | Ed
editor?.update(
() => {
if (!getLinkNodeInSelection(selection)) {
const node = $createTextNode(linkContent)
const node = $createLinkNode(url, { title })
node.append($createTextNode(linkContent))
$insertNodes([node])
node.select()
}
},
{ discrete: true }
)
} else {
editor?.dispatchCommand(TOGGLE_LINK_COMMAND, { url, title })
}

editor?.dispatchCommand(TOGGLE_LINK_COMMAND, { url, title })

r.pub(linkDialogState$, {
type: 'preview',
linkNodeKey: state.linkNodeKey,
Expand Down

0 comments on commit 1d1fc66

Please sign in to comment.