浏览代码

Allowed passing doc frag to Position.createFromParentAndOffset().

Piotrek Koszuliński 9 年之前
父节点
当前提交
b34b0c0007

+ 4 - 3
packages/ckeditor5-engine/src/treemodel/position.js

@@ -504,12 +504,13 @@ export default class Position {
 	/**
 	 * Creates a new position from the parent element and the offset in that element.
 	 *
-	 * @param {engine.treeModel.Element} parent Position parent element.
-	 * @param {Number} offset Position offset.
+	 * @param {engine.treeModel.Element|engine.treeModel.DocumentFragment} parent Position's parent element or
+	 * document fragment.
+	 * @param {Number} offset Position's offset.
 	 * @returns {engine.treeModel.Position}
 	 */
 	static createFromParentAndOffset( parent, offset ) {
-		if ( !( parent instanceof Element ) ) {
+		if ( !( parent instanceof Element || parent instanceof DocumentFragment ) ) {
 			/**
 			 * Position must be anchored in an element.
 			 *

+ 7 - 1
packages/ckeditor5-engine/tests/treemodel/position.js

@@ -110,9 +110,15 @@ describe( 'position', () => {
 
 		it( 'throws when parent is not an element', () => {
 			expect( () => {
-				expect( Position.createFromParentAndOffset( b, 0 ) );
+				Position.createFromParentAndOffset( b, 0 );
 			} ).to.throw( CKEditorError, /^position-in-text:/ );
 		} );
+
+		it( 'works with a doc frag', () => {
+			const frag = new DocumentFragment();
+
+			expect( Position.createFromParentAndOffset( frag, 0 ) ).to.have.property( 'root', frag );
+		} );
 	} );
 
 	describe( 'createAt', () => {