(cm)
| 761 | |
| 762 | // Highlight selection |
| 763 | function updateSelectionRange(cm) { |
| 764 | var display = cm.display, doc = cm.doc, sel = cm.doc.sel; |
| 765 | var fragment = document.createDocumentFragment(); |
| 766 | var clientWidth = display.lineSpace.offsetWidth, pl = paddingLeft(cm.display); |
| 767 | |
| 768 | function add(left, top, width, bottom) { |
| 769 | if (top < 0) top = 0; |
| 770 | fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left + |
| 771 | "px; top: " + top + "px; width: " + (width == null ? clientWidth - left : width) + |
| 772 | "px; height: " + (bottom - top) + "px")); |
| 773 | } |
| 774 | |
| 775 | function drawForLine(line, fromArg, toArg, retTop) { |
| 776 | var lineObj = getLine(doc, line); |
| 777 | var lineLen = lineObj.text.length, rVal = retTop ? Infinity : -Infinity; |
| 778 | function coords(ch) { |
| 779 | return charCoords(cm, Pos(line, ch), "div", lineObj); |
| 780 | } |
| 781 | |
| 782 | iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) { |
| 783 | var leftPos = coords(dir == "rtl" ? to - 1 : from); |
| 784 | var rightPos = coords(dir == "rtl" ? from : to - 1); |
| 785 | var left = leftPos.left, right = rightPos.right; |
| 786 | if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part |
| 787 | add(left, leftPos.top, null, leftPos.bottom); |
| 788 | left = pl; |
| 789 | if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top); |
| 790 | } |
| 791 | if (toArg == null && to == lineLen) right = clientWidth; |
| 792 | if (fromArg == null && from == 0) left = pl; |
| 793 | rVal = retTop ? Math.min(rightPos.top, rVal) : Math.max(rightPos.bottom, rVal); |
| 794 | if (left < pl + 1) left = pl; |
| 795 | add(left, rightPos.top, right - left, rightPos.bottom); |
| 796 | }); |
| 797 | return rVal; |
| 798 | } |
| 799 | |
| 800 | if (sel.from.line == sel.to.line) { |
| 801 | drawForLine(sel.from.line, sel.from.ch, sel.to.ch); |
| 802 | } else { |
| 803 | var fromObj = getLine(doc, sel.from.line); |
| 804 | var cur = fromObj, merged, path = [sel.from.line, sel.from.ch], singleLine; |
| 805 | while (merged = collapsedSpanAtEnd(cur)) { |
| 806 | var found = merged.find(); |
| 807 | path.push(found.from.ch, found.to.line, found.to.ch); |
| 808 | if (found.to.line == sel.to.line) { |
| 809 | path.push(sel.to.ch); |
| 810 | singleLine = true; |
| 811 | break; |
| 812 | } |
| 813 | cur = getLine(doc, found.to.line); |
| 814 | } |
| 815 | |
| 816 | // This is a single, merged line |
| 817 | if (singleLine) { |
| 818 | for (var i = 0; i < path.length; i += 3) |
| 819 | drawForLine(path[i], path[i+1], path[i+2]); |
| 820 | } else { |
no test coverage detected