Parcourir la source

Added root getter to the AttributeOperation.

Oskar Wróbel il y a 8 ans
Parent
commit
0aa01f7078

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

@@ -88,6 +88,13 @@ export default class AttributeOperation extends Operation {
 		}
 		}
 	}
 	}
 
 
+	/**
+	 * @inheritDoc
+	 */
+	get root() {
+		return this.range.root;
+	}
+
 	/**
 	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 *

+ 29 - 0
packages/ckeditor5-engine/tests/model/operation/attributeoperation.js

@@ -59,6 +59,35 @@ describe( 'AttributeOperation', () => {
 		} );
 		} );
 	} );
 	} );
 
 
+	describe( 'root', () => {
+		it( 'should return root of range when range is in document', () => {
+			const op = new AttributeOperation(
+				new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ),
+				'key',
+				'oldValue',
+				'newValue',
+				doc.version
+			);
+
+			expect( op.root ).to.equal( root );
+		} );
+
+		it( 'should return root of range when range is in document fragment', () => {
+			const docFrag = doc.batch().createDocumentFragment();
+			doc.batch().appendText( 'abc', null, docFrag );
+
+			const op = new AttributeOperation(
+				Range.createIn( docFrag ),
+				'key',
+				'oldValue',
+				'newValue',
+				doc.version
+			);
+
+			expect( op.root ).to.equal( docFrag );
+		} );
+	} );
+
 	it( 'should insert attribute to the set of nodes', () => {
 	it( 'should insert attribute to the set of nodes', () => {
 		root.insertChildren( 0, new Text( 'bar' ) );
 		root.insertChildren( 0, new Text( 'bar' ) );