|
@@ -4,6 +4,7 @@
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
import Selection from '../../src/view/selection';
|
|
import Selection from '../../src/view/selection';
|
|
|
|
|
+import DocumentSelection from '../../src/view/documentselection';
|
|
|
import Range from '../../src/view/range';
|
|
import Range from '../../src/view/range';
|
|
|
import Document from '../../src/view/document';
|
|
import Document from '../../src/view/document';
|
|
|
import Element from '../../src/view/element';
|
|
import Element from '../../src/view/element';
|
|
@@ -92,6 +93,14 @@ describe( 'Selection', () => {
|
|
|
expect( selection.isBackward ).to.be.true;
|
|
expect( selection.isBackward ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'should be able to create a selection from the other document selection', () => {
|
|
|
|
|
+ const otherSelection = new DocumentSelection( [ range2, range3 ], { backward: true } );
|
|
|
|
|
+ const selection = new Selection( otherSelection );
|
|
|
|
|
+
|
|
|
|
|
+ expect( Array.from( selection.getRanges() ) ).to.deep.equal( [ range2, range3 ] );
|
|
|
|
|
+ expect( selection.isBackward ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'should be able to create a fake selection from the other fake selection', () => {
|
|
it( 'should be able to create a fake selection from the other fake selection', () => {
|
|
|
const otherSelection = new Selection( [ range2, range3 ], { fake: true, label: 'foo bar baz' } );
|
|
const otherSelection = new Selection( [ range2, range3 ], { fake: true, label: 'foo bar baz' } );
|
|
|
const selection = new Selection( otherSelection );
|
|
const selection = new Selection( otherSelection );
|
|
@@ -131,7 +140,7 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return start of single range in selection', () => {
|
|
it( 'should return start of single range in selection', () => {
|
|
|
- selection._setTo( range1 );
|
|
|
|
|
|
|
+ selection.setTo( range1 );
|
|
|
const anchor = selection.anchor;
|
|
const anchor = selection.anchor;
|
|
|
|
|
|
|
|
expect( anchor.isEqual( range1.start ) ).to.be.true;
|
|
expect( anchor.isEqual( range1.start ) ).to.be.true;
|
|
@@ -139,7 +148,7 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return end of single range in selection when added as backward', () => {
|
|
it( 'should return end of single range in selection when added as backward', () => {
|
|
|
- selection._setTo( range1, { backward: true } );
|
|
|
|
|
|
|
+ selection.setTo( range1, { backward: true } );
|
|
|
const anchor = selection.anchor;
|
|
const anchor = selection.anchor;
|
|
|
|
|
|
|
|
expect( anchor.isEqual( range1.end ) ).to.be.true;
|
|
expect( anchor.isEqual( range1.end ) ).to.be.true;
|
|
@@ -147,7 +156,7 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should get anchor from last inserted range', () => {
|
|
it( 'should get anchor from last inserted range', () => {
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
|
expect( selection.anchor.isEqual( range2.start ) ).to.be.true;
|
|
expect( selection.anchor.isEqual( range2.start ) ).to.be.true;
|
|
|
} );
|
|
} );
|
|
@@ -159,14 +168,14 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return end of single range in selection', () => {
|
|
it( 'should return end of single range in selection', () => {
|
|
|
- selection._setTo( range1 );
|
|
|
|
|
|
|
+ selection.setTo( range1 );
|
|
|
const focus = selection.focus;
|
|
const focus = selection.focus;
|
|
|
|
|
|
|
|
expect( focus.isEqual( range1.end ) ).to.be.true;
|
|
expect( focus.isEqual( range1.end ) ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return start of single range in selection when added as backward', () => {
|
|
it( 'should return start of single range in selection when added as backward', () => {
|
|
|
- selection._setTo( range1, { backward: true } );
|
|
|
|
|
|
|
+ selection.setTo( range1, { backward: true } );
|
|
|
const focus = selection.focus;
|
|
const focus = selection.focus;
|
|
|
|
|
|
|
|
expect( focus.isEqual( range1.start ) ).to.be.true;
|
|
expect( focus.isEqual( range1.start ) ).to.be.true;
|
|
@@ -174,16 +183,16 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should get focus from last inserted range', () => {
|
|
it( 'should get focus from last inserted range', () => {
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
|
expect( selection.focus.isEqual( range2.end ) ).to.be.true;
|
|
expect( selection.focus.isEqual( range2.end ) ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- describe( '_setFocus()', () => {
|
|
|
|
|
|
|
+ describe( 'setFocus()', () => {
|
|
|
it( 'keeps all existing ranges when no modifications needed', () => {
|
|
it( 'keeps all existing ranges when no modifications needed', () => {
|
|
|
- selection._setTo( range1 );
|
|
|
|
|
- selection._setFocus( selection.focus );
|
|
|
|
|
|
|
+ selection.setTo( range1 );
|
|
|
|
|
+ selection.setFocus( selection.focus );
|
|
|
|
|
|
|
|
expect( count( selection.getRanges() ) ).to.equal( 1 );
|
|
expect( count( selection.getRanges() ) ).to.equal( 1 );
|
|
|
} );
|
|
} );
|
|
@@ -192,7 +201,7 @@ describe( 'Selection', () => {
|
|
|
const endPos = Position.createAt( el, 'end' );
|
|
const endPos = Position.createAt( el, 'end' );
|
|
|
|
|
|
|
|
expect( () => {
|
|
expect( () => {
|
|
|
- selection._setFocus( endPos );
|
|
|
|
|
|
|
+ selection.setFocus( endPos );
|
|
|
} ).to.throw( CKEditorError, /view-selection-setFocus-no-ranges/ );
|
|
} ).to.throw( CKEditorError, /view-selection-setFocus-no-ranges/ );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -200,9 +209,9 @@ describe( 'Selection', () => {
|
|
|
const startPos = Position.createAt( el, 1 );
|
|
const startPos = Position.createAt( el, 1 );
|
|
|
const endPos = Position.createAt( el, 2 );
|
|
const endPos = Position.createAt( el, 2 );
|
|
|
|
|
|
|
|
- selection._setTo( startPos );
|
|
|
|
|
|
|
+ selection.setTo( startPos );
|
|
|
|
|
|
|
|
- selection._setFocus( endPos );
|
|
|
|
|
|
|
+ selection.setFocus( endPos );
|
|
|
|
|
|
|
|
expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
|
|
expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
|
|
|
expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
|
|
expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
|
|
@@ -212,9 +221,9 @@ describe( 'Selection', () => {
|
|
|
const startPos = Position.createAt( el, 1 );
|
|
const startPos = Position.createAt( el, 1 );
|
|
|
const endPos = Position.createAt( el, 0 );
|
|
const endPos = Position.createAt( el, 0 );
|
|
|
|
|
|
|
|
- selection._setTo( startPos );
|
|
|
|
|
|
|
+ selection.setTo( startPos );
|
|
|
|
|
|
|
|
- selection._setFocus( endPos );
|
|
|
|
|
|
|
+ selection.setFocus( endPos );
|
|
|
|
|
|
|
|
expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
|
|
expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
|
|
|
expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
|
|
expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
|
|
@@ -226,9 +235,9 @@ describe( 'Selection', () => {
|
|
|
const endPos = Position.createAt( el, 2 );
|
|
const endPos = Position.createAt( el, 2 );
|
|
|
const newEndPos = Position.createAt( el, 3 );
|
|
const newEndPos = Position.createAt( el, 3 );
|
|
|
|
|
|
|
|
- selection._setTo( new Range( startPos, endPos ) );
|
|
|
|
|
|
|
+ selection.setTo( new Range( startPos, endPos ) );
|
|
|
|
|
|
|
|
- selection._setFocus( newEndPos );
|
|
|
|
|
|
|
+ selection.setFocus( newEndPos );
|
|
|
|
|
|
|
|
expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
|
|
expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
|
|
|
expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
|
|
expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
|
|
@@ -239,9 +248,9 @@ describe( 'Selection', () => {
|
|
|
const endPos = Position.createAt( el, 2 );
|
|
const endPos = Position.createAt( el, 2 );
|
|
|
const newEndPos = Position.createAt( el, 0 );
|
|
const newEndPos = Position.createAt( el, 0 );
|
|
|
|
|
|
|
|
- selection._setTo( new Range( startPos, endPos ) );
|
|
|
|
|
|
|
+ selection.setTo( new Range( startPos, endPos ) );
|
|
|
|
|
|
|
|
- selection._setFocus( newEndPos );
|
|
|
|
|
|
|
+ selection.setFocus( newEndPos );
|
|
|
|
|
|
|
|
expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
|
|
expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
|
|
|
expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
|
|
expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
|
|
@@ -253,9 +262,9 @@ describe( 'Selection', () => {
|
|
|
const endPos = Position.createAt( el, 2 );
|
|
const endPos = Position.createAt( el, 2 );
|
|
|
const newEndPos = Position.createAt( el, 3 );
|
|
const newEndPos = Position.createAt( el, 3 );
|
|
|
|
|
|
|
|
- selection._setTo( new Range( startPos, endPos ), { backward: true } );
|
|
|
|
|
|
|
+ selection.setTo( new Range( startPos, endPos ), { backward: true } );
|
|
|
|
|
|
|
|
- selection._setFocus( newEndPos );
|
|
|
|
|
|
|
+ selection.setFocus( newEndPos );
|
|
|
|
|
|
|
|
expect( selection.anchor.compareWith( endPos ) ).to.equal( 'same' );
|
|
expect( selection.anchor.compareWith( endPos ) ).to.equal( 'same' );
|
|
|
expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
|
|
expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
|
|
@@ -267,9 +276,9 @@ describe( 'Selection', () => {
|
|
|
const endPos = Position.createAt( el, 2 );
|
|
const endPos = Position.createAt( el, 2 );
|
|
|
const newEndPos = Position.createAt( el, 0 );
|
|
const newEndPos = Position.createAt( el, 0 );
|
|
|
|
|
|
|
|
- selection._setTo( new Range( startPos, endPos ), { backward: true } );
|
|
|
|
|
|
|
+ selection.setTo( new Range( startPos, endPos ), { backward: true } );
|
|
|
|
|
|
|
|
- selection._setFocus( newEndPos );
|
|
|
|
|
|
|
+ selection.setFocus( newEndPos );
|
|
|
|
|
|
|
|
expect( selection.anchor.compareWith( endPos ) ).to.equal( 'same' );
|
|
expect( selection.anchor.compareWith( endPos ) ).to.equal( 'same' );
|
|
|
expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
|
|
expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
|
|
@@ -285,12 +294,12 @@ describe( 'Selection', () => {
|
|
|
|
|
|
|
|
const newEndPos = Position.createAt( el, 0 );
|
|
const newEndPos = Position.createAt( el, 0 );
|
|
|
|
|
|
|
|
- selection._setTo( [
|
|
|
|
|
|
|
+ selection.setTo( [
|
|
|
new Range( startPos1, endPos1 ),
|
|
new Range( startPos1, endPos1 ),
|
|
|
new Range( startPos2, endPos2 )
|
|
new Range( startPos2, endPos2 )
|
|
|
] );
|
|
] );
|
|
|
|
|
|
|
|
- selection._setFocus( newEndPos );
|
|
|
|
|
|
|
+ selection.setFocus( newEndPos );
|
|
|
|
|
|
|
|
const ranges = Array.from( selection.getRanges() );
|
|
const ranges = Array.from( selection.getRanges() );
|
|
|
|
|
|
|
@@ -307,9 +316,9 @@ describe( 'Selection', () => {
|
|
|
const startPos = Position.createAt( el, 1 );
|
|
const startPos = Position.createAt( el, 1 );
|
|
|
const endPos = Position.createAt( el, 2 );
|
|
const endPos = Position.createAt( el, 2 );
|
|
|
|
|
|
|
|
- selection._setTo( new Range( startPos, endPos ) );
|
|
|
|
|
|
|
+ selection.setTo( new Range( startPos, endPos ) );
|
|
|
|
|
|
|
|
- selection._setFocus( startPos );
|
|
|
|
|
|
|
+ selection.setFocus( startPos );
|
|
|
|
|
|
|
|
expect( selection.focus.compareWith( startPos ) ).to.equal( 'same' );
|
|
expect( selection.focus.compareWith( startPos ) ).to.equal( 'same' );
|
|
|
expect( selection.isCollapsed ).to.be.true;
|
|
expect( selection.isCollapsed ).to.be.true;
|
|
@@ -322,8 +331,8 @@ describe( 'Selection', () => {
|
|
|
|
|
|
|
|
const spy = sinon.stub( Position, 'createAt' ).returns( newEndPos );
|
|
const spy = sinon.stub( Position, 'createAt' ).returns( newEndPos );
|
|
|
|
|
|
|
|
- selection._setTo( new Range( startPos, endPos ) );
|
|
|
|
|
- selection._setFocus( el, 'end' );
|
|
|
|
|
|
|
+ selection.setTo( new Range( startPos, endPos ) );
|
|
|
|
|
+ selection.setFocus( el, 'end' );
|
|
|
|
|
|
|
|
expect( spy.calledOnce ).to.be.true;
|
|
expect( spy.calledOnce ).to.be.true;
|
|
|
expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
|
|
expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
|
|
@@ -335,7 +344,7 @@ describe( 'Selection', () => {
|
|
|
describe( 'isCollapsed', () => {
|
|
describe( 'isCollapsed', () => {
|
|
|
it( 'should return true when there is single collapsed range', () => {
|
|
it( 'should return true when there is single collapsed range', () => {
|
|
|
const range = Range.createFromParentsAndOffsets( el, 5, el, 5 );
|
|
const range = Range.createFromParentsAndOffsets( el, 5, el, 5 );
|
|
|
- selection._setTo( range );
|
|
|
|
|
|
|
+ selection.setTo( range );
|
|
|
|
|
|
|
|
expect( selection.isCollapsed ).to.be.true;
|
|
expect( selection.isCollapsed ).to.be.true;
|
|
|
} );
|
|
} );
|
|
@@ -343,14 +352,14 @@ describe( 'Selection', () => {
|
|
|
it( 'should return false when there are multiple ranges', () => {
|
|
it( 'should return false when there are multiple ranges', () => {
|
|
|
const range1 = Range.createFromParentsAndOffsets( el, 5, el, 5 );
|
|
const range1 = Range.createFromParentsAndOffsets( el, 5, el, 5 );
|
|
|
const range2 = Range.createFromParentsAndOffsets( el, 15, el, 15 );
|
|
const range2 = Range.createFromParentsAndOffsets( el, 15, el, 15 );
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
|
expect( selection.isCollapsed ).to.be.false;
|
|
expect( selection.isCollapsed ).to.be.false;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return false when there is not collapsed range', () => {
|
|
it( 'should return false when there is not collapsed range', () => {
|
|
|
const range = Range.createFromParentsAndOffsets( el, 15, el, 16 );
|
|
const range = Range.createFromParentsAndOffsets( el, 15, el, 16 );
|
|
|
- selection._setTo( range );
|
|
|
|
|
|
|
+ selection.setTo( range );
|
|
|
|
|
|
|
|
expect( selection.isCollapsed ).to.be.false;
|
|
expect( selection.isCollapsed ).to.be.false;
|
|
|
} );
|
|
} );
|
|
@@ -360,11 +369,11 @@ describe( 'Selection', () => {
|
|
|
it( 'should return proper range count', () => {
|
|
it( 'should return proper range count', () => {
|
|
|
expect( selection.rangeCount ).to.equal( 0 );
|
|
expect( selection.rangeCount ).to.equal( 0 );
|
|
|
|
|
|
|
|
- selection._setTo( range1 );
|
|
|
|
|
|
|
+ selection.setTo( range1 );
|
|
|
|
|
|
|
|
expect( selection.rangeCount ).to.equal( 1 );
|
|
expect( selection.rangeCount ).to.equal( 1 );
|
|
|
|
|
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
|
expect( selection.rangeCount ).to.equal( 2 );
|
|
expect( selection.rangeCount ).to.equal( 2 );
|
|
|
} );
|
|
} );
|
|
@@ -375,17 +384,17 @@ describe( 'Selection', () => {
|
|
|
const range1 = Range.createFromParentsAndOffsets( el, 5, el, 10 );
|
|
const range1 = Range.createFromParentsAndOffsets( el, 5, el, 10 );
|
|
|
const range2 = Range.createFromParentsAndOffsets( el, 15, el, 16 );
|
|
const range2 = Range.createFromParentsAndOffsets( el, 15, el, 16 );
|
|
|
|
|
|
|
|
- selection._setTo( range1, { backward: true } );
|
|
|
|
|
|
|
+ selection.setTo( range1, { backward: true } );
|
|
|
expect( selection ).to.have.property( 'isBackward', true );
|
|
expect( selection ).to.have.property( 'isBackward', true );
|
|
|
|
|
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
expect( selection ).to.have.property( 'isBackward', false );
|
|
expect( selection ).to.have.property( 'isBackward', false );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'is false when last range is collapsed', () => {
|
|
it( 'is false when last range is collapsed', () => {
|
|
|
const range = Range.createFromParentsAndOffsets( el, 5, el, 5 );
|
|
const range = Range.createFromParentsAndOffsets( el, 5, el, 5 );
|
|
|
|
|
|
|
|
- selection._setTo( range, { backward: true } );
|
|
|
|
|
|
|
+ selection.setTo( range, { backward: true } );
|
|
|
|
|
|
|
|
expect( selection.isBackward ).to.be.false;
|
|
expect( selection.isBackward ).to.be.false;
|
|
|
} );
|
|
} );
|
|
@@ -393,7 +402,7 @@ describe( 'Selection', () => {
|
|
|
|
|
|
|
|
describe( 'getRanges', () => {
|
|
describe( 'getRanges', () => {
|
|
|
it( 'should return iterator with copies of all ranges', () => {
|
|
it( 'should return iterator with copies of all ranges', () => {
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
|
const iterable = selection.getRanges();
|
|
const iterable = selection.getRanges();
|
|
|
const ranges = Array.from( iterable );
|
|
const ranges = Array.from( iterable );
|
|
@@ -408,7 +417,7 @@ describe( 'Selection', () => {
|
|
|
|
|
|
|
|
describe( 'getFirstRange', () => {
|
|
describe( 'getFirstRange', () => {
|
|
|
it( 'should return copy of range with first position', () => {
|
|
it( 'should return copy of range with first position', () => {
|
|
|
- selection._setTo( [ range1, range2, range3 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2, range3 ] );
|
|
|
|
|
|
|
|
const range = selection.getFirstRange();
|
|
const range = selection.getFirstRange();
|
|
|
|
|
|
|
@@ -423,7 +432,7 @@ describe( 'Selection', () => {
|
|
|
|
|
|
|
|
describe( 'getLastRange', () => {
|
|
describe( 'getLastRange', () => {
|
|
|
it( 'should return copy of range with last position', () => {
|
|
it( 'should return copy of range with last position', () => {
|
|
|
- selection._setTo( [ range1, range2, range3 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2, range3 ] );
|
|
|
|
|
|
|
|
const range = selection.getLastRange();
|
|
const range = selection.getLastRange();
|
|
|
|
|
|
|
@@ -438,7 +447,7 @@ describe( 'Selection', () => {
|
|
|
|
|
|
|
|
describe( 'getFirstPosition', () => {
|
|
describe( 'getFirstPosition', () => {
|
|
|
it( 'should return copy of first position', () => {
|
|
it( 'should return copy of first position', () => {
|
|
|
- selection._setTo( [ range1, range2, range3 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2, range3 ] );
|
|
|
|
|
|
|
|
const position = selection.getFirstPosition();
|
|
const position = selection.getFirstPosition();
|
|
|
|
|
|
|
@@ -453,7 +462,7 @@ describe( 'Selection', () => {
|
|
|
|
|
|
|
|
describe( 'getLastPosition', () => {
|
|
describe( 'getLastPosition', () => {
|
|
|
it( 'should return copy of range with last position', () => {
|
|
it( 'should return copy of range with last position', () => {
|
|
|
- selection._setTo( [ range1, range2, range3 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2, range3 ] );
|
|
|
|
|
|
|
|
const position = selection.getLastPosition();
|
|
const position = selection.getLastPosition();
|
|
|
|
|
|
|
@@ -468,16 +477,16 @@ describe( 'Selection', () => {
|
|
|
|
|
|
|
|
describe( 'isEqual', () => {
|
|
describe( 'isEqual', () => {
|
|
|
it( 'should return true if selections equal', () => {
|
|
it( 'should return true if selections equal', () => {
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
|
const otherSelection = new Selection();
|
|
const otherSelection = new Selection();
|
|
|
- otherSelection._setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
+ otherSelection.setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
|
expect( selection.isEqual( otherSelection ) ).to.be.true;
|
|
expect( selection.isEqual( otherSelection ) ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return true if backward selections equal', () => {
|
|
it( 'should return true if backward selections equal', () => {
|
|
|
- selection._setTo( range1, { backward: true } );
|
|
|
|
|
|
|
+ selection.setTo( range1, { backward: true } );
|
|
|
|
|
|
|
|
const otherSelection = new Selection( [ range1 ], { backward: true } );
|
|
const otherSelection = new Selection( [ range1 ], { backward: true } );
|
|
|
|
|
|
|
@@ -485,7 +494,7 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return false if ranges count does not equal', () => {
|
|
it( 'should return false if ranges count does not equal', () => {
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
|
const otherSelection = new Selection( [ range1 ] );
|
|
const otherSelection = new Selection( [ range1 ] );
|
|
|
|
|
|
|
@@ -493,7 +502,7 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return false if ranges (other than the last added one) do not equal', () => {
|
|
it( 'should return false if ranges (other than the last added one) do not equal', () => {
|
|
|
- selection._setTo( [ range1, range3 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range3 ] );
|
|
|
|
|
|
|
|
const otherSelection = new Selection( [ range2, range3 ] );
|
|
const otherSelection = new Selection( [ range2, range3 ] );
|
|
|
|
|
|
|
@@ -501,7 +510,7 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return false if directions do not equal', () => {
|
|
it( 'should return false if directions do not equal', () => {
|
|
|
- selection._setTo( range1 );
|
|
|
|
|
|
|
+ selection.setTo( range1 );
|
|
|
|
|
|
|
|
const otherSelection = new Selection( [ range1 ], { backward: true } );
|
|
const otherSelection = new Selection( [ range1 ], { backward: true } );
|
|
|
|
|
|
|
@@ -516,14 +525,14 @@ describe( 'Selection', () => {
|
|
|
|
|
|
|
|
it( 'should return true if both selection are fake', () => {
|
|
it( 'should return true if both selection are fake', () => {
|
|
|
const otherSelection = new Selection( range1, { fake: true } );
|
|
const otherSelection = new Selection( range1, { fake: true } );
|
|
|
- selection._setTo( range1, { fake: true } );
|
|
|
|
|
|
|
+ selection.setTo( range1, { fake: true } );
|
|
|
|
|
|
|
|
expect( selection.isEqual( otherSelection ) ).to.be.true;
|
|
expect( selection.isEqual( otherSelection ) ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return false if both selection are fake but have different label', () => {
|
|
it( 'should return false if both selection are fake but have different label', () => {
|
|
|
const otherSelection = new Selection( [ range1 ], { fake: true, label: 'foo bar baz' } );
|
|
const otherSelection = new Selection( [ range1 ], { fake: true, label: 'foo bar baz' } );
|
|
|
- selection._setTo( range1, { fake: true, label: 'foo' } );
|
|
|
|
|
|
|
+ selection.setTo( range1, { fake: true, label: 'foo' } );
|
|
|
|
|
|
|
|
expect( selection.isEqual( otherSelection ) ).to.be.false;
|
|
expect( selection.isEqual( otherSelection ) ).to.be.false;
|
|
|
} );
|
|
} );
|
|
@@ -537,7 +546,7 @@ describe( 'Selection', () => {
|
|
|
|
|
|
|
|
describe( 'isSimilar', () => {
|
|
describe( 'isSimilar', () => {
|
|
|
it( 'should return true if selections equal', () => {
|
|
it( 'should return true if selections equal', () => {
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
|
const otherSelection = new Selection( [ range1, range2 ] );
|
|
const otherSelection = new Selection( [ range1, range2 ] );
|
|
|
|
|
|
|
@@ -545,7 +554,7 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return false if ranges count does not equal', () => {
|
|
it( 'should return false if ranges count does not equal', () => {
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
|
const otherSelection = new Selection( [ range1 ] );
|
|
const otherSelection = new Selection( [ range1 ] );
|
|
|
|
|
|
|
@@ -553,7 +562,7 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return false if trimmed ranges (other than the last added one) are not equal', () => {
|
|
it( 'should return false if trimmed ranges (other than the last added one) are not equal', () => {
|
|
|
- selection._setTo( [ range1, range3 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range3 ] );
|
|
|
|
|
|
|
|
const otherSelection = new Selection( [ range2, range3 ] );
|
|
const otherSelection = new Selection( [ range2, range3 ] );
|
|
|
|
|
|
|
@@ -561,7 +570,7 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return false if directions are not equal', () => {
|
|
it( 'should return false if directions are not equal', () => {
|
|
|
- selection._setTo( range1 );
|
|
|
|
|
|
|
+ selection.setTo( range1 );
|
|
|
|
|
|
|
|
const otherSelection = new Selection( [ range1 ], { backward: true } );
|
|
const otherSelection = new Selection( [ range1 ], { backward: true } );
|
|
|
|
|
|
|
@@ -591,7 +600,7 @@ describe( 'Selection', () => {
|
|
|
const rangeA2 = Range.createFromParentsAndOffsets( p2, 0, p2, 1 );
|
|
const rangeA2 = Range.createFromParentsAndOffsets( p2, 0, p2, 1 );
|
|
|
const rangeB2 = Range.createFromParentsAndOffsets( span2, 0, span2, 1 );
|
|
const rangeB2 = Range.createFromParentsAndOffsets( span2, 0, span2, 1 );
|
|
|
|
|
|
|
|
- selection._setTo( [ rangeA1, rangeA2 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ rangeA1, rangeA2 ] );
|
|
|
|
|
|
|
|
const otherSelection = new Selection( [ rangeB2, rangeB1 ] );
|
|
const otherSelection = new Selection( [ rangeB2, rangeB1 ] );
|
|
|
|
|
|
|
@@ -603,14 +612,14 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- describe( '_setTo()', () => {
|
|
|
|
|
|
|
+ describe( 'setTo()', () => {
|
|
|
describe( 'simple scenarios', () => {
|
|
describe( 'simple scenarios', () => {
|
|
|
it( 'should set selection ranges from the given selection', () => {
|
|
it( 'should set selection ranges from the given selection', () => {
|
|
|
- selection._setTo( range1 );
|
|
|
|
|
|
|
+ selection.setTo( range1 );
|
|
|
|
|
|
|
|
const otherSelection = new Selection( [ range2, range3 ], { backward: true } );
|
|
const otherSelection = new Selection( [ range2, range3 ], { backward: true } );
|
|
|
|
|
|
|
|
- selection._setTo( otherSelection );
|
|
|
|
|
|
|
+ selection.setTo( otherSelection );
|
|
|
|
|
|
|
|
expect( selection.rangeCount ).to.equal( 2 );
|
|
expect( selection.rangeCount ).to.equal( 2 );
|
|
|
expect( selection._ranges[ 0 ].isEqual( range2 ) ).to.be.true;
|
|
expect( selection._ranges[ 0 ].isEqual( range2 ) ).to.be.true;
|
|
@@ -622,21 +631,21 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should set selection on the given Range', () => {
|
|
it( 'should set selection on the given Range', () => {
|
|
|
- selection._setTo( range1 );
|
|
|
|
|
|
|
+ selection.setTo( range1 );
|
|
|
|
|
|
|
|
expect( Array.from( selection.getRanges() ) ).to.deep.equal( [ range1 ] );
|
|
expect( Array.from( selection.getRanges() ) ).to.deep.equal( [ range1 ] );
|
|
|
expect( selection.isBackward ).to.be.false;
|
|
expect( selection.isBackward ).to.be.false;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should set selection on the given iterable of Ranges', () => {
|
|
it( 'should set selection on the given iterable of Ranges', () => {
|
|
|
- selection._setTo( new Set( [ range1, range2 ] ) );
|
|
|
|
|
|
|
+ selection.setTo( new Set( [ range1, range2 ] ) );
|
|
|
|
|
|
|
|
expect( Array.from( selection.getRanges() ) ).to.deep.equal( [ range1, range2 ] );
|
|
expect( Array.from( selection.getRanges() ) ).to.deep.equal( [ range1, range2 ] );
|
|
|
expect( selection.isBackward ).to.be.false;
|
|
expect( selection.isBackward ).to.be.false;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should set collapsed selection on the given Position', () => {
|
|
it( 'should set collapsed selection on the given Position', () => {
|
|
|
- selection._setTo( range1.start );
|
|
|
|
|
|
|
+ selection.setTo( range1.start );
|
|
|
|
|
|
|
|
expect( Array.from( selection.getRanges() ).length ).to.equal( 1 );
|
|
expect( Array.from( selection.getRanges() ).length ).to.equal( 1 );
|
|
|
expect( Array.from( selection.getRanges() )[ 0 ].start ).to.deep.equal( range1.start );
|
|
expect( Array.from( selection.getRanges() )[ 0 ].start ).to.deep.equal( range1.start );
|
|
@@ -653,13 +662,13 @@ describe( 'Selection', () => {
|
|
|
|
|
|
|
|
const otherSelection = new Selection( [ range1 ] );
|
|
const otherSelection = new Selection( [ range1 ] );
|
|
|
|
|
|
|
|
- selection._setTo( otherSelection );
|
|
|
|
|
|
|
+ selection.setTo( otherSelection );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should set fake state and label', () => {
|
|
it( 'should set fake state and label', () => {
|
|
|
const label = 'foo bar baz';
|
|
const label = 'foo bar baz';
|
|
|
const otherSelection = new Selection( null, { fake: true, label } );
|
|
const otherSelection = new Selection( null, { fake: true, label } );
|
|
|
- selection._setTo( otherSelection );
|
|
|
|
|
|
|
+ selection.setTo( otherSelection );
|
|
|
|
|
|
|
|
expect( selection.isFake ).to.be.true;
|
|
expect( selection.isFake ).to.be.true;
|
|
|
expect( selection.fakeSelectionLabel ).to.equal( label );
|
|
expect( selection.fakeSelectionLabel ).to.equal( label );
|
|
@@ -669,7 +678,7 @@ describe( 'Selection', () => {
|
|
|
const otherSelection = new Selection();
|
|
const otherSelection = new Selection();
|
|
|
|
|
|
|
|
expect( () => {
|
|
expect( () => {
|
|
|
- otherSelection._setTo( {} );
|
|
|
|
|
|
|
+ otherSelection.setTo( {} );
|
|
|
} ).to.throw( /view-selection-setTo-not-selectable/ );
|
|
} ).to.throw( /view-selection-setTo-not-selectable/ );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -677,20 +686,20 @@ describe( 'Selection', () => {
|
|
|
const otherSelection = new Selection();
|
|
const otherSelection = new Selection();
|
|
|
|
|
|
|
|
expect( () => {
|
|
expect( () => {
|
|
|
- otherSelection._setTo();
|
|
|
|
|
|
|
+ otherSelection.setTo();
|
|
|
} ).to.throw( /view-selection-setTo-not-selectable/ );
|
|
} ).to.throw( /view-selection-setTo-not-selectable/ );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
describe( 'setting collapsed selection', () => {
|
|
describe( 'setting collapsed selection', () => {
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should collapse selection at position', () => {
|
|
it( 'should collapse selection at position', () => {
|
|
|
const position = new Position( el, 4 );
|
|
const position = new Position( el, 4 );
|
|
|
|
|
|
|
|
- selection._setTo( position );
|
|
|
|
|
|
|
+ selection.setTo( position );
|
|
|
const range = selection.getFirstRange();
|
|
const range = selection.getFirstRange();
|
|
|
|
|
|
|
|
expect( range.start.parent ).to.equal( el );
|
|
expect( range.start.parent ).to.equal( el );
|
|
@@ -702,14 +711,14 @@ describe( 'Selection', () => {
|
|
|
const foo = new Text( 'foo' );
|
|
const foo = new Text( 'foo' );
|
|
|
const p = new Element( 'p', null, foo );
|
|
const p = new Element( 'p', null, foo );
|
|
|
|
|
|
|
|
- selection._setTo( foo, 0 );
|
|
|
|
|
|
|
+ selection.setTo( foo, 0 );
|
|
|
let range = selection.getFirstRange();
|
|
let range = selection.getFirstRange();
|
|
|
|
|
|
|
|
expect( range.start.parent ).to.equal( foo );
|
|
expect( range.start.parent ).to.equal( foo );
|
|
|
expect( range.start.offset ).to.equal( 0 );
|
|
expect( range.start.offset ).to.equal( 0 );
|
|
|
expect( range.start.isEqual( range.end ) ).to.be.true;
|
|
expect( range.start.isEqual( range.end ) ).to.be.true;
|
|
|
|
|
|
|
|
- selection._setTo( p, 1 );
|
|
|
|
|
|
|
+ selection.setTo( p, 1 );
|
|
|
range = selection.getFirstRange();
|
|
range = selection.getFirstRange();
|
|
|
|
|
|
|
|
expect( range.start.parent ).to.equal( p );
|
|
expect( range.start.parent ).to.equal( p );
|
|
@@ -721,7 +730,7 @@ describe( 'Selection', () => {
|
|
|
const foo = new Text( 'foo' );
|
|
const foo = new Text( 'foo' );
|
|
|
|
|
|
|
|
expect( () => {
|
|
expect( () => {
|
|
|
- selection._setTo( foo );
|
|
|
|
|
|
|
+ selection.setTo( foo );
|
|
|
} ).to.throw( CKEditorError, /view-selection-setTo-required-second-parameter/ );
|
|
} ).to.throw( CKEditorError, /view-selection-setTo-required-second-parameter/ );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -729,21 +738,21 @@ describe( 'Selection', () => {
|
|
|
const foo = new Text( 'foo' );
|
|
const foo = new Text( 'foo' );
|
|
|
const p = new Element( 'p', null, foo );
|
|
const p = new Element( 'p', null, foo );
|
|
|
|
|
|
|
|
- selection._setTo( foo, 'end' );
|
|
|
|
|
|
|
+ selection.setTo( foo, 'end' );
|
|
|
let range = selection.getFirstRange();
|
|
let range = selection.getFirstRange();
|
|
|
|
|
|
|
|
expect( range.start.parent ).to.equal( foo );
|
|
expect( range.start.parent ).to.equal( foo );
|
|
|
expect( range.start.offset ).to.equal( 3 );
|
|
expect( range.start.offset ).to.equal( 3 );
|
|
|
expect( range.start.isEqual( range.end ) ).to.be.true;
|
|
expect( range.start.isEqual( range.end ) ).to.be.true;
|
|
|
|
|
|
|
|
- selection._setTo( foo, 'before' );
|
|
|
|
|
|
|
+ selection.setTo( foo, 'before' );
|
|
|
range = selection.getFirstRange();
|
|
range = selection.getFirstRange();
|
|
|
|
|
|
|
|
expect( range.start.parent ).to.equal( p );
|
|
expect( range.start.parent ).to.equal( p );
|
|
|
expect( range.start.offset ).to.equal( 0 );
|
|
expect( range.start.offset ).to.equal( 0 );
|
|
|
expect( range.start.isEqual( range.end ) ).to.be.true;
|
|
expect( range.start.isEqual( range.end ) ).to.be.true;
|
|
|
|
|
|
|
|
- selection._setTo( foo, 'after' );
|
|
|
|
|
|
|
+ selection.setTo( foo, 'after' );
|
|
|
range = selection.getFirstRange();
|
|
range = selection.getFirstRange();
|
|
|
|
|
|
|
|
expect( range.start.parent ).to.equal( p );
|
|
expect( range.start.parent ).to.equal( p );
|
|
@@ -754,7 +763,7 @@ describe( 'Selection', () => {
|
|
|
|
|
|
|
|
describe( 'setting collapsed selection at start', () => {
|
|
describe( 'setting collapsed selection at start', () => {
|
|
|
it( 'should collapse to start position and fire change event', done => {
|
|
it( 'should collapse to start position and fire change event', done => {
|
|
|
- selection._setTo( [ range1, range2, range3 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2, range3 ] );
|
|
|
selection.once( 'change', () => {
|
|
selection.once( 'change', () => {
|
|
|
expect( selection.rangeCount ).to.equal( 1 );
|
|
expect( selection.rangeCount ).to.equal( 1 );
|
|
|
expect( selection.isCollapsed ).to.be.true;
|
|
expect( selection.isCollapsed ).to.be.true;
|
|
@@ -762,13 +771,13 @@ describe( 'Selection', () => {
|
|
|
done();
|
|
done();
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- selection._setTo( selection.getFirstPosition() );
|
|
|
|
|
|
|
+ selection.setTo( selection.getFirstPosition() );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
describe( 'setting collapsed selection to end', () => {
|
|
describe( 'setting collapsed selection to end', () => {
|
|
|
it( 'should collapse to end position and fire change event', done => {
|
|
it( 'should collapse to end position and fire change event', done => {
|
|
|
- selection._setTo( [ range1, range2, range3 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2, range3 ] );
|
|
|
selection.once( 'change', () => {
|
|
selection.once( 'change', () => {
|
|
|
expect( selection.rangeCount ).to.equal( 1 );
|
|
expect( selection.rangeCount ).to.equal( 1 );
|
|
|
expect( selection.isCollapsed ).to.be.true;
|
|
expect( selection.isCollapsed ).to.be.true;
|
|
@@ -776,48 +785,48 @@ describe( 'Selection', () => {
|
|
|
done();
|
|
done();
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- selection._setTo( selection.getLastPosition() );
|
|
|
|
|
|
|
+ selection.setTo( selection.getLastPosition() );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
describe( 'removing all ranges', () => {
|
|
describe( 'removing all ranges', () => {
|
|
|
it( 'should remove all ranges and fire change event', done => {
|
|
it( 'should remove all ranges and fire change event', done => {
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
|
selection.once( 'change', () => {
|
|
selection.once( 'change', () => {
|
|
|
expect( selection.rangeCount ).to.equal( 0 );
|
|
expect( selection.rangeCount ).to.equal( 0 );
|
|
|
done();
|
|
done();
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- selection._setTo( null );
|
|
|
|
|
|
|
+ selection.setTo( null );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
describe( 'setting fake selection', () => {
|
|
describe( 'setting fake selection', () => {
|
|
|
it( 'should allow to set selection to fake', () => {
|
|
it( 'should allow to set selection to fake', () => {
|
|
|
- selection._setTo( range1, { fake: true } );
|
|
|
|
|
|
|
+ selection.setTo( range1, { fake: true } );
|
|
|
|
|
|
|
|
expect( selection.isFake ).to.be.true;
|
|
expect( selection.isFake ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should allow to set fake selection label', () => {
|
|
it( 'should allow to set fake selection label', () => {
|
|
|
const label = 'foo bar baz';
|
|
const label = 'foo bar baz';
|
|
|
- selection._setTo( range1, { fake: true, label } );
|
|
|
|
|
|
|
+ selection.setTo( range1, { fake: true, label } );
|
|
|
|
|
|
|
|
expect( selection.fakeSelectionLabel ).to.equal( label );
|
|
expect( selection.fakeSelectionLabel ).to.equal( label );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not set label when set to false', () => {
|
|
it( 'should not set label when set to false', () => {
|
|
|
const label = 'foo bar baz';
|
|
const label = 'foo bar baz';
|
|
|
- selection._setTo( range1, { fake: false, label } );
|
|
|
|
|
|
|
+ selection.setTo( range1, { fake: false, label } );
|
|
|
|
|
|
|
|
expect( selection.fakeSelectionLabel ).to.equal( '' );
|
|
expect( selection.fakeSelectionLabel ).to.equal( '' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should reset label when set to false', () => {
|
|
it( 'should reset label when set to false', () => {
|
|
|
const label = 'foo bar baz';
|
|
const label = 'foo bar baz';
|
|
|
- selection._setTo( range1, { fake: true, label } );
|
|
|
|
|
- selection._setTo( range1 );
|
|
|
|
|
|
|
+ selection.setTo( range1, { fake: true, label } );
|
|
|
|
|
+ selection.setTo( range1 );
|
|
|
|
|
|
|
|
expect( selection.fakeSelectionLabel ).to.equal( '' );
|
|
expect( selection.fakeSelectionLabel ).to.equal( '' );
|
|
|
} );
|
|
} );
|
|
@@ -830,11 +839,11 @@ describe( 'Selection', () => {
|
|
|
done();
|
|
done();
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- selection._setTo( range1, { fake: true, label: 'foo bar baz' } );
|
|
|
|
|
|
|
+ selection.setTo( range1, { fake: true, label: 'foo bar baz' } );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should be possible to create an empty fake selection', () => {
|
|
it( 'should be possible to create an empty fake selection', () => {
|
|
|
- selection._setTo( null, { fake: true, label: 'foo bar baz' } );
|
|
|
|
|
|
|
+ selection.setTo( null, { fake: true, label: 'foo bar baz' } );
|
|
|
|
|
|
|
|
expect( selection.fakeSelectionLabel ).to.equal( 'foo bar baz' );
|
|
expect( selection.fakeSelectionLabel ).to.equal( 'foo bar baz' );
|
|
|
expect( selection.isFake ).to.be.true;
|
|
expect( selection.isFake ).to.be.true;
|
|
@@ -843,8 +852,8 @@ describe( 'Selection', () => {
|
|
|
|
|
|
|
|
describe( 'setting selection to itself', () => {
|
|
describe( 'setting selection to itself', () => {
|
|
|
it( 'should correctly set ranges when setting to the same selection', () => {
|
|
it( 'should correctly set ranges when setting to the same selection', () => {
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
- selection._setTo( selection );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
|
|
+ selection.setTo( selection );
|
|
|
|
|
|
|
|
const ranges = Array.from( selection.getRanges() );
|
|
const ranges = Array.from( selection.getRanges() );
|
|
|
expect( ranges.length ).to.equal( 2 );
|
|
expect( ranges.length ).to.equal( 2 );
|
|
@@ -854,8 +863,8 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should correctly set ranges when setting to the same selection\'s ranges', () => {
|
|
it( 'should correctly set ranges when setting to the same selection\'s ranges', () => {
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
- selection._setTo( selection.getRanges() );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
|
|
+ selection.setTo( selection.getRanges() );
|
|
|
|
|
|
|
|
const ranges = Array.from( selection.getRanges() );
|
|
const ranges = Array.from( selection.getRanges() );
|
|
|
expect( ranges.length ).to.equal( 2 );
|
|
expect( ranges.length ).to.equal( 2 );
|
|
@@ -868,7 +877,7 @@ describe( 'Selection', () => {
|
|
|
describe( 'throwing errors', () => {
|
|
describe( 'throwing errors', () => {
|
|
|
it( 'should throw an error when range is invalid', () => {
|
|
it( 'should throw an error when range is invalid', () => {
|
|
|
expect( () => {
|
|
expect( () => {
|
|
|
- selection._setTo( [ { invalid: 'range' } ] );
|
|
|
|
|
|
|
+ selection.setTo( [ { invalid: 'range' } ] );
|
|
|
} ).to.throw( CKEditorError, 'view-selection-invalid-range: Invalid Range.' );
|
|
} ).to.throw( CKEditorError, 'view-selection-invalid-range: Invalid Range.' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -877,7 +886,7 @@ describe( 'Selection', () => {
|
|
|
const range2 = Range.createFromParentsAndOffsets( text, 7, text, 15 );
|
|
const range2 = Range.createFromParentsAndOffsets( text, 7, text, 15 );
|
|
|
|
|
|
|
|
expect( () => {
|
|
expect( () => {
|
|
|
- selection._setTo( [ range1, range2 ] );
|
|
|
|
|
|
|
+ selection.setTo( [ range1, range2 ] );
|
|
|
} ).to.throw( CKEditorError, 'view-selection-range-intersects' );
|
|
} ).to.throw( CKEditorError, 'view-selection-range-intersects' );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
@@ -888,7 +897,7 @@ describe( 'Selection', () => {
|
|
|
const textNode3 = new Text( 'baz' );
|
|
const textNode3 = new Text( 'baz' );
|
|
|
const element = new Element( 'p', null, [ textNode1, textNode2, textNode3 ] );
|
|
const element = new Element( 'p', null, [ textNode1, textNode2, textNode3 ] );
|
|
|
|
|
|
|
|
- selection._setTo( textNode2, 'on' );
|
|
|
|
|
|
|
+ selection.setTo( textNode2, 'on' );
|
|
|
|
|
|
|
|
const ranges = Array.from( selection.getRanges() );
|
|
const ranges = Array.from( selection.getRanges() );
|
|
|
expect( ranges.length ).to.equal( 1 );
|
|
expect( ranges.length ).to.equal( 1 );
|
|
@@ -901,7 +910,7 @@ describe( 'Selection', () => {
|
|
|
it( 'should allow setting selection inside an element', () => {
|
|
it( 'should allow setting selection inside an element', () => {
|
|
|
const element = new Element( 'p', null, [ new Text( 'foo' ), new Text( 'bar' ) ] );
|
|
const element = new Element( 'p', null, [ new Text( 'foo' ), new Text( 'bar' ) ] );
|
|
|
|
|
|
|
|
- selection._setTo( element, 'in' );
|
|
|
|
|
|
|
+ selection.setTo( element, 'in' );
|
|
|
|
|
|
|
|
const ranges = Array.from( selection.getRanges() );
|
|
const ranges = Array.from( selection.getRanges() );
|
|
|
expect( ranges.length ).to.equal( 1 );
|
|
expect( ranges.length ).to.equal( 1 );
|
|
@@ -914,7 +923,7 @@ describe( 'Selection', () => {
|
|
|
it( 'should allow setting backward selection inside an element', () => {
|
|
it( 'should allow setting backward selection inside an element', () => {
|
|
|
const element = new Element( 'p', null, [ new Text( 'foo' ), new Text( 'bar' ) ] );
|
|
const element = new Element( 'p', null, [ new Text( 'foo' ), new Text( 'bar' ) ] );
|
|
|
|
|
|
|
|
- selection._setTo( element, 'in', { backward: true } );
|
|
|
|
|
|
|
+ selection.setTo( element, 'in', { backward: true } );
|
|
|
|
|
|
|
|
const ranges = Array.from( selection.getRanges() );
|
|
const ranges = Array.from( selection.getRanges() );
|
|
|
expect( ranges.length ).to.equal( 1 );
|
|
expect( ranges.length ).to.equal( 1 );
|
|
@@ -932,19 +941,19 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return null if selection is placed in container that is not EditableElement', () => {
|
|
it( 'should return null if selection is placed in container that is not EditableElement', () => {
|
|
|
- selection._setTo( range1 );
|
|
|
|
|
|
|
+ selection.setTo( range1 );
|
|
|
|
|
|
|
|
expect( selection.editableElement ).to.be.null;
|
|
expect( selection.editableElement ).to.be.null;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return EditableElement when selection is placed inside', () => {
|
|
it( 'should return EditableElement when selection is placed inside', () => {
|
|
|
const viewDocument = new Document();
|
|
const viewDocument = new Document();
|
|
|
- const selection = viewDocument.selection;
|
|
|
|
|
|
|
+ selection.setTo( viewDocument.selection );
|
|
|
const root = createViewRoot( viewDocument, 'div', 'main' );
|
|
const root = createViewRoot( viewDocument, 'div', 'main' );
|
|
|
const element = new Element( 'p' );
|
|
const element = new Element( 'p' );
|
|
|
root._appendChildren( element );
|
|
root._appendChildren( element );
|
|
|
|
|
|
|
|
- selection._setTo( Range.createFromParentsAndOffsets( element, 0, element, 0 ) );
|
|
|
|
|
|
|
+ selection.setTo( Range.createFromParentsAndOffsets( element, 0, element, 0 ) );
|
|
|
|
|
|
|
|
expect( selection.editableElement ).to.equal( root );
|
|
expect( selection.editableElement ).to.equal( root );
|
|
|
} );
|
|
} );
|
|
@@ -958,14 +967,16 @@ describe( 'Selection', () => {
|
|
|
|
|
|
|
|
describe( 'getSelectedElement()', () => {
|
|
describe( 'getSelectedElement()', () => {
|
|
|
it( 'should return selected element', () => {
|
|
it( 'should return selected element', () => {
|
|
|
- const { selection, view } = parse( 'foo [<b>bar</b>] baz' );
|
|
|
|
|
|
|
+ const { selection: docSelection, view } = parse( 'foo [<b>bar</b>] baz' );
|
|
|
const b = view.getChild( 1 );
|
|
const b = view.getChild( 1 );
|
|
|
|
|
+ const selection = new Selection( docSelection );
|
|
|
|
|
|
|
|
expect( selection.getSelectedElement() ).to.equal( b );
|
|
expect( selection.getSelectedElement() ).to.equal( b );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return null if there is more than one range', () => {
|
|
it( 'should return null if there is more than one range', () => {
|
|
|
- const { selection } = parse( 'foo [<b>bar</b>] [<i>baz</i>]' );
|
|
|
|
|
|
|
+ const { selection: docSelection } = parse( 'foo [<b>bar</b>] [<i>baz</i>]' );
|
|
|
|
|
+ const selection = new Selection( docSelection );
|
|
|
|
|
|
|
|
expect( selection.getSelectedElement() ).to.be.null;
|
|
expect( selection.getSelectedElement() ).to.be.null;
|
|
|
} );
|
|
} );
|
|
@@ -975,13 +986,15 @@ describe( 'Selection', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return null if selection is not over single element #1', () => {
|
|
it( 'should return null if selection is not over single element #1', () => {
|
|
|
- const { selection } = parse( 'foo [<b>bar</b> ba}z' );
|
|
|
|
|
|
|
+ const { selection: docSelection } = parse( 'foo [<b>bar</b> ba}z' );
|
|
|
|
|
+ const selection = new Selection( docSelection );
|
|
|
|
|
|
|
|
expect( selection.getSelectedElement() ).to.be.null;
|
|
expect( selection.getSelectedElement() ).to.be.null;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return null if selection is not over single element #2', () => {
|
|
it( 'should return null if selection is not over single element #2', () => {
|
|
|
- const { selection } = parse( 'foo <b>{bar}</b> baz' );
|
|
|
|
|
|
|
+ const { selection: docSelection } = parse( 'foo <b>{bar}</b> baz' );
|
|
|
|
|
+ const selection = new Selection( docSelection );
|
|
|
|
|
|
|
|
expect( selection.getSelectedElement() ).to.be.null;
|
|
expect( selection.getSelectedElement() ).to.be.null;
|
|
|
} );
|
|
} );
|