MCPcopy
hub / github.com/witheve/Eve / normalizeSelection

Function normalizeSelection

src/codemirror.js:2070–2084  ·  view source on GitHub ↗
(ranges, primIndex)

Source from the content-addressed store, hash-verified

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

Callers 8

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

Calls 5

indexOfFunction · 0.85
minPosFunction · 0.85
maxPosFunction · 0.85
fromMethod · 0.80
toMethod · 0.80

Tested by

no test coverage detected