-
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
Fix overwriting text on paste #4356
Conversation
It's been a while since we last heard from you. We are marking this pull request as stale due to inactivity. Please provide the requested feedback or the pull request will be closed after next 7 days. |
4c15eb8
to
9df8b50
Compare
Rebased onto the 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.
Looks good, just some minor changes.
core/editable.js
Outdated
// Instead of getData method, we directly check the HTML | ||
// due to the fact that interal getData operates on latest snapshot, | ||
// not the current content (#4301). | ||
isEmptyEditable = html === '' || html.match( emptyParagraphRegexp ); |
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.
Is the emptyParagraphRegexp
check here because it's still possible to omit upcasting p
to div
with unfiltered_html
option? If so, we need unit tests covering this case. Not sure if it's possible to do it manually. Did you manage to reproduce with normal editor usage?
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 emptyParagraphRegexp
searches for empty div
, p
and several other elements. It's not a paragraph as an element, but just as a block of text.
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.
Thanks for explaining that, but still we are missing unit and manual tests for that case. I just wanted to add them quickly during this review, but find out that I'm actually not able to create any easily reproducible test case for that scenario. Could you update your PR with these tests for empty container elements? If it's just defensive programming, it would be still good to have some spying tests instead.
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 see that test /tests/core/editable/manual/enterdiv
is failing on Chrome - but it seems like it's also failing on master
branch. Not sure if the test started to failing or it has been poorly written. Maybe do you remember @Comandeer how this test should behave?
core/editable.js
Outdated
// Instead of getData method, we directly check the HTML | ||
// due to the fact that interal getData operates on latest snapshot, | ||
// not the current content (#4301). | ||
isEmptyEditable = html === '' || html.match( emptyParagraphRegexp ); |
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.
Thanks for explaining that, but still we are missing unit and manual tests for that case. I just wanted to add them quickly during this review, but find out that I'm actually not able to create any easily reproducible test case for that scenario. Could you update your PR with these tests for empty container elements? If it's just defensive programming, it would be still good to have some spying tests instead.
It's been a while since we last heard from you. We are marking this pull request as stale due to inactivity. Please provide the requested feedback or the pull request will be closed after next 7 days. |
In fact it was a regression introduced in #3380. Unit tests didn't check for it. I've added the missing test and fixed the current solution to include the case. I've also added tests for empty paragraph regex. |
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 test /tests/core/editable/manual/enterdiv
is still failing on Firefox, IE (not all editors).
If we've introduced regression recently and it has been already published, we should create a separate ticket for that. Could you do it with some explanation of why the regression happened, as you already checked it out and have more knowledge on the topic?
return CKEDITOR.tools.array.reduce( tags, function( tests, tag ) { | ||
var tagTests = CKEDITOR.tools.array.reduce( contents, function( tests, content ) { | ||
var test = {}; | ||
|
||
listener.removeListener(); | ||
spy.restore(); | ||
test[ 'empty paragraph test: ' + tag + ' with ' + CKEDITOR.tools.htmlEncode( content ) ] = function( editor ) { | ||
var html = '<div>foo</div><div>bar</div>'; | ||
|
||
assert.areSame( expectedGetDataCount, spy.callCount, 'getData count' ); | ||
assert.areSame( 0, i, 'beforeGetData count' ); | ||
} ); | ||
}; | ||
editor.editable().setHtml( generateEmptyParagraph( tag, content ) ); | ||
editor.insertHtml( html ); | ||
|
||
assert.areSame( html, editor.getData() ); | ||
}; | ||
|
||
return CKEDITOR.tools.object.merge( tests, test ); | ||
}, {} ); | ||
|
||
return CKEDITOR.tools.object.merge( tests, tagTests ); | ||
}, {} ); |
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.
Maybe this test generation code would be a bit more readable if we would extract the cartesian product as a separate helper function? So we could just write cartesianProduct( arr1, arr2 )
producing e.g. array-based tuple?
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.
After a second thought, it probably doesn't make much sense as the code is readable enough. Otherwise, we would have to avoid changing tests
state directly which may complicate this test further.
@Comandeer, @jacekbogdanski when you will be ready with this PR let's ask @ckeditor/qa-team (@LukaszGudel) to check it too 👍 |
It's been a while since we last heard from you. We are marking this pull request as stale due to inactivity. Please provide the requested feedback or the pull request will be closed after next 7 days. |
I did some wrap up about the whole issue with the current implementation, so we can finally proceed with this PR:
The best approach would be revisiting #2751 and going with the proper fix in the first place. However, since the proper fix may not be trivial and the current issue looks like something which may occur much more often when using the editor, I would be for keeping the current fix and extracting the proper solution as a separate ticket. To compare issues:
So, it makes more sense to go with the current workaround (since it's almost finished) and start thinking about a more complicated, general fix for selection (replacing #2751 entirely), then postponing the fix for the current issue and working on a new fix #2751 right now. I will go with another review round and if there are only minor issues left (like improving tests), we can go with this PR as the current solution. |
It's been a while since we last heard from you. We are marking this pull request as stale due to inactivity. Please provide the requested feedback or the pull request will be closed after next 7 days. |
It's been a while since we last heard from you. We are marking this pull request as stale due to inactivity. Please provide the requested feedback or the pull request will be closed after next 7 days. |
Looks like we are ready for some QA, @ckeditor/qa-team team could you help with testing this fix? We are focused on fixing #4301 but as explained in #4356 (comment) we still may have some issues with invalid div wrapping, but it should not be a part of this PR. I will extract a follow-up in a moment (#4572). |
Other than the scenario from this issue (paste some text from outside) I've found three other ways of inserting content to the editor that are also affected by this bug. Additionally, it is possible to:
In all of the above cases the result is the same, only the last one copied/inserted text is showing. On the |
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.
What is the purpose of this pull request?
Bug fix
Does your PR contain necessary tests?
All patches that 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
Did you follow the CKEditor 4 code style guide?
Your code should follow the guidelines from the CKEditor 4 code style guide which helps keep the entire codebase consistent.
What is the proposed changelog entry for this pull request?
What changes did you make?
I've removed the invocation of
getData()
and replaced it with direct checking of editable's HTML.Which issues does your PR resolve?
Closes #4301.