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

Function extendTo

src/codemirror.js:3738–3779  ·  view source on GitHub ↗
(pos)

Source from the content-addressed store, hash-verified

3736
3737 var lastPos = start;
3738 function extendTo(pos) {
3739 if (cmp(lastPos, pos) == 0) return;
3740 lastPos = pos;
3741
3742 if (type == "rect") {
3743 var ranges = [], tabSize = cm.options.tabSize;
3744 var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
3745 var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
3746 var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
3747 for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
3748 line <= end; line++) {
3749 var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
3750 if (left == right)
3751 ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos)));
3752 else if (text.length > leftPos)
3753 ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize))));
3754 }
3755 if (!ranges.length) ranges.push(new Range(start, start));
3756 setSelection(doc, normalizeSelection(startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
3757 {origin: "*mouse", scroll: false});
3758 cm.scrollIntoView(pos);
3759 } else {
3760 var oldRange = ourRange;
3761 var anchor = oldRange.anchor, head = pos;
3762 if (type != "single") {
3763 if (type == "double")
3764 var range = cm.findWordAt(pos);
3765 else
3766 var range = new Range(Pos(pos.line, 0), clipPos(doc, Pos(pos.line + 1, 0)));
3767 if (cmp(range.anchor, anchor) > 0) {
3768 head = range.head;
3769 anchor = minPos(oldRange.from(), range.anchor);
3770 } else {
3771 head = range.anchor;
3772 anchor = maxPos(oldRange.to(), range.head);
3773 }
3774 }
3775 var ranges = startSel.ranges.slice(0);
3776 ranges[ourIndex] = new Range(clipPos(doc, anchor), head);
3777 setSelection(doc, normalizeSelection(ranges, ourIndex), sel_mouse);
3778 }
3779 }
3780
3781 var editorSize = display.wrapper.getBoundingClientRect();
3782 // Used to ensure timeout re-tries don't fire when another extend

Callers 1

extendFunction · 0.85

Calls 10

getLineFunction · 0.85
setSelectionFunction · 0.85
normalizeSelectionFunction · 0.85
clipPosFunction · 0.85
minPosFunction · 0.85
maxPosFunction · 0.85
lastLineMethod · 0.80
scrollIntoViewMethod · 0.80
fromMethod · 0.80
toMethod · 0.80

Tested by

no test coverage detected