Browse Source

Fixed: Fixed containerChildrenMutated method so it better checks whether there were any children mutations.

Szymon Cofalik 8 years ago
parent
commit
bb0c8fd845
2 changed files with 33 additions and 3 deletions
  1. 3 3
      packages/ckeditor5-typing/src/input.js
  2. 30 0
      packages/ckeditor5-typing/tests/input.js

+ 3 - 3
packages/ckeditor5-typing/src/input.js

@@ -423,12 +423,12 @@ function containerChildrenMutated( mutations ) {
 
 
 	// Check if all mutations are `children` type, and there is no single text node mutation.
 	// Check if all mutations are `children` type, and there is no single text node mutation.
 	for ( const mutation of mutations ) {
 	for ( const mutation of mutations ) {
-		if ( mutation.type !== 'children' || getSingleTextNodeChange( mutation ) ) {
-			return false;
+		if ( mutation.type === 'children' && !getSingleTextNodeChange( mutation ) ) {
+			return true;
 		}
 		}
 	}
 	}
 
 
-	return true;
+	return false;
 }
 }
 
 
 // Returns true if provided array contains only {@link module:engine/model/text~Text model text nodes}.
 // Returns true if provided array contains only {@link module:engine/model/text~Text model text nodes}.

+ 30 - 0
packages/ckeditor5-typing/tests/input.js

@@ -947,6 +947,36 @@ describe( 'Input feature', () => {
 			expect( getModelData( model ) ).to.equal( '<paragraph><$text bold="true">[]textx</$text></paragraph>' );
 			expect( getModelData( model ) ).to.equal( '<paragraph><$text bold="true">[]textx</$text></paragraph>' );
 			expect( getViewData( view ) ).to.equal( '<p><strong>{}textx</strong></p>' );
 			expect( getViewData( view ) ).to.equal( '<p><strong>{}textx</strong></p>' );
 		} );
 		} );
+
+		// #117.
+		it( 'should handle mixed mutations', () => {
+			setModelData( model, '<paragraph><$text bold="true">Foo bar aple</$text></paragraph>' );
+
+			const paragraph = viewRoot.getChild( 0 );
+			const strong = paragraph.getChild( 0 );
+			const viewSelection = new ViewSelection();
+			viewSelection.setCollapsedAt( paragraph, 0 );
+
+			// Simulate mutations and DOM change.
+			domRoot.childNodes[ 0 ].innerHTML = '<strong>Foo bar </strong><b>apple</b>';
+			view.fire( 'mutations', [
+				{
+					type: 'text',
+					oldText: 'Foo bar aple',
+					newText: 'Foo bar ',
+					node: viewRoot.getChild( 0 ).getChild( 0 )
+				},
+				{
+					type: 'children',
+					oldChildren: [ strong ],
+					newChildren: [ strong, new ViewElement( 'b', null, new ViewText( 'apple' ) ) ],
+					node: paragraph
+				}
+			], viewSelection );
+
+			expect( getModelData( model ) ).to.equal( '<paragraph><$text bold="true">[]Foo bar apple</$text></paragraph>' );
+			expect( getViewData( view ) ).to.equal( '<p><strong>{}Foo bar apple</strong></p>' );
+		} );
 	} );
 	} );
 } );
 } );