MCPcopy Index your code
hub / github.com/csev/py4e / extendTo

Function extendTo

tools/pythonauto/static/codemirrorepl/codemirror.js:2629–2668  ·  view source on GitHub ↗
(pos)

Source from the content-addressed store, hash-verified

2627
2628 var lastPos = start;
2629 function extendTo(pos) {
2630 if (cmp(lastPos, pos) == 0) return;
2631 lastPos = pos;
2632
2633 if (type == "rect") {
2634 var ranges = [], tabSize = cm.options.tabSize;
2635 var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
2636 var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
2637 var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
2638 for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
2639 line <= end; line++) {
2640 var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
2641 if (left == right)
2642 ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos)));
2643 else if (text.length > leftPos)
2644 ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize))));
2645 }
2646 if (!ranges.length) ranges.push(new Range(start, start));
2647 setSelection(doc, normalizeSelection(startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex), sel_mouse);
2648 } else {
2649 var oldRange = ourRange;
2650 var anchor = oldRange.anchor, head = pos;
2651 if (type != "single") {
2652 if (type == "double")
2653 var range = findWordAt(doc, pos);
2654 else
2655 var range = new Range(Pos(pos.line, 0), clipPos(doc, Pos(pos.line + 1, 0)));
2656 if (cmp(range.anchor, anchor) > 0) {
2657 head = range.head;
2658 anchor = minPos(oldRange.from(), range.anchor);
2659 } else {
2660 head = range.anchor;
2661 anchor = maxPos(oldRange.to(), range.head);
2662 }
2663 }
2664 var ranges = startSel.ranges.slice(0);
2665 ranges[ourIndex] = new Range(clipPos(doc, anchor), head);
2666 setSelection(doc, normalizeSelection(ranges, ourIndex), sel_mouse);
2667 }
2668 }
2669
2670 var editorSize = display.wrapper.getBoundingClientRect();
2671 // Used to ensure timeout re-tries don't fire when another extend

Callers 1

extendFunction · 0.85

Calls 12

cmpFunction · 0.85
findColumnFunction · 0.85
PosFunction · 0.85
normalizeSelectionFunction · 0.85
minPosFunction · 0.85
maxPosFunction · 0.85
sliceMethod · 0.80
countColumnFunction · 0.70
getLineFunction · 0.70
setSelectionFunction · 0.70
findWordAtFunction · 0.70
clipPosFunction · 0.70

Tested by

no test coverage detected