8
0
Pārlūkot izejas kodu

Added `affectsData` property to `MarkerOperation`.

Maciej Bukowski 7 gadi atpakaļ
vecāks
revīzija
1ee00c5f66

+ 15 - 5
packages/ckeditor5-engine/src/model/operation/markeroperation.js

@@ -20,9 +20,10 @@ export default class MarkerOperation extends Operation {
 	 * @param {module:engine/model/range~Range} newRange Marker range after the change.
 	 * @param {module:engine/model/markercollection~MarkerCollection} markers Marker collection on which change should be executed.
 	 * @param {Number|null} baseVersion Document {@link module:engine/model/document~Document#version} on which operation
+	 * @param {Boolean} affectsData Specifies whether the marker operation changes the data model.
 	 * can be applied or `null` if the operation operates on detached (non-document) tree.
 	 */
-	constructor( name, oldRange, newRange, markers, baseVersion ) {
+	constructor( name, oldRange, newRange, markers, baseVersion, affectsData ) {
 		super( baseVersion );
 
 		/**
@@ -50,6 +51,14 @@ export default class MarkerOperation extends Operation {
 		this.newRange = newRange ? Range.createFromRange( newRange ) : null;
 
 		/**
+		 * Specifies whether the marker operation changes the data model.
+		 *
+		 * @readonly
+		 * @member {Boolean}
+		 */
+		this.affectsData = affectsData;
+
+		/**
 		 * Marker collection on which change should be executed.
 		 *
 		 * @private
@@ -71,7 +80,7 @@ export default class MarkerOperation extends Operation {
 	 * @returns {module:engine/model/operation/markeroperation~MarkerOperation} Clone of this operation.
 	 */
 	clone() {
-		return new MarkerOperation( this.name, this.oldRange, this.newRange, this._markers, this.baseVersion );
+		return new MarkerOperation( this.name, this.oldRange, this.newRange, this._markers, this.baseVersion, this.affectsData );
 	}
 
 	/**
@@ -80,7 +89,7 @@ export default class MarkerOperation extends Operation {
 	 * @returns {module:engine/model/operation/markeroperation~MarkerOperation}
 	 */
 	getReversed() {
-		return new MarkerOperation( this.name, this.newRange, this.oldRange, this._markers, this.baseVersion + 1 );
+		return new MarkerOperation( this.name, this.newRange, this.oldRange, this._markers, this.baseVersion + 1, this.affectsData );
 	}
 
 	/**
@@ -111,7 +120,7 @@ export default class MarkerOperation extends Operation {
 	}
 
 	/**
-	 * Creates `MarkerOperation` object from deserilized object, i.e. from parsed JSON string.
+	 * Creates `MarkerOperation` object from deserialized object, i.e. from parsed JSON string.
 	 *
 	 * @param {Object} json Deserialized JSON object.
 	 * @param {module:engine/model/document~Document} document Document on which this operation will be applied.
@@ -123,7 +132,8 @@ export default class MarkerOperation extends Operation {
 			json.oldRange ? Range.fromJSON( json.oldRange, document ) : null,
 			json.newRange ? Range.fromJSON( json.newRange, document ) : null,
 			document.model.markers,
-			json.baseVersion
+			json.baseVersion,
+			json.affectsData
 		);
 	}
 }

+ 1 - 1
packages/ckeditor5-engine/src/model/operation/operationfactory.js

@@ -37,7 +37,7 @@ operations[ RootAttributeOperation.className ] = RootAttributeOperation;
  */
 export default class OperationFactory {
 	/**
-	 * Creates concrete `Operation` object from deserilized object, i.e. from parsed JSON string.
+	 * Creates concrete `Operation` object from deserialized object, i.e. from parsed JSON string.
 	 *
 	 * @param {Object} json Deserialized JSON object.
 	 * @param {module:engine/model/document~Document} document Document on which this operation will be applied.

+ 18 - 15
packages/ckeditor5-engine/tests/model/operation/markeroperation.js

@@ -25,7 +25,7 @@ describe( 'MarkerOperation', () => {
 	} );
 
 	it( 'should have property type equal to "marker"', () => {
-		const op = new MarkerOperation( 'name', null, range, model.markers, 0 );
+		const op = new MarkerOperation( 'name', null, range, model.markers, 0, true );
 		expect( op.type ).to.equal( 'marker' );
 	} );
 
@@ -33,7 +33,7 @@ describe( 'MarkerOperation', () => {
 		sinon.spy( model.markers, '_set' );
 
 		model.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', null, range, model.markers, doc.version )
+			new MarkerOperation( 'name', null, range, model.markers, doc.version, true )
 		) );
 
 		expect( doc.version ).to.equal( 1 );
@@ -43,7 +43,7 @@ describe( 'MarkerOperation', () => {
 
 	it( 'should update marker in document marker collection', () => {
 		model.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', null, range, model.markers, doc.version )
+			new MarkerOperation( 'name', null, range, model.markers, doc.version, true )
 		) );
 
 		const range2 = Range.createFromParentsAndOffsets( root, 0, root, 3 );
@@ -51,7 +51,7 @@ describe( 'MarkerOperation', () => {
 		sinon.spy( model.markers, '_set' );
 
 		model.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', range, range2, model.markers, doc.version )
+			new MarkerOperation( 'name', range, range2, model.markers, doc.version, true )
 		) );
 
 		expect( doc.version ).to.equal( 2 );
@@ -61,13 +61,13 @@ describe( 'MarkerOperation', () => {
 
 	it( 'should remove marker from document marker collection', () => {
 		model.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', null, range, model.markers, doc.version )
+			new MarkerOperation( 'name', null, range, model.markers, doc.version, true )
 		) );
 
 		sinon.spy( model.markers, '_remove' );
 
 		model.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', range, null, model.markers, doc.version )
+			new MarkerOperation( 'name', range, null, model.markers, doc.version, true )
 		) );
 
 		expect( doc.version ).to.equal( 2 );
@@ -79,7 +79,7 @@ describe( 'MarkerOperation', () => {
 		sinon.spy( model.markers, 'fire' );
 
 		model.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', null, null, model.markers, doc.version )
+			new MarkerOperation( 'name', null, null, model.markers, doc.version, true )
 		) );
 
 		expect( model.markers.fire.notCalled ).to.be.true;
@@ -93,7 +93,7 @@ describe( 'MarkerOperation', () => {
 		sinon.spy( model.markers, 'fire' );
 
 		model.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', range, range, model.markers, doc.version )
+			new MarkerOperation( 'name', range, range, model.markers, doc.version, true )
 		) );
 
 		expect( model.markers.fire.notCalled ).to.be.true;
@@ -102,10 +102,10 @@ describe( 'MarkerOperation', () => {
 	it( 'should return MarkerOperation with swapped ranges as reverse operation', () => {
 		const range2 = Range.createFromParentsAndOffsets( root, 0, root, 3 );
 
-		const op1 = new MarkerOperation( 'name', null, range, model.markers, doc.version );
+		const op1 = new MarkerOperation( 'name', null, range, model.markers, doc.version, true );
 		const reversed1 = op1.getReversed();
 
-		const op2 = new MarkerOperation( 'name', range, range2, model.markers, doc.version );
+		const op2 = new MarkerOperation( 'name', range, range2, model.markers, doc.version, true );
 		const reversed2 = op2.getReversed();
 
 		expect( reversed1 ).to.be.an.instanceof( MarkerOperation );
@@ -115,15 +115,17 @@ describe( 'MarkerOperation', () => {
 		expect( reversed1.oldRange.isEqual( range ) ).to.be.true;
 		expect( reversed1.newRange ).to.be.null;
 		expect( reversed1.baseVersion ).to.equal( 1 );
+		expect( reversed1.affectsData ).to.be.true;
 
 		expect( reversed2.name ).to.equal( 'name' );
 		expect( reversed2.oldRange.isEqual( range2 ) ).to.be.true;
 		expect( reversed2.newRange.isEqual( range ) ).to.be.true;
 		expect( reversed2.baseVersion ).to.equal( 1 );
+		expect( reversed2.affectsData ).to.be.true;
 	} );
 
 	it( 'should create a MarkerOperation with the same parameters when cloned', () => {
-		const op = new MarkerOperation( 'name', null, range, model.markers, 0 );
+		const op = new MarkerOperation( 'name', null, range, model.markers, 0, true );
 		const clone = op.clone();
 
 		expect( clone ).to.be.an.instanceof( MarkerOperation );
@@ -132,7 +134,7 @@ describe( 'MarkerOperation', () => {
 
 	describe( 'toJSON', () => {
 		it( 'should create proper serialized object', () => {
-			const op = new MarkerOperation( 'name', null, range, model.markers, doc.version );
+			const op = new MarkerOperation( 'name', null, range, model.markers, doc.version, true );
 			const serialized = jsonParseStringify( op );
 
 			expect( serialized ).to.deep.equal( {
@@ -140,14 +142,15 @@ describe( 'MarkerOperation', () => {
 				baseVersion: 0,
 				name: 'name',
 				oldRange: null,
-				newRange: jsonParseStringify( range )
+				newRange: jsonParseStringify( range ),
+				affectsData: true
 			} );
 		} );
 	} );
 
 	describe( 'fromJSON', () => {
 		it( 'should create proper MarkerOperation from json object #1', () => {
-			const op = new MarkerOperation( 'name', null, range, model.markers, doc.version );
+			const op = new MarkerOperation( 'name', null, range, model.markers, doc.version, true );
 
 			const serialized = jsonParseStringify( op );
 			const deserialized = MarkerOperation.fromJSON( serialized, doc );
@@ -157,7 +160,7 @@ describe( 'MarkerOperation', () => {
 
 		it( 'should create proper MarkerOperation from json object #2', () => {
 			// Gotta love 100% CC.
-			const op = new MarkerOperation( 'name', range, null, model.markers, doc.version );
+			const op = new MarkerOperation( 'name', range, null, model.markers, doc.version, true );
 
 			const serialized = jsonParseStringify( op );
 			const deserialized = MarkerOperation.fromJSON( serialized, doc );