Skip to content

Commit 8bf1962

Browse files
ddnexusmarijnh
authored andcommitted
better vertical adjustment in scrollIntoView
1 parent c1c26ec commit 8bf1962

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/codemirror.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,11 @@ var CodeMirror = (function() {
620620
return scrollIntoView(cursor.x, cursor.y, cursor.x, cursor.yBot);
621621
}
622622
function scrollIntoView(x1, y1, x2, y2) {
623-
var pl = paddingLeft(), pt = paddingTop();
623+
var pl = paddingLeft(), pt = paddingTop(), lh = lineHeight();
624624
y1 += pt; y2 += pt; x1 += pl; x2 += pl;
625625
var screen = wrapper.clientHeight, screentop = wrapper.scrollTop, scrolled = false, result = true;
626-
if (y1 < screentop) {wrapper.scrollTop = Math.max(0, y1 - 10); scrolled = true;}
627-
else if (y2 > screentop + screen) {wrapper.scrollTop = y2 + 10 - screen; scrolled = true;}
626+
if (y1 < screentop) {wrapper.scrollTop = Math.max(0, y1 - 2*lh); scrolled = true;}
627+
else if (y2 > screentop + screen) {wrapper.scrollTop = y2 + lh - screen; scrolled = true;}
628628

629629
var screenw = wrapper.clientWidth, screenleft = wrapper.scrollLeft;
630630
if (x1 < screenleft) {wrapper.scrollLeft = Math.max(0, x1 - 10); scrolled = true;}
@@ -1698,7 +1698,7 @@ var CodeMirror = (function() {
16981698
mark = (markpos < marked.length) ? marked[markpos] : null;
16991699
}
17001700
}
1701-
nextMark();
1701+
nextMark();
17021702
while (pos < len) {
17031703
var upto = len;
17041704
var extraStyle = "";

0 commit comments

Comments
 (0)