浏览代码

Added root getter to the InsertOperation.

Oskar Wróbel 8 年之前
父节点
当前提交
fda472bc7e

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

@@ -56,6 +56,13 @@ export default class InsertOperation extends Operation {
 	}
 
 	/**
+	 * @inheritDoc
+	 */
+	get root() {
+		return this.position.root;
+	}
+
+	/**
 	 * Creates and returns an operation that has the same parameters as this operation.
 	 *
 	 * @returns {module:engine/model/operation/insertoperation~InsertOperation} Clone of this operation.

+ 24 - 0
packages/ckeditor5-engine/tests/model/operation/insertoperation.js

@@ -206,6 +206,30 @@ describe( 'InsertOperation', () => {
 		expect( op2.nodes.getNode( 0 ) ).not.to.equal( text );
 	} );
 
+	describe( 'root', () => {
+		it( 'should return operation root for document', () => {
+			const op = new InsertOperation(
+				new Position( root, [ 0 ] ),
+				new Text( 'x' ),
+				doc.version
+			);
+
+			expect( op.root ).to.equal( root );
+		} );
+
+		it( 'should return operation root for document fragment', () => {
+			const docFrag = doc.batch().createDocumentFragment();
+
+			const op = new InsertOperation(
+				new Position( docFrag, [ 0 ] ),
+				new Text( 'x' ),
+				doc.version
+			);
+
+			expect( op.root ).to.equal( docFrag );
+		} );
+	} );
+
 	describe( 'toJSON', () => {
 		it( 'should create proper json object', () => {
 			const position = new Position( root, [ 0 ] );