When removing the node containing the cursor, always prefer placing the cursor in a sibling text node #5923
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.
Description
Previously, when removing the node containing the cursor, the selection would enter a sibling inline in some circumstances, even when a sibling text node was available. This PR ensures that if a sibling text node is available, the cursor is always placed inside it.
Example
The most noticeable side-effect of this change occurs when pressing backspace at the start of line N when the last non-empty node in line N-1 is an inline.
Before:
before.mp4
After:
after.mp4
Context
The purpose of this change is to ensure that
editor.isSelectable
is respected when the default normalization rules remove an empty text node containing the cursor. Previously, the cursor could be placed inside a non-selectable inline if one was adjacent to the removed text node.See this commit for the full set of tests whose output is affected by this change (including tests added in this PR): 71f2161
If this is too big of a change to merge, an alternative would be to check inside the
remove_node
handler whether either theprev
ornext
text node is inside a non-selectable ancestor element and disqualify it if so.Checks
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)