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 #1201 from ckeditor/t/ckeditor5/676
Browse files Browse the repository at this point in the history
Fix: Added a 50ms timeout after `Document#focus` event before rendering to be sure that selection changes are processed on Firefox and Safari. Closes ckeditor/ckeditor5#676. Closes #1157. Closes #1155. Closes #1153.
  • Loading branch information
szymonkups authored Dec 12, 2017
2 parents 7e352e3 + 135a063 commit aba8e68
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
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

0 comments on commit aba8e68

Please sign in to comment.