|
@@ -3,7 +3,6 @@
|
|
|
* For licensing, see LICENSE.md.
|
|
* For licensing, see LICENSE.md.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-import Batch from '../../src/model/batch';
|
|
|
|
|
import Model from '../../src/model/model';
|
|
import Model from '../../src/model/model';
|
|
|
import Element from '../../src/model/element';
|
|
import Element from '../../src/model/element';
|
|
|
import Position from '../../src/model/position';
|
|
import Position from '../../src/model/position';
|
|
@@ -90,7 +89,7 @@ describe( 'LiveRange', () => {
|
|
|
range.detach();
|
|
range.detach();
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should fire change:range event with proper data when its boundaries are changed', () => {
|
|
|
|
|
|
|
+ it( 'should fire change:range event with when its boundaries are changed', () => {
|
|
|
const live = new LiveRange( new Position( root, [ 0, 1, 4 ] ), new Position( root, [ 0, 2, 2 ] ) );
|
|
const live = new LiveRange( new Position( root, [ 0, 1, 4 ] ), new Position( root, [ 0, 2, 2 ] ) );
|
|
|
const copy = Range.createFromRange( live );
|
|
const copy = Range.createFromRange( live );
|
|
|
|
|
|
|
@@ -99,15 +98,11 @@ describe( 'LiveRange', () => {
|
|
|
|
|
|
|
|
const sourcePosition = new Position( root, [ 2 ] );
|
|
const sourcePosition = new Position( root, [ 2 ] );
|
|
|
const targetPosition = new Position( root, [ 0 ] );
|
|
const targetPosition = new Position( root, [ 0 ] );
|
|
|
- const batch = new Batch();
|
|
|
|
|
- let op = null;
|
|
|
|
|
|
|
|
|
|
- model.enqueueChange( batch, writer => {
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
const sourceRange = Range.createFromPositionAndShift( sourcePosition, 1 );
|
|
const sourceRange = Range.createFromPositionAndShift( sourcePosition, 1 );
|
|
|
|
|
|
|
|
writer.move( sourceRange, targetPosition );
|
|
writer.move( sourceRange, targetPosition );
|
|
|
-
|
|
|
|
|
- op = batch.operations[ 0 ];
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
expect( spy.calledOnce ).to.be.true;
|
|
expect( spy.calledOnce ).to.be.true;
|
|
@@ -115,11 +110,11 @@ describe( 'LiveRange', () => {
|
|
|
// First parameter available in event should be a range that is equal to the live range before the live range changed.
|
|
// First parameter available in event should be a range that is equal to the live range before the live range changed.
|
|
|
expect( spy.args[ 0 ][ 1 ].isEqual( copy ) ).to.be.true;
|
|
expect( spy.args[ 0 ][ 1 ].isEqual( copy ) ).to.be.true;
|
|
|
|
|
|
|
|
- // Second parameter is the operation that changed the range.
|
|
|
|
|
- expect( spy.args[ 0 ][ 2 ] ).to.equal( op );
|
|
|
|
|
|
|
+ // Second parameter is null for operations that did not move the range into graveyard.
|
|
|
|
|
+ expect( spy.args[ 0 ][ 2 ] ).to.be.null;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should fire change:content event with proper data when content inside the range has changed', () => {
|
|
|
|
|
|
|
+ it( 'should fire change:content event when content inside the range has changed', () => {
|
|
|
const live = new LiveRange( new Position( root, [ 0, 1 ] ), new Position( root, [ 0, 3 ] ) );
|
|
const live = new LiveRange( new Position( root, [ 0, 1 ] ), new Position( root, [ 0, 3 ] ) );
|
|
|
|
|
|
|
|
const spy = sinon.spy();
|
|
const spy = sinon.spy();
|
|
@@ -127,15 +122,11 @@ describe( 'LiveRange', () => {
|
|
|
|
|
|
|
|
const sourcePosition = new Position( root, [ 0, 2, 0 ] );
|
|
const sourcePosition = new Position( root, [ 0, 2, 0 ] );
|
|
|
const targetPosition = new Position( root, [ 0, 4, 0 ] );
|
|
const targetPosition = new Position( root, [ 0, 4, 0 ] );
|
|
|
- const batch = new Batch();
|
|
|
|
|
- let op = null;
|
|
|
|
|
|
|
|
|
|
- model.enqueueChange( batch, writer => {
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
const sourceRange = Range.createFromPositionAndShift( sourcePosition, 2 );
|
|
const sourceRange = Range.createFromPositionAndShift( sourcePosition, 2 );
|
|
|
|
|
|
|
|
writer.move( sourceRange, targetPosition );
|
|
writer.move( sourceRange, targetPosition );
|
|
|
-
|
|
|
|
|
- op = batch.operations[ 0 ];
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
expect( spy.calledOnce ).to.be.true;
|
|
expect( spy.calledOnce ).to.be.true;
|
|
@@ -143,8 +134,40 @@ describe( 'LiveRange', () => {
|
|
|
// First parameter available in event should be a range that is equal to the live range before the live range changed.
|
|
// First parameter available in event should be a range that is equal to the live range before the live range changed.
|
|
|
expect( spy.args[ 0 ][ 1 ].isEqual( live ) ).to.be.true;
|
|
expect( spy.args[ 0 ][ 1 ].isEqual( live ) ).to.be.true;
|
|
|
|
|
|
|
|
- // Second parameter is the operation that changed the range.
|
|
|
|
|
- expect( spy.args[ 0 ][ 2 ] ).to.equal( op );
|
|
|
|
|
|
|
+ // Second parameter is null for operations that did not move the range into graveyard.
|
|
|
|
|
+ expect( spy.args[ 0 ][ 2 ] ).to.be.null;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should pass deletion position if range was removed (remove)', () => {
|
|
|
|
|
+ const live = new LiveRange( new Position( root, [ 0, 2 ] ), new Position( root, [ 0, 4 ] ) );
|
|
|
|
|
+
|
|
|
|
|
+ const spy = sinon.spy();
|
|
|
|
|
+ live.on( 'change:range', spy );
|
|
|
|
|
+
|
|
|
|
|
+ const sourcePosition = new Position( root, [ 0, 0 ] );
|
|
|
|
|
+
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.remove( Range.createFromPositionAndShift( sourcePosition, 6 ) );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ // Second parameter is deletion position.
|
|
|
|
|
+ expect( spy.args[ 0 ][ 2 ].isEqual( sourcePosition ) ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should pass deletion position if range was removed (merge)', () => {
|
|
|
|
|
+ const live = new LiveRange( new Position( root, [ 1 ] ), new Position( root, [ 2 ] ) );
|
|
|
|
|
+
|
|
|
|
|
+ const spy = sinon.spy();
|
|
|
|
|
+ live.on( 'change:range', spy );
|
|
|
|
|
+
|
|
|
|
|
+ const mergePosition = new Position( root, [ 1 ] );
|
|
|
|
|
+
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.merge( mergePosition );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ // Second parameter is deletion position.
|
|
|
|
|
+ expect( spy.args[ 0 ][ 2 ].isEqual( mergePosition ) ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
describe( 'should get transformed and fire change:range if', () => {
|
|
describe( 'should get transformed and fire change:range if', () => {
|