@@ -8,10 +8,14 @@ import { ie, ie_version } from "../util/browser.js"
88export function updateHeightsInViewport ( cm ) {
99 let display = cm . display
1010 let prevBottom = display . lineDiv . offsetTop
11+ let viewTop = Math . max ( 0 , display . scroller . getBoundingClientRect ( ) . top )
12+ let oldHeight = display . lineDiv . getBoundingClientRect ( ) . top
13+ let mustScroll = 0
1114 for ( let i = 0 ; i < display . view . length ; i ++ ) {
1215 let cur = display . view [ i ] , wrapping = cm . options . lineWrapping
1316 let height , width = 0
1417 if ( cur . hidden ) continue
18+ oldHeight += cur . line . height
1519 if ( ie && ie_version < 8 ) {
1620 let bot = cur . node . offsetTop + cur . node . offsetHeight
1721 height = bot - prevBottom
@@ -26,6 +30,7 @@ export function updateHeightsInViewport(cm) {
2630 }
2731 let diff = cur . line . height - height
2832 if ( diff > .005 || diff < - .005 ) {
33+ if ( oldHeight < viewTop ) mustScroll -= diff
2934 updateLineHeight ( cur . line , height )
3035 updateWidgetHeight ( cur . line )
3136 if ( cur . rest ) for ( let j = 0 ; j < cur . rest . length ; j ++ )
@@ -40,6 +45,7 @@ export function updateHeightsInViewport(cm) {
4045 }
4146 }
4247 }
48+ if ( Math . abs ( mustScroll ) > 2 ) display . scroller . scrollTop += mustScroll
4349}
4450
4551// Read and store the height of line widgets associated with the
0 commit comments