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 unicode sequences support #4326

Merged
merged 17 commits into from
Aug 13, 2021
Merged

Conversation

oliger
Copy link
Contributor

@oliger oliger commented Jun 8, 2021

Description

This PR follows up on #4305. It adds support for flag, keycap and tag unicode sequences.

Example

Without this PR:

CleanShot.2021-06-08.at.17.37.13.mp4

With this PR:

CleanShot.2021-06-08.at.17.39.47.mp4

Context

Improves getCharacterDistance so that it handles all Unicode sequences. Stop reversing the string when moving from right to left. Split it by codepoint and iterate from first to last when moving from left to right and iterate from last to first when moving from right to left.

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 Jun 8, 2021

🦋 Changeset detected

Latest commit: f584aeb

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

Copy link
Collaborator

@dylans dylans left a comment

Choose a reason for hiding this comment

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

Overall I think this is really amazing. I gave a few specific questions and feedback.

One note, parts of this change are very specific to knowledge about unicode, so more comments and references would be a good idea in my opinion.

I'm happy to review again after you've had time to address my suggestions.

package.json Show resolved Hide resolved
packages/slate/src/interfaces/editor.ts Outdated Show resolved Hide resolved
packages/slate/src/interfaces/editor.ts Outdated Show resolved Hide resolved
packages/slate/src/utils/string.ts Outdated Show resolved Hide resolved
packages/slate/src/utils/string.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@dylans dylans left a comment

Choose a reason for hiding this comment

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

Thanks @oliger, this looks great to me. I'm going to leave it open for a day or two in case anyone else has suggestions before we land it.

Copy link
Collaborator

@dylans dylans left a comment

Choose a reason for hiding this comment

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

@oliger please review the failing test, thanks!

@oliger
Copy link
Contributor Author

oliger commented Aug 12, 2021

Hello @dylans! Thanks for the review. A made some requested changes and left a comment. Concerning the comments I do agree that a bit more would be better. I am also sure that the code could be edited to be more readable... But unfortunately, I do not have the time to focus on this at the moment.

@oliger
Copy link
Contributor Author

oliger commented Aug 12, 2021

Looking at why the tests are failing... This is curious 🤔

@oliger oliger force-pushed the codepoint-sequences branch from c1ba914 to 651b9fc Compare August 12, 2021 12:47
@oliger
Copy link
Contributor Author

oliger commented Aug 12, 2021

@dylans tests are back to green. I also fixed a mistake I made while resolving conflict.

@dylans dylans merged commit 0025900 into ianstormtaylor:main Aug 13, 2021
@github-actions github-actions bot mentioned this pull request Aug 13, 2021
@dylans dylans mentioned this pull request Sep 11, 2021
dylans pushed a commit to dylans/slate that referenced this pull request Sep 13, 2021
* Add failing test

* Handle sequences

* Uncomment test cases

* Handle RTL unicode sequences

* Remove esrever

* Add tests

* Use iterator instead of Array.from

* Add changeset

* Rename split to splitByCharacterDistance

* Make reverse optional

* Fix casing

* Fix yarn.lock

* Fix tests

* Remove fast-deep-equal after bad merge
@gitcatrat
Copy link

@oliger How well do you remember all the unicode logic here?

I think you broke one case: variation selector, because I'm pretty sure that my initial unicode logic supported it.

Try to paste them here: https://www.slatejs.org/examples/richtext

Both emojis end with the following variation selector: https://emojipedia.org/emoji/%EF%B8%8F/

@oliger
Copy link
Contributor Author

oliger commented Sep 25, 2021

@gitcatrat Hello, it seems that the issue is related some BMP emojis not being white listed in isBMPEmoji. Not sure why it is not in the list... That being said we might want to change the code so that it does not rely on a white list.

I have no idea if it was working before and I cannot test as I have limited access to a computer at the moment. I am not sure if I'll have the time to focus on this anytime soon.

@oliger oliger mentioned this pull request Oct 1, 2021
5 tasks
z2devil pushed a commit to z2devil/slate that referenced this pull request Dec 6, 2024
* Add failing test

* Handle sequences

* Uncomment test cases

* Handle RTL unicode sequences

* Remove esrever

* Add tests

* Use iterator instead of Array.from

* Add changeset

* Rename split to splitByCharacterDistance

* Make reverse optional

* Fix casing

* Fix yarn.lock

* Fix tests

* Remove fast-deep-equal after bad merge
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.

3 participants