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

Commit 7cf835e

Browse files
author
Piotr Jasiun
authored
Merge pull request #470 from ckeditor/t/ckeditor5/1530
Fix: Prevented from changing the view document during the render phase. Closes ckeditor/ckeditor5#1530.
2 parents f83c8cb + 280de36 commit 7cf835e

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/editableui/editableuiview.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,19 @@ export default class EditableUIView extends View {
121121
_updateIsFocusedClasses() {
122122
const editingView = this._editingView;
123123

124-
editingView.change( writer => {
125-
const viewRoot = editingView.document.getRoot( this.name );
124+
if ( editingView.isRenderingInProgress ) {
125+
editingView.once( 'change:isRenderingInProgress', () => update( this ) );
126+
} else {
127+
update( this );
128+
}
126129

127-
writer.addClass( this.isFocused ? 'ck-focused' : 'ck-blurred', viewRoot );
128-
writer.removeClass( this.isFocused ? 'ck-blurred' : 'ck-focused', viewRoot );
129-
} );
130+
function update( view ) {
131+
editingView.change( writer => {
132+
const viewRoot = editingView.document.getRoot( view.name );
133+
134+
writer.addClass( view.isFocused ? 'ck-focused' : 'ck-blurred', viewRoot );
135+
writer.removeClass( view.isFocused ? 'ck-blurred' : 'ck-focused', viewRoot );
136+
} );
137+
}
130138
}
131139
}

tests/editableui/editableuiview.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ describe( 'EditableUIView', () => {
7878
expect( editingViewRoot.hasClass( 'ck-focused' ) ).to.be.false;
7979
expect( editingViewRoot.hasClass( 'ck-blurred' ) ).to.be.true;
8080
} );
81+
82+
// https://github.com/ckeditor/ckeditor5/issues/1530.
83+
it( 'should work when update is handled during the rendering phase', () => {
84+
view.isFocused = true;
85+
editingView.isRenderingInProgress = true;
86+
87+
expect( editingViewRoot.hasClass( 'ck-focused' ) ).to.be.true;
88+
expect( editingViewRoot.hasClass( 'ck-blurred' ) ).to.be.false;
89+
90+
view.isFocused = false;
91+
92+
expect( editingViewRoot.hasClass( 'ck-focused' ) ).to.be.true;
93+
expect( editingViewRoot.hasClass( 'ck-blurred' ) ).to.be.false;
94+
95+
editingView.isRenderingInProgress = false;
96+
97+
expect( editingViewRoot.hasClass( 'ck-focused' ) ).to.be.false;
98+
expect( editingViewRoot.hasClass( 'ck-blurred' ) ).to.be.true;
99+
} );
81100
} );
82101
} );
83102

0 commit comments

Comments
 (0)