Skip to content

Commit

Permalink
Use 'width' instead of 'right' style to draw selection
Browse files Browse the repository at this point in the history
Closes #745
  • Loading branch information
marijnh committed Sep 18, 2012
1 parent dc4a247 commit 314e7ea
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ window.CodeMirror = (function() {
var ie = /MSIE \d/.test(navigator.userAgent);
var ie_lt8 = /MSIE [1-7]\b/.test(navigator.userAgent);
var ie_lt9 = /MSIE [1-8]\b/.test(navigator.userAgent);
var quirksMode = ie && document.documentMode == 5;
var webkit = /WebKit\//.test(navigator.userAgent);
var chrome = /Chrome\//.test(navigator.userAgent);
var opera = /Opera\//.test(navigator.userAgent);
Expand Down Expand Up @@ -582,13 +581,12 @@ window.CodeMirror = (function() {
} else {
headPos = cursorCoords(cm, selHead(cm.view), "div");
var fragment = document.createDocumentFragment();
var clientWidth = display.lineSpace.clientWidth || display.lineSpace.offsetWidth;
var add = function(left, top, right, bottom) {
var clientWidth = display.lineSpace.clientWidth;
var add = function(left, top, width, bottom) {
if (top < 0) top = 0;
var rstyle = quirksMode ? "width: " + (!right ? clientWidth : clientWidth - right - left) + "px"
: "right: " + right + "px";
fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
"px; top: " + top + "px; " + rstyle + "; height: " + (bottom - top) + "px"));
"px; top: " + top + "px; width: " + (width == null ? clientWidth : width) +
"px; height: " + (bottom - top) + "px"));
};

var middleFrom = sel.from.line + 1, middleTo = sel.to.line - 1, sameLine = sel.from.line == sel.to.line;
Expand All @@ -601,13 +599,13 @@ window.CodeMirror = (function() {
var rightPos = coords(dir == "rtl" ? from : to - 1);
var left = leftPos.left, right = rightPos.right;
if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
add(left, leftPos.top, 0, leftPos.bottom);
add(left, leftPos.top, null, leftPos.bottom);
left = paddingLeft(display);
if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, 0, rightPos.top);
if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
}
if (toArg == null && to == lineLen) right = clientWidth;
rVal = retTop ? Math.min(rightPos.top, rVal) : Math.max(rightPos.bottom, rVal);
add(left, rightPos.top, clientWidth - right, rightPos.bottom);
add(left, rightPos.top, right - left, rightPos.bottom);
});
return rVal;
};
Expand All @@ -634,7 +632,7 @@ window.CodeMirror = (function() {
middleTop = Math.min(middleTop, top.top);
middleBot = Math.max(middleBot, bottom.bottom);
}
if (middleTop < middleBot) add(paddingLeft(display), middleTop, 0, middleBot);
if (middleTop < middleBot) add(paddingLeft(display), middleTop, null, middleBot);

removeChildrenAndAdd(display.selectionDiv, fragment);
display.cursor.style.display = display.otherCursor.style.display = "none";
Expand Down

0 comments on commit 314e7ea

Please sign in to comment.