-
Notifications
You must be signed in to change notification settings - Fork 40
T/1299: Create writer#updateMarker() method. #1388
Conversation
…ng writer.setMarker() API.
# Conflicts: # tests/model/document.js
Since we have a separate method for updating marker we can rename setMarker to addMarker. |
src/model/writer.js
Outdated
* | ||
* setMarker( markerName, range ); | ||
* setMarker( markerName, { range } ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be updateMarker
.
src/model/writer.js
Outdated
* | ||
* setMarker( range ) | ||
* setMarker( marker, { range, usingOperation: true } ); | ||
* setMarker( markerName, { range, usingOperation: true } ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be updateMarker
.
tests/model/writer.js
Outdated
} ); | ||
|
||
return marker; | ||
} | ||
|
||
function updateMarker( markerOrNameOrRange, rangeOrManagedUsingOperations, options ) { | ||
model.enqueueChange( batch, writer => { | ||
writer.updateMarker( markerOrNameOrRange, rangeOrManagedUsingOperations, options ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updateMarker
has different parameters.
I agree with @oskarwrobel. We used to have |
src/model/writer.js
Outdated
* @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}. |
There was a problem hiding this comment.
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
.
src/model/writer.js
Outdated
} | ||
|
||
const currentMarker = this.model.markers.get( markerName ); | ||
const range = options && options.range; | ||
const usingOperation = !!options && !!options.usingOperation; |
There was a problem hiding this comment.
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.
src/model/writer.js
Outdated
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// : currentMarker.managedUsingOperations;
?
tests/model/writer.js
Outdated
const spy = sinon.spy(); | ||
|
||
model.on( 'applyOperation', spy ); | ||
|
||
setMarker( 'name', range, { usingOperation: true } ); | ||
updateMarker( marker, { usingOperation: true } ); |
There was a problem hiding this comment.
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.
tests/model/writer.js
Outdated
|
||
sinon.assert.calledOnce( spy ); | ||
|
||
updateMarker( 'name', { range } ); |
There was a problem hiding this comment.
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.
Tests for At the same time, there are missing tests to check if |
* | ||
* setMarker( range ) | ||
* updateMarker( marker, { range, usingOperation: true } ); | ||
* updateMarker( markerName, { range, usingOperation: true } ); |
There was a problem hiding this comment.
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.
src/model/writer.js
Outdated
applyMarkerOperation( this, markerName, currentMarker.getRange(), null ); | ||
} | ||
|
||
return this.model.markers._set( markerName, newRange, usingOperation ); | ||
} | ||
this.model.markers._set( markerName, range, hasUsingOperationDefined ? usingOperation : currentMarker.managedUsingOperations ); |
There was a problem hiding this comment.
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?
OK to have this clear, the
|
@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. |
Other: Rename `setMarker` to `addMarker` (see ckeditor/ckeditor5-engine#1388).
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 amarker
instance as a parameter. To update existing marker usewriter#updateMarker()
method.BREAKING CHANGE: The
options.usingOperation
option inwriter#setMarker()
is now a required one.BREAKING CHANGE: The
range
parameter was removed. Useoptions.range
instead.Additional information
Other repositories that required changes:
Suggested merge message for other repositores: