Fix bug with updating a deselected selection and void block selection issues #1075
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 two things fixed here. The first one is a fix for
content.updateSelection
when the selection is deselected andanchorKey
andfocusKey
is unset. It should then return as the rest of the code acts onanchorKey
andfocusKey
.The second fix is regarding selecting void nodes. When selecting text from a non-void block to the end, neighbouring a void-block, the
focusOffset
is (most of the time) set at the end of the void block when it shouldn't. This will delete the void block as well when you press backspace. Therefore make sure that thefocusOffset
is always set to 0 in the void block in those conditions.Also if you move the cursor to a void-block, the same problem occur. It is most of the time set to anchor and focusOffset 1, making it impossible to delete it. In this case, set the
anchorOffset
to 0.This was what I originally tried to fix in #1042
which was reverted via #1063 because of issues. It was probably the wrong place trying to fix it, but I hope this PR will make it proper and there are no side effects. Unfortunately it is a bit difficult to test because it relies on browser behaviour.