Browse Source

Made sure that a normalized model is returned by the new converters.

Piotrek Koszuliński 9 years ago
parent
commit
119e12df19

+ 4 - 3
packages/ckeditor5-paragraph/src/paragraph.js

@@ -11,6 +11,7 @@ import Plugin from '../core/plugin.js';
 
 import ModelElement from '../engine/model/element.js';
 import ModelPosition from '../engine/model/position.js';
+import ModelRange from '../engine/model/range.js';
 import ViewElement from '../engine/view/element.js';
 import ViewRange from '../engine/view/range.js';
 
@@ -160,7 +161,7 @@ function autoparagraphParagraphLikeElements( doc, evt, data, consumable, convers
 
 	const convertedChildren = conversionApi.convertChildren( data.input, consumable, data );
 
-	modelWriter.insert( ModelPosition.createAt( paragraph ), convertedChildren );
+	paragraph.appendChildren( modelWriter.normalizeNodes( convertedChildren ) );
 
 	// Remove the created paragraph from the stack for other converters.
 	// See https://github.com/ckeditor/ckeditor5-engine/issues/736
@@ -177,8 +178,8 @@ function mergeSubsequentParagraphs( evt, data ) {
 		const nextSibling = node.nextSibling;
 
 		if ( paragraphsToMerge.has( node ) && paragraphsToMerge.has( nextSibling ) ) {
-			node.appendChildren( nextSibling.getChildren() );
-			nextSibling.remove();
+			modelWriter.insert( ModelPosition.createAt( node, 'end' ), Array.from( nextSibling.getChildren() ) );
+			modelWriter.remove( ModelRange.createOn( nextSibling ) );
 		} else {
 			node = node.nextSibling;
 		}

+ 21 - 0
packages/ckeditor5-paragraph/tests/paragraph.js

@@ -14,6 +14,9 @@ import { getData as getViewData } from 'ckeditor5/engine/dev-utils/view.js';
 
 import buildViewConverter from 'ckeditor5/engine/conversion/buildviewconverter.js';
 
+import ModelDocumentFragment from 'ckeditor5/engine/model/documentfragment.js';
+import ModelText from 'ckeditor5/engine/model/text.js';
+
 describe( 'Paragraph feature', () => {
 	let editor, doc;
 
@@ -154,6 +157,14 @@ describe( 'Paragraph feature', () => {
 
 				expect( stringifyModel( modelFragment ) ).to.equal( '' );
 			} );
+
+			it( 'creates normalized model', () => {
+				const modelFragment = editor.data.parse( 'foo<b>bar</b>bom' );
+
+				expect( modelFragment ).to.be.instanceof( ModelDocumentFragment );
+				expect( modelFragment.getChild( 0 ).childCount ).to.equal( 1 );
+				expect( modelFragment.getChild( 0 ).getChild( 0 ) ).to.be.instanceOf( ModelText );
+			} );
 		} );
 
 		describe( 'generic block converter (paragraph-like element handling)', () => {
@@ -273,6 +284,16 @@ describe( 'Paragraph feature', () => {
 						'<paragraph>bom</paragraph><paragraph>bim</paragraph>'
 					);
 			} );
+
+			it( 'creates normalized model', () => {
+				const modelFragment = editor.data.parse( '<h1><span>foo</span><span>bar</span>' );
+
+				expect( stringifyModel( modelFragment ) ).to.equal( '<paragraph>foobar</paragraph>' );
+
+				expect( modelFragment ).to.be.instanceof( ModelDocumentFragment );
+				expect( modelFragment.getChild( 0 ).childCount ).to.equal( 1 );
+				expect( modelFragment.getChild( 0 ).getChild( 0 ) ).to.be.instanceOf( ModelText );
+			} );
 		} );
 	} );