MCPcopy Create free account
hub / github.com/sql-js/sql.js / extendTo

Function extendTo

GUI/codemirror/lib/codemirror.js:2660–2699  ·  view source on GitHub ↗
(pos)

Source from the content-addressed store, hash-verified

2658
2659 var lastPos = start;
2660 function extendTo(pos) {
2661 if (cmp(lastPos, pos) == 0) return;
2662 lastPos = pos;
2663
2664 if (type == "rect") {
2665 var ranges = [], tabSize = cm.options.tabSize;
2666 var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
2667 var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
2668 var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
2669 for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
2670 line <= end; line++) {
2671 var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
2672 if (left == right)
2673 ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos)));
2674 else if (text.length > leftPos)
2675 ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize))));
2676 }
2677 if (!ranges.length) ranges.push(new Range(start, start));
2678 setSelection(doc, normalizeSelection(startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex), sel_mouse);
2679 } else {
2680 var oldRange = ourRange;
2681 var anchor = oldRange.anchor, head = pos;
2682 if (type != "single") {
2683 if (type == "double")
2684 var range = findWordAt(doc, pos);
2685 else
2686 var range = new Range(Pos(pos.line, 0), clipPos(doc, Pos(pos.line + 1, 0)));
2687 if (cmp(range.anchor, anchor) > 0) {
2688 head = range.head;
2689 anchor = minPos(oldRange.from(), range.anchor);
2690 } else {
2691 head = range.anchor;
2692 anchor = maxPos(oldRange.to(), range.head);
2693 }
2694 }
2695 var ranges = startSel.ranges.slice(0);
2696 ranges[ourIndex] = new Range(clipPos(doc, anchor), head);
2697 setSelection(doc, normalizeSelection(ranges, ourIndex), sel_mouse);
2698 }
2699 }
2700
2701 var editorSize = display.wrapper.getBoundingClientRect();
2702 // Used to ensure timeout re-tries don't fire when another extend

Callers 1

extendFunction · 0.85

Calls 8

getLineFunction · 0.85
findColumnFunction · 0.85
setSelectionFunction · 0.85
normalizeSelectionFunction · 0.85
findWordAtFunction · 0.85
clipPosFunction · 0.85
minPosFunction · 0.85
maxPosFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…