diff --git a/src/model/selection.js b/src/model/selection.js index be0a09ddc..43df92e4d 100644 --- a/src/model/selection.js +++ b/src/model/selection.js @@ -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' ); diff --git a/tests/model/selection.js b/tests/model/selection.js index 1bd1b159a..ec42ed30a 100644 --- a/tests/model/selection.js +++ b/tests/model/selection.js @@ -1247,17 +1247,13 @@ describe( 'Selection', () => { it( 'returns true if the entire content in $root is selected', () => { setData( doc, '

[Foo

Bom

Bar]

' ); - 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, '

Fo[o

Bom

Bar]

' ); - 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', () => { @@ -1284,9 +1280,19 @@ describe( 'Selection', () => { setData( doc, '

[Foo]

' ); - 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, '

Foo bar bom.

[]' ); - expect( doc.selection.isEntireContentSelected( root ) ).to.equal( false ); + expect( doc.selection.isEntireContentSelected() ).to.equal( false ); } ); } ); } );