8
0
Просмотр исходного кода

Prevented `EditingController` from updating view if there are no changes.

Maciej Bukowski 7 лет назад
Родитель
Сommit
2d9377d63f

+ 4 - 2
packages/ckeditor5-engine/src/controller/editingcontroller.js

@@ -78,9 +78,11 @@ export default class EditingController {
 			this.view._renderingDisabled = true;
 		}, { priority: 'highest' } );
 
-		this.listenTo( this.model, '_afterChanges', () => {
+		this.listenTo( this.model, '_afterChanges', ( data, { modelChanged } ) => {
 			this.view._renderingDisabled = false;
-			this.view.render();
+			if ( modelChanged ) {
+				this.view.render();
+			}
 		}, { priority: 'lowest' } );
 
 		// Whenever model document is changed, convert those changes to the view (using model.Document#differ).

+ 5 - 1
packages/ckeditor5-engine/src/model/document.js

@@ -155,7 +155,11 @@ export default class Document {
 		// fire `change` event for features and conversion and then reset the differ.
 		// Fire `change:data` event when at least one operation or buffered marker changes the data.
 		this.listenTo( model, '_change', ( evt, writer ) => {
-			if ( !this.differ.isEmpty || hasSelectionChanged ) {
+			const documentChanged = !this.differ.isEmpty || hasSelectionChanged;
+
+			evt.return = documentChanged;
+
+			if ( documentChanged ) {
 				this._callPostFixers( writer );
 
 				if ( this.differ.hasDataChanges() ) {

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

@@ -683,6 +683,7 @@ export default class Model {
 	 */
 	_runPendingChanges() {
 		const ret = [];
+		let modelChanged = false;
 
 		this.fire( '_beforeChanges' );
 
@@ -695,14 +696,14 @@ export default class Model {
 			const callbackReturnValue = this._pendingChanges[ 0 ].callback( this._currentWriter );
 			ret.push( callbackReturnValue );
 
-			// Fire internal `_change` event.
-			this.fire( '_change', this._currentWriter );
+			// Fire internal `_change` event and collect the change result.
+			modelChanged = modelChanged || this.fire( '_change', this._currentWriter );
 
 			this._pendingChanges.shift();
 			this._currentWriter = null;
 		}
 
-		this.fire( '_afterChanges' );
+		this.fire( '_afterChanges', { modelChanged } );
 
 		return ret;
 	}