Przeglądaj źródła

Changed: `model.Document#getAppliedDeltas` should return empty string if no deltas were applied.

Szymon Cofalik 8 lat temu
rodzic
commit
cc1e6b7709

+ 7 - 2
packages/ckeditor5-engine/src/dev-utils/enableenginedebug.js

@@ -462,16 +462,21 @@ function enableReplayerTools() {
 	ModelDocument.prototype.applyOperation = function( operation ) {
 		if ( !this._lastDelta ) {
 			this._appliedDeltas = [];
-			this._lastDelta = operation.delta;
 		} else if ( this._lastDelta !== operation.delta ) {
 			this._appliedDeltas.push( this._lastDelta.toJSON() );
-			this._lastDelta = operation.delta;
 		}
 
+		this._lastDelta = operation.delta;
+
 		_modelDocumentApplyOperation.call( this, operation );
 	};
 
 	ModelDocument.prototype.getAppliedDeltas = function() {
+		// No deltas has been applied yet, return empty string.
+		if ( !this._lastDelta ) {
+			return '';
+		}
+
 		const appliedDeltas = this._appliedDeltas.concat( this._lastDelta.toJSON() );
 
 		return appliedDeltas.map( JSON.stringify ).join( LOG_SEPARATOR );

+ 2 - 0
packages/ckeditor5-engine/tests/dev-utils/enableenginedebug.js

@@ -717,6 +717,8 @@ describe( 'debug tools', () => {
 		it( 'getAppliedDeltas()', () => {
 			const modelDoc = new ModelDocument();
 
+			expect( modelDoc.getAppliedDeltas() ).to.equal( '' );
+
 			const otherRoot = modelDoc.createRoot( '$root', 'otherRoot' );
 			const firstEle = new ModelElement( 'paragraph' );
 			const removedEle = new ModelElement( 'paragraph', null, [ new ModelText( 'foo' ) ] );