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

Commit 2f5af98

Browse files
author
Piotr Jasiun
authored
Merge pull request #1569 from ckeditor/t/1564
Other: View post-fixer should be called once while rendering model changes. Closes #1564. BREAKING CHANGE: View post-fixers are now called once while rendering model changes.
2 parents 9b95a8a + abfd48b commit 2f5af98

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/view/view.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,13 @@ export default class View {
361361
callback( this._writer );
362362
this._ongoingChange = false;
363363

364-
// Execute all document post-fixers after the change.
365-
this._postFixersInProgress = true;
366-
this.document._callPostFixers( this._writer );
367-
this._postFixersInProgress = false;
368-
364+
// This lock is used by editing controller to render changes from outer most model.change() once. As plugins might call
365+
// view.change() inside model.change() block - this will ensures that postfixers and rendering are called once after all changes.
369366
if ( !this._renderingDisabled ) {
367+
this._postFixersInProgress = true;
368+
this.document._callPostFixers( this._writer );
369+
this._postFixersInProgress = false;
370+
370371
this.fire( 'render' );
371372
}
372373
}

tests/controller/editingcontroller.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,22 @@ describe( 'EditingController', () => {
431431
expect( changeListenerSpy.calledOnce ).to.be.true;
432432
} );
433433

434+
it( 'should call view post-fixers once for model.change() block', () => {
435+
const postfixerSpy = sinon.spy();
436+
437+
editing.view.document.registerPostFixer( postfixerSpy );
438+
439+
model.change( writer => {
440+
executeSomeModelChange( writer );
441+
442+
editing.view.change( writer => {
443+
executeSomeViewChange( writer );
444+
} );
445+
} );
446+
447+
sinon.assert.calledOnce( postfixerSpy );
448+
} );
449+
434450
function executeSomeModelChange( writer ) {
435451
const range = new ModelRange( new ModelPosition( modelRoot, [ 0, 1 ] ), new ModelPosition( modelRoot, [ 2, 2 ] ) );
436452
writer.addMarker( 'marker1', { range, usingOperation: true } );

0 commit comments

Comments
 (0)