-
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 unwanted additional spaces added around pasted text on Windows #33607
Conversation
This comment has been minimized.
This comment has been minimized.
Ok @ellatrix it looks like this solves the reported Issue. If you have time to review my implementation that would be great. |
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.
Given that this is based on a documented OS specific issue that other editos encountered I say it's ✅ But we have a paste-handler that could handle this better than directly in Rich Text?
🤔 Yeh actually it might be better moved to there. Let me see... |
This comment has been minimized.
This comment has been minimized.
Ok it looks like we go down the gutenberg/packages/block-editor/src/components/rich-text/use-paste-handler.js Lines 109 to 120 in 339a7d7
@ellatrix I'd like to understand whether you agree that it's a good idea to strip the Windows specific fragment markers in all cases as I've done in this PR. If we don't do it here then it's never handled because whilst the |
…larity As we're not sure about this fix let's not create a public API via utils. Instead revert to inlining. Also renaming the function to make it's purpose clearer. It's not a generic normalizing function so let's make it obvious this is Windows specific.
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 think this is a good fix and despite my doubts about the place where the fix is applied we can always refactor this later.
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 tested it in Edge. Sometimes when you copy more than one words (with multiple spaces in between) and paste it somewhere, the copied texts are messed up, in a unpredictable way. Are you able to reproduce it?
No I'm not. Screen.Capture.on.2021-08-10.at.13-48-34.movAre you able to provide exact steps to reproduce? |
@kevin940726 Let me know if can no longer replicate this. If you can't then I think we should look to merge the fix as it's been around for a while now and folk are waiting on the PR to land. |
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 can't reproduce the bug anymore, let's ship it 👍
packages/block-editor/src/components/rich-text/use-paste-handler.js
Outdated
Show resolved
Hide resolved
b4a86eb
to
6a0db13
Compare
Could you please add an integration test? |
I believe the bug is only reproducible on Windows though, so not sure if we have the established testing environment yet. |
@kevin940726 A lot of the integration tests we have are for Windows. We just need a copy of the HTML that was inserted. See https://github.com/WordPress/gutenberg/tree/trunk/test/integration/fixtures/documents. Please add an integration test because issues like this are easy to regress with refactors. |
Greetings 👋 Yes good point. I was thinking along same lines as Kai with the Windows specific nature of the issue, but Ella's information puts a different spin on it. I'll put it on my list to add a test. |
Description
When pasting text internally within the editor on Windows additional spaces are added to either side of the pasted text.
two
.two
.This appears to be due to windows providing additional unwanted data when retrieving
text/html
from the clipboard event data. The actual content copied is:When this passes through the editor's paste mechanics and the format API we end up with spaces around the text.
To fix this, this PR attempts to use regex to remove:
It does not remove whitespace inside the "Fragment" comments because the user may have intentionally copied some spaces which we would want to preserve.
Fixes #33283
How has this been tested?
Hello I am some text. Let's copy me
.Also test on Mac to ensure it doesn't regress this implementation.
Screenshots
Windows
Before
Screen.Capture.on.2021-07-21.at.17-05-19.mov
After
Screen.Capture.on.2021-07-22.at.11-59-51.mp4
Mac OS
The below shows only the after fix as the bug did not manifest itself on Mac even before this fix.
Screen.Capture.on.2021-07-22.at.11-58-39.mp4
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).