MCPcopy Index your code
hub / github.com/DHTMLX/gantt / drawSelectionRange

Function drawSelectionRange

samples/common/codehighlight/codemirror.js:3180–3270  ·  view source on GitHub ↗
(cm, range, output)

Source from the content-addressed store, hash-verified

3178
3179 // Draws the given range as a highlighted selection
3180 function drawSelectionRange(cm, range, output) {
3181 var display = cm.display, doc = cm.doc;
3182 var fragment = document.createDocumentFragment();
3183 var padding = paddingH(cm.display), leftSide = padding.left;
3184 var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;
3185 var docLTR = doc.direction == "ltr";
3186
3187 function add(left, top, width, bottom) {
3188 if (top < 0) { top = 0; }
3189 top = Math.round(top);
3190 bottom = Math.round(bottom);
3191 fragment.appendChild(elt("div", null, "CodeMirror-selected", ("position: absolute; left: " + left + "px;\n top: " + top + "px; width: " + (width == null ? rightSide - left : width) + "px;\n height: " + (bottom - top) + "px")));
3192 }
3193
3194 function drawForLine(line, fromArg, toArg) {
3195 var lineObj = getLine(doc, line);
3196 var lineLen = lineObj.text.length;
3197 var start, end;
3198 function coords(ch, bias) {
3199 return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
3200 }
3201
3202 function wrapX(pos, dir, side) {
3203 var extent = wrappedLineExtentChar(cm, lineObj, null, pos);
3204 var prop = (dir == "ltr") == (side == "after") ? "left" : "right";
3205 var ch = side == "after" ? extent.begin : extent.end - (/\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1);
3206 return coords(ch, prop)[prop]
3207 }
3208
3209 var order = getOrder(lineObj, doc.direction);
3210 iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir, i) {
3211 var ltr = dir == "ltr";
3212 var fromPos = coords(from, ltr ? "left" : "right");
3213 var toPos = coords(to - 1, ltr ? "right" : "left");
3214
3215 var openStart = fromArg == null && from == 0, openEnd = toArg == null && to == lineLen;
3216 var first = i == 0, last = !order || i == order.length - 1;
3217 if (toPos.top - fromPos.top <= 3) { // Single line
3218 var openLeft = (docLTR ? openStart : openEnd) && first;
3219 var openRight = (docLTR ? openEnd : openStart) && last;
3220 var left = openLeft ? leftSide : (ltr ? fromPos : toPos).left;
3221 var right = openRight ? rightSide : (ltr ? toPos : fromPos).right;
3222 add(left, fromPos.top, right - left, fromPos.bottom);
3223 } else { // Multiple lines
3224 var topLeft, topRight, botLeft, botRight;
3225 if (ltr) {
3226 topLeft = docLTR && openStart && first ? leftSide : fromPos.left;
3227 topRight = docLTR ? rightSide : wrapX(from, dir, "before");
3228 botLeft = docLTR ? leftSide : wrapX(to, dir, "after");
3229 botRight = docLTR && openEnd && last ? rightSide : toPos.right;
3230 } else {
3231 topLeft = !docLTR ? leftSide : wrapX(from, dir, "before");
3232 topRight = !docLTR && openStart && first ? rightSide : fromPos.right;
3233 botLeft = !docLTR && openEnd && last ? leftSide : toPos.left;
3234 botRight = !docLTR ? rightSide : wrapX(to, dir, "after");
3235 }
3236 add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom);
3237 if (fromPos.bottom < toPos.top) { add(leftSide, fromPos.bottom, null, toPos.top); }

Callers 1

prepareSelectionFunction · 0.85

Calls 6

paddingHFunction · 0.85
displayWidthFunction · 0.85
drawForLineFunction · 0.85
getLineFunction · 0.85
visualLineFunction · 0.85
addFunction · 0.70

Tested by

no test coverage detected