diff --git a/src/components/Menu/ActionInsertLink.vue b/src/components/Menu/ActionInsertLink.vue index be59e2d68bf..17155eb148b 100644 --- a/src/components/Menu/ActionInsertLink.vue +++ b/src/components/Menu/ActionInsertLink.vue @@ -200,7 +200,7 @@ export default { // Avoid issues when parsing urls later on in markdown that might be entered in an invalid format (e.g. "mailto: example@example.com") const href = url.replaceAll(' ', '%20') const chain = this.$editor.chain() - // Check if any text is selected, if not insert the lunk using the given text property + // Check if any text is selected, if not insert the link using the given text property if (this.$editor.view.state?.selection.empty) { chain.insertContent({ type: 'paragraph', @@ -231,11 +231,12 @@ export default { linkPicker() { getLinkWithPicker(null, true) .then(link => { - this.$editor - .chain() - .focus() - .insertContent(link + ' ') - .run() + const chain = this.$editor.chain() + if (this.$editor.view.state?.selection.empty) { + chain.focus().insertContent(link + ' ').run() + } else { + chain.setLink({ href: link }).focus().run() + } }) .catch(error => { console.error('Smart picker promise rejected', error)