Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: make edit link responsive at trailing cursor boundary

kashaf-ansari-dev7654ecd54430
diff --git a/packages/editor/src/toolbar/tools/link.tsx b/packages/editor/src/toolbar/tools/link.tsx
index 88df5739d..2f678f8f8 100644
--- a/packages/editor/src/toolbar/tools/link.tsx
+++ b/packages/editor/src/toolbar/tools/link.tsx
@@ -154,24 +154,28 @@ export function EditLink(props: ToolProps) {
title={props.title}
isEditing
onDone={(attributes) => {
- if (selectedNode.current)
- editor.chain().focus().setTextSelection(selectedNode.current).run();
+ editor.chain().focus().extendMarkRange("link").run();
editor.commands.setLink(attributes);
hide();
}}
onClick={() => {
- if (!selectedNode.current) return;
+ editor.commands.extendMarkRange("link");
- const { node } = selectedNode.current;
- if (!node) return;
+ const href = attrs?.href;
+ if (!href) return;
- const selectedText = node.textContent;
- const mark = findMark(node, "link");
+ const selectedText =
+ editor.state.doc.textBetween(
+ editor.state.selection.from,
+ editor.state.selection.to
+ ) ||
+ selectedNode.current?.node?.textContent ||
+ editor.state.selection.$from.nodeBefore?.textContent ||
+ "";
- if (!mark) return;
return {
title: selectedText,
- href: mark.attrs.href
+ href
};
}}
/>