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

Commit

Permalink
Merge pull request #1138 from ckeditor/t/1137
Browse files Browse the repository at this point in the history
Feature: Introduced `model.DocumentSelection#hasOwnRange` property. Closes #1137.
  • Loading branch information
Reinmar authored Sep 12, 2017
2 parents 88630b7 + 1347a0d commit 4feb678
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/model/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
12 changes: 12 additions & 0 deletions tests/model/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 4feb678

Please sign in to comment.