8
0
Просмотр исходного кода

Change: rename RemoveOperation#_insertHolderElement to #_needsHolderElement, add some comments.

Szymon Cofalik 9 лет назад
Родитель
Сommit
606d97f8c0

+ 9 - 2
packages/ckeditor5-engine/src/model/operation/removeoperation.js

@@ -66,19 +66,26 @@ export default class RemoveOperation extends MoveOperation {
 	 * @protected
 	 * @type {Boolean}
 	 */
-	get _insertHolderElement() {
+	get _needsHolderElement() {
 		if ( this.delta ) {
+			// Let's look up all operations from this delta in the same order as they are in the delta.
 			for ( let operation of this.delta.operations ) {
+				// We are interested only in `RemoveOperation`s.
 				if ( operation instanceof RemoveOperation ) {
+					// If the first `RemoveOperation` in the delta is this operation, this operation
+					// needs to insert holder element in the graveyard.
 					if ( operation == this ) {
 						return true;
 					} else if ( operation._holderElementOffset == this._holderElementOffset ) {
+						// If there is a `RemoveOperation` in this delta that "points" to the same holder element offset,
+						// that operation will already insert holder element at that offset. We should not create another holder.
 						return false;
 					}
 				}
 			}
 		}
 
+		// By default `RemoveOperation` needs holder element, so set it so, if the operation does not have delta.
 		return true;
 	}
 
@@ -104,7 +111,7 @@ export default class RemoveOperation extends MoveOperation {
 	 * @inheritDoc
 	 */
 	_execute() {
-		if ( this._insertHolderElement ) {
+		if ( this._needsHolderElement ) {
 			const graveyard = this.targetPosition.root;
 			const holderElement = new Element( '$graveyardHolder' );
 

+ 2 - 2
packages/ckeditor5-engine/src/model/operation/transform.js

@@ -149,7 +149,7 @@ const ot = {
 			// Special case when MoveOperation is in fact a RemoveOperation. RemoveOperation not only moves nodes but also
 			// creates a "holder" element for them in graveyard. If there was a RemoveOperation pointing to an offset
 			// before this AttributeOperation, we have to increment AttributeOperation's offset.
-			if ( b instanceof RemoveOperation && b._insertHolderElement &&
+			if ( b instanceof RemoveOperation && b._needsHolderElement &&
 				a.range.root == b.targetPosition.root && a.range.start.path[ 0 ] >= b._holderElementOffset
 			) {
 				// Do not change original operation!
@@ -259,7 +259,7 @@ const ot = {
 			// (usually) creates a "holder" element for them in graveyard. Each RemoveOperation should move nodes to different
 			// "holder" element. If `a` operation points after `b` operation, we move `a` offset to acknowledge
 			// "holder" element insertion.
-			if ( a instanceof RemoveOperation && b instanceof RemoveOperation && b._insertHolderElement ) {
+			if ( a instanceof RemoveOperation && b instanceof RemoveOperation && b._needsHolderElement ) {
 				const aTarget = a.targetPosition.path[ 0 ];
 				const bTarget = b.targetPosition.path[ 0 ];