Преглед изворни кода

Renamed #_splitElements to #_removeIfEmpty.

Oskar Wróbel пре 8 година
родитељ
комит
ef362050e3

+ 13 - 13
packages/ckeditor5-engine/src/conversion/viewconversiondispatcher.js

@@ -112,13 +112,13 @@ export default class ViewConversionDispatcher {
 		this._model = model;
 
 		/**
-		 * Store of split elements that was created as a result of conversion using {@link #_splitToAllowedParent}.
-		 * We need to remember these elements because at the end of conversion we want to remove all empty elements.
+		 * List of elements that will be checked after conversion process and if element in the list will be empty it
+		 * will be removed from conversion result.
 		 *
 		 * @protected
 		 * @type {Set<module:engine/model/element~Element>}
 		 */
-		this._splitElements = new Set();
+		this._removeIfEmpty = new Set();
 
 		/**
 		 * Position inside top element of context tree.
@@ -185,8 +185,8 @@ export default class ViewConversionDispatcher {
 
 			// When there is a conversion result.
 			if ( modelRange ) {
-				// Remove all empty elements that was created as a result of split.
-				this._removeEmptySplitElements();
+				// Remove all empty elements that was added to #_removeIfEmpty list.
+				this._removeEmptyElements();
 
 				// Move all items that was converted to context tree to document fragment.
 				for ( const item of Array.from( this._contextPosition.parent.getChildren() ) ) {
@@ -201,7 +201,7 @@ export default class ViewConversionDispatcher {
 			this._contextPosition = null;
 
 			// Clear split elements.
-			this._splitElements.clear();
+			this._removeIfEmpty.clear();
 
 			// Clear conversion API.
 			this.conversionApi.writer = null;
@@ -290,7 +290,7 @@ export default class ViewConversionDispatcher {
 		// <notSplit><split1><split2>[pos]</split2>[pos]</split1>[omit]<split1>[pos]<split2>[pos]</split2></split1></notSplit>
 		for ( const position of splitResult.range.getPositions() ) {
 			if ( !position.isEqual( splitResult.position ) ) {
-				this._splitElements.add( position.parent );
+				this._removeIfEmpty.add( position.parent );
 			}
 		}
 
@@ -301,26 +301,26 @@ export default class ViewConversionDispatcher {
 	}
 
 	/**
-	 * Checks if {@link #_splitElements} contains empty elements and remove them.
+	 * Checks if {@link #_removeIfEmpty} contains empty elements and remove them.
 	 * We need to do it smart because there could be elements that are not empty because contains
-	 * other empty split elements and after removing its children they become available to remove.
+	 * other empty elements and after removing its children they become available to remove.
 	 * We need to continue iterating over split elements as long as any element will be removed.
 	 *
 	 * @private
 	 */
-	_removeEmptySplitElements() {
+	_removeEmptyElements() {
 		let removed = false;
 
-		for ( const element of this._splitElements ) {
+		for ( const element of this._removeIfEmpty ) {
 			if ( element.isEmpty ) {
 				this.conversionApi.writer.remove( element );
-				this._splitElements.delete( element );
+				this._removeIfEmpty.delete( element );
 				removed = true;
 			}
 		}
 
 		if ( removed ) {
-			this._removeEmptySplitElements();
+			this._removeEmptyElements();
 		}
 	}
 

+ 10 - 10
packages/ckeditor5-engine/tests/conversion/viewconversiondispatcher.js

@@ -41,7 +41,7 @@ describe( 'ViewConversionDispatcher', () => {
 		it( 'should have properties', () => {
 			const dispatcher = new ViewConversionDispatcher( model );
 
-			expect( dispatcher._splitElements ).to.instanceof( Set );
+			expect( dispatcher._removeIfEmpty ).to.instanceof( Set );
 		} );
 	} );
 
@@ -64,13 +64,13 @@ describe( 'ViewConversionDispatcher', () => {
 			// Conversion process properties should be undefined/empty before conversion.
 			expect( dispatcher.conversionApi.writer ).to.not.ok;
 			expect( dispatcher.conversionApi.data ).to.not.ok;
-			expect( dispatcher._splitElements.size ).to.equal( 0 );
+			expect( dispatcher._removeIfEmpty.size ).to.equal( 0 );
 
 			dispatcher.on( 'element', ( evt, data, conversionApi ) => {
 				// Check conversion api params.
 				expect( conversionApi.writer ).to.instanceof( ModelWriter );
 				expect( conversionApi.data ).to.deep.equal( {} );
-				expect( dispatcher._splitElements.size ).to.equal( 0 );
+				expect( dispatcher._removeIfEmpty.size ).to.equal( 0 );
 
 				// Remember writer to check in next converter that is exactly the same instance (the same undo step).
 				writer = conversionApi.writer;
@@ -79,7 +79,7 @@ describe( 'ViewConversionDispatcher', () => {
 				conversionApi.data.foo = 'bar';
 
 				// Add empty element and mark as a split result to check in next converter.
-				dispatcher._splitElements.add( conversionApi.writer.createElement( 'paragraph' ) );
+				dispatcher._removeIfEmpty.add( conversionApi.writer.createElement( 'paragraph' ) );
 
 				// Convert children - this will call second converter.
 				conversionApi.convertChildren( data.viewItem, data.cursorPosition );
@@ -95,7 +95,7 @@ describe( 'ViewConversionDispatcher', () => {
 				expect( conversionApi.data ).to.deep.equal( { foo: 'bar' } );
 
 				// Split element is remembered as well.
-				expect( dispatcher._splitElements.size ).to.equal( 1 );
+				expect( dispatcher._removeIfEmpty.size ).to.equal( 1 );
 
 				spy();
 			} );
@@ -108,7 +108,7 @@ describe( 'ViewConversionDispatcher', () => {
 			// Conversion process properties should be cleared after conversion.
 			expect( dispatcher.conversionApi.writer ).to.not.ok;
 			expect( dispatcher.conversionApi.data ).to.not.ok;
-			expect( dispatcher._splitElements.size ).to.equal( 0 );
+			expect( dispatcher._removeIfEmpty.size ).to.equal( 0 );
 		} );
 
 		it( 'should fire viewCleanup event on converted view part', () => {
@@ -274,10 +274,10 @@ describe( 'ViewConversionDispatcher', () => {
 				conversionApi.writer.append( innerSplit, outerSplit );
 				conversionApi.writer.insert( outerSplit, ModelPosition.createBefore( paragraph ) );
 
-				dispatcher._splitElements.add( emptySplit );
-				dispatcher._splitElements.add( notEmptySplit );
-				dispatcher._splitElements.add( outerSplit );
-				dispatcher._splitElements.add( innerSplit );
+				dispatcher._removeIfEmpty.add( emptySplit );
+				dispatcher._removeIfEmpty.add( notEmptySplit );
+				dispatcher._removeIfEmpty.add( outerSplit );
+				dispatcher._removeIfEmpty.add( innerSplit );
 
 				data.modelRange = ModelRange.createOn( paragraph );
 				data.cursorPosition = data.modelRange.end;