Skip to content

Commit

Permalink
make sure visibleLines doesn't return bogus range
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Mar 26, 2011
1 parent d09d397 commit 8e146ce
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ var CodeMirror = (function() {

function visibleLines() {
var lh = lineHeight(), top = wrapper.scrollTop - paddingTop();
return {from: Math.max(0, Math.floor(top / lh)),
return {from: Math.min(lines.length, Math.max(0, Math.floor(top / lh))),
to: Math.min(lines.length, Math.ceil((top + wrapper.clientHeight) / lh))};
}
// Uses a set of changes plus the current scroll position to
Expand Down Expand Up @@ -1043,7 +1043,7 @@ var CodeMirror = (function() {
function lineHeight() {
var nlines = lineDiv.childNodes.length;
if (nlines) return lineDiv.offsetHeight / nlines;
else return measure.offsetHeight || 1;
else return measure.firstChild.offsetHeight || 1;
}
function charWidth() {return (measure.firstChild.offsetWidth || 320) / 40;}
function paddingTop() {return lineSpace.offsetTop;}
Expand Down

0 comments on commit 8e146ce

Please sign in to comment.