8
0
Maciej Bukowski 7 лет назад
Родитель
Сommit
197b869687

+ 18 - 18
packages/ckeditor5-engine/src/model/document.js

@@ -278,6 +278,21 @@ export default class Document {
 		this._postFixers.add( postFixer );
 	}
 
+	/**
+	 * A custom `toJSON()` method to solve child-parent circular dependencies.
+	 *
+	 * @returns {Object} A clone of this object with the document property changed to a string.
+	 */
+	toJSON() {
+		const json = clone( this );
+
+		// Due to circular references we need to remove parent reference.
+		json.selection = '[engine.model.DocumentSelection]';
+		json.model = '[engine.model.Model]';
+
+		return json;
+	}
+
 	/**
 	 * Check if there were any changes done on document, and if so, call post-fixers,
 	 * fire `change` event for features and conversion and then reset the differ.
@@ -289,7 +304,7 @@ export default class Document {
 	 * @param {module:engine/model/writer~Writer writer} writer The writer on which post-fixers will be called.
 	 */
 	_runPostFixersAndResetDiffer( writer ) {
-		if ( this._hasDocumentChangedFromTheLastChangeBlock() ) {
+		if ( this._hasDocumentChanged() ) {
 			this._callPostFixers( writer );
 
 			if ( this.differ.hasDataChanges() ) {
@@ -310,27 +325,12 @@ export default class Document {
 	 * or {@link module:engine/model/model~Model#change `change()` block}.
 	 *
 	 * @protected
-	 * @returns {Boolean} Returns `true` when document has changed from the last change block.
+	 * @returns {Boolean} Returns `true` if document has changed from the differ's reset.
 	 */
-	_hasDocumentChangedFromTheLastChangeBlock() {
+	_hasDocumentChanged() {
 		return !this.differ.isEmpty || this._hasSelectionChangedFromTheLastChangeBlock;
 	}
 
-	/**
-	 * A custom `toJSON()` method to solve child-parent circular dependencies.
-	 *
-	 * @returns {Object} A clone of this object with the document property changed to a string.
-	 */
-	toJSON() {
-		const json = clone( this );
-
-		// Due to circular references we need to remove parent reference.
-		json.selection = '[engine.model.DocumentSelection]';
-		json.model = '[engine.model.Model]';
-
-		return json;
-	}
-
 	/**
 	 * Returns the default root for this document which is either the first root that was added to the document using
 	 * {@link #createRoot} or the {@link #graveyard graveyard root} if no other roots were created.

+ 4 - 4
packages/ckeditor5-engine/src/model/model.js

@@ -696,8 +696,8 @@ export default class Model {
 			const callbackReturnValue = this._pendingChanges[ 0 ].callback( this._currentWriter );
 			ret.push( callbackReturnValue );
 
-			// Collect an information whether the model document has changed during from the last pending change callback.
-			hasModelDocumentChanged = hasModelDocumentChanged || this.document._hasDocumentChangedFromTheLastChangeBlock();
+			// Collect an information whether the model document has changed during from the last pending change.
+			hasModelDocumentChanged = hasModelDocumentChanged || this.document._hasDocumentChanged();
 
 			// Fire '_change' event before resetting differ.
 			this.fire( '_change', this._currentWriter );
@@ -740,8 +740,8 @@ export default class Model {
 	 * @protected
 	 * @event _afterChanges
 	 * @param {Object} options
-	 * @param {Boolean} options.hasModelDocumentChanged A boolean indicates whether the model document has changed during the
-	 * {@link module:engine/model/model~Model#change} blocks.
+	 * @param {Boolean} options.hasModelDocumentChanged `true` if the model document has changed during the
+	 * {@link module:engine/model/model~Model#change} or {@link module:engine/model/model~Model#enqueueChange} blocks.
 	 */
 
 	/**