From 45f6f372807d0a88454ef756612a63335848a812 Mon Sep 17 00:00:00 2001 From: Rogier Wiertz <72399947+rawstream@users.noreply.github.com> Date: Sat, 28 Sep 2024 16:54:49 +0200 Subject: [PATCH] fix: create TextNode when adding a link (fix #3260) Also create a new TextNode when the selection is not empty. --- apps/editor/src/wysiwyg/marks/link.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/editor/src/wysiwyg/marks/link.ts b/apps/editor/src/wysiwyg/marks/link.ts index 27ceeba4ec..42ecf80d5e 100644 --- a/apps/editor/src/wysiwyg/marks/link.ts +++ b/apps/editor/src/wysiwyg/marks/link.ts @@ -64,19 +64,15 @@ export class Link extends Mark { return (payload) => (state, dispatch) => { const { linkUrl, linkText = '' } = payload!; const { schema, tr, selection } = state; - const { empty, from, to } = selection; + const { from, to } = selection; - if (from && to && linkUrl) { + if (from && to && linkUrl && linkText) { const attrs = { linkUrl }; const mark = schema.mark('link', attrs); - if (empty && linkText) { - const node = createTextNode(schema, linkText, mark); + const node = createTextNode(schema, linkText, mark); - tr.replaceRangeWith(from, to, node); - } else { - tr.addMark(from, to, mark); - } + tr.replaceRangeWith(from, to, node); dispatch!(tr.scrollIntoView());