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

Function computeReplacedSel

static/editor.md/lib/codemirror/lib/codemirror.js:4135–4152  ·  view source on GitHub ↗
(doc, changes, hint)

Source from the content-addressed store, hash-verified

4133 // Used by replaceSelections to allow moving the selection to the
4134 // start or around the replaced test. Hint may be "start" or "around".
4135 function computeReplacedSel(doc, changes, hint) {
4136 var out = [];
4137 var oldPrev = Pos(doc.first, 0), newPrev = oldPrev;
4138 for (var i = 0; i < changes.length; i++) {
4139 var change = changes[i];
4140 var from = offsetPos(change.from, oldPrev, newPrev);
4141 var to = offsetPos(changeEnd(change), oldPrev, newPrev);
4142 oldPrev = change.to;
4143 newPrev = to;
4144 if (hint == "around") {
4145 var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0;
4146 out[i] = new Range(inv ? to : from, inv ? from : to);
4147 } else {
4148 out[i] = new Range(from, from);
4149 }
4150 }
4151 return new Selection(out, doc.sel.primIndex);
4152 }
4153
4154 // Allow "beforeChange" event handlers to influence a change
4155 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