Skip to content

Commit

Permalink
emit an event in RichContentEditable when getting a link to let the u…
Browse files Browse the repository at this point in the history
…pper context prevent text insertion

Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
  • Loading branch information
julien-nc committed Mar 15, 2023
1 parent 99e2d03 commit 102e4db
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/components/NcRichContenteditable/NcRichContenteditable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export default {
'submit',
'paste',
'update:value',
'link-picker-submit',
],
data() {
Expand Down Expand Up @@ -427,10 +428,19 @@ export default {
.then(link => {
// replace dummy temp element by a text node which contains the link
const tmpElem = document.getElementById('tmp-link-result-node')
const newElem = document.createTextNode(link)
tmpElem.replaceWith(newElem)
this.setCursorAfter(newElem)
this.updateValue(this.$refs.contenteditable.innerHTML)
const eventData = {
link,
run: true,
}
this.$emit('link-picker-submit', eventData)
if (eventData.run) {
const newElem = document.createTextNode(link)
tmpElem.replaceWith(newElem)
this.setCursorAfter(newElem)
this.updateValue(this.$refs.contenteditable.innerHTML)
} else {
tmpElem.remove()
}
})
.catch((error) => {
console.debug('Link picker promise rejected:', error)
Expand Down

0 comments on commit 102e4db

Please sign in to comment.