-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix pasting MS Word table #55206
base: trunk
Are you sure you want to change the base?
Fix pasting MS Word table #55206
Conversation
Size Change: +11 B (0%) Total Size: 1.65 MB
ℹ️ View Unchanged
|
Thanks for the PR! When I tried to paste from Excel, the following error appeared in the browser console.
Therefore, I added a process to export |
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.
This PR works correctly for me!
Copy from Google docs (spreadsheet)
- ✅ Normal table
- ✅ Table with merged cells
Copy from MS Word
- ✅ Normal table
- ✅ Table with merged cells
Others
I also tested whether the issue fixed in #33607 caused a regression.
- ✅ When you copy and paste inline text, there are no spaces at either end.
- ✅ If you intentionally copy and paste text that contains spaces, spaces will remain.
22b9b5ec4bb7919a3b329918ed12094b.mp4
I would be happy if this PR could address the following two things:
- Add raw-handling test (Like
ms-excel-table-in|out.html
for example?) - I think this PR will expose
getPasteEventData()
function, so how about adding JSDoc so that it is reflected in the README?
Yes, I'll add a test, and I'll lock the function as a private api for now |
Flaky tests detected in d9c7457e0f684afc88f1f940a0e0939e84bba19c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6469903118
|
d9c7457
to
a50954a
Compare
This latest PR appears to re-introduce the issue fixed in #33607. 6c6919e68eda92b8c2269248d427a1ab.mp4For example, if I copy and paste the word "WordPress" from within a paragraph block, the HTML before filtering will look like this:
It looks like it's probably because there's an extra text node before export default function msFragmentRemover( node ) {
if (
node.nodeType === node.COMMENT_NODE &&
[ 'StartFragment', 'EndFragment' ].includes( node.textContent.trim() )
) {
// Remove unnecessary text nodes before StartFragment or after EndFragment.
const textNode =
node.textContent.trim() === 'StartFragment'
? node.previousSibling
: node.nextSibling;
if ( textNode && textNode.nodeType === textNode.TEXT_NODE ) {
remove( textNode );
}
// Remove the fragment comment node.
remove( node );
}
} |
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
What?
Fixes #42570.
Pasting tables (and potentially other stuff) from MS Word is broken because everything before and and after the StartFragment/EndFragment comments is stripped.
This is a regression caused by #33607.
Why?
How?
The solution is to reuse the battle tested strippers from the paste handler instead of doing something different.
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast