Skip to content

Commit

Permalink
fix(LinkBubble): Restore selection after updating the link
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Jan 24, 2024
1 parent 7befed9 commit 5441d7a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/Link/LinkBubbleView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,19 @@ export default {
},
setLinkUrl(href) {
this.editor.chain().extendMarkRange('link').setLink({ href }).focus().run()
// Store current selection to restore it after setLink
const selection = { ...this.editor.view.state.selection }
const { ranges } = selection
const from = Math.min(...ranges.map(range => range.$from.pos))
const to = Math.max(...ranges.map(range => range.$to.pos))
console.debug('selection', selection)
this.editor.chain()
.extendMarkRange('link')
.setLink({ href })
.setTextSelection({ from, to })
.focus()
.run()
},
removeLink() {
Expand Down

0 comments on commit 5441d7a

Please sign in to comment.