Ver código fonte

Changed: Added model.DocumentSelection#hasOwnRange.

Szymon Cofalik 8 anos atrás
pai
commit
e3ab9e393f

+ 11 - 0
packages/ckeditor5-engine/src/model/documentselection.js

@@ -119,6 +119,17 @@ export default class DocumentSelection extends Selection {
 		return this._ranges.length ? this._ranges.length : 1;
 	}
 
+	/**
+	 * Describes whether `DocumentSelection` has own range(s) set, or if it is defaulted to
+	 * {@link module:engine/model/document~Document#_getDefaultRange document's default range}.
+	 *
+	 * @readonly
+	 * @type {Boolean}
+	 */
+	get hasOwnRange() {
+		return this._ranges.length > 0;
+	}
+
 	/**
 	 * Unbinds all events previously bound by document selection.
 	 */

+ 12 - 0
packages/ckeditor5-engine/tests/model/documentselection.js

@@ -181,6 +181,18 @@ describe( 'DocumentSelection', () => {
 		} );
 	} );
 
+	describe( 'hasOwnRange', () => {
+		it( 'should return true if selection has any ranges set', () => {
+			selection.addRange( new Range( new Position( root, [ 0 ] ), new Position( root, [ 0 ] ) ) );
+
+			expect( selection.hasOwnRange ).to.be.true;
+		} );
+
+		it( 'should return false if selection has a default range', () => {
+			expect( selection.hasOwnRange ).to.be.false;
+		} );
+	} );
+
 	describe( 'addRange()', () => {
 		it( 'should convert added Range to LiveRange', () => {
 			selection.addRange( range );