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; Fix context menu pasting supporting lexical format to maintain style #6765

Closed

Conversation

citruscai
Copy link
Contributor

Description

clipboard API doesnt support "application/x-lexical-editor" type which is causing pasting through context menu to lose orignal style of copied text
Trying to register application/x-lexical-format in the but $onPasteForRichText is only storing text/html and text/plain
Describe the changes in this pull request

Closes #6720 (attempts to)
see video for more info

Recording.2024-10-25.131106.mp4

Test plan

TBD

Before

After

TBD

Copy link

vercel bot commented Oct 25, 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 Oct 25, 2024 6:52pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 25, 2024 6:52pm

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

github-actions bot commented Oct 25, 2024

size-limit report 📦

Path Size
lexical - cjs 29.94 KB (0%)
lexical - esm 29.78 KB (0%)
@lexical/rich-text - cjs 38.6 KB (0%)
@lexical/rich-text - esm 31.64 KB (0%)
@lexical/plain-text - cjs 37.2 KB (0%)
@lexical/plain-text - esm 29 KB (0%)
@lexical/react - cjs 40.34 KB (0%)
@lexical/react - esm 33 KB (0%)

packages/lexical-clipboard/src/clipboard.ts Outdated Show resolved Hide resolved
packages/lexical-clipboard/src/clipboard.ts Outdated Show resolved Hide resolved
Comment on lines 524 to 533
export function $getClipboardDataFromSelection(
selection: BaseSelection | null = $getSelection(),
editor: LexicalEditor = $getEditor(),
): LexicalClipboardData {
const clipboardData: LexicalClipboardData = {
'text/plain': selection ? selection.getTextContent() : '',
'web application/x-lexical-editor': $getLexicalContent(editor, selection),
};
if (selection) {
const editor = $getEditor();
for (const [mimeType, $editorFn] of clipboardDataFunctions) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need any of the changes in this function, since clipboardDataFunctions will handle the export of the new web custom type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi!! i committed your suggestions and ran it locally. still having problem with paste losing style :(
image

citruscai and others added 2 commits October 25, 2024 13:40
Co-authored-by: Bob Ippolito <bob@redivi.com>
Co-authored-by: Bob Ippolito <bob@redivi.com>
@ivailop7 ivailop7 added the extended-tests Run extended e2e tests on a PR label Oct 26, 2024
@ivailop7
Copy link
Collaborator

Could we add a test please. Happy to merge quickly, once we have a test.

@etrepum
Copy link
Collaborator

etrepum commented Oct 26, 2024

I think there may still be some issues here, perhaps only the async api can write web custom formats, or maybe it needs to be serialized in some other way to get picked up. The docs are not very clear on this. Possibly the execCommand hack could be done here to solve it a different way? I won't have a lot of time to investigate further until next week

@citruscai
Copy link
Contributor Author

update: think i found a solution and just tested it. need to clean my code up and create tests and will push commits tomorrow thinkt im also gonna make a new PR and close this one

@citruscai citruscai closed this Oct 28, 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
4 participants