You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
focus quill
insert text
check selection in text-changed event
varquill=newQuill('#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);
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.
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).
Steps for reproduce:
focus quill
insert text
check selection in text-changed event
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
The text was updated successfully, but these errors were encountered: