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

Bug Fix: ContextMenu Paste option not preserving style #6780

Merged

Conversation

citruscai
Copy link
Contributor

Description

When you paste a text with a different font size or custom style using the context menu, the pasted text loses it's style and is the default style.

Closes #6720

Test plan

Before

lexicalpastebug.mp4

After

lexicalpastefix.mp4

Copy link

vercel bot commented Oct 30, 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 Nov 5, 2024 0:18am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 5, 2024 0:18am

@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 Oct 30, 2024
Copy link

github-actions bot commented Oct 30, 2024

size-limit report 📦

Path Size
lexical - cjs 29.94 KB (0%)
lexical - esm 29.78 KB (0%)
@lexical/rich-text - cjs 38.59 KB (0%)
@lexical/rich-text - esm 31.65 KB (0%)
@lexical/plain-text - cjs 37.25 KB (0%)
@lexical/plain-text - esm 28.94 KB (0%)
@lexical/react - cjs 40.32 KB (0%)
@lexical/react - esm 33.01 KB (0%)

@@ -1358,7 +1358,7 @@ function applyTextFormatFromStyle(
if (shouldApply && !lexicalNode.hasFormat(shouldApply)) {
lexicalNode.toggleFormat(shouldApply);
}

lexicalNode.setStyle(style.cssText);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is one workaround it but it breaks other things, it's not generally desirable or backwards compatible for all styles to be imported because the editor doesn't know how to work with most of the styles available in CSS and you would be stuck with them since you can't manage them from the editor. For example if you pasted some text with margins or padding or something like that you wouldn't really be able to get rid of it without deleting the text.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In this particular case, the solution should be implemented such that it only works in the playground via some configuration and doesn't change the existing import behavior of TextNode

Copy link
Contributor Author

@citruscai citruscai Oct 30, 2024

Choose a reason for hiding this comment

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

In this particular case, the solution should be implemented such that it only works in the playground via some configuration and doesn't change the existing import behavior of TextNode

should i do something similiar like the above code? such as only supporting certain custom styles like font size and background color and not sure what else

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, but in order to maintain backwards compatibility the code has to be done somewhere else. I replied to your discord with an untested sketch of some code that will probably get close, using the html import configuration option that will be documented via #6762

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.

Everything looks good, only one test failure this run and it's a flaky test that has passed before and passes locally for me. In the last commit I added some extra locking around clipboard related tests to hopefully make them more reliable.

I think this is good to go and will get merged shortly. Great work!

@etrepum etrepum added this pull request to the merge queue Nov 5, 2024
Merged via the queue into facebook:main with commit c5f4722 Nov 5, 2024
39 of 40 checks passed
@etrepum etrepum mentioned this pull request Nov 7, 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.

Bug: use PASTE_COMMAND command lost some style
3 participants