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

Fix overly-aggressive unhangRange #5193

Merged
merged 1 commit into from Nov 17, 2022
Merged

Conversation

SmilinBrian
Copy link
Contributor

Description
Editor.unhangRange() could decide to proceed with an adjustment in cases where the range was not hanging. Because the algorithm it uses always skips over the first node it encounters, this meant the selection was adjusted in non-hanging cases. This change reduces the chances of an incorrect decision to adjust. Transforms now pass the voids flag to unhangRange() as it seems logical that the adjusted range should reflect the intention of the operation.

This change fixes a unit test I added for markable voids that had to be skipped because of the unhangRange() error, and fixes a couple other long-skipped tests.

Example
Previous code behavior in the Mentions example when the range is not hanging and the word "Test" is typed:
BadUnhangRange
Because the range gets adjusted even though it is not hanging, the inline element at the end of the line remains.

New code behavior in the same scenario:
FixedUnhangRange

Context
The unhangRange logic error mostly centers around testing for offset === 0 in the end of the range. This meant that if the end of the selection is in or after an inline void element the adjustment would be triggered incorrectly because of the empty Texts associated and adjacent to those.

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

`Editor.unhangRange()` could decide to proceed with an adjustment in cases where the range was not hanging.
Because the algorithm it uses *always* skips over the first node it encounters, this meant the selection was adjusted in non-hanging cases.
This change reduces the chances of an incorrect decision to adjust.
Transforms now pass the `voids` flag to `unhangRange()` as it seems logical that the adjusted range should reflect the intention of the operation.
This fixes a unit test I added for markable voids that had to be skipped because of the `unhangRange()` error, and fixes a couple other long-skipped tests.
@changeset-bot
Copy link

changeset-bot bot commented Nov 10, 2022

🦋 Changeset detected

Latest commit: ddbcab6

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

@dylans dylans merged commit 6909a8f into ianstormtaylor:main Nov 17, 2022
@github-actions github-actions bot mentioned this pull request Nov 17, 2022
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.

None yet

2 participants