Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Removed the 'model.Node#document.' property.
Browse files Browse the repository at this point in the history
  • Loading branch information
pomek committed Feb 28, 2020
1 parent 5a4ab82 commit 21390a9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 55 deletions.
17 changes: 0 additions & 17 deletions src/model/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions src/model/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 } );

Expand Down Expand Up @@ -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;

Expand Down
11 changes: 0 additions & 11 deletions src/model/textproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
19 changes: 0 additions & 19 deletions tests/model/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down
5 changes: 0 additions & 5 deletions tests/model/textproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 21390a9

Please sign in to comment.