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

Function extendTo

external/.scrollLibs.js:10228–10271  ·  view source on GitHub ↗
(pos)

Source from the content-addressed store, hash-verified

10226
10227 var lastPos = start
10228 function extendTo(pos) {
10229 if (cmp(lastPos, pos) == 0) {
10230 return
10231 }
10232 lastPos = pos
10233
10234 if (behavior.unit == "rectangle") {
10235 var ranges = [],
10236 tabSize = cm.options.tabSize
10237 var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize)
10238 var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize)
10239 var left = Math.min(startCol, posCol),
10240 right = Math.max(startCol, posCol)
10241 for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line)); line <= end; line++) {
10242 var text = getLine(doc, line).text,
10243 leftPos = findColumn(text, left, tabSize)
10244 if (left == right) {
10245 ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos)))
10246 } else if (text.length > leftPos) {
10247 ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize))))
10248 }
10249 }
10250 if (!ranges.length) {
10251 ranges.push(new Range(start, start))
10252 }
10253 setSelection(doc, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex), { origin: "*mouse", scroll: false })
10254 cm.scrollIntoView(pos)
10255 } else {
10256 var oldRange = ourRange
10257 var range$$1 = rangeForUnit(cm, pos, behavior.unit)
10258 var anchor = oldRange.anchor,
10259 head
10260 if (cmp(range$$1.anchor, anchor) > 0) {
10261 head = range$$1.head
10262 anchor = minPos(oldRange.from(), range$$1.anchor)
10263 } else {
10264 head = range$$1.anchor
10265 anchor = maxPos(oldRange.to(), range$$1.head)
10266 }
10267 var ranges$1 = startSel.ranges.slice(0)
10268 ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head))
10269 setSelection(doc, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse)
10270 }
10271 }
10272
10273 var editorSize = display.wrapper.getBoundingClientRect()
10274 // Used to ensure timeout re-tries don't fire when another extend

Callers 1

extendFunction · 0.85

Calls 15

cmpFunction · 0.85
countColumnFunction · 0.85
getLineFunction · 0.85
findColumnFunction · 0.85
PosFunction · 0.85
setSelectionFunction · 0.85
normalizeSelectionFunction · 0.85
rangeForUnitFunction · 0.85
minPosFunction · 0.85
maxPosFunction · 0.85
bidiSimplifyFunction · 0.85
clipPosFunction · 0.85

Tested by

no test coverage detected