From 7ac539823fc6d08f83ba64aa29a92a287f83f1db Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Fri, 10 Aug 2012 13:34:41 +0200 Subject: [PATCH] Fix bug in coordsChar Page-up would sometimes scroll all the way to the top even though it shouldn't, because of a poorly chosen check in coordsChar. The new check should no longer get false positives. --- lib/codemirror.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/codemirror.js b/lib/codemirror.js index 8c37cbc67e..ae569c7e74 100644 --- a/lib/codemirror.js +++ b/lib/codemirror.js @@ -1707,8 +1707,8 @@ var CodeMirror = (function() { } // Coords must be lineSpace-local function coordsChar(x, y) { - if (y < 0) return {line: 0, ch: 0}; var th = textHeight(), cw = charWidth(), heightPos = displayOffset + Math.floor(y / th); + if (heightPos < 0) return {line: 0, ch: 0}; var lineNo = lineAtHeight(doc, heightPos); if (lineNo >= doc.size) return {line: doc.size - 1, ch: getLine(doc.size - 1).text.length}; var lineObj = getLine(lineNo), text = lineObj.text;