fix(widget-markdown): properly check for selection when inserting links (#4075)

This commit is contained in:
Erez Rokah
2020-07-27 18:02:42 +02:00
committed by GitHub
parent 04ccb56e66
commit a4b7481a99
3 changed files with 90 additions and 5 deletions

View File

@ -7,12 +7,18 @@ const Link = ({ type }) => ({
const url = getUrl();
if (!url) return;
// If no text is selected, use the entered URL as text.
if (editor.value.isCollapsed) {
editor.insertText(url).moveFocusBackward(0 - url.length);
const selection = editor.value.selection;
const isCollapsed = selection && selection.isCollapsed;
if (isCollapsed) {
// If no text is selected, use the entered URL as text.
return editor.insertInline({
type,
data: { url },
nodes: [{ object: 'text', text: url }],
});
} else {
return editor.wrapInline({ type, data: { url } }).moveToEnd();
}
return editor.wrapInline({ type, data: { url } }).moveToEnd();
}
},
},