Skip to content

Commit

Permalink
fix: create TextNode when adding a link (fix nhn#3260)
Browse files Browse the repository at this point in the history
Also create a new TextNode when the selection is not empty.
  • Loading branch information
rawstream committed Sep 28, 2024
1 parent 0c5c11b commit 45f6f37
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions apps/editor/src/wysiwyg/marks/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit 45f6f37

Please sign in to comment.