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

Function normalizeSelection

static/mergely/lib/codemirror.js:2065–2079  ·  view source on GitHub ↗
(ranges, primIndex)

Source from the content-addressed store, hash-verified

2063 // build a selection out of it. 'Consumes' ranges array (modifying
2064 // it).
2065 function normalizeSelection(ranges, primIndex) {
2066 var prim = ranges[primIndex];
2067 ranges.sort(function(a, b) { return cmp(a.from(), b.from()); });
2068 primIndex = indexOf(ranges, prim);
2069 for (var i = 1; i < ranges.length; i++) {
2070 var cur = ranges[i], prev = ranges[i - 1];
2071 if (cmp(prev.to(), cur.from()) >= 0) {
2072 var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
2073 var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
2074 if (i <= primIndex) --primIndex;
2075 ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
2076 }
2077 }
2078 return new Selection(ranges, primIndex);
2079 }
2080
2081 function simpleSelection(anchor, head) {
2082 return new Selection([new Range(anchor, head || anchor)], 0);

Callers 8

extendSelectionsFunction · 0.70
replaceOneSelectionFunction · 0.70
filterSelectionChangeFunction · 0.70
skipAtomicInSelectionFunction · 0.70
leftButtonSelectFunction · 0.70
extendToFunction · 0.70
computeSelAfterChangeFunction · 0.70
codemirror.jsFile · 0.70

Calls 4

indexOfFunction · 0.70
minPosFunction · 0.70
maxPosFunction · 0.70
cmpFunction · 0.50

Tested by

no test coverage detected