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

Changed: MarkerOperation execution should always result in firing Document#event:change.

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

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

@@ -94,14 +94,10 @@ export default class MarkerOperation extends Operation {
 	 * @inheritDoc
 	 */
 	_execute() {
-		// If old range and new range are "same", operation should not do anything.
 		if ( this.oldRange === null && this.newRange === null ) {
-			return;
-		} else if ( this.oldRange !== null && this.newRange !== null && this.oldRange.isEqual( this.newRange ) ) {
-			return;
+			return { name: this.name, type: 'remove' };
 		}
 
-		// At this point either `this.oldRange` or `this.newRange` has to be not-null.
 		const document = ( this.oldRange || this.newRange ).root.document;
 		let type;
 

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

@@ -62,7 +62,7 @@ describe( 'Batch', () => {
 
 			doc.batch().setMarker( marker );
 
-			expect( doc.fire.calledWith( 'marker' ) );
+			expect( doc.fire.calledWith( 'change', 'marker' ) ).to.be.true;
 		} );
 
 		it( 'should throw if marker with given name does not exist and range is not passed', () => {

+ 8 - 9
packages/ckeditor5-engine/tests/model/operation/markeroperation.js

@@ -94,21 +94,20 @@ describe( 'MarkerOperation', () => {
 		expect( doc.fire.called ).to.be.true;
 	} );
 
-	it( 'should not cause change event if operation does not change marker', () => {
-		const range = Range.createFromParentsAndOffsets( root, 0, root, 3 );
-		doc.markers.set( 'name', range );
-
+	it( 'should cause a change event when applied if oldRange and newRange are null', () => {
 		sinon.spy( doc, 'fire' );
 
-		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'name', range, range, doc.version )
-		) );
+		doc.on( 'change', ( evt, type, changes ) => {
+			expect( type ).to.equal( 'marker' );
+			expect( changes.name ).to.equal( 'name' );
+			expect( changes.type ).to.equal( 'remove' );
+		} );
 
 		doc.applyOperation( wrapInDelta(
-			new MarkerOperation( 'otherName', null, null, doc.version )
+			new MarkerOperation( 'name', null, null, doc.version )
 		) );
 
-		expect( doc.fire.notCalled ).to.be.true;
+		expect( doc.fire.calledWith( 'change', 'marker' ) ).to.be.true;
 	} );
 
 	it( 'should return MarkerOperation with swapped ranges as reverse operation', () => {