Преглед на файлове

Emptied elements should be removed, just like in case of splitting at the start/end.

Piotrek Koszuliński преди 8 години
родител
ревизия
953252bc3f
променени са 2 файла, в които са добавени 8 реда и са изтрити 20 реда
  1. 1 15
      packages/ckeditor5-image/src/image/converters.js
  2. 7 5
      packages/ckeditor5-image/tests/image/imageengine.js

+ 1 - 15
packages/ckeditor5-image/src/image/converters.js

@@ -206,9 +206,6 @@ export function hoistImageThroughElement( evt, data ) {
 
 	// This will hold newly generated output. At the beginning it is only the original element.
 	const newOutput = [];
-	// Flag describing whether original element had any non-autohoisted children. If not, it will not be
-	// included in `newOutput` and this will have to be fixed.
-	let hasNonAutohoistedChildren = false;
 
 	// Check if any of its children is to be hoisted...
 	// Start from the last child - it is easier to break that way.
@@ -263,22 +260,11 @@ export function hoistImageThroughElement( evt, data ) {
 			if ( data.output.childCount > 0 ) {
 				newOutput.unshift( data.output );
 			}
-		} else {
-			hasNonAutohoistedChildren = true;
 		}
 	}
 
-	// If output has changed...
+	// If the output has changed pass it further.
 	if ( newOutput.length ) {
-		if ( !hasNonAutohoistedChildren ) {
-			// Fix scenario where original element has been completely removed from results:
-			// input:				<parent><autohoistedElement /><autohoistedElement /></parent>
-			// after autohoisting:	<autohoistedElement /><autohoistedElement />
-			// after this fix:		<autohoistedElement /><autohoistedElement /><parent></parent>
-			newOutput.push( data.output );
-		}
-
-		// Normalize new output and set is as result output.
 		data.output = new ModelDocumentFragment( newOutput );
 	}
 }

+ 7 - 5
packages/ckeditor5-image/tests/image/imageengine.js

@@ -219,8 +219,7 @@ describe( 'ImageEngine', () => {
 
 					expect( getModelData( document, { withoutSelection: true } ) ).to.equal(
 						'<image alt="foo" src="foo.jpg"></image>' +
-						'<image alt="foo" src="foo.jpg"></image>' +
-						'<div></div>'
+						'<image alt="foo" src="foo.jpg"></image>'
 					);
 				} );
 
@@ -244,11 +243,14 @@ describe( 'ImageEngine', () => {
 				it( 'deep autohoisting #2', () => {
 					document.schema.allow( { name: 'div', inside: 'div' } );
 
-					editor.setData( '<div><div><div><img src="foo.jpg" alt="foo" /></div></div></div>' );
+					editor.setData(
+						'<div>x</div>' +
+						'<div><div><div><img src="foo.jpg" alt="foo" /></div></div></div>' +
+						'<div>y</div>'
+					);
 
 					expect( getModelData( document, { withoutSelection: true } ) ).to.equal(
-						'<image alt="foo" src="foo.jpg"></image>' +
-						'<div><div><div></div></div></div>'
+						'<div>x</div><image alt="foo" src="foo.jpg"></image><div>y</div>'
 					);
 				} );