MCPcopy
hub / github.com/csev/py4e / drawSelectionRange

Function drawSelectionRange

tools/pythonauto/static/codemirrorepl/codemirror.js:1275–1346  ·  view source on GitHub ↗
(cm, range, output)

Source from the content-addressed store, hash-verified

1273
1274 // Draws the given range as a highlighted selection
1275 function drawSelectionRange(cm, range, output) {
1276 var display = cm.display, doc = cm.doc;
1277 var fragment = document.createDocumentFragment();
1278 var padding = paddingH(cm.display), leftSide = padding.left, rightSide = display.lineSpace.offsetWidth - padding.right;
1279
1280 function add(left, top, width, bottom) {
1281 if (top < 0) top = 0;
1282 top = Math.round(top);
1283 bottom = Math.round(bottom);
1284 fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
1285 "px; top: " + top + "px; width: " + (width == null ? rightSide - left : width) +
1286 "px; height: " + (bottom - top) + "px"));
1287 }
1288
1289 function drawForLine(line, fromArg, toArg) {
1290 var lineObj = getLine(doc, line);
1291 var lineLen = lineObj.text.length;
1292 var start, end;
1293 function coords(ch, bias) {
1294 return charCoords(cm, Pos(line, ch), "div", lineObj, bias);
1295 }
1296
1297 iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
1298 var leftPos = coords(from, "left"), rightPos, left, right;
1299 if (from == to) {
1300 rightPos = leftPos;
1301 left = right = leftPos.left;
1302 } else {
1303 rightPos = coords(to - 1, "right");
1304 if (dir == "rtl") { var tmp = leftPos; leftPos = rightPos; rightPos = tmp; }
1305 left = leftPos.left;
1306 right = rightPos.right;
1307 }
1308 if (fromArg == null && from == 0) left = leftSide;
1309 if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
1310 add(left, leftPos.top, null, leftPos.bottom);
1311 left = leftSide;
1312 if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
1313 }
1314 if (toArg == null && to == lineLen) right = rightSide;
1315 if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
1316 start = leftPos;
1317 if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
1318 end = rightPos;
1319 if (left < leftSide + 1) left = leftSide;
1320 add(left, rightPos.top, right - left, rightPos.bottom);
1321 });
1322 return {start: start, end: end};
1323 }
1324
1325 var sFrom = range.from(), sTo = range.to();
1326 if (sFrom.line == sTo.line) {
1327 drawForLine(sFrom.line, sFrom.ch, sTo.ch);
1328 } else {
1329 var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
1330 var singleVLine = visualLine(fromLine) == visualLine(toLine);
1331 var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
1332 var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;

Callers 1

updateSelectionFunction · 0.85

Calls 6

paddingHFunction · 0.70
drawForLineFunction · 0.70
getLineFunction · 0.70
visualLineFunction · 0.70
addFunction · 0.70
appendChildMethod · 0.45

Tested by

no test coverage detected