Fix loss of caret on image insertion in campaign from popup

This commit is contained in:
Kailash Nadh 2020-08-01 16:09:55 +05:30
parent 13a252a7b3
commit 2143def136
1 changed files with 7 additions and 5 deletions

View File

@ -95,6 +95,11 @@ export default {
radioFormat: this.contentType, radioFormat: this.contentType,
}, },
// Last position of the cursor in the editor before the media popup
// was opened. This is used to insert media on selection from the poup
// where the caret may be lost.
lastSel: null,
// Quill editor options. // Quill editor options.
options: { options: {
placeholder: 'Content here', placeholder: 'Content here',
@ -189,15 +194,12 @@ export default {
}, },
toggleMedia() { toggleMedia() {
this.lastSel = this.$refs.quill.quill.getSelection();
this.isMediaVisible = !this.isMediaVisible; this.isMediaVisible = !this.isMediaVisible;
}, },
onMediaSelect(m) { onMediaSelect(m) {
const sel = this.$refs.quill.quill.getSelection(); this.$refs.quill.quill.insertEmbed(this.lastSel.index || 0, 'image', m.url);
if (!sel) {
return;
}
this.$refs.quill.quill.insertEmbed(sel.index, 'image', m.url);
}, },
}, },