Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Nodes are removed from their old parent when they are appended to new parent #1141

Merged
merged 4 commits into from
Sep 15, 2017

Conversation

scofalik
Copy link
Contributor

@scofalik scofalik commented Sep 12, 2017

Suggested merge commit message (convention)

Fix: view and model nodes will now be removed from their old parent when they are added to a new parent to prevent having same node on multiple elements' children lists. Closes ckeditor/ckeditor5#4182.

BREAKING CHANGE: If you will append view or model node that already has a parent, that node will be first removed from it's parent. This is important if you iterate through element's children and they are moved during that iteration. In that case it's safest to cache the element's children in an array.

@scofalik
Copy link
Contributor Author

Needed to fix a test in typing ckeditor/ckeditor5-typing#121

Reinmar added a commit to ckeditor/ckeditor5-typing that referenced this pull request Sep 12, 2017
Tests: Test fix connected with changes in the engine (ckeditor/ckeditor5-engine#1141).
@@ -852,7 +852,7 @@ function _convertViewElements( rootNode ) {
const convertedElement = rootNode.is( 'documentFragment' ) ? new ViewDocumentFragment() : _convertElement( rootNode );

// Convert all child nodes.
for ( const child of rootNode.getChildren() ) {
for ( const child of [ ...rootNode.getChildren() ] ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COMMMWENTR~!!#@

Copy link
Contributor Author

@scofalik scofalik Sep 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so serious?

// Convert to array because it is correct to do so. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -235,6 +235,11 @@ export default class DocumentFragment {
nodes = normalize( nodes );

for ( const node of nodes ) {
// If node that is being added to this element is already inside another element, first remove it from the old parent.
if ( node.parent !== null ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitating whether I'd rather like if ( node.parent ) or !== null ;| Dunno

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!== null is easier to find when searching codebase

@scofalik
Copy link
Contributor Author

What's up with this PR?

@Reinmar
Copy link
Member

Reinmar commented Sep 14, 2017

W8ing for me having time to check it.

@Reinmar Reinmar merged commit dec9c28 into master Sep 15, 2017
@Reinmar Reinmar deleted the t/1139b branch September 15, 2017 09:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Children nodes are inserted to new parent without first removing them from their old parent
2 participants