Skip to content

Commit

Permalink
Clip negative scroll-to coordinates
Browse files Browse the repository at this point in the history
Closes #6139
  • Loading branch information
marijnh committed Feb 7, 2020
1 parent 5f72273 commit 72988bf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/display/scrolling.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export function updateScrollTop(cm, val) {
}

export function setScrollTop(cm, val, forceScroll) {
val = Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val)
val = Math.max(0, Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val))
if (cm.display.scroller.scrollTop == val && !forceScroll) return
cm.doc.scrollTop = val
cm.display.scrollbars.setScrollTop(val)
Expand All @@ -175,7 +175,7 @@ export function setScrollTop(cm, val, forceScroll) {
// Sync scroller and scrollbar, ensure the gutter elements are
// aligned.
export function setScrollLeft(cm, val, isScroller, forceScroll) {
val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth)
val = Math.max(0, Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth))
if ((isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) && !forceScroll) return
cm.doc.scrollLeft = val
alignHorizontally(cm)
Expand Down

0 comments on commit 72988bf

Please sign in to comment.