Преглед на файлове

Merge pull request #785 from ckeditor/t/783

Changed: MarkerOperation should be passed MarkerCollection instance.
Piotr Jasiun преди 8 години
родител
ревизия
c75aaddd4c

+ 28 - 23
packages/ckeditor5-engine/src/model/delta/markerdelta.js

@@ -53,13 +53,14 @@ export default class MarkerDelta extends Delta {
  *
  * @chainable
  * @method module:engine/model/batch~Batch#setMarker
- * @param {module:engine/model/markercollection~Marker|String} markerOrName Marker to update or marker name to add or update.
- * @param {module:engine/model/range~Range} [range] Marker range.
+ * @param {module:engine/model/markercollection~Marker|String} markerOrName Marker or marker name to add or update.
+ * @param {module:engine/model/range~Range} [newRange] Marker range.
  */
-register( 'setMarker', function( markerOrName, range ) {
+register( 'setMarker', function( markerOrName, newRange ) {
 	const name = typeof markerOrName == 'string' ? markerOrName : markerOrName.name;
+	const currentMarker = this.document.markers.get( name );
 
-	if ( !range && !this.document.markers.has( name ) ) {
+	if ( !newRange && !currentMarker ) {
 		/**
 		 * Range parameter is required when adding a new marker.
 		 *
@@ -68,11 +69,16 @@ register( 'setMarker', function( markerOrName, range ) {
 		throw new CKEditorError( 'batch-setMarker-no-range: Range parameter is required when adding a new marker.' );
 	}
 
-	if ( !range ) {
-		range = this.document.markers.get( name ).getRange();
-	}
+	const currentRange = currentMarker ? currentMarker.getRange() : null;
 
-	addOperation( this, name, range );
+	if ( !newRange ) {
+		// If `newRange` is not given, treat this as synchronizing existing marker.
+		// Create `MarkerOperation` with `oldRange` set to `null`, so reverse operation will remove the marker.
+		addOperation( this, name, null, currentRange );
+	} else {
+		// Just change marker range.
+		addOperation( this, name, currentRange, newRange );
+	}
 
 	return this;
 } );
@@ -82,24 +88,12 @@ register( 'setMarker', function( markerOrName, range ) {
  *
  * @chainable
  * @method module:engine/model/batch~Batch#removeMarker
- * @param {module:engine/model/markerscollection~Marker|String} markerOrName
+ * @param {module:engine/model/markerscollection~Marker|String} markerOrName Marker or marker name to remove.
  */
 register( 'removeMarker', function( markerOrName ) {
 	const name = typeof markerOrName == 'string' ? markerOrName : markerOrName.name;
 
-	addOperation( this, name, null );
-
-	return this;
-} );
-
-function addOperation( batch, name, newRange ) {
-	const doc = batch.document;
-
-	const delta = new MarkerDelta();
-	const marker = doc.markers.get( name );
-	const oldRange = marker ? marker.getRange() : null;
-
-	if ( !newRange && !oldRange ) {
+	if ( !this.document.markers.has( name ) ) {
 		/**
 		 * Trying to remove marker that does not exist.
 		 *
@@ -108,7 +102,18 @@ function addOperation( batch, name, newRange ) {
 		throw new CKEditorError( 'batch-removeMarker-no-marker: Trying to remove marker that does not exist.' );
 	}
 
-	const operation = new MarkerOperation( name, oldRange, newRange, doc.version );
+	const oldRange = this.document.markers.get( name ).getRange();
+
+	addOperation( this, name, oldRange, null );
+
+	return this;
+} );
+
+function addOperation( batch, name, oldRange, newRange ) {
+	const doc = batch.document;
+	const delta = new MarkerDelta();
+
+	const operation = new MarkerOperation( name, oldRange, newRange, doc.markers, doc.version );
 
 	batch.addDelta( delta );
 	delta.addOperation( operation );

+ 12 - 5
packages/ckeditor5-engine/src/model/markercollection.js

@@ -79,8 +79,15 @@ export default class MarkerCollection {
 	 */
 	set( markerOrName, range ) {
 		const markerName = markerOrName instanceof Marker ? markerOrName.name : markerOrName;
+		const oldMarker = this._markers.get( markerName );
+
+		if ( oldMarker ) {
+			const oldRange = oldMarker.getRange();
+
+			if ( oldRange.isEqual( range ) ) {
+				return oldMarker;
+			}
 
-		if ( this._markers.has( markerName ) ) {
 			this.remove( markerName );
 		}
 
@@ -101,13 +108,13 @@ export default class MarkerCollection {
 	 */
 	remove( markerOrName ) {
 		const markerName = markerOrName instanceof Marker ? markerOrName.name : markerOrName;
-		const marker = this._markers.get( markerName );
+		const oldMarker = this._markers.get( markerName );
 
-		if ( marker ) {
+		if ( oldMarker ) {
 			this._markers.delete( markerName );
-			this.fire( 'remove', marker );
+			this.fire( 'remove', oldMarker );
 
-			this._destroyMarker( marker );
+			this._destroyMarker( oldMarker );
 
 			return true;
 		}

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

@@ -9,7 +9,6 @@
 
 import Operation from './operation';
 import Range from '../range';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 /**
  * @extends module:engine/model/operation/operation~Operation
@@ -19,9 +18,10 @@ export default class MarkerOperation extends Operation {
 	 * @param {String} name Marker name.
 	 * @param {module:engine/model/range~Range} oldRange Marker range before the change.
 	 * @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} baseVersion {@link module:engine/model/document~Document#version} on which the operation can be applied.
 	 */
-	constructor( name, oldRange, newRange, baseVersion ) {
+	constructor( name, oldRange, newRange, markers, baseVersion ) {
 		super( baseVersion );
 
 		/**
@@ -32,24 +32,6 @@ export default class MarkerOperation extends Operation {
 		 */
 		this.name = name;
 
-		if ( ( oldRange && !oldRange.root.document ) || ( newRange && !newRange.root.document ) ) {
-			/**
-			 * MarkerOperation range must be inside a document.
-			 *
-			 * @error marker-operation-range-not-in-document
-			 */
-			throw new CKEditorError( 'marker-operation-range-not-in-document: MarkerOperation range must be inside a document.' );
-		} else if ( oldRange && newRange && oldRange.root.document != newRange.root.document ) {
-			/**
-			 * MarkerOperation ranges must be inside same document.
-			 *
-			 * @error marker-operation-ranges-in-different-documents
-			 */
-			throw new CKEditorError(
-				'marker-operation-ranges-in-different-documents: MarkerOperation ranges must be inside same document.'
-			);
-		}
-
 		/**
 		 * Marker range before the change.
 		 *
@@ -65,6 +47,14 @@ export default class MarkerOperation extends Operation {
 		 * @member {module:engine/model/range~Range}
 		 */
 		this.newRange = newRange ? Range.createFromRange( newRange ) : null;
+
+		/**
+		 * Marker collection on which change should be executed.
+		 *
+		 * @private
+		 * @member {module:engine/model/markercollection~MarkerCollection}
+		 */
+		this._markers = markers;
 	}
 
 	/**
@@ -79,7 +69,7 @@ export default class MarkerOperation extends Operation {
 	 * @returns {module:engine/model/operation/markeroperation~MarkerOperation}
 	 */
 	clone() {
-		return new MarkerOperation( this.name, this.oldRange, this.newRange, this.baseVersion );
+		return new MarkerOperation( this.name, this.oldRange, this.newRange, this._markers, this.baseVersion );
 	}
 
 	/**
@@ -87,25 +77,16 @@ export default class MarkerOperation extends Operation {
 	 * @returns {module:engine/model/operation/markeroperation~MarkerOperation}
 	 */
 	getReversed() {
-		return new MarkerOperation( this.name, this.newRange, this.oldRange, this.baseVersion + 1 );
+		return new MarkerOperation( this.name, this.newRange, this.oldRange, this._markers, this.baseVersion + 1 );
 	}
 
 	/**
 	 * @inheritDoc
 	 */
 	_execute() {
-		// Make a change in Document#markers only when something actually changes, that is
-		// `this.oldRange` and `this.newRange` are different.
-		const changeInMarkersCollection =
-			!( this.oldRange === null && this.newRange === null ) &&
-			!( this.oldRange !== null && this.newRange !== null && this.oldRange.isEqual( this.newRange ) );
-
 		const type = this.newRange ? 'set' : 'remove';
 
-		if ( changeInMarkersCollection ) {
-			const document = ( this.oldRange || this.newRange ).root.document;
-			document.markers[ type ]( this.name, this.newRange );
-		}
+		this._markers[ type ]( this.name, this.newRange );
 
 		return { name: this.name, type: type };
 	}
@@ -116,7 +97,7 @@ export default class MarkerOperation extends Operation {
 	toJSON() {
 		const json = super.toJSON();
 
-		delete json._document;
+		delete json._markers;
 
 		return json;
 	}
@@ -140,6 +121,7 @@ export default class MarkerOperation extends Operation {
 			json.name,
 			json.oldRange ? Range.fromJSON( json.oldRange, document ) : null,
 			json.newRange ? Range.fromJSON( json.newRange, document ) : null,
+			document.markers,
 			json.baseVersion
 		);
 	}

+ 9 - 4
packages/ckeditor5-engine/tests/model/delta/markerdelta.js

@@ -42,14 +42,16 @@ describe( 'Batch', () => {
 			const marker = doc.markers.get( 'name' );
 			const range2 = Range.createFromParentsAndOffsets( root, 0, root, 0 );
 
-			doc.batch().setMarker( marker, range2 );
+			const batch = doc.batch().setMarker( marker, range2 );
+			const op = batch.deltas[ 0 ].operations[ 0 ];
 
 			expect( doc.markers.get( 'name' ).getRange().isEqual( range2 ) ).to.be.true;
+			expect( op.oldRange.isEqual( range ) ).to.be.true;
+			expect( op.newRange.isEqual( range2 ) ).to.be.true;
 		} );
 
 		it( 'should accept empty range parameter if marker instance is passed', () => {
-			doc.markers.set( 'name', range );
-			const marker = doc.markers.get( 'name' );
+			const marker = doc.markers.set( 'name', range );
 
 			sinon.spy( doc, 'fire' );
 
@@ -60,9 +62,12 @@ describe( 'Batch', () => {
 				}
 			} );
 
-			doc.batch().setMarker( marker );
+			const batch = doc.batch().setMarker( marker );
+			const op = batch.deltas[ 0 ].operations[ 0 ];
 
 			expect( doc.fire.calledWith( 'change', 'marker' ) ).to.be.true;
+			expect( op.oldRange ).to.be.null;
+			expect( op.newRange.isEqual( range ) ).to.be.true;
 		} );
 
 		it( 'should throw if marker with given name does not exist and range is not passed', () => {

+ 13 - 5
packages/ckeditor5-engine/tests/model/markercollection.js

@@ -52,15 +52,12 @@ describe( 'MarkerCollection', () => {
 		} );
 
 		it( 'should fire remove event, and create a new marker if marker with given name was in the collection', () => {
-			markers.set( 'name', range );
-			const marker1 = markers.get( 'name' );
+			const marker1 = markers.set( 'name', range );
 
 			sinon.spy( markers, 'fire' );
 
-			const result = markers.set( 'name', range2 );
-			const marker2 = markers.get( 'name' );
+			const marker2 = markers.set( 'name', range2 );
 
-			expect( result ).to.equal( marker2 );
 			expect( markers.fire.calledWithExactly( 'remove', marker1 ) ).to.be.true;
 			expect( markers.fire.calledWithExactly( 'add', marker2 ) ).to.be.true;
 
@@ -70,6 +67,17 @@ describe( 'MarkerCollection', () => {
 			expect( marker1 ).not.to.equal( marker2 );
 		} );
 
+		it( 'should not fire event and return the same marker if given marker has a range equal to given range', () => {
+			const marker1 = markers.set( 'name', range );
+
+			sinon.spy( markers, 'fire' );
+
+			const marker2 = markers.set( 'name', range );
+
+			expect( marker1 ).to.equal( marker2 );
+			expect( markers.fire.notCalled ).to.be.true;
+		} );
+
 		it( 'should accept marker instance instead of name', () => {
 			markers.set( 'name', range );
 			const marker1 = markers.get( 'name' );

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

@@ -5,10 +5,8 @@
 
 import Document from '../../../src/model/document';
 import Text from '../../../src/model/text';
-import DocumentFragment from '../../../src/model/documentfragment';
 import Range from '../../../src/model/range';
 import MarkerOperation from '../../../src/model/operation/markeroperation';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import { jsonParseStringify, wrapInDelta } from '../../model/_utils/utils';
 
 function matchRange( range ) {
@@ -26,7 +24,7 @@ describe( 'MarkerOperation', () => {
 	} );
 
 	it( 'should have property type equal to "marker"', () => {
-		const op = new MarkerOperation( 'name', null, range, 0 );
+		const op = new MarkerOperation( 'name', null, range, doc.markers, 0 );
 		expect( op.type ).to.equal( 'marker' );
 	} );
 
@@ -41,7 +39,7 @@ describe( 'MarkerOperation', () => {
 		} );
 
 		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', null, range, doc.version )
+			new MarkerOperation( 'name', null, range, doc.markers, doc.version )
 		) );
 
 		expect( doc.version ).to.equal( 1 );
@@ -52,7 +50,7 @@ describe( 'MarkerOperation', () => {
 
 	it( 'should update marker in document marker collection', () => {
 		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', null, range, doc.version )
+			new MarkerOperation( 'name', null, range, doc.markers, doc.version )
 		) );
 
 		const range2 = Range.createFromParentsAndOffsets( root, 0, root, 3 );
@@ -61,7 +59,7 @@ describe( 'MarkerOperation', () => {
 		sinon.spy( doc, 'fire' );
 
 		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', range, range2, doc.version )
+			new MarkerOperation( 'name', range, range2, doc.markers, doc.version )
 		) );
 
 		expect( doc.version ).to.equal( 2 );
@@ -72,7 +70,7 @@ describe( 'MarkerOperation', () => {
 
 	it( 'should remove marker from document marker collection', () => {
 		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', null, range, doc.version )
+			new MarkerOperation( 'name', null, range, doc.markers, doc.version )
 		) );
 
 		sinon.spy( doc.markers, 'remove' );
@@ -85,7 +83,7 @@ describe( 'MarkerOperation', () => {
 		} );
 
 		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', range, null, doc.version )
+			new MarkerOperation( 'name', range, null, doc.markers, doc.version )
 		) );
 
 		expect( doc.version ).to.equal( 2 );
@@ -94,7 +92,7 @@ describe( 'MarkerOperation', () => {
 		expect( doc.fire.called ).to.be.true;
 	} );
 
-	it( 'should fire document change event but not document markers remove event if oldRange and newRange are null', () => {
+	it( 'should fire document change event but not document markers remove event if removing non-existing range', () => {
 		sinon.spy( doc, 'fire' );
 		sinon.spy( doc.markers, 'fire' );
 
@@ -105,14 +103,16 @@ describe( 'MarkerOperation', () => {
 		} );
 
 		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', null, null, doc.version )
+			new MarkerOperation( 'name', null, null, doc.markers, doc.version )
 		) );
 
 		expect( doc.fire.calledWith( 'change', 'marker' ) ).to.be.true;
 		expect( doc.markers.fire.notCalled ).to.be.true;
 	} );
 
-	it( 'should fire document change event but not document markers remove event if oldRange and newRange are equal', () => {
+	it( 'should fire document change event but not document markers set event if newRange is same as current marker range', () => {
+		doc.markers.set( 'name', range );
+
 		sinon.spy( doc, 'fire' );
 		sinon.spy( doc.markers, 'fire' );
 
@@ -123,7 +123,7 @@ describe( 'MarkerOperation', () => {
 		} );
 
 		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', range, range, doc.version )
+			new MarkerOperation( 'name', range, range, doc.markers, doc.version )
 		) );
 
 		expect( doc.fire.calledWith( 'change', 'marker' ) ).to.be.true;
@@ -133,10 +133,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, doc.version );
+		const op1 = new MarkerOperation( 'name', null, range, doc.markers, doc.version );
 		const reversed1 = op1.getReversed();
 
-		const op2 = new MarkerOperation( 'name', range, range2, doc.version );
+		const op2 = new MarkerOperation( 'name', range, range2, doc.markers, doc.version );
 		const reversed2 = op2.getReversed();
 
 		expect( reversed1 ).to.be.an.instanceof( MarkerOperation );
@@ -154,44 +154,16 @@ describe( 'MarkerOperation', () => {
 	} );
 
 	it( 'should create a MarkerOperation with the same parameters when cloned', () => {
-		const op = new MarkerOperation( 'name', null, range, 0 );
+		const op = new MarkerOperation( 'name', null, range, doc.markers, 0 );
 		const clone = op.clone();
 
 		expect( clone ).to.be.an.instanceof( MarkerOperation );
 		expect( clone ).to.deep.equal( op );
 	} );
 
-	it( 'should throw if oldRange is not in a document', () => {
-		const docFrag = new DocumentFragment();
-		const rangeInDocFrag = Range.createIn( docFrag );
-
-		expect( () => {
-			new MarkerOperation( 'name', rangeInDocFrag, null, 0 );
-		} ).to.throw( CKEditorError, /^marker-operation-range-not-in-document/ );
-	} );
-
-	it( 'should throw if newRange is not in a document', () => {
-		const docFrag = new DocumentFragment();
-		const rangeInDocFrag = Range.createIn( docFrag );
-
-		expect( () => {
-			new MarkerOperation( 'name', null, rangeInDocFrag, 0 );
-		} ).to.throw( CKEditorError, /^marker-operation-range-not-in-document/ );
-	} );
-
-	it( 'should throw if ranges are in different documents', () => {
-		const document2 = new Document();
-		const root2 = document2.createRoot();
-		const rangeInRoot2 = Range.createIn( root2 );
-
-		expect( () => {
-			new MarkerOperation( 'name', range, rangeInRoot2, 0 );
-		} ).to.throw( CKEditorError, /^marker-operation-ranges-in-different-documents/ );
-	} );
-
 	describe( 'toJSON', () => {
 		it( 'should create proper serialized object', () => {
-			const op = new MarkerOperation( 'name', null, range, doc.version );
+			const op = new MarkerOperation( 'name', null, range, doc.markers, doc.version );
 			const serialized = jsonParseStringify( op );
 
 			expect( serialized ).to.deep.equal( {
@@ -206,7 +178,7 @@ describe( 'MarkerOperation', () => {
 
 	describe( 'fromJSON', () => {
 		it( 'should create proper MarkerOperation from json object #1', () => {
-			const op = new MarkerOperation( 'name', null, range, doc.version );
+			const op = new MarkerOperation( 'name', null, range, doc.markers, doc.version );
 
 			const serialized = jsonParseStringify( op );
 			const deserialized = MarkerOperation.fromJSON( serialized, doc );
@@ -216,7 +188,7 @@ describe( 'MarkerOperation', () => {
 
 		it( 'should create proper MarkerOperation from json object #2', () => {
 			// Gotta love 100% CC.
-			const op = new MarkerOperation( 'name', range, null, doc.version );
+			const op = new MarkerOperation( 'name', range, null, doc.markers, doc.version );
 
 			const serialized = jsonParseStringify( op );
 			const deserialized = MarkerOperation.fromJSON( serialized, doc );

+ 10 - 10
packages/ckeditor5-engine/tests/model/operation/transform.js

@@ -418,7 +418,7 @@ describe( 'transform', () => {
 		describe( 'by MarkerOperation', () => {
 			it( 'no position update', () => {
 				const newRange = new Range( new Position( root, [ 0, 2, 0 ] ), new Position( root, [ 0, 2, 4 ] ) );
-				let transformBy = new MarkerOperation( 'name', null, newRange, baseVersion );
+				let transformBy = new MarkerOperation( 'name', null, newRange, doc.markers, baseVersion );
 
 				let transOp = transform( op, transformBy );
 
@@ -1142,7 +1142,7 @@ describe( 'transform', () => {
 			describe( 'by MarkerOperation', () => {
 				it( 'no operation update', () => {
 					const newRange = new Range( new Position( root, [ 0, 2, 0 ] ), new Position( root, [ 0, 2, 8 ] ) );
-					let transformBy = new MarkerOperation( 'name', null, newRange, baseVersion );
+					let transformBy = new MarkerOperation( 'name', null, newRange, doc.markers, baseVersion );
 
 					let transOp = transform( op, transformBy );
 
@@ -1620,7 +1620,7 @@ describe( 'transform', () => {
 		describe( 'by MarkerOperation', () => {
 			it( 'no position update', () => {
 				const newRange = new Range( new Position( root, [ 0, 2, 0 ] ), new Position( root, [ 0, 2, 8 ] ) );
-				let transformBy = new MarkerOperation( 'name', null, newRange, baseVersion );
+				let transformBy = new MarkerOperation( 'name', null, newRange, doc.markers, baseVersion );
 
 				let transOp = transform( op, transformBy );
 
@@ -2746,7 +2746,7 @@ describe( 'transform', () => {
 		describe( 'by MarkerOperation', () => {
 			it( 'no position update', () => {
 				const newRange = new Range( new Position( root, [ 2, 2, 3 ] ), new Position( root, [ 2, 2, 8 ] ) );
-				let transformBy = new MarkerOperation( 'name', null, newRange, baseVersion );
+				let transformBy = new MarkerOperation( 'name', null, newRange, doc.markers, baseVersion );
 
 				let transOp = transform( op, transformBy );
 
@@ -2897,7 +2897,7 @@ describe( 'transform', () => {
 		describe( 'by MarkerOperation', () => {
 			it( 'no position update', () => {
 				const newRange = new Range( new Position( root, [ 0, 2, 0 ] ), new Position( root, [ 0, 2, 8 ] ) );
-				let transformBy = new MarkerOperation( 'name', null, newRange, baseVersion );
+				let transformBy = new MarkerOperation( 'name', null, newRange, doc.markers, baseVersion );
 
 				let transOp = transform( op, transformBy );
 
@@ -3021,7 +3021,7 @@ describe( 'transform', () => {
 		describe( 'by MarkerOperation', () => {
 			it( 'no operation update', () => {
 				const newRange = new Range( new Position( root, [ 0, 2, 0 ] ), new Position( root, [ 0, 2, 8 ] ) );
-				let transformBy = new MarkerOperation( 'name', null, newRange, baseVersion );
+				let transformBy = new MarkerOperation( 'name', null, newRange, doc.markers, baseVersion );
 
 				let transOp = transform( op, transformBy );
 
@@ -3190,7 +3190,7 @@ describe( 'transform', () => {
 		beforeEach( () => {
 			oldRange = Range.createFromParentsAndOffsets( root, 1, root, 4 );
 			newRange = Range.createFromParentsAndOffsets( root, 10, root, 12 );
-			op = new MarkerOperation( 'name', oldRange, newRange, baseVersion );
+			op = new MarkerOperation( 'name', oldRange, newRange, doc.markers, baseVersion );
 
 			expected = {
 				name: 'name',
@@ -3340,7 +3340,7 @@ describe( 'transform', () => {
 
 		describe( 'by MarkerOperation', () => {
 			it( 'different marker name: no operation update', () => {
-				let transformBy = new MarkerOperation( 'otherName', oldRange, newRange, baseVersion );
+				let transformBy = new MarkerOperation( 'otherName', oldRange, newRange, doc.markers, baseVersion );
 
 				let transOp = transform( op, transformBy );
 
@@ -3350,7 +3350,7 @@ describe( 'transform', () => {
 
 			it( 'same marker name and is important: convert to NoOperation', () => {
 				const anotherRange = Range.createFromParentsAndOffsets( root, 2, root, 2 );
-				let transformBy = new MarkerOperation( 'name', oldRange, anotherRange, baseVersion );
+				let transformBy = new MarkerOperation( 'name', oldRange, anotherRange, doc.markers, baseVersion );
 
 				let transOp = transform( op, transformBy );
 
@@ -3363,7 +3363,7 @@ describe( 'transform', () => {
 
 			it( 'same marker name and is less important: update oldRange parameter', () => {
 				const anotherRange = Range.createFromParentsAndOffsets( root, 2, root, 2 );
-				let transformBy = new MarkerOperation( 'name', oldRange, anotherRange, baseVersion );
+				let transformBy = new MarkerOperation( 'name', oldRange, anotherRange, doc.markers, baseVersion );
 
 				let transOp = transform( op, transformBy, true );