nodebb-plugin-composer-quill icon indicating copy to clipboard operation
nodebb-plugin-composer-quill copied to clipboard

Emoji or Mention insertion bumps the cursor index too far

Open PostMidnight opened this issue 6 years ago • 2 comments

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.

PostMidnight avatar Aug 01 '19 18:08 PostMidnight

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;
	});

PostMidnight avatar Aug 02 '19 05:08 PostMidnight

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.

PostMidnight avatar Aug 02 '19 12:08 PostMidnight