From a7fb56dcf9db6f01a53aaafcddcc0e6ecd19d1c4 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke <marijnh@gmail.com> Date: Mon, 23 Jul 2012 16:27:19 +0200 Subject: [PATCH] Test for end-of-line measurement bugs --- test/index.html | 1 + test/test.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/test/index.html b/test/index.html index 1f8559a5..d6a2d4c2 100644 --- a/test/index.html +++ b/test/index.html @@ -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;} diff --git a/test/test.js b/test/test.js index 54eeba58..49615142 100644 --- a/test/test.js +++ b/test/test.js @@ -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}); -- GitLab