Simplify SelectionChangeObserver update logic #1095
Merged
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.
This introduces some changes to simplify
SelectionChangeObserver
. The main motivation for the changes is to fix some bugs that came up in iOS 17, but the end result should be simpler logic too.Firstly, this removes the fallback to polling for selection changes when
selectionchange
event is not available. Theselectionchange
API has been available in all browsers for a long time now. The last browsers to add support for it were Firefox in version 52, and Chrome for Android, both in 2017.Secondly, it removes a condition to check if the selected for DOM range has changed since the last time the
SelectionChangeObserver
was called. This check causes problems on Safari 17 when you drag the cursor to select text. Safari weirdly reports the selection range as being collapsed, even when you select multiple characters. This, in turn, causes theSelectionManager
to think that the selection is collapsed and not trying to find where it ends. The end result for the user is that they can not apply formatting or links to the whole selected text.This is ultimately a Safari bug, but it's not clear that we need to check for DOM range equality in the first place. We only do this because the original implementation of the
SelectionChangeObserver
used polling to check for selection changes, instead of relying on theselectionchange
event. Now that we're using theselectionchange
event, we can assume that if a selection change event fires, the selection has changed.