Bladeren bron

Added root getter to the MarkerOperation.

Oskar Wróbel 8 jaren geleden
bovenliggende
commit
295999133c

+ 7 - 0
packages/ckeditor5-engine/src/model/operation/markeroperation.js

@@ -64,6 +64,13 @@ export default class MarkerOperation extends Operation {
 		return 'marker';
 	}
 
+	/**
+	 * @inheritDoc
+	 */
+	get root() {
+		return this.newRange ? this.newRange.root : this.oldRange.root;
+	}
+
 	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *

+ 14 - 0
packages/ckeditor5-engine/tests/model/operation/markeroperation.js

@@ -161,6 +161,20 @@ describe( 'MarkerOperation', () => {
 		expect( clone ).to.deep.equal( op );
 	} );
 
+	describe( 'type', () => {
+		it( 'should return root of new marker range when new marker is added', () => {
+			const op = new MarkerOperation( 'name', null, range, doc.markers, doc.version );
+
+			expect( op.root ).to.equal( root );
+		} );
+
+		it( 'should return root of old marker range when marker is removed', () => {
+			const op = new MarkerOperation( 'name', range, null, doc.markers, doc.version );
+
+			expect( op.root ).to.equal( root );
+		} );
+	} );
+
 	describe( 'toJSON', () => {
 		it( 'should create proper serialized object', () => {
 			const op = new MarkerOperation( 'name', null, range, doc.markers, doc.version );