Skip to content

Commit

Permalink
ff mac does not have integer charwidth. compensate for this
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Feb 18, 2011
1 parent 569a3d0 commit c9d8817
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ var CodeMirror = (function() {
div.className = "CodeMirror";
div.innerHTML =
'<div style="position: relative">' +
'<pre style="position: absolute; visibility: hidden"><span>-</span></pre>' +
'<pre style="position: absolute; visibility: hidden">' +
'<span>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</span></pre>' +
'<div style="position: relative">' +
'<div class="CodeMirror-gutter"></div>' +
'<div style="overflow: hidden; position: absolute; width: 0">' +
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;}

Expand Down

0 comments on commit c9d8817

Please sign in to comment.