From c9d8817a296d21ae2fc79d55bef5310c301e4f12 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Fri, 18 Feb 2011 11:06:23 +0100 Subject: [PATCH] ff mac does not have integer charwidth. compensate for this --- lib/codemirror.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/codemirror.js b/lib/codemirror.js index 1dca8ff20a..3f3c89d9fd 100644 --- a/lib/codemirror.js +++ b/lib/codemirror.js @@ -372,7 +372,8 @@ var CodeMirror = (function() { div.className = "CodeMirror"; div.innerHTML = '
' + - '
-
' + + '
' + 
+           'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
' + '
' + '
' + '
' + @@ -1133,12 +1134,13 @@ var CodeMirror = (function() { } function charX(line, pos) { - var text = lines[line].text; + var text = lines[line].text, span = measure.firstChild; if (text.lastIndexOf("\t", pos) == -1) return pos * charWidth(); + var old = span.firstChild.nodeValue; try { - measure.firstChild.firstChild.nodeValue = text.slice(0, pos); - return measure.firstChild.offsetWidth; - } finally {measure.firstChild.firstChild.nodeValue = "-";} + span.firstChild.nodeValue = text.slice(0, pos); + return span.offsetWidth; + } finally {span.firstChild.nodeValue = old;} } function charFromX(line, x) { var text = lines[line].text, cw = charWidth(); @@ -1169,7 +1171,7 @@ var CodeMirror = (function() { if (nlines) return lineDiv.offsetHeight / nlines; else return measure.offsetHeight || 1; } - function charWidth() {return measure.firstChild.offsetWidth || 1;} + function charWidth() {return (measure.firstChild.offsetWidth || 320) / 40;} function paddingTop() {return lineWrap.offsetTop;} function paddingLeft() {return lineWrap.offsetLeft;}