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

Add a 50ms timeout after document#focus event before rendering #1201

Merged
merged 1 commit into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/view/observer/focusobserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default class FocusObserver extends DomEventObserver {
// We need to wait until `SelectionObserver` handle the event and then render. Otherwise rendering will
// overwrite new DOM selection with selection from the view.
// See https://github.com/ckeditor/ckeditor5-engine/issues/795 for more details.
this._renderTimeoutId = setTimeout( () => document.render(), 0 );
// Long timeout is needed to solve #676 and https://github.com/ckeditor/ckeditor5-engine/issues/1157 issues.
this._renderTimeoutId = setTimeout( () => document.render(), 50 );
} );

document.on( 'blur', ( evt, data ) => {
Expand Down
6 changes: 3 additions & 3 deletions tests/view/observer/focusobserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ describe( 'FocusObserver', () => {
expect( viewDocument.isFocused ).to.be.true;
} );

it( 'should delay rendering to the next iteration of event loop', () => {
it( 'should delay rendering by 50ms', () => {
const renderSpy = sinon.spy( viewDocument, 'render' );
const clock = sinon.useFakeTimers();

observer.onDomEvent( { type: 'focus', target: domMain } );
sinon.assert.notCalled( renderSpy );
clock.tick( 0 );
clock.tick( 50 );
sinon.assert.called( renderSpy );

clock.restore();
Expand All @@ -134,7 +134,7 @@ describe( 'FocusObserver', () => {
observer.onDomEvent( { type: 'focus', target: domMain } );
sinon.assert.notCalled( renderSpy );
observer.destroy();
clock.tick( 0 );
clock.tick( 50 );
sinon.assert.notCalled( renderSpy );

clock.restore();
Expand Down