Skip to content
This repository was archived by the owner on Jan 20, 2022. It is now read-only.

Commit ce81079

Browse files
committed
fix: Improve behavior when pasting urls to auto-link them
1 parent 7fe2fa4 commit ce81079

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/plugins/MarkdownPaste.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default class MarkdownPaste extends Extension {
3333
return true;
3434
}
3535

36-
// Is this link embedable? Create an embed!
36+
// Is this link embeddable? Create an embed!
3737
const { embeds } = this.editor.props;
3838

3939
if (embeds) {
@@ -49,10 +49,22 @@ export default class MarkdownPaste extends Extension {
4949
}
5050
}
5151
}
52+
53+
// well, it's not an embed and there is no text selected – so just
54+
// go ahead and insert the link directly
55+
const transaction = view.state.tr
56+
.insertText(text, state.selection.from, state.selection.to)
57+
.addMark(
58+
state.selection.from,
59+
state.selection.to + text.length,
60+
state.schema.marks.link.create({ href: text })
61+
);
62+
view.dispatch(transaction);
63+
return true;
5264
}
5365

54-
// otherwise, if we have html then fallback to the default HTML
55-
// parser behavior that comes with Prosemirror.
66+
// otherwise, if we have html on the clipboard then fallback to the
67+
// default HTML parser behavior that comes with Prosemirror.
5668
if (text.length === 0 || html) return false;
5769

5870
event.preventDefault();

0 commit comments

Comments
 (0)