Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emoji or Mention insertion bumps the cursor index too far #77

Open
PostMidnight opened this issue Aug 1, 2019 · 2 comments
Open

Emoji or Mention insertion bumps the cursor index too far #77

PostMidnight opened this issue Aug 1, 2019 · 2 comments

Comments

@PostMidnight
Copy link

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
Copy link
Author

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
Copy link
Author

PostMidnight commented Aug 2, 2019

Mention fixed by #79
The code above is still needed however, for emoji support via dialog box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant