MCPcopy
hub / github.com/witheve/Eve / drawSelectionRange

Function drawSelectionRange

src/codemirror.js:2349–2421  ·  view source on GitHub ↗
(cm, range, output)

Source from the content-addressed store, hash-verified

2347
2348 // Draws the given range as a highlighted selection
2349 function drawSelectionRange(cm, range, output) {
2350 var display = cm.display, doc = cm.doc;
2351 var fragment = document.createDocumentFragment();
2352 var padding = paddingH(cm.display), leftSide = padding.left;
2353 var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;
2354
2355 function add(left, top, width, bottom) {
2356 if (top < 0) top = 0;
2357 top = Math.round(top);
2358 bottom = Math.round(bottom);
2359 fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
2360 "px; top: " + top + "px; width: " + (width == null ? rightSide - left : width) +
2361 "px; height: " + (bottom - top) + "px"));
2362 }
2363
2364 function drawForLine(line, fromArg, toArg) {
2365 var lineObj = getLine(doc, line);
2366 var lineLen = lineObj.text.length;
2367 var start, end;
2368 function coords(ch, bias) {
2369 return charCoords(cm, Pos(line, ch), "div", lineObj, bias);
2370 }
2371
2372 iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
2373 var leftPos = coords(from, "left"), rightPos, left, right;
2374 if (from == to) {
2375 rightPos = leftPos;
2376 left = right = leftPos.left;
2377 } else {
2378 rightPos = coords(to - 1, "right");
2379 if (dir == "rtl") { var tmp = leftPos; leftPos = rightPos; rightPos = tmp; }
2380 left = leftPos.left;
2381 right = rightPos.right;
2382 }
2383 if (fromArg == null && from == 0) left = leftSide;
2384 if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
2385 add(left, leftPos.top, null, leftPos.bottom);
2386 left = leftSide;
2387 if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
2388 }
2389 if (toArg == null && to == lineLen) right = rightSide;
2390 if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
2391 start = leftPos;
2392 if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
2393 end = rightPos;
2394 if (left < leftSide + 1) left = leftSide;
2395 add(left, rightPos.top, right - left, rightPos.bottom);
2396 });
2397 return {start: start, end: end};
2398 }
2399
2400 var sFrom = range.from(), sTo = range.to();
2401 if (sFrom.line == sTo.line) {
2402 drawForLine(sFrom.line, sFrom.ch, sTo.ch);
2403 } else {
2404 var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
2405 var singleVLine = visualLine(fromLine) == visualLine(toLine);
2406 var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;

Callers 1

prepareSelectionFunction · 0.85

Calls 8

paddingHFunction · 0.85
displayWidthFunction · 0.85
drawForLineFunction · 0.85
getLineFunction · 0.85
visualLineFunction · 0.85
fromMethod · 0.80
toMethod · 0.80
addFunction · 0.70

Tested by

no test coverage detected