Skip to content

Commit

Permalink
Switch measureLine over to getBoundingClientRect
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Sep 18, 2012
1 parent b57f74d commit dc4a247
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion doc/upgrade_v3.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h2 id=gutters>Gutter model</h2>
Gutter markers are now specified as DOM nodes, rather than HTML
snippets.</p>

<p>The gutters no longer horizontally scroll along with the content.
<p>The gutters no longer horizontally scrolls along with the content.
The <code>fixedGutter</code> option was removed (since it is now the
only behavior).</p>

Expand Down
15 changes: 8 additions & 7 deletions lib/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,30 +744,31 @@ window.CodeMirror = (function() {
var atEnd = ch && ch == line.text.length;
var pre = lineContent(cm, line, atEnd ? ch - 1 : ch);
removeChildrenAndAdd(display.measure, pre);
var anchor = pre.anchor;
var anchor = pre.anchor, outer = anchor.offsetParent.getBoundingClientRect();
// We'll sample once at the top, once at the bottom of the line,
// to get the real line height (in case there tokens on the line
// with bigger fonts)
anchor.style.verticalAlign = "top";
var left = anchor.offsetLeft, right = left + anchor.offsetWidth;
var box1 = anchor.getBoundingClientRect(), left = box1.left - outer.left, right = box1.right - outer.left;
if (ie) {
var left1 = anchor.offsetLeft;
// In IE, verticalAlign does not influence offsetTop, unless
// the element is an inline-block. Unfortunately, inline
// blocks have different wrapping behaviour, so we have to do
// some icky thing with inserting "Zero-Width No-Break Spaces"
// to compensate for wrapping artifacts.
anchor.style.display = "inline-block";
if (wrapping && anchor.offsetLeft != left) {
if (wrapping && anchor.offsetLeft != left1) {
anchor.parentNode.insertBefore(document.createTextNode("\ufeff"), anchor);
if (anchor.offsetLeft != left)
if (anchor.offsetLeft != left1)
anchor.parentNode.insertBefore(document.createTextNode("\ufeff"), anchor.nextSibling);
if (anchor.offsetLeft != left)
if (anchor.offsetLeft != left1)
anchor.parentNode.removeChild(anchor.previousSibling);
}
}
var top = Math.max(0, anchor.offsetTop);
var top = Math.max(0, box1.top - outer.top);
anchor.style.verticalAlign = "bottom";
var bottom = Math.min(anchor.offsetTop + anchor.offsetHeight, pre.offsetHeight);
var bottom = Math.min(anchor.getBoundingClientRect().bottom - outer.top, pre.offsetHeight);
if (atEnd) left = right;

// Store result in the cache
Expand Down

0 comments on commit dc4a247

Please sign in to comment.