Bladeren bron

Fixed: model.Position#getAncestors.

Szymon Cofalik 8 jaren geleden
bovenliggende
commit
5261f62014

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

@@ -262,7 +262,11 @@ export default class Position {
 	 * @returns {Array.<module:engine/model/item~Item>} Array with ancestors.
 	 */
 	getAncestors() {
-		return this.parent.getAncestors( { includeNode: true, parentFirst: true } );
+		if ( this.parent instanceof DocumentFragment ) {
+			return [ this.parent ];
+		} else {
+			return this.parent.getAncestors( { includeNode: true, parentFirst: true } );
+		}
 	}
 
 	/**

+ 6 - 0
packages/ckeditor5-engine/tests/model/position.js

@@ -505,6 +505,12 @@ describe( 'position', () => {
 		it( 'should return position parent element and it\'s ancestors', () => {
 			expect( new Position( root, [ 1, 1, 1 ] ).getAncestors() ).to.deep.equal( [ li2, ul, root ] );
 		} );
+
+		it( 'should return DocumentFragment if position is directly in document fragment', () => {
+			const docFrag = new DocumentFragment();
+
+			expect( new Position( docFrag, [ 0 ] ).getAncestors() ).to.deep.equal( [ docFrag ] );
+		} );
 	} );
 
 	describe( 'getCommonPath', () => {