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

Add tests for Editor.unhangRange() #4703

Merged
merged 4 commits into from
Dec 22, 2021

Conversation

e1himself
Copy link
Contributor

@e1himself e1himself commented Nov 30, 2021

Description

Add tests for Editor.unhangRange()

Issue

Related to #3683

Example

n/a

Context

Editor.unhangRange() has zero tests. So it's really difficult to understand how it should work.
Also any changes to its behavior will not have obvious effect visible in tests expectations.

This PR documents the existing behavior of Editor.unhangRange() without modifying it.

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

@changeset-bot
Copy link

changeset-bot bot commented Nov 30, 2021

🦋 Changeset detected

Latest commit: d28d619

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

Comment on lines +22 to +25
export const output = {
anchor: { path: [0, 0], offset: 0 },
focus: { path: [0, 0], offset: 25 },
}
Copy link
Contributor Author

@e1himself e1himself Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right: it completely skipped the second paragraph. I am going to fix this with a separate PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment on lines +25 to +28
export const output = {
anchor: { path: [0, 0], offset: 6 },
focus: { path: [0, 2], offset: 0 },
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't perform unhanging to for text nodes.

Which actually prevents using it to work around inconsistent browsers behavior related to onDOMSelectionChange.

Related tickets: #3336 #3374 #2317 #3840 #4634

Would you be okay if extend Editor.unhangRange() to also unhang Text nodes?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be ok with this.

Comment on lines +8 to +12
<text>
before
<anchor />
</text>
<text>selected</text>
Copy link
Contributor Author

@e1himself e1himself Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #3683 it was guessed that unhangRange should also unhang the starting point of the selection by moving it forward: #3683 (comment)

I wonder if introducing this behavior does make sense with the original intention of this method. Does it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original intention was ambiguous here (afaik), so I'd be fine with introducing this change assuming no one strongly disagrees.

Copy link
Contributor

@bryanph bryanph Jan 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would solve at least this issue I think: #4793. Might also be good to consider inlines as well for this kind of case?

@e1himself
Copy link
Contributor Author

@dylans could someone please take a look at this PR? is there something wrong with it or was it just missed? Thanks!

@dylans
Copy link
Collaborator

dylans commented Dec 22, 2021

@dylans could someone please take a look at this PR? is there something wrong with it or was it just missed? Thanks!

Just missed, reviewing again now, thanks!

Comment on lines +25 to +28
export const output = {
anchor: { path: [0, 0], offset: 6 },
focus: { path: [0, 2], offset: 0 },
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be ok with this.

Comment on lines +8 to +12
<text>
before
<anchor />
</text>
<text>selected</text>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original intention was ambiguous here (afaik), so I'd be fine with introducing this change assuming no one strongly disagrees.

Comment on lines +22 to +25
export const output = {
anchor: { path: [0, 0], offset: 0 },
focus: { path: [0, 0], offset: 25 },
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@dylans dylans merged commit 205d4b7 into ianstormtaylor:main Dec 22, 2021
@github-actions github-actions bot mentioned this pull request Dec 22, 2021
@dylans
Copy link
Collaborator

dylans commented Dec 22, 2021

@e1himself this may have broken integration tests so I may need to revert it until all tests pass. I'll let you know.

@e1himself e1himself deleted the dev/editor-unhang-range-tests branch December 23, 2021 13:42
@TheSpyder
Copy link
Collaborator

TheSpyder commented Jan 7, 2022

There aren't zero tests, as I discovered in #4203, but it's more tested accidentally. This is good to see; when I eventually get time to finish my PR I'll move the tests I added into this folder 👍

DougReeder pushed a commit to DougReeder/slate that referenced this pull request Apr 3, 2022
* Add tests for Editor.unhangRange()

* Extend tests for `Editor.unhangRange()` to cover voids

* Fix lint

* Add changeset
z2devil pushed a commit to z2devil/slate that referenced this pull request Dec 6, 2024
* Add tests for Editor.unhangRange()

* Extend tests for `Editor.unhangRange()` to cover voids

* Fix lint

* Add changeset
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.

4 participants