Emoji or Mention insertion bumps the cursor index too far
Steps to reproduce: add mention or emoji. The cursor should be placed right after the inserted mention/emoji, but unfortunately it is placed far from it. I suspect it has to do with Quill not counting characters in the same manner composer does.
I was able to solve this for emojis by calling quill.setSelection(range.index + 1, 0), immediatly after insertion (see below). @julianlam is there a similar hook for mentions? There we have two issues, one related to the cursor jumping forward as was with emojis, and the second related to the insertion point that sometimes moves one line down.
$(window).on('action:composer.insertIntoTextarea', function (evt, data) {
let quill = $(data.textarea).parent().find('.ql-container').data('quill');
if(quill) {
let range = quill.getSelection();
//const text = `:${name}: `;
const text = `${data.value} `;
if (range) {
if (range.length === 0) {
//User cursor is at index
} else {
//User has highlighted text - deleting and replacing with emoji
quill.deleteText(range.index, range.length);
}
quill.clipboard.dangerouslyPasteHTML(range.index, text);
quill.setSelection(range.index + 1, 0);
}
}
data.preventDefault = true;
});
Mention fixed by https://github.com/NodeBB/nodebb-plugin-composer-quill/issues/79 The code above is still needed however, for emoji support via dialog box.