Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make calculateScrollPos behave sanely when object doesn't fit into view

  • Loading branch information...
commit 6cf4289de7e5295bd8dc5ee796d0e2bce8f4cbb1 1 parent f15a14e
@marijnh marijnh authored
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/codemirror.js
View
9 lib/codemirror.js
@@ -2530,11 +2530,16 @@ window.CodeMirror = (function() {
function calculateScrollPos(cm, x1, y1, x2, y2) {
var display = cm.display, pt = paddingTop(display);
y1 += pt; y2 += pt;
+ if (y1 < 0) y1 = 0;
var screen = display.scroller.clientHeight - scrollerCutOff, screentop = display.scroller.scrollTop, result = {};
var docBottom = cm.doc.height + paddingVert(display);
var atTop = y1 < pt + 10, atBottom = y2 + pt > docBottom - 10;
- if (y1 < screentop) result.scrollTop = atTop ? 0 : Math.max(0, y1);
- else if (y2 > screentop + screen) result.scrollTop = (atBottom ? docBottom : y2) - screen;
+ if (y1 < screentop) {
+ result.scrollTop = atTop ? 0 : y1;
+ } else if (y2 > screentop + screen) {
+ var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen);
+ if (newTop != screentop) result.scrollTop = newTop;
+ }
var screenw = display.scroller.clientWidth - scrollerCutOff, screenleft = display.scroller.scrollLeft;
x1 += display.gutters.offsetWidth; x2 += display.gutters.offsetWidth;
Please sign in to comment.
Something went wrong with that request. Please try again.