File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ class Selection {
86
86
87
87
focus ( ) {
88
88
if ( this . hasFocus ( ) ) return ;
89
- this . root . focus ( ) ;
89
+ this . root . focus ( { preventScroll : true } ) ;
90
90
this . setRange ( this . savedRange ) ;
91
91
}
92
92
@@ -318,7 +318,7 @@ class Selection {
318
318
const selection = document . getSelection ( ) ;
319
319
if ( selection == null ) return ;
320
320
if ( startNode != null ) {
321
- if ( ! this . hasFocus ( ) ) this . root . focus ( ) ;
321
+ if ( ! this . hasFocus ( ) ) this . root . focus ( { preventScroll : true } ) ;
322
322
const { native } = this . getNativeRange ( ) || { } ;
323
323
if (
324
324
native == null
Original file line number Diff line number Diff line change @@ -41,6 +41,24 @@ describe('Selection', function () {
41
41
} ) ;
42
42
} ) ;
43
43
44
+ describe ( 'focusing should not trigger scroll' , function ( ) {
45
+ beforeEach ( function ( ) {
46
+ this . initialize ( HTMLElement , '<div></div>' ) ;
47
+ this . selection = this . initialize ( Selection , '<p>0123</p>' , this . container ) ;
48
+ spyOn ( this . selection . root , 'focus' ) . and . callThrough ( ) ;
49
+ } ) ;
50
+
51
+ it ( 'on focus method call (T1297029)' , function ( ) {
52
+ this . selection . focus ( ) ;
53
+ expect ( this . selection . root . focus ) . toHaveBeenCalledOnceWith ( { preventScroll : true } ) ;
54
+ } ) ;
55
+
56
+ it ( 'on setNativeRange method call' , function ( ) {
57
+ this . selection . setNativeRange ( this . container . firstChild , 0 ) ;
58
+ expect ( this . selection . root . focus ) . toHaveBeenCalledOnceWith ( { preventScroll : true } ) ;
59
+ } ) ;
60
+ } ) ;
61
+
44
62
describe ( 'getRange()' , function ( ) {
45
63
it ( 'empty document' , function ( ) {
46
64
const selection = this . initialize ( Selection , '' ) ;
You can’t perform that action at this time.
0 commit comments