Przeglądaj źródła

Node.getDocument() should return null it the parent is null or DocumentFragment.

Piotr Jasiun 9 lat temu
rodzic
commit
0515a28b17

+ 2 - 1
packages/ckeditor5-engine/src/view/node.js

@@ -87,7 +87,8 @@ export default class Node {
 	 * @returns {engine.view.Document|null} View Document of the node or null.
 	 */
 	getDocument() {
-		if ( this.parent ) {
+		// Parent might be Node, null or DocumentFragment.
+		if ( this.parent instanceof Node ) {
 			return this.parent.getDocument();
 		} else {
 			return null;

+ 8 - 0
packages/ckeditor5-engine/tests/view/node.js

@@ -9,6 +9,7 @@
 
 import Element from '/ckeditor5/engine/view/element.js';
 import Text from '/ckeditor5/engine/view/text.js';
+import DocumentFragment from '/ckeditor5/engine/view/documentfragment.js';
 import RootEditableElement from '/ckeditor5/engine/view/rooteditableelement.js';
 import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
 
@@ -146,6 +147,13 @@ describe( 'Node', () => {
 			expect( parent.getDocument() ).to.equal( docMock );
 			expect( child.getDocument() ).to.equal( docMock );
 		} );
+
+		it( 'should return null if element is inside DocumentFragment', () => {
+			const child = new Element( 'p' );
+			new DocumentFragment( [ child ] );
+
+			expect( child.getDocument() ).to.be.null;
+		} );
 	} );
 
 	describe( 'getRoot', () => {