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

Commit aba8e68

Browse files
authored
Merge pull request #1201 from ckeditor/t/ckeditor5/676
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.
2 parents 7e352e3 + 135a063 commit aba8e68

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/view/observer/focusobserver.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export default class FocusObserver extends DomEventObserver {
3535
// We need to wait until `SelectionObserver` handle the event and then render. Otherwise rendering will
3636
// overwrite new DOM selection with selection from the view.
3737
// See https://github.com/ckeditor/ckeditor5-engine/issues/795 for more details.
38-
this._renderTimeoutId = setTimeout( () => document.render(), 0 );
38+
// Long timeout is needed to solve #676 and https://github.com/ckeditor/ckeditor5-engine/issues/1157 issues.
39+
this._renderTimeoutId = setTimeout( () => document.render(), 50 );
3940
} );
4041

4142
document.on( 'blur', ( evt, data ) => {

tests/view/observer/focusobserver.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ describe( 'FocusObserver', () => {
115115
expect( viewDocument.isFocused ).to.be.true;
116116
} );
117117

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

122122
observer.onDomEvent( { type: 'focus', target: domMain } );
123123
sinon.assert.notCalled( renderSpy );
124-
clock.tick( 0 );
124+
clock.tick( 50 );
125125
sinon.assert.called( renderSpy );
126126

127127
clock.restore();
@@ -134,7 +134,7 @@ describe( 'FocusObserver', () => {
134134
observer.onDomEvent( { type: 'focus', target: domMain } );
135135
sinon.assert.notCalled( renderSpy );
136136
observer.destroy();
137-
clock.tick( 0 );
137+
clock.tick( 50 );
138138
sinon.assert.notCalled( renderSpy );
139139

140140
clock.restore();

0 commit comments

Comments
 (0)