Skip to content

Commit

Permalink
feat: Floating link editor for AutoLinkNode and conversion to LinkNod…
Browse files Browse the repository at this point in the history
…e once modified
  • Loading branch information
umaranis committed Mar 26, 2024
1 parent f38c047 commit 425375a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<script lang="ts">
import './FloatingLinkEditor.css';
import {$isLinkNode as isLinkNode, TOGGLE_LINK_COMMAND} from '@lexical/link';
import {
$isLinkNode as isLinkNode,
$isAutoLinkNode as isAutoLinkNode,
TOGGLE_LINK_COMMAND,
$createLinkNode as createLinkNode,
} from '@lexical/link';
import {
mergeRegister,
$findMatchingParent as findMatchingParent,
Expand Down Expand Up @@ -161,6 +166,20 @@
if (lastSelection !== null) {
if (linkUrl !== '') {
editor.dispatchCommand(TOGGLE_LINK_COMMAND, sanitizeUrl(editedLinkUrl));
editor.update(() => {
const selection = getSelection();
if (isRangeSelection(selection)) {
const parent = getSelectedNode(selection).getParent();
if (isAutoLinkNode(parent)) {
const linkNode = createLinkNode(parent.getURL(), {
rel: parent.__rel,
target: parent.__target,
title: parent.__title,
});
parent.replace(linkNode, true);
}
}
});
}
$isEditMode = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
const node = getSelectedNode(selection);
const linkParent = findMatchingParent(node, isLinkNode);
const autoLinkParent = findMatchingParent(node, isAutoLinkNode);
// We don't want this menu to open for auto links.
if (linkParent !== null && autoLinkParent === null) {
if (linkParent !== null || autoLinkParent !== null) {
$isLink = true;
} else {
$isLink = false;
Expand Down

0 comments on commit 425375a

Please sign in to comment.