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

Commit

Permalink
Merge db1299d into 00fbf7f
Browse files Browse the repository at this point in the history
  • Loading branch information
scofalik committed Jul 27, 2018
2 parents 00fbf7f + db1299d commit 8714357
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
16 changes: 15 additions & 1 deletion src/model/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,21 @@ export default class Selection {
// Check whether there is any range in new ranges set that is different than all already added ranges.
const anyNewRange = newRanges.some( newRange => {
if ( !( newRange instanceof Range ) ) {
throw new CKEditorError( 'model-selection-added-not-range: Trying to add an object that is not an instance of Range.' );
/**
* Selection range set to an object that is not an instance of {@link module:engine/model/range~Range}.
*
* Only {@link module:engine/model/range~Range} instances can be used to set a selection.
* Common mistakes leading to this error are:
*
* * using DOM `Range` object,
* * incorrect CKEditor 5 installation with multiple `ckeditor5-engine` packages having different versions.
*
* @error model-selection-set-ranges-not-range
*/
throw new CKEditorError(
'model-selection-set-ranges-not-range: ' +
'Selection range set to an object that is not an instance of model.Range.'
);
}

return this._ranges.every( oldRange => {
Expand Down
10 changes: 9 additions & 1 deletion src/view/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,15 @@ export default class Selection {
*/
_addRange( range, isBackward = false ) {
if ( !( range instanceof Range ) ) {
throw new CKEditorError( 'view-selection-invalid-range: Invalid Range.' );
/**
* Selection range set to an object that is not an instance of {@link module:engine/view/range~Range}.
*
* @error view-selection-add-range-not-range
*/
throw new CKEditorError(
'view-selection-add-range-not-range: ' +
'Selection range set to an object that is not an instance of view.Range'
);
}

this._pushRange( range );
Expand Down
2 changes: 1 addition & 1 deletion tests/model/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ describe( 'DocumentSelection', () => {
it( 'should throw an error when range is invalid', () => {
expect( () => {
selection._setTo( [ { invalid: 'range' } ] );
} ).to.throw( CKEditorError, /model-selection-added-not-range/ );
} ).to.throw( CKEditorError, /model-selection-set-ranges-not-range/ );
} );

it( 'should log a warning when trying to set selection to the graveyard', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/model/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ describe( 'Selection', () => {
it( 'should throw an error when range is invalid', () => {
expect( () => {
selection._setRanges( [ { invalid: 'range' } ] );
} ).to.throw( CKEditorError, /model-selection-added-not-range/ );
} ).to.throw( CKEditorError, /model-selection-set-ranges-not-range/ );
} );

it( 'should remove all ranges and add given ranges', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/view/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe( 'DocumentSelection', () => {
expect( () => {
// eslint-disable-next-line no-new
new DocumentSelection( [ { invalid: 'range' } ] );
} ).to.throw( CKEditorError, 'view-selection-invalid-range: Invalid Range.' );
} ).to.throw( CKEditorError, /view-selection-add-range-not-range/ );
} );

it( 'should throw an error when ranges intersects', () => {
Expand Down Expand Up @@ -1004,7 +1004,7 @@ describe( 'DocumentSelection', () => {
it( 'should throw an error when range is invalid', () => {
expect( () => {
documentSelection._setTo( [ { invalid: 'range' } ] );
} ).to.throw( CKEditorError, 'view-selection-invalid-range: Invalid Range.' );
} ).to.throw( CKEditorError, /view-selection-add-range-not-range/ );
} );

it( 'should throw when range is intersecting with already added range', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/view/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe( 'Selection', () => {
expect( () => {
// eslint-disable-next-line no-new
new Selection( [ { invalid: 'range' } ] );
} ).to.throw( CKEditorError, 'view-selection-invalid-range: Invalid Range.' );
} ).to.throw( CKEditorError, /view-selection-add-range-not-range/ );
} );

it( 'should throw an error when ranges intersects', () => {
Expand Down Expand Up @@ -878,7 +878,7 @@ describe( 'Selection', () => {
it( 'should throw an error when range is invalid', () => {
expect( () => {
selection.setTo( [ { invalid: 'range' } ] );
} ).to.throw( CKEditorError, 'view-selection-invalid-range: Invalid Range.' );
} ).to.throw( CKEditorError, /view-selection-add-range-not-range/ );
} );

it( 'should throw when range is intersecting with already added range', () => {
Expand Down

0 comments on commit 8714357

Please sign in to comment.