-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
There was a problem hiding this 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?
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. |
The default behavior of the browser is to copy tables with tabs delimiting cells and newlines delimiting rows |
updated, updated.movI'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'); |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, added a test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
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