File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change 11import $ from 'jquery'
22import rangy from 'rangy'
3+ import viewport from './util/viewport'
34
45import * as content from './content'
56import * as parser from './parser'
@@ -92,7 +93,9 @@ export default class Cursor {
9293 // Without setting focus() Firefox is not happy (seems setting a selection is not enough.
9394 // Probably because Firefox can handle multiple selections).
9495 if ( this . win . document . activeElement !== this . host ) {
96+ const { x, y} = viewport . getScrollPosition ( this . win )
9597 $ ( this . host ) . focus ( )
98+ this . win . scrollTo ( x , y )
9699 }
97100 rangy . getSelection ( this . win ) . setSingleRange ( this . range )
98101 }
@@ -140,12 +143,9 @@ export default class Cursor {
140143 const coords = this . range . nativeRange . getBoundingClientRect ( )
141144 if ( positioning === 'fixed' ) return coords
142145
143- // code from mdn: https://developer.mozilla.org/en-US/docs/Web/API/window.scrollX
144- const win = this . win
145- const x = ( win . pageXOffset !== undefined ) ? win . pageXOffset : ( win . document . documentElement || win . document . body . parentNode || win . document . body ) . scrollLeft
146- const y = ( win . pageYOffset !== undefined ) ? win . pageYOffset : ( win . document . documentElement || win . document . body . parentNode || win . document . body ) . scrollTop
147146
148147 // translate into absolute positions
148+ const { x, y} = viewport . getScrollPosition ( this . win )
149149 return {
150150 top : coords . top + y ,
151151 bottom : coords . bottom + y ,
Original file line number Diff line number Diff line change 1+ // code from mdn: https://developer.mozilla.org/en-US/docs/Web/API/window.scrollX
2+ export function getScrollPosition ( win ) {
3+ const x = ( win . pageXOffset !== undefined ) ? win . pageXOffset : ( win . document . documentElement || win . document . body . parentNode || win . document . body ) . scrollLeft
4+ const y = ( win . pageYOffset !== undefined ) ? win . pageYOffset : ( win . document . documentElement || win . document . body . parentNode || win . document . body ) . scrollTop
5+ return { x, y}
6+ }
You can’t perform that action at this time.
0 commit comments