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

Function normalizeSelection

static/editor.md/lib/codemirror/lib/codemirror.js:1969–1983  ·  view source on GitHub ↗
(ranges, primIndex)

Source from the content-addressed store, hash-verified

1967 // build a selection out of it. 'Consumes' ranges array (modifying
1968 // it).
1969 function normalizeSelection(ranges, primIndex) {
1970 var prim = ranges[primIndex];
1971 ranges.sort(function(a, b) { return cmp(a.from(), b.from()); });
1972 primIndex = indexOf(ranges, prim);
1973 for (var i = 1; i < ranges.length; i++) {
1974 var cur = ranges[i], prev = ranges[i - 1];
1975 if (cmp(prev.to(), cur.from()) >= 0) {
1976 var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
1977 var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
1978 if (i <= primIndex) --primIndex;
1979 ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
1980 }
1981 }
1982 return new Selection(ranges, primIndex);
1983 }
1984
1985 function simpleSelection(anchor, head) {
1986 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