-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Handle whitespaces #2651
Comments
Damn... this is tricky, because the DOM -> view converter has here a really tricky job to do. Simple case:
I'm thinking now that every nbsp in a The situation when copy-pasting within an editor is a bit different, because we could tell that the HTML in the clipboard exactly represents the data that we have. Unfortunately, that wouldn't work when copying from the editor and pasting somewhere else ;|. Does it mean that we should mark our spaces as well? And write in a |
What's is this case? A nbsp in the model? If yes, then I think that mark them is not a big deal, after all, we should not expect to have too many of them. |
Yes, that's the case. And I agree that it shouldn't be a big deal. I imagine that on view -> DOM conversion we'd wrap them with spans and that would allow to preserve them on DOM -> view conversion. Initially, I thought that we'd also need to write in a |
I'm good to go with that in that way... actually, I always imagined we would do so, because I don't see another way, as well :) |
Still, I'm worried a lot about content pasted from outside, in which we won't know what was supposed to be an
|
I have a feeling that something's changed in Chrome's behaviour and I also see that we may have some problem with losing spaces. When I copy this content: I get this results: The spaces in the "paste" section (which represents a content from the native data transfer) are Perhaps I forgot something, but I don't recall us cleaning up these spaces which means that we may be losing them somewhere. I guess it'd be good to check that as pasting content into the editor works really bad now in Chrome. I think it worked much better a few months ago and this may be the missing E.g. this is the result in Safari which still produces them: |
OK, it's definitely something in the engine, because this test fails: it.only( 'does not lose whitespaces in Chrome\'s paste-like content', () => {
const fragment = dataProcessor.toView(
'<meta charset=\'utf-8\'>' +
'<span>This is the<span>\u00a0</span></span>' +
'<a href="url">third developer preview</a>' +
'<span><span>\u00a0</span>of<span>\u00a0</span></span>' +
'<strong>CKEditor\u00a05</strong>' +
'<span>.</span>'
);
expect( stringify( fragment ) ).to.equal(
'<span>This is the<span>\u00a0</span></span>' +
'<a href="url">third developer preview</a>' +
'<span><span>\u00a0</span>of<span>\u00a0</span></span>' +
'<strong>CKEditor\u00a05</strong>' +
'<span>.</span>'
);
// Just to be sure... stringify() uses conversion and the browser extensively,
// so it's not entirely safe.
expect( fragment.getChild( 0 ).getChild( 1 ).getChild( 0 ).data ).to.equal( '\u00a0' );
expect( fragment.getChild( 2 ).getChild( 0 ).getChild( 0 ).data ).to.equal( '\u00a0' );
expect( fragment.getChild( 2 ).getChild( 2 ).getChild( 0 ).data ).to.equal( '\u00a0' );
} ); But I can't write a view-level test which would prove this ;| Strangely, they pass. |
Actually, we have two issues here:
|
This turned out to be https://github.com/ckeditor/ckeditor5-engine/issues/404. Not something that we can quickly fix so I'm not going to work on that now. However, as the case in that engine's ticket shows – this issue may lead to losing spaces in some situations. E.g., when something like this was pasted: |
Issue described in https://github.com/ckeditor/ckeditor5-clipboard/issues/2#issuecomment-310417731 and discussed after that was moved to https://github.com/ckeditor/ckeditor5-clipboard/issues/24. |
There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may be relevant, so if you're interested in the solution, leave a comment or reaction under this issue. |
We've closed your issue due to inactivity over the last year. We understand that the issue may still be relevant. If so, feel free to open a new one (and link this issue to it). |
Edit: I decided to generalise this ticket to handling copied and pasted whitespaces. See my 2nd comment to understand better the scope. In general, we need to:
nbsps
(the usual Chrome's behaviour).The problem is that here we start dealing with various technical limitations and browser quirks.
Webkit&Blink have terrible nature to put
<span classs="Apple-converted-space"> </span>
in many places in the clipboard content. They replace what was a normal space in the original content, polluting the content in a result.We're currently stripping those spans using a stupid regexp, but yeah... it's stupid. We're also replacing singular
 
s with normal spaces in order to fix the most popular case when there's only a single space inside such span.However, something like this would be nicer:
At the view stage we can freely replace every space inside those spans with a normal space, without breaking series of them (because in the view they are not encoded).
Unfortunately, the above code doesn't work because upon conversion to view spans are emptied ;|. This looks like some bug in the engine, but I don't have time to debug it now.
The text was updated successfully, but these errors were encountered: