Răsfoiți Sursa

Changed: MoveOperation#isSticky flag now setable by Deltas.

Szymon Cofalik 9 ani în urmă
părinte
comite
cc32b11501

+ 1 - 0
packages/ckeditor5-engine/src/treemodel/delta/mergedelta.js

@@ -93,6 +93,7 @@ register( 'merge', function( position ) {
 	const positionBefore = Position.createFromParentAndOffset( nodeBefore, nodeBefore.getChildCount() );
 
 	const move = new MoveOperation( positionAfter, nodeAfter.getChildCount(), positionBefore, this.doc.version );
+	move.isSticky = true;
 	delta.addOperation( move );
 	this.doc.applyOperation( move );
 

+ 1 - 0
packages/ckeditor5-engine/src/treemodel/delta/splitdelta.js

@@ -108,6 +108,7 @@ register( 'split', function( position ) {
 		Position.createFromParentAndOffset( copy, 0 ),
 		this.doc.version
 	);
+	move.isSticky = true;
 
 	delta.addOperation( move );
 	this.doc.applyOperation( move );

+ 1 - 0
packages/ckeditor5-engine/src/treemodel/delta/unwrapdelta.js

@@ -77,6 +77,7 @@ register( 'unwrap', function( element ) {
 	let sourcePosition = Position.createFromParentAndOffset( element, 0 );
 
 	const move = new MoveOperation( sourcePosition, element.getChildCount(), Position.createBefore( element ), this.doc.version );
+	move.isSticky = true;
 	delta.addOperation( move );
 	this.doc.applyOperation( move );
 

+ 19 - 16
packages/ckeditor5-engine/src/treemodel/operation/moveoperation.js

@@ -49,30 +49,30 @@ export default class MoveOperation extends Operation {
 		 * @member {core.treeModel.Position} core.treeModel.operation.MoveOperation#targetPosition
 		 */
 		this.targetPosition = Position.createFromPosition( targetPosition );
+
+		/**
+		 * Defines whether `MoveOperation` is sticky. If `MoveOperation` is sticky, during
+		 * {@link core.treeModel.operation.transform operational transformation} if there will be an operation that
+		 * inserts some nodes at the position equal to the boundary of this `MoveOperation`, that operation will
+		 * get their insertion path updated to the position where this `MoveOperation` moves the range.
+		 *
+		 * @type {Boolean}
+		 */
+		this.isSticky = false;
 	}
 
 	get type() {
 		return 'move';
 	}
 
-	/**
-	 * Defines whether `MoveOperation` is sticky. If `MoveOperation` is sticky, during
-	 * {@link core.treeModel.operation.transform operational transformation} if there will be an operation that
-	 * inserts some nodes at the position equal to the boundary of this `MoveOperation`, that operation will
-	 * get their insertion path updated to the position where this `MoveOperation` moves the range.
-	 *
-	 * @protected
-	 * @type {Boolean}
-	 */
-	get isSticky() {
-		return true;
-	}
-
 	/**
 	 * @returns {core.treeModel.operation.MoveOperation}
 	 */
 	clone() {
-		return new this.constructor( this.sourcePosition, this.howMany, this.targetPosition, this.baseVersion );
+		const op = new this.constructor( this.sourcePosition, this.howMany, this.targetPosition, this.baseVersion );
+		op.isSticky = this.isSticky;
+
+		return op;
 	}
 
 	/**
@@ -82,7 +82,10 @@ export default class MoveOperation extends Operation {
 		let newSourcePosition = this.targetPosition.getTransformedByDeletion( this.sourcePosition, this.howMany );
 		let newTargetPosition = this.sourcePosition.getTransformedByInsertion( this.targetPosition, this.howMany );
 
-		return new this.constructor( newSourcePosition, this.howMany, newTargetPosition, this.baseVersion + 1 );
+		const op = new this.constructor( newSourcePosition, this.howMany, newTargetPosition, this.baseVersion + 1 );
+		op.isSticky = this.isSticky;
+
+		return op;
 	}
 
 	_execute() {
@@ -112,7 +115,7 @@ export default class MoveOperation extends Operation {
 			throw new CKEditorError(
 				'operation-move-nodes-do-not-exist: The nodes which should be moved do not exist.'
 			);
-		} else if ( sourceElement === targetElement && sourceOffset <= targetOffset && targetOffset < sourceOffset + this.howMany ) {
+		} else if ( sourceElement === targetElement && sourceOffset < targetOffset && targetOffset < sourceOffset + this.howMany ) {
 			/**
 			 * Trying to move a range of nodes into the middle of that range.
 			 *

+ 0 - 4
packages/ckeditor5-engine/src/treemodel/operation/removeoperation.js

@@ -35,10 +35,6 @@ export default class RemoveOperation extends MoveOperation {
 		return 'remove';
 	}
 
-	get isSticky() {
-		return false;
-	}
-
 	/**
 	 * @returns {core.treeModel.operation.ReinsertOperation}
 	 */

+ 1 - 1
packages/ckeditor5-engine/tests/treemodel/operation/moveoperation.js

@@ -40,7 +40,7 @@ describe( 'MoveOperation', () => {
 			doc.version
 		);
 
-		expect( op.isSticky ).to.be.true;
+		expect( op.isSticky ).to.be.false;
 	} );
 
 	it( 'should move from one node to another', () => {