@@ -8,10 +8,14 @@ import { ie, ie_version } from "../util/browser.js"
8
8
export function updateHeightsInViewport ( cm ) {
9
9
let display = cm . display
10
10
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
11
14
for ( let i = 0 ; i < display . view . length ; i ++ ) {
12
15
let cur = display . view [ i ] , wrapping = cm . options . lineWrapping
13
16
let height , width = 0
14
17
if ( cur . hidden ) continue
18
+ oldHeight += cur . line . height
15
19
if ( ie && ie_version < 8 ) {
16
20
let bot = cur . node . offsetTop + cur . node . offsetHeight
17
21
height = bot - prevBottom
@@ -26,6 +30,7 @@ export function updateHeightsInViewport(cm) {
26
30
}
27
31
let diff = cur . line . height - height
28
32
if ( diff > .005 || diff < - .005 ) {
33
+ if ( oldHeight < viewTop ) mustScroll -= diff
29
34
updateLineHeight ( cur . line , height )
30
35
updateWidgetHeight ( cur . line )
31
36
if ( cur . rest ) for ( let j = 0 ; j < cur . rest . length ; j ++ )
@@ -40,6 +45,7 @@ export function updateHeightsInViewport(cm) {
40
45
}
41
46
}
42
47
}
48
+ if ( Math . abs ( mustScroll ) > 2 ) display . scroller . scrollTop += mustScroll
43
49
}
44
50
45
51
// Read and store the height of line widgets associated with the
0 commit comments