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

Commit

Permalink
Reverted changes from the #1657. Added mechanism basing directly on t…
Browse files Browse the repository at this point in the history
…he view changes.
  • Loading branch information
ma2ciek committed Feb 5, 2019
1 parent af95675 commit e185e76
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
6 changes: 2 additions & 4 deletions src/controller/editingcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ export default class EditingController {
this.view._renderingDisabled = true;
}, { priority: 'highest' } );

this.listenTo( this.model, '_afterChanges', ( evt, { hasModelDocumentChanged } ) => {
this.listenTo( this.model, '_afterChanges', () => {
this.view._renderingDisabled = false;
if ( hasModelDocumentChanged ) {
this.view.render();
}
this.view.render();
}, { priority: 'lowest' } );

// Whenever model document is changed, convert those changes to the view (using model.Document#differ).
Expand Down
4 changes: 2 additions & 2 deletions src/model/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ export default class Document {
}

/**
* Used to register a post-fixer callback. A post-fixer mechanism guarantees that the features that listen to
* the {@link module:engine/model/model~Model#event:_change model's change event} will operate on a correct model state.
* Used to register a post-fixer callback. A post-fixer mechanism guarantees that the features
* will operate on a correct model state.
*
* An execution of a feature may lead to an incorrect document tree state. The callbacks are used to fix the document tree after
* it has changed. Post-fixers are fired just after all changes from the outermost change block were applied but
Expand Down
8 changes: 1 addition & 7 deletions src/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,6 @@ export default class Model {
*/
_runPendingChanges() {
const ret = [];
let hasModelDocumentChanged = false;

this.fire( '_beforeChanges' );

Expand All @@ -696,9 +695,6 @@ 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.
hasModelDocumentChanged = hasModelDocumentChanged || this.document._hasDocumentChangedFromTheLastChangeBlock();

// Fire '_change' event before resetting differ.
this.fire( '_change', this._currentWriter );

Expand All @@ -708,7 +704,7 @@ export default class Model {
this._currentWriter = null;
}

this.fire( '_afterChanges', { hasModelDocumentChanged } );
this.fire( '_afterChanges' );

return ret;
}
Expand Down Expand Up @@ -739,8 +735,6 @@ export default class Model {
*
* @protected
* @event _afterChanges
* @param {Object} options
* @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.
*/

Expand Down
18 changes: 17 additions & 1 deletion src/view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export default class View {
*/
this._renderingDisabled = false;

this._hasChangedSinceTheLastRendering = false;

/**
* DowncastWriter instance used in {@link #change change method) callbacks.
*
Expand All @@ -163,6 +165,14 @@ export default class View {

// Informs that layout has changed after render.
this.document.fire( 'layoutChanged' );

// Reset the `_hasChangedSinceTheLastRendering` flag after rendering.
this._hasChangedSinceTheLastRendering = false;
} );

// Listen to the selection changes.
this.listenTo( this.document.selection, 'change', () => {
this._hasChangedSinceTheLastRendering = true;
} );
}

Expand Down Expand Up @@ -192,6 +202,10 @@ export default class View {
viewRoot.on( 'change:attributes', ( evt, node ) => this._renderer.markToSync( 'attributes', node ) );
viewRoot.on( 'change:text', ( evt, node ) => this._renderer.markToSync( 'text', node ) );

viewRoot.on( 'change', () => {
this._hasChangedSinceTheLastRendering = true;
} );

for ( const observer of this._observers.values() ) {
observer.observe( domRoot, name );
}
Expand Down Expand Up @@ -292,6 +306,7 @@ export default class View {
const editable = this.document.selection.editableElement;

if ( editable ) {
this._hasChangedSinceTheLastRendering = true;
this.domConverter.focus( editable );
this.render();
} else {
Expand Down Expand Up @@ -368,7 +383,8 @@ export default class View {

// This lock is used by editing controller to render changes from outer most model.change() once. As plugins might call
// view.change() inside model.change() block - this will ensures that postfixers and rendering are called once after all changes.
if ( !this._renderingDisabled ) {
// Also, we don't need to render anything if there're no changes since last rendering.
if ( !this._renderingDisabled && this._hasChangedSinceTheLastRendering ) {
this._postFixersInProgress = true;
this.document._callPostFixers( this._writer );
this._postFixersInProgress = false;
Expand Down

0 comments on commit e185e76

Please sign in to comment.