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

Commit

Permalink
"Selection#isEntireContentSelected()" has a default value for paramet…
Browse files Browse the repository at this point in the history
…er. Improved docs and tests.
  • Loading branch information
Kamil Piechaczek committed Aug 10, 2017
1 parent 99dde1e commit 9ee9e12
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/model/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,14 @@ export default class Selection {
}

/**
* Checks whether the entire content in specified element is selected.
* Checks whether the selection contains the entire content of the given element. This means that selection must start
* at a position {@link module:engine/model/position~Position#isTouching touching} the element's start and ends at position
* touching the element's end.
*
* @param {module:engine/model/element~Element} element
* @param {module:engine/model/element~Element} [element=this.anchor.root]
* @returns {Boolean}
*/
isEntireContentSelected( element ) {
isEntireContentSelected( element = this.anchor.root ) {
const limitStartPosition = Position.createAt( element );
const limitEndPosition = Position.createAt( element, 'end' );

Expand Down
22 changes: 14 additions & 8 deletions tests/model/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1247,17 +1247,13 @@ describe( 'Selection', () => {
it( 'returns true if the entire content in $root is selected', () => {
setData( doc, '<p>[Foo</p><p>Bom</p><p>Bar]</p>' );

const root = doc.getRoot();

expect( doc.selection.isEntireContentSelected( root ) ).to.equal( true );
expect( doc.selection.isEntireContentSelected() ).to.equal( true );
} );

it( 'returns false when only a fragment of the content in $root is selected', () => {
setData( doc, '<p>Fo[o</p><p>Bom</p><p>Bar]</p>' );

const root = doc.getRoot();

expect( doc.selection.isEntireContentSelected( root ) ).to.equal( false );
expect( doc.selection.isEntireContentSelected() ).to.equal( false );
} );

it( 'returns true if the entire content in specified element is selected', () => {
Expand All @@ -1284,9 +1280,19 @@ describe( 'Selection', () => {

setData( doc, '<p><img></img>[Foo]</p>' );

const root = doc.getRoot();
expect( doc.selection.isEntireContentSelected() ).to.equal( false );
} );

it( 'returns true if the content is empty', () => {
setData( doc, '[]' );

expect( doc.selection.isEntireContentSelected() ).to.equal( true );
} );

it( 'returns false if empty selection is at the end of non-empty content', () => {
setData( doc, '<p>Foo bar bom.</p>[]' );

expect( doc.selection.isEntireContentSelected( root ) ).to.equal( false );
expect( doc.selection.isEntireContentSelected() ).to.equal( false );
} );
} );
} );

0 comments on commit 9ee9e12

Please sign in to comment.