MCPcopy Create free account
hub / github.com/breck7/scroll / drawSelectionRange

Function drawSelectionRange

external/.scrollLibs.js:4490–4608  ·  view source on GitHub ↗
(cm, range$$1, output)

Source from the content-addressed store, hash-verified

4488
4489 // Draws the given range as a highlighted selection
4490 function drawSelectionRange(cm, range$$1, output) {
4491 var display = cm.display,
4492 doc = cm.doc
4493 var fragment = document.createDocumentFragment()
4494 var padding = paddingH(cm.display),
4495 leftSide = padding.left
4496 var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right
4497 var docLTR = doc.direction == "ltr"
4498
4499 function add(left, top, width, bottom) {
4500 if (top < 0) {
4501 top = 0
4502 }
4503 top = Math.round(top)
4504 bottom = Math.round(bottom)
4505 fragment.appendChild(
4506 elt(
4507 "div",
4508 null,
4509 "CodeMirror-selected",
4510 "position: absolute; left: " + left + "px;\n top: " + top + "px; width: " + (width == null ? rightSide - left : width) + "px;\n height: " + (bottom - top) + "px"
4511 )
4512 )
4513 }
4514
4515 function drawForLine(line, fromArg, toArg) {
4516 var lineObj = getLine(doc, line)
4517 var lineLen = lineObj.text.length
4518 var start, end
4519 function coords(ch, bias) {
4520 return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
4521 }
4522
4523 function wrapX(pos, dir, side) {
4524 var extent = wrappedLineExtentChar(cm, lineObj, null, pos)
4525 var prop = (dir == "ltr") == (side == "after") ? "left" : "right"
4526 var ch = side == "after" ? extent.begin : extent.end - (/\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1)
4527 return coords(ch, prop)[prop]
4528 }
4529
4530 var order = getOrder(lineObj, doc.direction)
4531 iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir, i) {
4532 var ltr = dir == "ltr"
4533 var fromPos = coords(from, ltr ? "left" : "right")
4534 var toPos = coords(to - 1, ltr ? "right" : "left")
4535
4536 var openStart = fromArg == null && from == 0,
4537 openEnd = toArg == null && to == lineLen
4538 var first = i == 0,
4539 last = !order || i == order.length - 1
4540 if (toPos.top - fromPos.top <= 3) {
4541 // Single line
4542 var openLeft = (docLTR ? openStart : openEnd) && first
4543 var openRight = (docLTR ? openEnd : openStart) && last
4544 var left = openLeft ? leftSide : (ltr ? fromPos : toPos).left
4545 var right = openRight ? rightSide : (ltr ? toPos : fromPos).right
4546 add(left, fromPos.top, right - left, fromPos.bottom)
4547 } else {

Callers 1

prepareSelectionFunction · 0.85

Calls 8

paddingHFunction · 0.85
displayWidthFunction · 0.85
drawForLineFunction · 0.85
getLineFunction · 0.85
visualLineFunction · 0.85
maxMethod · 0.80
addFunction · 0.70
fromMethod · 0.45

Tested by

no test coverage detected