Ver Fonte

Change variables names. Add docs.

Piotr Jasiun há 7 anos atrás
pai
commit
2740249f66

+ 9 - 5
packages/ckeditor5-engine/src/controller/editingcontroller.js

@@ -70,18 +70,22 @@ export default class EditingController {
 		const selection = doc.selection;
 		const markers = this.model.markers;
 
-		// Whenever model document is changed, convert those changes to the view (using model.Document#differ).
-		// Do it on 'low' priority, so changes are converted after other listeners did their job.
-		// Also convert model selection.
+		// Various plugins listen on model changes (on selection change, post fixers, etc.) and changes the view as a
+		// result of the model change, what causes rendering in the middle of conversion, sometimes before the selection
+		// is converted. This is why we want to disable rendering as long as one is in the `model.change` block.
+		// See  https://github.com/ckeditor/ckeditor5-engine/issues/1528
 		this.listenTo( this.model, '_beforeChanges', () => {
-			this.view.disabledRendering = true;
+			this.view._disabledRendering = true;
 		}, { priority: 'highest' } );
 
 		this.listenTo( this.model, '_afterChanges', () => {
-			this.view.disabledRendering = false;
+			this.view._disabledRendering = false;
 			this.view.render();
 		}, { priority: 'lowest' } );
 
+		// Whenever model document is changed, convert those changes to the view (using model.Document#differ).
+		// Do it on 'low' priority, so changes are converted after other listeners did their job.
+		// Also convert model selection.
 		this.listenTo( doc, 'change', () => {
 			this.view.change( writer => {
 				this.downcastDispatcher.convertChanges( doc.differ, writer );

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

@@ -370,7 +370,7 @@ export default class Model {
 	_runPendingChanges() {
 		const ret = [];
 
-		this.fire( '_beforeChanges', this._currentWriter );
+		this.fire( '_beforeChanges' );
 
 		while ( this._pendingChanges.length ) {
 			// Create a new writer using batch instance created for this chain of changes.
@@ -388,7 +388,7 @@ export default class Model {
 			this._currentWriter = null;
 		}
 
-		this.fire( '_afterChanges', this._currentWriter );
+		this.fire( '_afterChanges' );
 
 		return ret;
 	}
@@ -404,6 +404,22 @@ export default class Model {
 	 * @param {module:engine/model/writer~Writer} writer `Writer` instance that has been used in the change block.
 	 */
 
+	/**
+	 * Fired when enter the first {@link module:engine/model/model~Model#enqueueChange} or
+	 * {@link module:engine/model/model~Model#change} block of the pending changes.
+	 *
+	 * @protected
+	 * @event _beforeChanges
+	 */
+
+	/**
+	 * Fired when leave the last {@link module:engine/model/model~Model#enqueueChange} or
+	 * {@link module:engine/model/model~Model#change} block of the pending changes.
+	 *
+	 * @protected
+	 * @event _afterChanges
+	 */
+
 	/**
 	 * Fired every time any {@link module:engine/model/operation/operation~Operation operation} is applied on the model
 	 * using {@link #applyOperation}.

+ 9 - 1
packages/ckeditor5-engine/src/view/view.js

@@ -126,6 +126,14 @@ export default class View {
 		 */
 		this._postFixersInProgress = false;
 
+		/**
+		 * Internal flag to temporary disable rendering. See usage in the editing controller.
+		 *
+		 * @protected
+		 * @member {Boolean} module:engine/view/view~View#_disabledRendering
+		 */
+		this._disabledRendering = false;
+
 		/**
 		 * DowncastWriter instance used in {@link #change change method) callbacks.
 		 *
@@ -358,7 +366,7 @@ export default class View {
 		this.document._callPostFixers( this._writer );
 		this._postFixersInProgress = false;
 
-		if ( !this.disabledRendering ) {
+		if ( !this._disabledRendering ) {
 			this.fire( 'render' );
 		}
 	}