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

Commit cb18a95

Browse files
authored
Merge pull request #952 from ckeditor/t/951
Fix: `DomConverter` should actively prevent unwanted scrolling on focus. Closes #951. Closes #707. Closes #706.
2 parents d328811 + 7431a14 commit cb18a95

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/view/domconverter.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import ViewDocumentFragment from './documentfragment';
1818
import ViewTreeWalker from './treewalker';
1919
import { BR_FILLER, INLINE_FILLER_LENGTH, isBlockFiller, isInlineFiller, startsWithFiller, getDataWithoutFiller } from './filler';
2020

21+
import global from '@ckeditor/ckeditor5-utils/src/dom/global';
2122
import indexOf from '@ckeditor/ckeditor5-utils/src/dom/indexof';
2223
import getAncestors from '@ckeditor/ckeditor5-utils/src/dom/getancestors';
2324
import getCommonAncestor from '@ckeditor/ckeditor5-utils/src/dom/getcommonancestor';
@@ -734,7 +735,15 @@ export default class DomConverter {
734735
const domEditable = this.getCorrespondingDomElement( viewEditable );
735736

736737
if ( domEditable && domEditable.ownerDocument.activeElement !== domEditable ) {
738+
const { scrollX, scrollY } = global.window;
739+
const { scrollLeft, scrollTop } = domEditable;
740+
737741
domEditable.focus();
742+
743+
// https://github.com/ckeditor/ckeditor5-engine/issues/951
744+
domEditable.scrollLeft = scrollLeft;
745+
domEditable.scrollTop = scrollTop;
746+
global.window.scrollTo( scrollX, scrollY );
738747
}
739748
}
740749

tests/view/domconverter/domconverter.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ViewEditable from '../../../src/view/editableelement';
1010
import ViewDocument from '../../../src/view/document';
1111
import { BR_FILLER, NBSP_FILLER } from '../../../src/view/filler';
1212
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
13+
import global from '@ckeditor/ckeditor5-utils/src/dom/global';
1314

1415
testUtils.createSinonSandbox();
1516

@@ -66,6 +67,32 @@ describe( 'DomConverter', () => {
6667

6768
expect( focusSpy.calledOnce ).to.be.true;
6869
} );
70+
71+
// https://github.com/ckeditor/ckeditor5-engine/issues/951
72+
it( 'should actively prevent window scroll in WebKit', () => {
73+
const scrollToSpy = testUtils.sinon.stub( global.window, 'scrollTo' );
74+
const scrollLeftSpy = sinon.spy();
75+
const scrollTopSpy = sinon.spy();
76+
77+
Object.defineProperties( domEditable, {
78+
scrollLeft: {
79+
get: () => 20,
80+
set: scrollLeftSpy
81+
},
82+
scrollTop: {
83+
get: () => 200,
84+
set: scrollTopSpy
85+
}
86+
} );
87+
88+
global.window.scrollX = 10;
89+
global.window.scrollY = 100;
90+
91+
converter.focus( viewEditable );
92+
sinon.assert.calledWithExactly( scrollToSpy, 10, 100 );
93+
sinon.assert.calledWithExactly( scrollLeftSpy, 20 );
94+
sinon.assert.calledWithExactly( scrollTopSpy, 200 );
95+
} );
6996
} );
7097

7198
describe( 'DOM nodes type checking', () => {

0 commit comments

Comments
 (0)