This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
Use Selection.prototype.containsNode for better caret tracking #1442
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are a lot of open issues so I am not sure what issues if any this would close, but here is what I've got:
focus
beforeselectionchange
focus
beforeselectionchange
focus
afterselectionchange
focus
afterselectionchange
when focus was not in the documentfocus
afterselectionchange
when the caret is placed after all nodes in the editorfocus
beforeselectionchange
otherwiseThe
SelectionObserver
was checking whether or not the editor was focused and using that to decide whether or not it could skip firing theselectionChange
event for theDocument
. But thanks to the last two browsers on that list, we cannot actually be sure if theselectionchange
DOM event is irrelevant just by checking whether we have focus. This pull request instead checks whether the resulting DOM selection includes all or part of the editor element, resulting in a better experience in Firefox and IE. Otherwise, every time you click back into the editor, your caret jumps back to where it was the last time the editor had focus. 👎