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-table] Fix table selection paste as plain text #6548

Merged
merged 5 commits into from
Aug 25, 2024

Conversation

ivailop7
Copy link
Collaborator

Fixes #6541

Before:
Double pasting incorrectly, since it was reading all nodes - rows and cells.

before_table_paste_plaintext.mov

After:
Pasting correctly, since reading only cells.

after_table_paste_plaintext.mov

Copy link

vercel bot commented Aug 24, 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 Aug 25, 2024 0:38am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 25, 2024 0:38am

@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 Aug 24, 2024
@ivailop7 ivailop7 added the extended-tests Run extended e2e tests on a PR label Aug 24, 2024
@ivailop7 ivailop7 changed the title Fix table selection paste as plain text [lexical-table] Fix table selection paste as plain text Aug 24, 2024
Copy link

github-actions bot commented Aug 24, 2024

size-limit report 📦

Path Size
lexical - cjs 29.38 KB (0%)
lexical - esm 29.24 KB (0%)
@lexical/rich-text - cjs 37.89 KB (0%)
@lexical/rich-text - esm 31.07 KB (0%)
@lexical/plain-text - cjs 36.49 KB (0%)
@lexical/plain-text - esm 28.41 KB (0%)
@lexical/react - cjs 39.61 KB (0%)
@lexical/react - esm 32.52 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.

Isn't it expected for the content to be the rows delimited by newlines and the cells delimited by tabs?

@ivailop7
Copy link
Collaborator Author

Isn't it expected for the content to be the rows delimited by newlines and the cells delimited by tabs?

One of the more popular editors I tried does it this way - cell per new line, which I think makes more sense to manipulate further if one wanted the output as plain text. Another one I tried does it the way you decribed. I don't mind chaning the paste structure, I'm unsure on the right output layout.

@etrepum
Copy link
Collaborator

etrepum commented Aug 24, 2024

The default behavior of the browser is to copy tables with tabs delimiting cells and newlines delimiting rows

@ivailop7
Copy link
Collaborator Author

The default behavior of the browser is to copy tables with tabs delimiting cells and newlines delimiting rows

updated,

updated.mov

I'm sure there's a more elegant way to concat correctly, but it does the job.

const row = node.__parent;
const nextRow = (nodes[i + 1] || {}).__parent;
textContent +=
(node.getTextContent() || ' ') + (nextRow !== row ? '\n' : '\t');
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 the || ' ' matches browser expectations (when I tried it with a table the browser doesn't insert whitespace that isn't in the content, other than the delimiters) but the rest looks good to me. Would be nice to have some tests!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated, added a test

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 good!

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: "text/plain" clipboard data of copied table cells is incorrect
3 participants