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

Commit

Permalink
Merge pull request #470 from ckeditor/t/ckeditor5/1530
Browse files Browse the repository at this point in the history
Fix: Prevented from changing the view document during the render phase. Closes ckeditor/ckeditor5#1530.
  • Loading branch information
Piotr Jasiun authored Feb 18, 2019
2 parents f83c8cb + 280de36 commit 7cf835e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/editableui/editableuiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,19 @@ export default class EditableUIView extends View {
_updateIsFocusedClasses() {
const editingView = this._editingView;

editingView.change( writer => {
const viewRoot = editingView.document.getRoot( this.name );
if ( editingView.isRenderingInProgress ) {
editingView.once( 'change:isRenderingInProgress', () => update( this ) );
} else {
update( this );
}

writer.addClass( this.isFocused ? 'ck-focused' : 'ck-blurred', viewRoot );
writer.removeClass( this.isFocused ? 'ck-blurred' : 'ck-focused', viewRoot );
} );
function update( view ) {
editingView.change( writer => {
const viewRoot = editingView.document.getRoot( view.name );

writer.addClass( view.isFocused ? 'ck-focused' : 'ck-blurred', viewRoot );
writer.removeClass( view.isFocused ? 'ck-blurred' : 'ck-focused', viewRoot );
} );
}
}
}
19 changes: 19 additions & 0 deletions tests/editableui/editableuiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ describe( 'EditableUIView', () => {
expect( editingViewRoot.hasClass( 'ck-focused' ) ).to.be.false;
expect( editingViewRoot.hasClass( 'ck-blurred' ) ).to.be.true;
} );

// https://github.com/ckeditor/ckeditor5/issues/1530.
it( 'should work when update is handled during the rendering phase', () => {
view.isFocused = true;
editingView.isRenderingInProgress = true;

expect( editingViewRoot.hasClass( 'ck-focused' ) ).to.be.true;
expect( editingViewRoot.hasClass( 'ck-blurred' ) ).to.be.false;

view.isFocused = false;

expect( editingViewRoot.hasClass( 'ck-focused' ) ).to.be.true;
expect( editingViewRoot.hasClass( 'ck-blurred' ) ).to.be.false;

editingView.isRenderingInProgress = false;

expect( editingViewRoot.hasClass( 'ck-focused' ) ).to.be.false;
expect( editingViewRoot.hasClass( 'ck-blurred' ) ).to.be.true;
} );
} );
} );

Expand Down

0 comments on commit 7cf835e

Please sign in to comment.