Ver código fonte

Added isSticky property to MoveOperation and it's child classes.

Szymon Cofalik 9 anos atrás
pai
commit
c8f15b01cd

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

@@ -51,10 +51,26 @@ export default class MoveOperation extends Operation {
 		this.targetPosition = Position.createFromPosition( targetPosition );
 	}
 
+	/**
+	 * @see core.treeModel.operation.Operation#type
+	 */
 	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}
 	 */

+ 10 - 0
packages/ckeditor5-engine/src/treemodel/operation/reinsertoperation.js

@@ -28,7 +28,17 @@ export default class ReinsertOperation extends MoveOperation {
 		return new RemoveOperation( this.targetPosition, this.howMany, this.baseVersion + 1 );
 	}
 
+	/**
+	 * @see core.treeModel.operation.Operation#type
+	 */
 	get type() {
 		return 'reinsert';
 	}
+
+	/**
+	 * @see core.treeModel.operation.MoveOperation#isSticky
+	 */
+	get isSticky() {
+		return false;
+	}
 }

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

@@ -31,10 +31,20 @@ export default class RemoveOperation extends MoveOperation {
 		super( position, howMany, graveyardPosition, baseVersion );
 	}
 
+	/**
+	 * @see core.treeModel.operation.Operation#type
+	 */
 	get type() {
 		return 'remove';
 	}
 
+	/**
+	 * @see core.treeModel.operation.MoveOperation#isSticky
+	 */
+	get isSticky() {
+		return false;
+	}
+
 	/**
 	 * @returns {core.treeModel.operation.ReinsertOperation}
 	 */

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

@@ -32,6 +32,17 @@ describe( 'MoveOperation', () => {
 		expect( op.type ).to.equal( 'move' );
 	} );
 
+	it( 'should be sticky', () => {
+		const op = new MoveOperation(
+			new Position( root, [ 0, 0 ] ),
+			1,
+			new Position( root, [ 1, 0 ] ),
+			doc.version
+		);
+
+		expect( op.isSticky ).to.be.true;
+	} );
+
 	it( 'should move from one node to another', () => {
 		let p1 = new Element( 'p1', [], new Element( 'x' ) );
 		let p2 = new Element( 'p2' );

+ 4 - 0
packages/ckeditor5-engine/tests/treemodel/operation/reinsertoperation.js

@@ -36,6 +36,10 @@ describe( 'ReinsertOperation', () => {
 		expect( operation.type ).to.equal( 'reinsert' );
 	} );
 
+	it( 'should not be sticky', () => {
+		expect( operation.isSticky ).to.be.false;
+	} );
+
 	it( 'should extend MoveOperation class', () => {
 		expect( operation ).to.be.instanceof( MoveOperation );
 	} );

+ 10 - 0
packages/ckeditor5-engine/tests/treemodel/operation/removeoperation.js

@@ -32,6 +32,16 @@ describe( 'RemoveOperation', () => {
 		expect( op.type ).to.equal( 'remove' );
 	} );
 
+	it( 'should not be sticky', () => {
+		const op = new RemoveOperation(
+			new Position( root, [ 2 ] ),
+			2,
+			doc.version
+		);
+
+		expect( op.isSticky ).to.be.false;
+	} );
+
 	it( 'should extend MoveOperation class', () => {
 		let operation = new RemoveOperation(
 			new Position( root, [ 2 ] ),