Skip to content

Commit

Permalink
Smooth out scroll artifacts produced by line height changes
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Aug 26, 2021
1 parent 070b1ba commit 7f35cf7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/display/update_lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import { ie, ie_version } from "../util/browser.js"
export function updateHeightsInViewport(cm) {
let display = cm.display
let prevBottom = display.lineDiv.offsetTop
let viewTop = Math.max(0, display.scroller.getBoundingClientRect().top)
let oldHeight = display.lineDiv.getBoundingClientRect().top
let mustScroll = 0
for (let i = 0; i < display.view.length; i++) {
let cur = display.view[i], wrapping = cm.options.lineWrapping
let height, width = 0
if (cur.hidden) continue
oldHeight += cur.line.height
if (ie && ie_version < 8) {
let bot = cur.node.offsetTop + cur.node.offsetHeight
height = bot - prevBottom
Expand All @@ -26,6 +30,7 @@ export function updateHeightsInViewport(cm) {
}
let diff = cur.line.height - height
if (diff > .005 || diff < -.005) {
if (oldHeight < viewTop) mustScroll -= diff
updateLineHeight(cur.line, height)
updateWidgetHeight(cur.line)
if (cur.rest) for (let j = 0; j < cur.rest.length; j++)
Expand All @@ -40,6 +45,7 @@ export function updateHeightsInViewport(cm) {
}
}
}
if (Math.abs(mustScroll) > 2) display.scroller.scrollTop += mustScroll
}

// Read and store the height of line widgets associated with the
Expand Down

0 comments on commit 7f35cf7

Please sign in to comment.