Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
scofalik opened this issue Feb 12, 2018 · 7 comments · Fixed by ckeditor/ckeditor5-engine#1388
Assignees
Labels
package:engine type:improvement This issue reports a possible enhancement of an existing feature.
Milestone

Comments

@scofalik
Copy link
Contributor

When creating a marker you can set whether the marker is managed through operations:

const marker = modelWriter.setMarker( 'myMarker', myRange, { usingOperations: true } );

However, at the moment, the method works in a way, that you need to pass that object every time because when not set, the option will be overwritten:

modelWriter.setMarker( marker, myOtherRange ); // Will set `usingOperations` to `false`.

Instead, when options object is not set, setMarker call should not change any options. Only this should change an option:

modelWriter.setMarker( marker, myOtherRange, { usingOperations: false } );
@pjasiun
Copy link

pjasiun commented Feb 22, 2018

Writing this comment I realised that it would be inconsistent: setSelection will reset selection options but setMarker will not.

This is why I think we should split this method and have separate changeMarker/updateMaker.

const marker = setMarker( [ name = uid() ], range, [ options ] );

updateMarker( markerOrName, [ range ], [ options ] )

Set marker should not accept "marker" as the first parameter. It could create a new marker instance and should return marker instance. It removes old maker if the marker with such name existed.

Update marker should not create new marker instance but only update the existing instance. It should return nothing. It should change only options you define.

@pjasiun pjasiun assigned jodator and unassigned scofalik Mar 27, 2018
@pjasiun
Copy link

pjasiun commented Mar 27, 2018

To make it safer we should make option.usingOperation obligated in setMarker, so it needs to be defined every time you use this method. It is too easy to make a mistake now.

@jodator
Copy link
Contributor

jodator commented Mar 28, 2018

@pjasiun does option.usingOperation should be obligatory for updateMarker()?

@pjasiun
Copy link

pjasiun commented Mar 28, 2018

@pjasiun does option.usingOperation should be obligatory for updateMarker()?

No. The whole point of updateMarker is that it will do not change range or option if you do not set it.

@jodator
Copy link
Contributor

jodator commented Mar 28, 2018

@pjasiun just wanted to be sure.

Anyway second question:

writer.setMarker( [ name ], range, options );
writer.updateMarker( markerOrName, range, [ options ] )

I have problem with the first parameter (name) being optional in setMarker() and options object being required.

Optional parameters should go as last but it looks weir a bit now.

writer.setMarker( range, { using: true } );
writer.setMarker( range, { using: true }, 'myMarker' );

writer.updateMarker( 'myMarker', range );
writer.updateMarker( 'myMarker', range, { using: true } );

Or maybe:

writer.setMarker( range, 'myMarker', { using: false } );
writer.setMarker( range, { using: true } );


writer.updateMarker( range, 'myMarker' );
writer.updateMarker( range, myMarker, { using: true } );

I can see at least two sensible options:

  1. Make options.usingOperation optional in setMarker().
  2. Make setMarker( range, options, name ) and updateMarker( name, range, options ).

@jodator
Copy link
Contributor

jodator commented Mar 28, 2018

After talks with @pjasiun and that we cannot come to a cleaner solution will make name param required for writer#setMarker() as:

  • we do not have usages for empty name
  • developer can call uid() and pass it as a name

@pjasiun
Copy link

pjasiun commented Mar 28, 2018

Yep. Also, we agreed to move range to options.

pjasiun referenced this issue in ckeditor/ckeditor5-engine Apr 6, 2018
Feature: Introduce `writer#updateMarker()` method. Closes #1299.

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.
@mlewand mlewand transferred this issue from ckeditor/ckeditor5-engine Oct 9, 2019
@mlewand mlewand added this to the iteration 15 milestone Oct 9, 2019
@mlewand mlewand added module:model type:improvement This issue reports a possible enhancement of an existing feature. package:engine labels Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:engine type:improvement This issue reports a possible enhancement of an existing feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants