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

Commit

Permalink
Merge fb188e7 into f3358cc
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2ciek committed Oct 23, 2019
2 parents f3358cc + fb188e7 commit 765355b
Show file tree
Hide file tree
Showing 28 changed files with 436 additions and 1,297 deletions.
588 changes: 0 additions & 588 deletions src/dev-utils/enableenginedebug.js

This file was deleted.

96 changes: 96 additions & 0 deletions src/dev-utils/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/**
* @module engine/dev-utils/utils
*/

/* globals console */

/**
* Helper function, converts a map to the 'key1="value1" key2="value1"' format.
*
* @private
* @param {Map} map Map to convert.
* @returns {String} Converted map.
*/
export function convertMapToTags( map ) {
let string = '';

for ( const entry of map ) {
string += ` ${ entry[ 0 ] }=${ JSON.stringify( entry[ 1 ] ) }`;
}

return string;
}

/**
* Helper function, converts a map to the '{"key1":"value1","key2":"value2"}' format.
*
* @private
* @param {Map} map Map to convert.
* @returns {String} Converted map.
*/
export function convertMapToStringifiedObject( map ) {
const obj = {};

for ( const entry of map ) {
obj[ entry[ 0 ] ] = entry[ 1 ];
}

return JSON.stringify( obj );
}

/**
* @private
*/
export const treeDump = Symbol( '_treeDump' );
const maxTreeDumpLength = 20;

/**
* Helper function, stores the `document` state for a given `version` as a string in a private property.
*
* @private
* @param {*} document
* @param {*} version
*/
export function dumpTrees( document, version ) {
console.log( document, version );

let string = '';

for ( const root of document.roots ) {
string += root.printTree() + '\n';
}

document[ treeDump ][ version ] = string.substr( 0, string.length - 1 ); // Remove the last "\n".

const overflow = document[ treeDump ].length - maxTreeDumpLength;

if ( overflow > 0 ) {
document[ treeDump ][ overflow - 1 ] = null;
}
}

export function initDocumentDumping( document ) {
document[ treeDump ] = [];
}

/**
* Helper function that dumps document for the given version.
*
* @private
* @param {*} document
* @param {*} version
*/
export function logDocument( document, version ) {
console.log( '--------------------' );

if ( document[ treeDump ][ version ] ) {
console.log( document[ treeDump ][ version ] );
} else {
console.log( 'Tree log unavailable for given version: ' + version );
}
}
7 changes: 7 additions & 0 deletions src/model/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import mix from '@ckeditor/ckeditor5-utils/src/mix';
import { isInsideSurrogatePair, isInsideCombinedSymbol } from '@ckeditor/ckeditor5-utils/src/unicode';
import { clone } from 'lodash-es';

// @if CK_DEBUG_ENGINE // const { logDocument } = require( '../dev-utils/utils' );

const graveyardName = '$graveyard';

/**
Expand Down Expand Up @@ -465,6 +467,11 @@ export default class Document {
* @event change:data
* @param {module:engine/model/batch~Batch} batch The batch that was used in the executed changes block.
*/

// @if CK_DEBUG_ENGINE // log( version = null ) {
// @if CK_DEBUG_ENGINE // version = version === null ? this.version : version;
// @if CK_DEBUG_ENGINE // logDocument( this, version );
// @if CK_DEBUG_ENGINE // }
}

mix( Document, EmitterMixin );
Expand Down
40 changes: 40 additions & 0 deletions src/model/documentfragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import Text from './text';
import TextProxy from './textproxy';
import isIterable from '@ckeditor/ckeditor5-utils/src/isiterable';

// @if CK_DEBUG_ENGINE // const { stringifyMap } = require( '../dev-utils/utils' );

/**
* DocumentFragment represents a part of model which does not have a common root but it's top-level nodes
* can be seen as siblings. In other words, it is a detached part of model tree, without a root.
Expand Down Expand Up @@ -318,6 +320,44 @@ export default class DocumentFragment {

return nodes;
}

// @if CK_DEBUG_ENGINE // toString() {
// @if CK_DEBUG_ENGINE // return 'documentFragment';
// @if CK_DEBUG_ENGINE // }

// @if CK_DEBUG_ENGINE // log() {
// @if CK_DEBUG_ENGINE // console.log( 'ModelDocumentFragment: ' + this );
// @if CK_DEBUG_ENGINE // }

// @if CK_DEBUG_ENGINE // printTree() {
// @if CK_DEBUG_ENGINE // let string = 'ModelDocumentFragment: [';

// @if CK_DEBUG_ENGINE // for ( const child of this.getChildren() ) {
// @if CK_DEBUG_ENGINE // string += '\n';

// @if CK_DEBUG_ENGINE // if ( child.is( 'text' ) ) {
// @if CK_DEBUG_ENGINE // const textAttrs = stringifyMap( child._attrs );

// @if CK_DEBUG_ENGINE // string += '\t'.repeat( 1 );

// @if CK_DEBUG_ENGINE // if ( textAttrs !== '' ) {
// @if CK_DEBUG_ENGINE // string += `<$text${ textAttrs }>` + child.data + '</$text>';
// @if CK_DEBUG_ENGINE // } else {
// @if CK_DEBUG_ENGINE // string += child.data;
// @if CK_DEBUG_ENGINE // }
// @if CK_DEBUG_ENGINE // } else {
// @if CK_DEBUG_ENGINE // string += child.printTree( 1 );
// @if CK_DEBUG_ENGINE // }
// @if CK_DEBUG_ENGINE // }

// @if CK_DEBUG_ENGINE // string += '\n]';

// @if CK_DEBUG_ENGINE // return string;
// @if CK_DEBUG_ENGINE // }

// @if CK_DEBUG_ENGINE // logTree() {
// @if CK_DEBUG_ENGINE // console.log( this.printTree() );
// @if CK_DEBUG_ENGINE // }
}

// Converts strings to Text and non-iterables to arrays.
Expand Down
63 changes: 63 additions & 0 deletions src/model/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import Text from './text';
import TextProxy from './textproxy';
import isIterable from '@ckeditor/ckeditor5-utils/src/isiterable';

// @if CK_DEBUG_ENGINE // const { stringifyMap, convertMapToStringifiedObject, convertMapToTags } = require( '../dev-utils/utils' );

/**
* Model element. Type of {@link module:engine/model/node~Node node} that has a {@link module:engine/model/element~Element#name name} and
* {@link module:engine/model/element~Element#getChildren child nodes}.
Expand Down Expand Up @@ -322,6 +324,67 @@ export default class Element extends Node {

return new Element( json.name, json.attributes, children );
}

// @if CK_DEBUG_ENGINE // toString() {
// @if CK_DEBUG_ENGINE // return `<${ this.rootName || this.name }>`;
// @if CK_DEBUG_ENGINE // }

// @if CK_DEBUG_ENGINE // log() {
// @if CK_DEBUG_ENGINE // console.log( 'ModelElement: ' + this );
// @if CK_DEBUG_ENGINE // }

// @if CK_DEBUG_ENGINE // logExtended() {
// @if CK_DEBUG_ENGINE // console.log( `ModelElement: ${ this }, ${ this.childCount } children,
// @if CK_DEBUG_ENGINE // attrs: ${ convertMapToStringifiedObject( this.getAttributes() ) }` );
// @if CK_DEBUG_ENGINE // }

// @if CK_DEBUG_ENGINE // logAll() {
// @if CK_DEBUG_ENGINE // console.log( '--------------------' );
// @if CK_DEBUG_ENGINE //
// @if CK_DEBUG_ENGINE // this.logExtended();
// @if CK_DEBUG_ENGINE // console.log( 'List of children:' );
// @if CK_DEBUG_ENGINE //
// @if CK_DEBUG_ENGINE // for ( const child of this.getChildren() ) {
// @if CK_DEBUG_ENGINE // child.log();
// @if CK_DEBUG_ENGINE // }
// @if CK_DEBUG_ENGINE // }

// @if CK_DEBUG_ENGINE // printTree( level = 0) {
// @if CK_DEBUG_ENGINE // let string = '';

// @if CK_DEBUG_ENGINE // string += '\t'.repeat( level );
// @if CK_DEBUG_ENGINE // string += `<${ this.rootName || this.name }${ convertMapToTags( this.getAttributes() ) }>`;

// @if CK_DEBUG_ENGINE // for ( const child of this.getChildren() ) {
// @if CK_DEBUG_ENGINE // string += '\n';

// @if CK_DEBUG_ENGINE // if ( child.is( 'text' ) ) {
// @if CK_DEBUG_ENGINE // const textAttrs = convertMapToTags( child._attrs );

// @if CK_DEBUG_ENGINE // string += '\t'.repeat( level + 1 );

// @if CK_DEBUG_ENGINE // if ( textAttrs !== '' ) {
// @if CK_DEBUG_ENGINE // string += `<$text${ textAttrs }>` + child.data + '</$text>';
// @if CK_DEBUG_ENGINE // } else {
// @if CK_DEBUG_ENGINE // string += child.data;
// @if CK_DEBUG_ENGINE // }
// @if CK_DEBUG_ENGINE // } else {
// @if CK_DEBUG_ENGINE // string += child.printTree( level + 1 );
// @if CK_DEBUG_ENGINE // }
// @if CK_DEBUG_ENGINE // }

// @if CK_DEBUG_ENGINE // if ( this.childCount ) {
// @if CK_DEBUG_ENGINE // string += '\n' + '\t'.repeat( level );
// @if CK_DEBUG_ENGINE // }

// @if CK_DEBUG_ENGINE // string += `</${ this.rootName || this.name }>`;

// @if CK_DEBUG_ENGINE // return string;
// @if CK_DEBUG_ENGINE // }

// @if CK_DEBUG_ENGINE // logTree() {
// @if CK_DEBUG_ENGINE // console.log( this.printTree() );
// @if CK_DEBUG_ENGINE // }
}

// Converts strings to Text and non-iterables to arrays.
Expand Down
33 changes: 33 additions & 0 deletions src/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import getSelectedContent from './utils/getselectedcontent';
import { injectSelectionPostFixer } from './utils/selection-post-fixer';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';

// @if CK_DEBUG_ENGINE // const { dumpTrees } = require( '../dev-utils/utils' );
// @if CK_DEBUG_ENGINE // const { OperationReplayer } = require( '../dev-utils/operationreplayer' ).default;

/**
* Editor's data model. Read about the model in the
* {@glink framework/guides/architecture/editing-engine engine architecture guide}.
Expand Down Expand Up @@ -116,6 +119,10 @@ export default class Model {
} );

injectSelectionPostFixer( this );

// @if CK_DEBUG_ENGINE // this.on( 'applyOperation', () => {
// @if CK_DEBUG_ENGINE // dumpTrees( this.document, this.document.version );
// @if CK_DEBUG_ENGINE // }, { priority: 'lowest' } );
}

/**
Expand Down Expand Up @@ -233,9 +240,35 @@ export default class Model {
* @param {module:engine/model/operation/operation~Operation} operation The operation to apply.
*/
applyOperation( operation ) {
// @if CK_DEBUG_ENGINE // console.log( 'Applying ' + operation );

// @if CK_DEBUG_ENGINE // if ( !this._operationLogs ) {
// @if CK_DEBUG_ENGINE // this._operationLogs = [];
// @if CK_DEBUG_ENGINE // }

// @if CK_DEBUG_ENGINE // this._operationLogs.push( JSON.stringify( operation ) );

// @if CK_DEBUG_ENGINE //if ( !this._appliedOperations ) {
// @if CK_DEBUG_ENGINE // this._appliedOperations = [];
// @if CK_DEBUG_ENGINE //}

// @if CK_DEBUG_ENGINE //this._appliedOperations.push( operation );

operation._execute();
}

// @if CK_DEBUG_ENGINE // getAppliedOperation() {
// @if CK_DEBUG_ENGINE // if ( !this._appliedOperations ) {
// @if CK_DEBUG_ENGINE // return '';
// @if CK_DEBUG_ENGINE // }

// @if CK_DEBUG_ENGINE // return this._appliedOperations.map( JSON.stringify ).join( '-------' );
// @if CK_DEBUG_ENGINE // }

// @if CK_DEBUG_ENGINE // createReplayer( stringifiedOperations ) {
// @if CK_DEBUG_ENGINE // return new OperationReplayer( this, '-------', stringifiedOperations );
// @if CK_DEBUG_ENGINE // }

/**
* Inserts content at the position in the editor specified by the selection, as one would expect the paste
* functionality to work.
Expand Down
6 changes: 6 additions & 0 deletions src/model/operation/attributeoperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,10 @@ export default class AttributeOperation extends Operation {
static fromJSON( json, document ) {
return new AttributeOperation( Range.fromJSON( json.range, document ), json.key, json.oldValue, json.newValue, json.baseVersion );
}

// @if CK_DEBUG_ENGINE // toString() {
// @if CK_DEBUG_ENGINE // return `AttributeOperation( ${ this.baseVersion } ): ` +
// @if CK_DEBUG_ENGINE // `"${ this.key }": ${ JSON.stringify( this.oldValue ) }` +
// @if CK_DEBUG_ENGINE // ` -> ${ JSON.stringify( this.newValue ) }, ${ this.range }`;
// @if CK_DEBUG_ENGINE // }
}
10 changes: 10 additions & 0 deletions src/model/operation/detachoperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import Range from '../range';
import { _remove } from './utils';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';

// @if CK_DEBUG_ENGINE // const ModelRange = require( '../range' ).default;

/**
* Operation to permanently remove node from detached root.
* Note this operation is only a local operation and won't be send to the other clients.
Expand Down Expand Up @@ -90,4 +92,12 @@ export default class DetachOperation extends Operation {
static get className() {
return 'DetachOperation';
}

// @if CK_DEBUG_ENGINE // toString() {
// @if CK_DEBUG_ENGINE // const range = ModelRange._createFromPositionAndShift( this.sourcePosition, this.howMany );
// @if CK_DEBUG_ENGINE // const nodes = Array.from( range.getItems() );
// @if CK_DEBUG_ENGINE // const nodeString = nodes.length > 1 ? `[ ${ nodes.length } ]` : nodes[ 0 ];

// @if CK_DEBUG_ENGINE // return `DetachOperation( ${ this.baseVersion } ): ${ nodeString } -> ${ range }`;
// @if CK_DEBUG_ENGINE // }
}
6 changes: 6 additions & 0 deletions src/model/operation/insertoperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,10 @@ export default class InsertOperation extends Operation {

return insert;
}

// @if CK_DEBUG_ENGINE // toString() {
// @if CK_DEBUG_ENGINE // const nodeString = this.nodes.length > 1 ? `[ ${ this.nodes.length } ]` : this.nodes.getNode( 0 );

// @if CK_DEBUG_ENGINE // return `InsertOperation( ${ this.baseVersion } ): ${ nodeString } -> ${ this.position }`;
// @if CK_DEBUG_ENGINE // }
}
5 changes: 5 additions & 0 deletions src/model/operation/markeroperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,9 @@ export default class MarkerOperation extends Operation {
json.baseVersion
);
}

// @if CK_DEBUG_ENGINE // toString() {
// @if CK_DEBUG_ENGINE // return `MarkerOperation( ${ this.baseVersion } ): ` +
// @if CK_DEBUG_ENGINE // `"${ this.name }": ${ this.oldRange } -> ${ this.newRange }`;
// @if CK_DEBUG_ENGINE // }
}
6 changes: 6 additions & 0 deletions src/model/operation/mergeoperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,10 @@ export default class MergeOperation extends Operation {

return new this( sourcePosition, json.howMany, targetPosition, graveyardPosition, json.baseVersion );
}

// @if CK_DEBUG_ENGINE // toString() {
// @if CK_DEBUG_ENGINE // return `MergeOperation( ${ this.baseVersion } ): ` +
// @if CK_DEBUG_ENGINE // `${ this.sourcePosition } -> ${ this.targetPosition }` +
// @if CK_DEBUG_ENGINE // ` ( ${ this.howMany } ), ${ this.graveyardPosition }`;
// @if CK_DEBUG_ENGINE // }
}
8 changes: 8 additions & 0 deletions src/model/operation/moveoperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import compareArrays from '@ckeditor/ckeditor5-utils/src/comparearrays';
import { _move } from './utils';

// @if CK_DEBUG_ENGINE // const ModelRange = require( '../range' ).default;

/**
* Operation to move a range of {@link module:engine/model/item~Item model items}
* to given {@link module:engine/model/position~Position target position}.
Expand Down Expand Up @@ -198,4 +200,10 @@ export default class MoveOperation extends Operation {

return new this( sourcePosition, json.howMany, targetPosition, json.baseVersion );
}

// @if CK_DEBUG_ENGINE // toString() {
// @if CK_DEBUG_ENGINE // const range = ModelRange._createFromPositionAndShift( this.sourcePosition, this.howMany );

// @if CK_DEBUG_ENGINE // return `MoveOperation( ${ this.baseVersion } ): ${ range } -> ${ this.targetPosition }`;
// @if CK_DEBUG_ENGINE // }
}
4 changes: 4 additions & 0 deletions src/model/operation/nooperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ export default class NoOperation extends Operation {
static get className() {
return 'NoOperation';
}

// @if CK_DEBUG_ENGINE // toString() {
// @if CK_DEBUG_ENGINE // return `NoOperation( ${ this.baseVersion } )`;
// @if CK_DEBUG_ENGINE // }
}
Loading

0 comments on commit 765355b

Please sign in to comment.