-
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 for: Editor with enterMode set to ENTER_DIV alters content on paste #2776
Conversation
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 fix doesn't work correctly with div
plugin:
- Cut content from the editor.
- Insert
div
using div button in the toolbar. - Select the newly added
div
by pressing it in elements path. - Paste content.
Expected:
The pasted content is untouched.
Actual:
The first div
is replaced by parent div
:
<div>This is some sample text.<div>New line.</div></div>
I'm wondering if just removing body > div
tag when it's the only element and it's empty, wouldn't be a better solution.
core/editable.js
Outdated
@@ -2081,6 +2082,17 @@ | |||
return nodesData; | |||
} | |||
|
|||
// Prevent inserting div into div when Editor is in ENTER_DIV mode, and target element is an empty div. | |||
function preventInsertingDiv( nodeName, element, editor ) { |
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 second parameter can use some better name, e.g. container
. Now nodeName
and element
seem to be about the same element.
tests/core/editable/enterdiv.js
Outdated
}; | ||
|
||
var tests = { | ||
// 2751 |
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.
Our convention for tests is // (#<issue number>)
.
93116b6
to
abf9805
Compare
Simplified solution by doing as above. |
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 was able to produce such output:
<div><div><div><div><div><div><div><div><div><div><div><div><div><div><div>This is some sample text.</div><div>New line.</div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
- Cut editor's content.
- Insert
div
using div button from the toolbar. - Select the newly created
div
element via element's path. - Paste.
- Select all.
- Paste.
- Repeat steps 5-6 several times.
That's an issue with selection. In Chrome and Safari using native Extracted to #2801 |
Guys, just FYI:
Is a perfectly valid selection, and should not be a condition to any bug. |
@mlewand I've thought this through. Merging divs doesn't sound like good option to me. User can have
Content will be wrapped by duplicated divs. I don't think we can safely cover every possible case by merging divs. However I have another idea for this case. I'll skip details for now, if it works I will push updates. |
Reported it on chromium and team confirmed that they can reproduce it: |
abf9805
to
9fbac06
Compare
The original case which is reproduced also on Firefox is covered by this PR. Other cases which are present only on Chrome/Safari are upstream issues. I've updated manual test, to reflect that. |
Added expected for each editor. Hide editors for which test fails because of an upstream. Updated test description.
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.
LGTM!
What is the purpose of this pull request?
Bug fix
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
What changes did you make?
When a
div
is to be inserted in another emptydiv
I've forced triggering logic which is normally trigerred when element is not allowed in selection.Closes #2751