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

[lexical][Breaking Change][lexical-rich-text][lexical-playground] Feature: Support capitalization format #6897

Merged
merged 27 commits into from
Dec 14, 2024

Conversation

bedre7
Copy link
Contributor

@bedre7 bedre7 commented Dec 2, 2024

Description

This PR aims to add capitalization formats to text formatting options. Most text editors support capitalization formats. Currently, there is no way to change the capitalization of a written text without rewriting it entirely. The new capitalization formats added are lowercase, uppercase, and capitalize.

The behavior of capitalization format in other editors such as Google Docs, is as follows:

  1. A piece of text can be selected and its capitalization can be changed
  2. If a capitalization format was activated, it should revert to default when the Enter, Space, or Tab keys are pressed.

Test plan

Unit tests and e2e tests have been added

Before

There was no option to change the capitalization of existing text; users had to rewrite the entire text.

After

A selection's capitalization can be changed, allowing users to easily switch between lowercase and uppercase formats without needing to rewrite the text.

support-capitalization.mp4

Acknowledgement

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 2, 2024
Copy link

vercel bot commented Dec 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 14, 2024 6:22pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 14, 2024 6:22pm

Copy link

github-actions bot commented Dec 2, 2024

size-limit report 📦

Path Size
lexical - cjs 31.2 KB (0%)
lexical - esm 31.04 KB (0%)
@lexical/rich-text - cjs 40.16 KB (0%)
@lexical/rich-text - esm 32.95 KB (0%)
@lexical/plain-text - cjs 38.77 KB (0%)
@lexical/plain-text - esm 30.16 KB (0%)
@lexical/react - cjs 42.05 KB (0%)
@lexical/react - esm 34.24 KB (0%)

Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

I think overall this looks great, but it would also make sense to support Title Case (text-transform: capitalize). Screenshot of Google Docs for reference:

Screenshot 2024-12-02 at 20 35 35

@bedre7
Copy link
Contributor Author

bedre7 commented Dec 3, 2024

I think overall this looks great, but it would also make sense to support Title Case (text-transform: capitalize). Screenshot of Google Docs for reference:

Screenshot 2024-12-02 at 20 35 35

Thanks for the feedback, that's a good point. I had implemented Title Case at first but then I realized there is an edge case that needs to be addressed. Unfortunately, text-transform: capitalize only capitalizes the first letter of each word, leaving the rest of the characters unchanged (for example: hELLO wORLD ends up being HELLO WORLD when it should have been Hello World). The only workaround I could find was converting the selection text to lowercase first, then the text-transform CSS property would work as expected. If this is acceptable, I'm happy to add it. What do you think?

Reference to the workaround I mentioned: https://stackoverflow.com/a/13793667/14920149

@bedre7 bedre7 changed the title [Do Not Merge][lexical][lexical-rich-text][lexical-playground] Feature: Support capitalization format [lexical][lexical-rich-text][lexical-playground] Feature: Support capitalization format Dec 13, 2024
@bedre7 bedre7 marked this pull request as ready for review December 13, 2024 11:38
@bedre7
Copy link
Contributor Author

bedre7 commented Dec 13, 2024

Hi @etrepum, it's now ready for review.

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Dec 13, 2024
etrepum
etrepum previously approved these changes Dec 14, 2024
packages/lexical/flow/Lexical.js.flow Outdated Show resolved Hide resolved
Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

Looks great! The only thing I noticed was a missing 'capitalize' in the flow type, but I committed a fix for that. Will merge once I see what the test run looks like just to be sure.

@etrepum etrepum added this pull request to the merge queue Dec 14, 2024
Merged via the queue into facebook:main with commit 8d9d945 Dec 14, 2024
40 checks passed
@potatowagon potatowagon changed the title [lexical][lexical-rich-text][lexical-playground] Feature: Support capitalization format [lexical][Breaking Change][lexical-rich-text][lexical-playground] Feature: Support capitalization format Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants