Skip to content

Commit 8e146ce

Browse files
committed
make sure visibleLines doesn't return bogus range
1 parent d09d397 commit 8e146ce

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/codemirror.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ var CodeMirror = (function() {
604604

605605
function visibleLines() {
606606
var lh = lineHeight(), top = wrapper.scrollTop - paddingTop();
607-
return {from: Math.max(0, Math.floor(top / lh)),
607+
return {from: Math.min(lines.length, Math.max(0, Math.floor(top / lh))),
608608
to: Math.min(lines.length, Math.ceil((top + wrapper.clientHeight) / lh))};
609609
}
610610
// Uses a set of changes plus the current scroll position to
@@ -1043,7 +1043,7 @@ var CodeMirror = (function() {
10431043
function lineHeight() {
10441044
var nlines = lineDiv.childNodes.length;
10451045
if (nlines) return lineDiv.offsetHeight / nlines;
1046-
else return measure.offsetHeight || 1;
1046+
else return measure.firstChild.offsetHeight || 1;
10471047
}
10481048
function charWidth() {return (measure.firstChild.offsetWidth || 320) / 40;}
10491049
function paddingTop() {return lineSpace.offsetTop;}

0 commit comments

Comments
 (0)