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

T/1172-b Conversion refactor #1206

Merged
merged 12 commits into from
Dec 15, 2017
Merged

T/1172-b Conversion refactor #1206

merged 12 commits into from
Dec 15, 2017

Conversation

scofalik
Copy link
Contributor

@scofalik scofalik commented Dec 15, 2017

Suggested merge commit message (convention)

Other: Conversion refactoring. Introduced model.Differ. Changes now will be converted after all changes in a change block are done. Closes ckeditor/ckeditor5#4202.

@@ -368,7 +379,7 @@ export default class Mapper {
* We are in the text node so we can simple find the offset.
* <p>fo<b>ba|r</b>bom</p> -> expected offset: 2, actual offset: 2 -> position found
*
* @private
* @protected
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 still private.

* @returns {module:engine/view/position~Position} Corresponding view position.
*/
toViewPosition( modelPosition ) {
toViewPosition( modelPosition, isPhantom = false ) {
Copy link

Choose a reason for hiding this comment

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

Instead of isPhantom -> options.isPhantom.

const viewStart = conversionApi.mapper.toViewPosition( data.position );

const modelEnd = data.position.getShiftedBy( data.length );
const viewEnd = conversionApi.mapper.toViewPosition( modelEnd, true );
Copy link

Choose a reason for hiding this comment

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

const viewEnd = conversionApi.mapper.toViewPosition( modelEnd, { isPhantom: true } ); would be more readable.


// If marker's range is not collapsed - consume all items inside.
for ( const value of markerRange ) {
if ( !consumable.consume( value.item, eventName ) ) {
Copy link

Choose a reason for hiding this comment

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

Why consume is removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some time there were no consumables and I forgot to bring back this part of code.

this.convertInsert( Range.createFromPositionAndShift( entry.position, entry.length ) );
} else if ( entry.type == 'remove' ) {
this.convertRemove( entry.position, entry.length, entry.name );
} else {
Copy link

@pjasiun pjasiun Dec 15, 2017

Choose a reason for hiding this comment

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

Comment missing.

// Check all changed elements.
for ( const element of this._changesInElement.keys() ) {
// If the element is inside other changed element, skip changes in this element.
if ( this._isInsertedOrRemoved( element ) ) {
Copy link

Choose a reason for hiding this comment

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

Add comment that it's all about children.

const changes = this._changesInElement.get( element ).sort( ( a, b ) => {
if ( a.offset === b.offset ) {
if ( a.type != b.type ) {
return a.type == 'remove' ? -1 : 1;
Copy link

Choose a reason for hiding this comment

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

Comment needed.


for ( const change of changes ) {
if ( change.offset > offset ) {
actions.push( ...'e'.repeat( change.offset - offset ).split( '' ) );
Copy link

Choose a reason for hiding this comment

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

Comment "fill holes between end of one change and beginning of another with 'e'".

// - 'e' for 'equal' - when item at that position did not change,
// - 'i' for 'insert' - when item at that position was inserted,
// - 'r' for 'remove' - when item at that position was removed,
// - 'a' for 'attribute' - when item at that position has it attributes changed.
Copy link

Choose a reason for hiding this comment

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

A single sample would be great.

// Add diff item.
diffs.push( {
type: 'attribute',
position: range.start,
Copy link

Choose a reason for hiding this comment

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

It's strange that I get both position and range.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

position is useful for further sorting (as other changes has position too), but I will remove it from the final results. BTW. attribute change item also has length which is not used at all - I will remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It appears that I was wrong, both length and position are used in further processing but also both are not really needed later so they can be removed before changes are returned by getChanges()

old.howMany = inc.offset - old.offset;

// Unshift to prevent further processing of this change.
changes.unshift( { type: 'attribute', offset: incEnd, howMany: howMany - old.howMany, count: this._changeCount++ } );
Copy link

Choose a reason for hiding this comment

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

Comment why you add change in the first place is needed.

Copy link

Choose a reason for hiding this comment

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

And since you unshift because you know that this function is called in the loop, the loop should be moved inside the function.

const howManyAfter = howMany - old.howMany - inc.howMany;

// Unshift to prevent further processing of this change.
changes.unshift( { type: 'attribute', offset: inc.offset, howMany: howManyAfter, count: this._changeCount++ } );
Copy link

Choose a reason for hiding this comment

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

Why?

const changeItem = { type: 'attribute', offset: oldEnd, howMany: incEnd - oldEnd, count: this._changeCount++ };

for ( const oldChange of changes ) {
this._handleChange( changeItem, oldChange, changes );
Copy link

Choose a reason for hiding this comment

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

Why?

}

/**
* Calculates diff between old model tree state (before all the buffered operations) and the new model tree state
Copy link

Choose a reason for hiding this comment

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

(before all the buffered operations) -> (since the last {@link #reset})?

* return;
* }
*
* const sibling = modelPosition.nodeBefore; // Might crash for phantom position that does not exist in model.
Copy link

Choose a reason for hiding this comment

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

modelPosition.nodeBefore -> data.modelPosition.nodeBefore?

}
};
}

/**
* Function factory, creates a default model-to-view converter for removing {@link module:engine/view/uielement~UIElement ui element}
* basing on marker remove change.
* Function factory, creates a converter that converts model marker add/change/remove to the view.
Copy link

Choose a reason for hiding this comment

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

Add, change?

* evt.stop();
* } );
*
* Callback that "overrides" other callback:
* Callback that overrides other callback:
Copy link

Choose a reason for hiding this comment

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

I would remove this sample, it is too complicated, after reading it I understand less than before. Instead you could add a regular convresion for attribute->wrap (like bold).

@scofalik scofalik force-pushed the t/1172-b branch 2 times, most recently from c51ce54 to 57d8e04 Compare December 15, 2017 15:37
@pjasiun pjasiun merged commit 6479bfd into master Dec 15, 2017
@pjasiun pjasiun deleted the t/1172-b branch December 15, 2017 16:22
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.

Conversion refactor
2 participants