MCPcopy Create free account
hub / github.com/TruthHun/BookStack / computeReplacedSel

Function computeReplacedSel

static/mergely/lib/codemirror.js:4314–4331  ·  view source on GitHub ↗
(doc, changes, hint)

Source from the content-addressed store, hash-verified

4312 // Used by replaceSelections to allow moving the selection to the
4313 // start or around the replaced test. Hint may be "start" or "around".
4314 function computeReplacedSel(doc, changes, hint) {
4315 var out = [];
4316 var oldPrev = Pos(doc.first, 0), newPrev = oldPrev;
4317 for (var i = 0; i < changes.length; i++) {
4318 var change = changes[i];
4319 var from = offsetPos(change.from, oldPrev, newPrev);
4320 var to = offsetPos(changeEnd(change), oldPrev, newPrev);
4321 oldPrev = change.to;
4322 newPrev = to;
4323 if (hint == "around") {
4324 var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0;
4325 out[i] = new Range(inv ? to : from, inv ? from : to);
4326 } else {
4327 out[i] = new Range(from, from);
4328 }
4329 }
4330 return new Selection(out, doc.sel.primIndex);
4331 }
4332
4333 // Allow "beforeChange" event handlers to influence a change
4334 function filterChange(doc, change, update) {

Callers 1

codemirror.jsFile · 0.70

Calls 2

offsetPosFunction · 0.70
cmpFunction · 0.50

Tested by

no test coverage detected