From 21390a93bde53517bec3e82fedc9cb1ea77d5187 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Thu, 27 Feb 2020 11:56:05 +0100 Subject: [PATCH] Removed the 'model.Node#document.' property. --- src/model/node.js | 17 ----------------- src/model/selection.js | 11 ++++++++--- src/model/textproxy.js | 11 ----------- tests/model/node.js | 19 ------------------- tests/model/textproxy.js | 5 ----- 5 files changed, 8 insertions(+), 55 deletions(-) diff --git a/src/model/node.js b/src/model/node.js index 3795350b1..5c5800139 100644 --- a/src/model/node.js +++ b/src/model/node.js @@ -188,23 +188,6 @@ export default class Node { return root; } - /** - * {@link module:engine/model/document~Document Document} that owns this node or `null` if the node has no parent or is inside - * a {@link module:engine/model/documentfragment~DocumentFragment DocumentFragment}. - * - * @readonly - * @type {module:engine/model/document~Document|null} - */ - get document() { - // This is a top element of a sub-tree. - if ( this.root == this ) { - return null; - } - - // Root may be `DocumentFragment` which does not have document property. - return this.root.document || null; - } - /** * Gets path to the node. The path is an array containing starting offsets of consecutive ancestors of this node, * beginning from {@link module:engine/model/node~Node#root root}, down to this node's starting offset. The path can be used to diff --git a/src/model/selection.js b/src/model/selection.js index be1fe8682..1ec167eae 100644 --- a/src/model/selection.js +++ b/src/model/selection.js @@ -829,7 +829,9 @@ function isUnvisitedBlock( element, visited ) { visited.add( element ); - return element.document.model.schema.isBlock( element ) && element.parent; + const document = element.is( 'rootElement' ) ? element.document : element.root.document; + + return document.model.schema.isBlock( element ) && element.parent; } // Checks if the given element is a $block was not previously visited and is a top block in a range. @@ -841,7 +843,9 @@ function isUnvisitedTopBlock( element, visited, range ) { // It will search until first ancestor that is a limit element. // Marks all ancestors as already visited to not include any of them later on. function getParentBlock( position, visited ) { - const schema = position.parent.document.model.schema; + const element = position.parent; + const document = element.is( 'rootElement' ) ? element.document : element.root.document; + const schema = document.model.schema; const ancestors = position.parent.getAncestors( { parentFirst: true, includeSelf: true } ); @@ -887,7 +891,8 @@ function isTopBlockInRange( block, range ) { // @param {module:engine/model/node~Node} node // @returns {module:engine/model/node~Node|undefined} function findAncestorBlock( node ) { - const schema = node.document.model.schema; + const document = node.is( 'rootElement' ) ? node.document : node.root.document; + const schema = document.model.schema; let parent = node.parent; diff --git a/src/model/textproxy.js b/src/model/textproxy.js index 1d4a0a9cf..f3946f8c4 100644 --- a/src/model/textproxy.js +++ b/src/model/textproxy.js @@ -163,17 +163,6 @@ export default class TextProxy { return this.textNode.root; } - /** - * {@link module:engine/model/document~Document Document} that owns text node represented by this text proxy or `null` if the text node - * has no parent or is inside a {@link module:engine/model/documentfragment~DocumentFragment DocumentFragment}. - * - * @readonly - * @type {module:engine/model/document~Document|null} - */ - get document() { - return this.textNode.document; - } - /** * Checks whether this object is of the given. * diff --git a/tests/model/node.js b/tests/model/node.js index 4284c5ecb..f684fdfc9 100644 --- a/tests/model/node.js +++ b/tests/model/node.js @@ -75,25 +75,6 @@ describe( 'Node', () => { expect( node ).to.have.property( 'previousSibling' ).that.is.null; } ); - - it( 'document', () => { - expect( root ).to.have.property( 'document' ).that.equals( doc ); - - expect( one ).to.have.property( 'document' ).that.equals( doc ); - expect( two ).to.have.property( 'document' ).that.equals( doc ); - expect( three ).to.have.property( 'document' ).that.equals( doc ); - - expect( textBA ).to.have.property( 'document' ).that.equals( doc ); - expect( img ).to.have.property( 'document' ).that.equals( doc ); - expect( textR ).to.have.property( 'document' ).that.equals( doc ); - - expect( node ).to.have.property( 'document' ).that.is.null; - - // DocumentFragment does not have document property, so node's document property should be null. - const docFrag = new DocumentFragment(); - docFrag._appendChild( node ); - expect( node ).to.have.property( 'document' ).that.is.null; - } ); } ); describe( 'constructor()', () => { diff --git a/tests/model/textproxy.js b/tests/model/textproxy.js index c5c8938d6..294ea2b85 100644 --- a/tests/model/textproxy.js +++ b/tests/model/textproxy.js @@ -38,11 +38,6 @@ describe( 'TextProxy', () => { expect( textProxyNoParent ).to.have.property( 'root' ).that.equals( textNoParent ); } ); - it( 'should have document property', () => { - expect( textProxy ).to.have.property( 'document' ).that.equals( doc ); - expect( textProxyNoParent ).to.have.property( 'document' ).that.equals( null ); - } ); - it( 'should have parent property', () => { expect( textProxy ).to.have.property( 'parent' ).that.equals( element ); expect( textProxyNoParent ).to.have.property( 'parent' ).that.equals( null );