(cm)
| 820 | |
| 821 | // Highlight selection |
| 822 | function updateSelectionRange(cm) { |
| 823 | var display = cm.display, doc = cm.doc, sel = cm.doc.sel; |
| 824 | var fragment = document.createDocumentFragment(); |
| 825 | var padding = paddingH(cm.display), leftSide = padding.left, rightSide = display.lineSpace.offsetWidth - padding.right; |
| 826 | |
| 827 | function add(left, top, width, bottom) { |
| 828 | if (top < 0) top = 0; |
| 829 | fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left + |
| 830 | "px; top: " + top + "px; width: " + (width == null ? rightSide - left : width) + |
| 831 | "px; height: " + (bottom - top) + "px")); |
| 832 | } |
| 833 | |
| 834 | function drawForLine(line, fromArg, toArg) { |
| 835 | var lineObj = getLine(doc, line); |
| 836 | var lineLen = lineObj.text.length; |
| 837 | var start, end; |
| 838 | function coords(ch, bias) { |
| 839 | return charCoords(cm, Pos(line, ch), "div", lineObj, bias); |
| 840 | } |
| 841 | |
| 842 | iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) { |
| 843 | var leftPos = coords(from, "left"), rightPos, left, right; |
| 844 | if (from == to) { |
| 845 | rightPos = leftPos; |
| 846 | left = right = leftPos.left; |
| 847 | } else { |
| 848 | rightPos = coords(to - 1, "right"); |
| 849 | if (dir == "rtl") { var tmp = leftPos; leftPos = rightPos; rightPos = tmp; } |
| 850 | left = leftPos.left; |
| 851 | right = rightPos.right; |
| 852 | } |
| 853 | if (fromArg == null && from == 0) left = leftSide; |
| 854 | if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part |
| 855 | add(left, leftPos.top, null, leftPos.bottom); |
| 856 | left = leftSide; |
| 857 | if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top); |
| 858 | } |
| 859 | if (toArg == null && to == lineLen) right = rightSide; |
| 860 | if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left) |
| 861 | start = leftPos; |
| 862 | if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right) |
| 863 | end = rightPos; |
| 864 | if (left < leftSide + 1) left = leftSide; |
| 865 | add(left, rightPos.top, right - left, rightPos.bottom); |
| 866 | }); |
| 867 | return {start: start, end: end}; |
| 868 | } |
| 869 | |
| 870 | if (sel.from.line == sel.to.line) { |
| 871 | drawForLine(sel.from.line, sel.from.ch, sel.to.ch); |
| 872 | } else { |
| 873 | var fromLine = getLine(doc, sel.from.line), toLine = getLine(doc, sel.to.line); |
| 874 | var singleVLine = visualLine(doc, fromLine) == visualLine(doc, toLine); |
| 875 | var leftEnd = drawForLine(sel.from.line, sel.from.ch, singleVLine ? fromLine.text.length : null).end; |
| 876 | var rightStart = drawForLine(sel.to.line, singleVLine ? 0 : null, sel.to.ch).start; |
| 877 | if (singleVLine) { |
| 878 | if (leftEnd.top < rightStart.top - 2) { |
| 879 | add(leftEnd.right, leftEnd.top, null, leftEnd.bottom); |
no test coverage detected