From afcbdb6b4cbbbd057706ff9e0eb4a4cec054c499 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke <marijnh@gmail.com> Date: Tue, 22 Apr 2014 10:23:01 +0200 Subject: [PATCH] Fix bug in posFromMouse for rectangular coords It was returning negative values in the ch field. Issue #2485 --- lib/codemirror.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/codemirror.js b/lib/codemirror.js index 63f83be77..138f10d22 100644 --- a/lib/codemirror.js +++ b/lib/codemirror.js @@ -2507,7 +2507,7 @@ var coords = coordsChar(cm, x, y), line; if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) { var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length; - coords = Pos(coords.line, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff); + coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff)); } return coords; } -- GitLab