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

Commit

Permalink
Merge pull request #941 from ckeditor/t/940
Browse files Browse the repository at this point in the history
Feature: When engine debugging is on, deltas that are results of transformation will keep their history of changes in `#history` property. Closes #940.
  • Loading branch information
scofalik authored May 9, 2017
2 parents d391190 + 2864957 commit 7d8db49
Show file tree
Hide file tree
Showing 18 changed files with 524 additions and 283 deletions.
71 changes: 53 additions & 18 deletions src/dev-utils/enableenginedebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

/* global console */

import DeltaReplayer from './deltareplayer';

import ModelPosition from '../model/position';
import ModelRange from '../model/range';
import ModelText from '../model/text';
Expand All @@ -33,6 +35,7 @@ import RenameDelta from '../model/delta/renamedelta';
import SplitDelta from '../model/delta/splitdelta';
import UnwrapDelta from '../model/delta/unwrapdelta';
import WrapDelta from '../model/delta/wrapdelta';
import deltaTransform from '../model/delta/transform';
import ModelDocument from '../model/document';
import ModelDocumentFragment from '../model/documentfragment';
import ModelRootElement from '../model/rootelement';
Expand All @@ -46,7 +49,7 @@ import ViewDocumentFragment from '../view/documentfragment';
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import Editor from '@ckeditor/ckeditor5-core/src/editor/editor';

import DeltaReplayer from './deltareplayer';
import clone from '@ckeditor/ckeditor5-utils/src/lib/lodash/clone';

const treeDump = Symbol( '_treeDump' );

Expand Down Expand Up @@ -268,38 +271,38 @@ function enableLoggingTools() {
};

AttributeOperation.prototype.toString = function() {
return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
`"${ this.key }": ${ JSON.stringify( this.oldValue ) } -> ${ JSON.stringify( this.newValue ) }, ${ this.range }`;
};

InsertOperation.prototype.toString = function() {
return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
`[ ${ this.nodes.length } ] -> ${ this.position }`;
};

MarkerOperation.prototype.toString = function() {
return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
`"${ this.name }": ${ this.oldRange } -> ${ this.newRange }`;
};

MoveOperation.prototype.toString = function() {
const range = ModelRange.createFromPositionAndShift( this.sourcePosition, this.howMany );

return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
`${ range } -> ${ this.targetPosition }`;
};

NoOperation.prototype.toString = function() {
return 'NoOperation';
return `NoOperation( ${ this.baseVersion } )`;
};

RenameOperation.prototype.toString = function() {
return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
`${ this.position }: "${ this.oldName }" -> "${ this.newName }"`;
};

RootAttributeOperation.prototype.toString = function() {
return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
`"${ this.key }": ${ JSON.stringify( this.oldValue ) } -> ${ JSON.stringify( this.newValue ) }, ${ this.root.rootName }`;
};

Expand All @@ -317,27 +320,59 @@ function enableLoggingTools() {
}
};

Delta.prototype._saveHistory = function( itemToSave ) {
const history = itemToSave.before.history ? itemToSave.before.history : [];

itemToSave.before = clone( itemToSave.before );
delete itemToSave.before.history;
itemToSave.before = JSON.stringify( itemToSave.before );

itemToSave.transformedBy = clone( itemToSave.transformedBy );
delete itemToSave.transformedBy.history;
itemToSave.transformedBy = JSON.stringify( itemToSave.transformedBy );

this.history = history.concat( itemToSave );
};

const _deltaTransformTransform = deltaTransform.transform;

deltaTransform.transform = function( a, b, isAMoreImportantThanB ) {
const results = _deltaTransformTransform( a, b, isAMoreImportantThanB );

for ( let i = 0; i < results.length; i++ ) {
results[ i ]._saveHistory( {
before: a,
transformedBy: b,
wasImportant: isAMoreImportantThanB,
resultIndex: i,
resultsTotal: results.length
} );
}

return results;
};

AttributeDelta.prototype.toString = function() {
return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
`"${ this.key }": -> ${ JSON.stringify( this.value ) }, ${ this.range }, ${ this.operations.length } ops`;
};

InsertDelta.prototype.toString = function() {
const op = this._insertOperation;

return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
`[ ${ op.nodes.length } ] -> ${ op.position }`;
};

MarkerDelta.prototype.toString = function() {
const op = this.operations[ 0 ];

return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
`"${ op.name }": ${ op.oldRange } -> ${ op.newRange }`;
};

MergeDelta.prototype.toString = function() {
return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
this.position.toString();
};

Expand All @@ -350,38 +385,38 @@ function enableLoggingTools() {
opStrings.push( `${ range } -> ${ op.targetPosition }` );
}

return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
opStrings.join( '; ' );
};

RenameDelta.prototype.toString = function() {
const op = this.operations[ 0 ];

return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
`${ op.position }: "${ op.oldName }" -> "${ op.newName }"`;
};

RootAttributeDelta.prototype.toString = function() {
const op = this.operations[ 0 ];

return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
`"${ op.key }": ${ JSON.stringify( op.oldValue ) } -> ${ JSON.stringify( op.newValue ) }, ${ op.root.rootName }`;
};

SplitDelta.prototype.toString = function() {
return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
this.position.toString();
};

UnwrapDelta.prototype.toString = function() {
return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
this.position.toString();
};

WrapDelta.prototype.toString = function() {
const wrapElement = this._insertOperation.nodes.getNode( 0 );

return getClassName( this ) + ': ' +
return getClassName( this ) + `( ${ this.baseVersion } ): ` +
`${ this.range } -> ${ wrapElement }`;
};

Expand Down
4 changes: 3 additions & 1 deletion src/model/delta/basic-transformations.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* @module engine/model/delta/basic-transformations
*/

import { addTransformationCase, defaultTransform } from './transform';
import deltaTransform from './transform';
const addTransformationCase = deltaTransform.addTransformationCase;
const defaultTransform = deltaTransform.defaultTransform;

import Range from '../range';
import Position from '../position';
Expand Down
7 changes: 7 additions & 0 deletions src/model/delta/deltafactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ export default class DeltaFactory {
delta.addOperation( OperationFactory.fromJSON( operation, doc ) );
}

// Rewrite all other properties.
for ( let prop in json ) {
if ( prop != '__className' && delta[ prop ] === undefined ) {
delta[ prop ] = json[ prop ];
}
}

return delta;
}

Expand Down
Loading

0 comments on commit 7d8db49

Please sign in to comment.