Răsfoiți Sursa

Simplified toElement conversion and increased CC of ViewConverterBuilder.

Oskar Wróbel 8 ani în urmă
părinte
comite
d8e03e309d

+ 1 - 9
packages/ckeditor5-engine/src/conversion/buildviewconverter.js

@@ -335,16 +335,8 @@ class ViewConverterBuilder {
 					//
 					// after: <allowed>[]</allowed>
 					// before: <allowed>[<converted><child></child></converted><child></child><converted>]</converted></allowed>
-					} else if ( childrenOutput.end.parent !== childrenOutput.end.root ) {
-						output.end = Position.createAfter( childrenOutput.end.parent );
-
-					// Finally when we are sure that element and its parent was not split we need to put selection
-					// after element.
-					//
-					// after: <allowed>[]</allowed>
-					// before: <allowed>[<converted></converted>]</allowed>
 					} else {
-						output.end = Position.createAfter( modelElement );
+						output.end = Position.createAfter( childrenOutput.end.parent );
 					}
 
 					data.output = output;

+ 36 - 0
packages/ckeditor5-engine/tests/conversion/buildviewconverter.js

@@ -125,6 +125,42 @@ describe( 'View converter builder', () => {
 		expect( modelToString( conversionResult ) ).to.equal( '<image src="foo.jpg"></image>' );
 	} );
 
+	it( 'should convert to model element when element children are not allowed in parent (empty split elements should be removed)', () => {
+		schema.register( 'section', {
+			inheritAllFrom: '$block'
+		} );
+
+		buildViewConverter().for( dispatcher )
+			.fromElement( 'p' )
+			.toElement( 'paragraph' );
+
+		buildViewConverter().for( dispatcher )
+			.fromElement( 'section' )
+			.toElement( 'section' );
+
+		const input = new ViewContainerElement( 'p', null, [
+			new ViewText( 'foo' ),
+			new ViewContainerElement( 'section', null, [
+				new ViewContainerElement( 'p', null, [
+					new ViewText( 'abc' ),
+					new ViewContainerElement( 'section' ),
+					new ViewText( 'cde' ),
+				] )
+			] ),
+			new ViewText( 'bar' ),
+		] );
+
+		const conversionResult = dispatcher.convert( input );
+
+		expect( modelToString( conversionResult ) ).to.equal(
+			'<paragraph>foo</paragraph>' +
+			'<paragraph>abc</paragraph>' +
+			'<section></section>' +
+			'<paragraph>cde</paragraph>' +
+			'<paragraph>bar</paragraph>'
+		);
+	} );
+
 	it( 'should convert from view element to model attribute', () => {
 		buildViewConverter().for( dispatcher ).fromElement( 'strong' ).toAttribute( 'bold', true );