Skip to content

Commit

Permalink
Test for end-of-line measurement bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Jul 23, 2012
1 parent 4e244d2 commit a7fb56d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/index.html
Expand Up @@ -5,6 +5,7 @@
<link rel="stylesheet" href="../lib/codemirror.css">
<script src="../lib/codemirror.js"></script>
<script src="../mode/javascript/javascript.js"></script>
<script src="../mode/xml/xml.js"></script>

<style type="text/css">
.ok {color: #090;}
Expand Down
19 changes: 19 additions & 0 deletions test/test.js
Expand Up @@ -465,3 +465,22 @@ testCM("wrappingAndResizing", function(cm) {
eqPos(pos, cm.coordsChar({x: coords.x + 2, y: coords.y + 2}));
});
});

testCM("measureEndOfLine", function(cm) {
cm.setSize(null, "auto");
var inner = cm.getWrapperElement().getElementsByClassName("CodeMirror-lines")[0].firstChild;
var w = 20, lh = inner.offsetHeight;
for (var step = 10;; w += step) {
cm.setSize(w);
if (inner.offsetHeight < 2.5 * lh) {
if (step == 10) { w -= 10; step = 1; }
else { break; }
}
}
cm.setValue(cm.getValue() + "\n\n");
var endPos = cm.charCoords({line: 0, ch: 18}, "local");
is(endPos.y > lh * .8, "not at top");
is(endPos.x > w - 20, "not at right");
endPos = cm.charCoords({line: 0, ch: 18});
eqPos(cm.coordsChar({x: endPos.x, y: endPos.y + 2}), {line: 0, ch: 18});
}, {mode: "text/html", value: "<!-- foo barrr -->", lineWrapping: true});

0 comments on commit a7fb56d

Please sign in to comment.