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

T/1211 Operations that do not operate on document should have baseVersion set to null #1220

Merged
merged 8 commits into from
Jan 18, 2018

Conversation

scofalik
Copy link
Contributor

@scofalik scofalik commented Dec 28, 2017

Suggested merge commit message (convention)

Other: Operations that do not operate on a document should have baseVersion set to null. Closes ckeditor/ckeditor5#4223.
Fixed: Markers again are properly converted in engine.controller.DataController.
Fixed: Markers are cleared now before an operation is applied to model.Document tree to fix scenarios where marker range could not be converted to the view after the model changed.


Additional information

This PR bases on #1216. Please close that PR first.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling c57548c on t/1211 into aea6119 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling f33f579 on t/1211 into aea6119 on master.

@pjasiun
Copy link

pjasiun commented Jan 5, 2018

I will wait with the review to close #1216.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling f571c52 on t/1211 into 2592bf1 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling b6b74e0 on t/1211 into 2592bf1 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 2f51f45 on t/1211 into 2592bf1 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling f9d3887 on t/1211 into f56bddf on master.

const modelRange = ModelRange.createIn( modelElementOrFragment );

const viewDocumentFragment = new ViewDocumentFragment();
this.mapper.bindElements( modelElementOrFragment, viewDocumentFragment );

this.modelToView.convertInsert( modelRange );

if ( !modelElementOrFragment.is( 'documentFragment' ) ) {
// Then, if document element is converted, convert markers.
// Get only those markers that contain or are contained by the element.
Copy link

Choose a reason for hiding this comment

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

What other elements do we have?

// it would be impossible to map some markers to view (if, for example, marker boundary parent got removed).
//
// `removedMarkers` keeps information which markers already has been removed to prevent removing them twice.
// (The second remove would not be at "the soonest moment" and it could crash.)
Copy link

Choose a reason for hiding this comment

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

(The second remove would not be at "the soonest moment" and it could crash.)
I don't get it.

removedMarkers.add( marker.name );
this.modelToView.convertMarkerRemove( marker.name, markerRange );

// TODO: This stinks but this is the safest place to have this code.
Copy link

Choose a reason for hiding this comment

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

You mean all of these listeners? ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

}, { priority: 'high' } );

// If a marker with given name was added again, remove it from `removedMarkers`. This is to prevent a bug in
// a situation when marker is removed, then added, then removed again (would not got removed if it is saved in `removedMarkers`).
Copy link

Choose a reason for hiding this comment

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

Are you sure we need this? If a marker is added, we add it on "changes done", so it should not be removed immediately, only removed from differ.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wow, good catch! I've added a test and it is true that it is not only unnecessary but it's even harmful.

@@ -574,7 +564,9 @@ export default class Writer {
const delta = new RenameDelta();
this.batch.addDelta( delta );

const renameOperation = new RenameOperation( Position.createBefore( element ), element.name, newName, this.model.document.version );
const version = element.root.document ? this.model.document.version : null;
Copy link

Choose a reason for hiding this comment

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

More natural is: element.root.document ? element.root.document.version : null;

@@ -605,21 +597,24 @@ export default class Writer {
}

const copy = new Element( splitElement.name, splitElement.getAttributes() );
const insertVersion = splitElement.root.document ? this.model.document.version : null;
Copy link

Choose a reason for hiding this comment

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

splitElement.root.document ? splitElement.root.document.version : null;

@@ -670,16 +665,20 @@ export default class Writer {
const delta = new WrapDelta();
this.batch.addDelta( delta );

const insert = new InsertOperation( range.end, element, this.model.document.version );
const insertVersion = range.root.document ? this.model.document.version : null;
Copy link

Choose a reason for hiding this comment

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

range.root.document ? range.root.document.version : null;

@@ -707,26 +706,20 @@ export default class Writer {
this.batch.addDelta( delta );

const sourcePosition = Position.createFromParentAndOffset( element, 0 );
const moveVersion = sourcePosition.root.document ? this.model.document.version : null;
Copy link

Choose a reason for hiding this comment

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

sourcePosition.root.document ? sourcePosition.root.document : null;


if ( position.root.document ) {
const doc = model.document;
const gyPosition = new Position( doc.graveyard, [ 0 ] );
Copy link

Choose a reason for hiding this comment

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

graveyardPosition

Changed: Minor refactor tweaks and doc tweaks.
@pjasiun pjasiun merged commit b527d7f into master Jan 18, 2018
@pjasiun pjasiun deleted the t/1211 branch January 18, 2018 14:22
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 13bc98c on t/1211 into f56bddf on master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants