Преглед изворни кода

"Selection#isEntireContentSelected()" has a default value for parameter. Improved docs and tests.

Kamil Piechaczek пре 8 година
родитељ
комит
5d1388aa7b

+ 5 - 3
packages/ckeditor5-engine/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}
 	 * @returns {Boolean}
 	 */
 	 */
-	isEntireContentSelected( element ) {
+	isEntireContentSelected( element = this.anchor.root ) {
 		const limitStartPosition = Position.createAt( element );
 		const limitStartPosition = Position.createAt( element );
 		const limitEndPosition = Position.createAt( element, 'end' );
 		const limitEndPosition = Position.createAt( element, 'end' );
 
 

+ 14 - 8
packages/ckeditor5-engine/tests/model/selection.js

@@ -1247,17 +1247,13 @@ describe( 'Selection', () => {
 		it( 'returns true if the entire content in $root is selected', () => {
 		it( 'returns true if the entire content in $root is selected', () => {
 			setData( doc, '<p>[Foo</p><p>Bom</p><p>Bar]</p>' );
 			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', () => {
 		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>' );
 			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', () => {
 		it( 'returns true if the entire content in specified element is selected', () => {
@@ -1284,9 +1280,19 @@ describe( 'Selection', () => {
 
 
 			setData( doc, '<p><img></img>[Foo]</p>' );
 			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 );
 		} );
 		} );
 	} );
 	} );
 } );
 } );