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

Inconsistent selection after insert between browsers #1007

Closed
sergop321 opened this issue Sep 26, 2016 · 3 comments
Closed

Inconsistent selection after insert between browsers #1007

sergop321 opened this issue Sep 26, 2016 · 3 comments

Comments

@sergop321
Copy link

sergop321 commented Sep 26, 2016

Steps for reproduce:

focus quill
insert text
check selection in text-changed event

var quill = new Quill('#editor-container', {
  placeholder: 'Compose an epic...',
});

quill.on('text-change', function () {
  console.log(quill.getSelection(false));
});

setTimeout(function () {
  quill.focus();
  quill.insertText(0, 'This is just a test text');
}, 3000);

codepen with example
http://codepen.io/anon/pen/ZpKZwo

In Chrome Version 53.0.2785.116 (64-bit) Mac will log Range {index: 24, length: 0}
In FireFox Version 49.0.1 Mac will log Range {index: 0, length: 0}

Without the focus chrome logs the same as firefox so it seems like a bug in chrome

@jhchen
Copy link
Member

jhchen commented Sep 26, 2016

When a DOM node that the selection is in is modified, browsers are unpredictable in what they do. So Quill calculates what the selection should be and restores it. The problem it seems it this restoration happens after the text-change event is emitted. So the workaround at the moment is to set a timeout or defer in the text-change handler before querying the selection.

quill.on('text-change', function () {
  setTimeout(function() {
    console.log(quill.getSelection(false));
  }, 1);
});

@sergop321
Copy link
Author

The workaround worked great, it actually solved a lot minor bugs with the selection on text-change event (I was getting wrong selection in chrome after link node).

@jhchen
Copy link
Member

jhchen commented Oct 21, 2016

This is fixed in v1.1.1

@jhchen jhchen closed this as completed Oct 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants