Skip to content
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

Correcting the splitting logic in setNodes #4168

Merged
merged 5 commits into from
Apr 13, 2021

Conversation

ridhambhat
Copy link
Contributor

@ridhambhat ridhambhat commented Apr 4, 2021

Description

This pull request aims to solves a couple of things:

  • In setNodes, if splitting has to happen, it should be set to always at :
    • start if anchor is not at the start of the node
    • end if focus is not at the end of the node
  • In normalizeNode, while iterating through children, the variable prev pointed towards wrong node in some cases. Fixed that by getting value of prev from updated node.

Issue

Fixes: #4038

Example

Old behavior
Old behavior
New behavior
New Behaviour

Context

For the splitting logic, if always is not set for the mentioned conditions, then for the case where anchor is at the end of one node and focus is at the start of another node, the selection bleeds through and properties is applied on nodes where it is not intended. It is safer to split nodes and have empty nodes which will be normalized later.

For the normalization, in particular conditions when a text node was sandwiched between two empty text nodes, then due to the way previous variable was calculated in logic before, it pointed to the wrong node, not taking in account that it could have been merged/deleted. To correct this behavior, now prev is taken from an updated copy of the base node at each iteration.

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.)

Those conditions are:
- When the anchor does not lie at the start of a node.
- When the focus does not lie at the end of a node.
Previously, in the case the previous node gets merged in last iteration,
prev pointer could be pointing to the wrong node.
That posed problems, especially when normalizing empty text nodes.
So, now in every iteration, we get a copy of updated node structure,
and take value of prev from that.
- In this, since anchor and focus bleeds on both sides, splits happen.
- Empty text nodes are introduced on either side.
- New properties are set in the new node selection.
- Normalization happens and takes care of those empty text nodes.
@changeset-bot
Copy link

changeset-bot bot commented Apr 4, 2021

🦋 Changeset detected

Latest commit: 60b3537

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

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

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

@ianstormtaylor
Copy link
Owner

ianstormtaylor commented Apr 13, 2021

Thanks @ridhambhat, great PR!

@ianstormtaylor ianstormtaylor merged commit 95f402c into ianstormtaylor:main Apr 13, 2021
@github-actions github-actions bot mentioned this pull request Apr 13, 2021
beorn pushed a commit to beorn/slate that referenced this pull request Apr 13, 2021
* Defined conditions to always split nodes

Those conditions are:
- When the anchor does not lie at the start of a node.
- When the focus does not lie at the end of a node.

* prev variable now points to correct updated node.

Previously, in the case the previous node gets merged in last iteration,
prev pointer could be pointing to the wrong node.
That posed problems, especially when normalizing empty text nodes.
So, now in every iteration, we get a copy of updated node structure,
and take value of prev from that.

* Test to check splitting and normalization logic.

- In this, since anchor and focus bleeds on both sides, splits happen.
- Empty text nodes are introduced on either side.
- New properties are set in the new node selection.
- Normalization happens and takes care of those empty text nodes.

* Create two-lies-appear.md

* Update two-lies-appear.md

Co-authored-by: Ian Storm Taylor <ian@ianstormtaylor.com>
z2devil pushed a commit to z2devil/slate that referenced this pull request Dec 6, 2024
* Defined conditions to always split nodes

Those conditions are:
- When the anchor does not lie at the start of a node.
- When the focus does not lie at the end of a node.

* prev variable now points to correct updated node.

Previously, in the case the previous node gets merged in last iteration,
prev pointer could be pointing to the wrong node.
That posed problems, especially when normalizing empty text nodes.
So, now in every iteration, we get a copy of updated node structure,
and take value of prev from that.

* Test to check splitting and normalization logic.

- In this, since anchor and focus bleeds on both sides, splits happen.
- Empty text nodes are introduced on either side.
- New properties are set in the new node selection.
- Normalization happens and takes care of those empty text nodes.

* Create two-lies-appear.md

* Update two-lies-appear.md

Co-authored-by: Ian Storm Taylor <ian@ianstormtaylor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bold/italic/underline can be applied to more than selected text
2 participants