@@ -7,17 +7,26 @@ export function startObserving(sourcePane: HTMLElement, targetPane: HTMLElement)
77 return ;
88 }
99
10+ // Skip phantom scroll events where the editor didn't actually move
11+ states . lastSourceScrollTop = sourcePane . scrollTop ;
12+ const didScroll = ( ) => {
13+ if ( Math . abs ( sourcePane . scrollTop - states . lastSourceScrollTop ) < 0.5 ) {
14+ return ;
15+ }
16+
17+ states . lastSourceScrollTop = sourcePane . scrollTop ;
18+ syncScrollProgress ( sourcePane , targetPane ) ;
19+ } ;
20+
1021 if ( 'onscrollend' in window ) {
11- sourcePane . addEventListener ( 'scrollend' , ( ) => syncScrollProgress ( sourcePane , targetPane ) ) ;
22+ sourcePane . addEventListener ( 'scrollend' , didScroll ) ;
1223 } else {
1324 sourcePane . addEventListener ( 'scroll' , ( ) => {
1425 if ( states . scrollUpdater !== undefined ) {
1526 clearTimeout ( states . scrollUpdater ) ;
1627 }
1728
18- states . scrollUpdater = setTimeout ( ( ) => {
19- syncScrollProgress ( sourcePane , targetPane ) ;
20- } , 100 ) ;
29+ states . scrollUpdater = setTimeout ( didScroll , 100 ) ;
2130 } ) ;
2231 }
2332}
@@ -135,7 +144,9 @@ function clampProgressValue(value: number) {
135144}
136145
137146const states : {
147+ lastSourceScrollTop : number ;
138148 scrollUpdater : ReturnType < typeof setTimeout > | undefined ;
139149} = {
150+ lastSourceScrollTop : 0 ,
140151 scrollUpdater : undefined ,
141152} ;
0 commit comments