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

Function computeReplacedSel

external/.scrollLibs.js:6436–6455  ·  view source on GitHub ↗
(doc, changes, hint)

Source from the content-addressed store, hash-verified

6434 // Used by replaceSelections to allow moving the selection to the
6435 // start or around the replaced test. Hint may be "start" or "around".
6436 function computeReplacedSel(doc, changes, hint) {
6437 var out = []
6438 var oldPrev = Pos(doc.first, 0),
6439 newPrev = oldPrev
6440 for (var i = 0; i < changes.length; i++) {
6441 var change = changes[i]
6442 var from = offsetPos(change.from, oldPrev, newPrev)
6443 var to = offsetPos(changeEnd(change), oldPrev, newPrev)
6444 oldPrev = change.to
6445 newPrev = to
6446 if (hint == "around") {
6447 var range = doc.sel.ranges[i],
6448 inv = cmp(range.head, range.anchor) < 0
6449 out[i] = new Range(inv ? to : from, inv ? from : to)
6450 } else {
6451 out[i] = new Range(from, from)
6452 }
6453 }
6454 return new Selection(out, doc.sel.primIndex)
6455 }
6456
6457 // Used to get the editor into a consistent state again when options change.
6458

Callers 1

.scrollLibs.jsFile · 0.85

Calls 4

PosFunction · 0.85
offsetPosFunction · 0.85
changeEndFunction · 0.85
cmpFunction · 0.85

Tested by

no test coverage detected