MCPcopy Create free account
hub / github.com/sql-js/sql.js / normalizeSelection

Function normalizeSelection

GUI/codemirror/lib/codemirror.js:1012–1026  ·  view source on GitHub ↗
(ranges, primIndex)

Source from the content-addressed store, hash-verified

1010 // build a selection out of it. 'Consumes' ranges array (modifying
1011 // it).
1012 function normalizeSelection(ranges, primIndex) {
1013 var prim = ranges[primIndex];
1014 ranges.sort(function(a, b) { return cmp(a.from(), b.from()); });
1015 primIndex = indexOf(ranges, prim);
1016 for (var i = 1; i < ranges.length; i++) {
1017 var cur = ranges[i], prev = ranges[i - 1];
1018 if (cmp(prev.to(), cur.from()) >= 0) {
1019 var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
1020 var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
1021 if (i <= primIndex) --primIndex;
1022 ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
1023 }
1024 }
1025 return new Selection(ranges, primIndex);
1026 }
1027
1028 function simpleSelection(anchor, head) {
1029 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 3

indexOfFunction · 0.85
minPosFunction · 0.85
maxPosFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…