Skip to content

When removing the node containing the cursor, always prefer placing the cursor in a sibling text node #5923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

12joan
Copy link
Contributor

@12joan 12joan commented Jul 24, 2025

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 the prev or next text node is inside a non-selectable ancestor element and disqualify it if so.

Checks

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn fix.)
  • The relevant examples still work. (Run examples with yarn start.)
  • You've added a changeset if changing functionality. (Add one with yarn changeset add.)

Copy link

changeset-bot bot commented Jul 24, 2025

🦋 Changeset detected

Latest commit: 9a59635

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
slate Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dylans dylans merged commit ba33735 into ianstormtaylor:main Jul 26, 2025
11 checks passed
This was referenced Jul 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants