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

Commit

Permalink
Fixed: Writer#updateMarker() should not change markers mangedUsingOpe…
Browse files Browse the repository at this point in the history
…ration when usingOperation is not specified.
  • Loading branch information
jodator committed Apr 4, 2018
1 parent 7d00bb6 commit 76f0608
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/model/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -903,16 +903,18 @@ export default class Writer {
}

const range = options && options.range;
const usingOperation = !!options && !!options.usingOperation;

const hasUsingOperationDefined = !!options && typeof options.usingOperation == 'boolean';
const usingOperation = !!options && !!options.usingOperation; // : currentMarker.managedUsingOperations;

if ( !usingOperation ) {
// If marker changes to a marker that do not use operations then we need to create additional operation
// that removes that marker first.
if ( currentMarker.managedUsingOperations ) {
if ( hasUsingOperationDefined && currentMarker.managedUsingOperations ) {
applyMarkerOperation( this, markerName, currentMarker.getRange(), null );
}

this.model.markers._set( markerName, range, usingOperation );
this.model.markers._set( markerName, range, hasUsingOperationDefined ? usingOperation : currentMarker.managedUsingOperations );

return;
}
Expand Down
28 changes: 22 additions & 6 deletions tests/model/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,7 @@ describe( 'Writer', () => {
addMarker( 'name', { range, usingOperation: true } );
const op = batch.deltas[ 0 ].operations[ 0 ];

expect( spy.calledOnce ).to.be.true;
sinon.assert.calledOnce( spy );
expect( spy.firstCall.args[ 1 ][ 0 ].type ).to.equal( 'marker' );
expect( op.oldRange ).to.be.null;
expect( op.newRange.isEqual( range ) ).to.be.true;
Expand Down Expand Up @@ -2086,7 +2086,7 @@ describe( 'Writer', () => {

const op = batch.deltas[ 0 ].operations[ 0 ];

expect( spy.calledOnce ).to.be.true;
sinon.assert.calledOnce( spy );
expect( spy.firstCall.args[ 1 ][ 0 ].type ).to.equal( 'marker' );
expect( op.oldRange ).to.be.null;
expect( op.newRange.isEqual( range ) ).to.be.true;
Expand All @@ -2097,14 +2097,14 @@ describe( 'Writer', () => {
model.on( 'applyOperation', spy );

addMarker( 'name', { range, usingOperation: true } );
updateMarker( 'name', { range } );
updateMarker( 'name', { range, usingOperation: false } );

const marker = model.markers.get( 'name' );

const op1 = batch.deltas[ 0 ].operations[ 0 ];
const op2 = batch.deltas[ 1 ].operations[ 0 ];

expect( spy.calledTwice ).to.be.true;
sinon.assert.calledTwice( spy );
expect( spy.firstCall.args[ 1 ][ 0 ].type ).to.equal( 'marker' );
expect( spy.secondCall.args[ 1 ][ 0 ].type ).to.equal( 'marker' );

Expand All @@ -2117,6 +2117,22 @@ describe( 'Writer', () => {
expect( marker.managedUsingOperations ).to.be.false;
} );

it( 'should not create additional operation when using operation is not specified', () => {
const spy = sinon.spy();
model.on( 'applyOperation', spy );

addMarker( 'name', { range, usingOperation: true } );

sinon.assert.calledOnce( spy );

updateMarker( 'name', { range } );

const marker = model.markers.get( 'name' );

sinon.assert.calledOnce( spy );
expect( marker.managedUsingOperations ).to.be.true;
} );

it( 'should enable changing marker to be managed using operation', () => {
const spy = sinon.spy();
model.on( 'applyOperation', spy );
Expand All @@ -2126,7 +2142,7 @@ describe( 'Writer', () => {

const marker = model.markers.get( 'name' );

expect( spy.calledOnce ).to.be.true;
sinon.assert.calledOnce( spy );
expect( spy.firstCall.args[ 1 ][ 0 ].type ).to.equal( 'marker' );

expect( marker.managedUsingOperations ).to.be.true;
Expand Down Expand Up @@ -2210,7 +2226,7 @@ describe( 'Writer', () => {

removeMarker( marker );

expect( spy.calledOnce ).to.be.true;
sinon.assert.calledOnce( spy );
expect( spy.firstCall.args[ 1 ][ 0 ].type ).to.equal( 'marker' );
expect( model.markers.get( 'name' ) ).to.be.null;
} );
Expand Down

0 comments on commit 76f0608

Please sign in to comment.