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

T/1299: Create writer#updateMarker() method. #1388

Merged
merged 12 commits into from
Apr 6, 2018
Merged

T/1299: Create writer#updateMarker() method. #1388

merged 12 commits into from
Apr 6, 2018

Conversation

jodator
Copy link
Contributor

@jodator jodator commented Mar 28, 2018

Suggested merge commit message (convention)

Feature: Introduce writer#updateMarker() method. Closes ckeditor/ckeditor5#4276.

BREAKING CHANGE: The writer#setMarker() method is used only to create a new marker and it does not accept a marker instance as a parameter. To update existing marker use writer#updateMarker() method.
BREAKING CHANGE: The options.usingOperation option in writer#setMarker() is now a required one.
BREAKING CHANGE: The range parameter was removed. Use options.range instead.


Additional information

Other repositories that required changes:

Suggested merge message for other repositores:

Aligned code to changes in writer#setMarker method.

@coveralls
Copy link

coveralls commented Mar 28, 2018

Coverage Status

Coverage decreased (-0.1%) to 99.878% when pulling 49b99b4 on t/1299 into 47e4f9f on master.

@jodator jodator requested a review from pjasiun March 28, 2018 14:26
@oskarwrobel
Copy link
Contributor

Since we have a separate method for updating marker we can rename setMarker to addMarker.

*
* setMarker( markerName, range );
* setMarker( markerName, { range } );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be updateMarker.

*
* setMarker( range )
* setMarker( marker, { range, usingOperation: true } );
* setMarker( markerName, { range, usingOperation: true } );
Copy link

@pjasiun pjasiun Mar 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be updateMarker.

} );

return marker;
}

function updateMarker( markerOrNameOrRange, rangeOrManagedUsingOperations, options ) {
model.enqueueChange( batch, writer => {
writer.updateMarker( markerOrNameOrRange, rangeOrManagedUsingOperations, options );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateMarker has different parameters.

@pjasiun
Copy link

pjasiun commented Mar 30, 2018

Since we have a separate method for updating marker we can rename setMarker to addMarker.

I agree with @oskarwrobel. We used to have setMarker to make it similar to setAttribute. But since these methods have different parameters it does not matter and addMarker makes more sense.

* @param {Object} options
* @param {Boolean} options.usingOperation Flag indicated whether the marker should be added by MarkerOperation.
* @param {module:engine/model/range~Range} options.range Marker range.
* See {@link module:engine/model/markercollection~Marker#managedUsingOperations}.
Copy link

@pjasiun pjasiun Mar 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This see is for usingOperation. Not for range.

}

const currentMarker = this.model.markers.get( markerName );
const range = options && options.range;
const usingOperation = !!options && !!options.usingOperation;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I do not understand something or was not clear enough, but if I call writer.updateMarker( name, { range } ); (with usingOperation not specified), then usingOperation should not change. So only range should change. This code looks like it changes usingOperation to false in such case. Also, I can not find a test which checks this.

throw new CKEditorError( 'writer-setMarker-no-range: Range parameter is required when adding a new marker.' );
}
const hasUsingOperationDefined = !!options && typeof options.usingOperation == 'boolean';
const usingOperation = !!options && !!options.usingOperation; // : currentMarker.managedUsingOperations;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// : currentMarker.managedUsingOperations;?

const spy = sinon.spy();

model.on( 'applyOperation', spy );

setMarker( 'name', range, { usingOperation: true } );
updateMarker( marker, { usingOperation: true } );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't change range nor usingOperation. I do not get what this test is about.


sinon.assert.calledOnce( spy );

updateMarker( 'name', { range } );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above. You don't change range nor usingOperation. I do not get what this test is about.

@pjasiun
Copy link

pjasiun commented Apr 4, 2018

Tests for updateMarker are bad. First, there is no point to set the same range or usingOperation value in addMarker and then in updateMarker in that many tests. It might be a good idea to have one or two tests like this to be sure that nothing bad happens if the range or usingOperation parameter is the same, but it should be an edge case.

At the same time, there are missing tests to check if updateMarker really update markers. It should be possible to change the value of usingOperation or range or both using this method and this is what should be deeply tested.

*
* setMarker( range )
* updateMarker( marker, { range, usingOperation: true } );
* updateMarker( markerName, { range, usingOperation: true } );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no range in a sample to show that you can update only usingOperation: true parameter.

applyMarkerOperation( this, markerName, currentMarker.getRange(), null );
}

return this.model.markers._set( markerName, newRange, usingOperation );
}
this.model.markers._set( markerName, range, hasUsingOperationDefined ? usingOperation : currentMarker.managedUsingOperations );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if range is not defined?

@jodator
Copy link
Contributor Author

jodator commented Apr 5, 2018

OK to have this clear, the updateMarker() should

  1. updateMarker( marker, { range } ) - change marker's range (usingOperation as defined in addMarker()
  2. updateMarker( marker, { usingOperation: true } ) - change marker's mangedUsingOperation to true (if usingOperation was not defined in addMarker()
  3. updateMarker( marker, { usingOperation: false } ) - change marker's mangedUsingOperation to false (if usingOperation was defined in addMarker()
  4. updateMarker( marker, { range, usingOperation ) - change marker's range and change it's managedUsingOperation if it is different then current marker's mangedUsingOperation.

@jodator
Copy link
Contributor Author

jodator commented Apr 5, 2018

@pjasiun OK I've revisited the test and I hope that all cases are handled. In particular I've added (changed) that if a marker was created not using operations and we update it with a new range the operations that is registered is for the updated range directly).

And vice versa if a manged marker is updated to be not managed by operations with a new range the operation that removes the marker is for current range but the marker is updated to a new range.

@pjasiun pjasiun merged commit bed647f into master Apr 6, 2018
@pjasiun pjasiun deleted the t/1299 branch April 6, 2018 08:43
pjasiun pushed a commit to ckeditor/ckeditor5-undo that referenced this pull request Apr 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

model.writer#setMarker should not change marker's options when they are not set
4 participants