-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Enable widget clipboard manipulation #3168
Conversation
Rebased onto latest |
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've found an edge case:
- Open manual test.
- Select all content inside the editor.
- Cut it and paste.
Expected:
Widget was replaced by prepared content.
Unexpected:
Widget was pasted as is, without any transformation.
I think it would be very counter-intuitive for users to see that widget behaves differently when pasted with some other content than when pasted alone.
Please also update version tags.
I've update the implementation to use internally our I haven't add unit tests, because I want some early review to see if the whole approach is feasible at all. |
@jacekbogdanski I remember you talked about some selection blinking when trying to come up with the solution, can you just take a quick glimpse on @Comandeer proposal to see if the solution is similar and same issue may occur? |
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.
The biggest change here as far as I understand correctly, is that previously when selection containing widget was copied, simply entire widget HTML (upcasted) was copied. Now, it's downcasted version is copied. When pasted back it needs to be upcasted (does it also happen when copying single widget now?). I'm not sure yet, if there are any cases which may be negatively affected by this 🤔
Found two issues after some brief testing:
- After cut/paste widget it is not possible to cut again if entire content is selected:
And the blinking mentioned in #3168 (comment) (you may talk to @jacekbogdanski if he tried to solved this issue):
Also please update version tags to 4.13.0
.
Overall, it looks to be a good direction 👍And the fact that it doesn't required big clipboard refactor is a plus.
plugins/widget/plugin.js
Outdated
@@ -2494,6 +2511,7 @@ | |||
// * FF tends to copy all blocks up to the copybin container. | |||
// * IE tends to copy only the copybin, without its container. | |||
// * We use spans on IE and blockless editors, but divs in other cases. | |||
// We are really sorry for summoning Zalgo… |
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.
😱
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.
😱
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 wonder if we really need this line 😛
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.
H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ
parserFragment = CKEDITOR.htmlParser.fragment.fromHtml( widget.getClipboardHtml() ); | ||
|
||
retElement = parserFragment.children[ 0 ]; | ||
} |
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 wonder how it will work with the code below, managing editables output 🤔 Does the fact that custom widget HTML (getClipboardHtml()
) is provided means any editables will be simply replaced by this custom HTML? If so there is no need to process them in any way. WDYT?
And second thing, I wonder how it will (or should) work with nested widgets? Can you check it and also add such test (we don't have many nested widget cases but still worth checking)?
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.
Everything seems to work correctly. Editables and nested widgets are replaced by the outermost widget's getClipboardHtml
result.
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.
Shouldn't we mentioned in the getClipboardHtml()
docs that for nested widget it will overwrite/replace entire widget HTML (no matter nesting/editables content)? Or is it obvious? 🤔
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.
TBH it seems rather obvious, but there will be no harm mentioning it directly in docs.
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.
And the blinking mentioned in #3168 (comment) (you may talk to @jacekbogdanski if he tried to solved this issue):
Yep, I was talking about this selection blinking, unfortunately, didn't have time to work on it. As I already have taken a look at this PR, I'm providing small feedback:
Overall it looks nice, especially that widgets are now downcasted, but as already @f1ames mentioned, I'm wondering if we can go with such big change 🤔 Users may have already some integrations relaying on upcasted widget HTML, as it has been working like that from the beginning. Maybe we could provide some configuration option as a fallback in that case? I'm really for cleaning up clipboard data, not sure if it's not "too breaking" change.
plugins/widget/plugin.js
Outdated
@@ -2494,6 +2511,7 @@ | |||
// * FF tends to copy all blocks up to the copybin container. | |||
// * IE tends to copy only the copybin, without its container. | |||
// * We use spans on IE and blockless editors, but divs in other cases. | |||
// We are really sorry for summoning Zalgo… |
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.
😱
Actually the new logic is not even fired when the whole content is selected due to #3352. I found it during trying to write unit test for the new logic handling multiple widgets. |
Actually by default the upcasted HTML is returned, via default I'm thinking about making |
I've fixed failing tests in IE8 and Safari. Additionally I've refactored copybin to have a nicer API via The only issue left is the one with selecting all content and cutting, but I'm afraid that it's connected with deeper issues with selecting widgets, as can be seen in unit tests, e.g. Safari has incorrect selection, when only two nested widgets are selected and IE8 does not select widgets if whole wrappers are not contained inside the range. |
Does it always happen? I recall you mentioned something about |
It's already extracted as #3352. Probably it would be much more difficult to fix than the proposed refactor of clipboard handling and because of that I don't see much sense in delaying this change. |
What is the purpose of this pull request?
Feature request
Does your PR contain necessary tests?
All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.
This PR contains
Proposed changelog entry
What changes did you make?
Added new widget
getClipboardHtml
member allowing to customize HTML copied to the clipboard during copy, cut and drop operations.Closes #3138.