MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / normalizeSelection

Function normalizeSelection

lib/web/CodeMirror/src/model/selection.js:64–80  ·  view source on GitHub ↗
(cm, ranges, primIndex)

Source from the content-addressed store, hash-verified

62// build a selection out of it. 'Consumes' ranges array (modifying
63// it).
64export function normalizeSelection(cm, ranges, primIndex) {
65 let mayTouch = cm && cm.options.selectionsMayTouch
66 let prim = ranges[primIndex]
67 ranges.sort((a, b) => cmp(a.from(), b.from()))
68 primIndex = indexOf(ranges, prim)
69 for (let i = 1; i < ranges.length; i++) {
70 let cur = ranges[i], prev = ranges[i - 1]
71 let diff = cmp(prev.to(), cur.from())
72 if (mayTouch && !cur.empty() ? diff > 0 : diff >= 0) {
73 let from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to())
74 let inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head
75 if (i <= primIndex) --primIndex
76 ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to))
77 }
78 }
79 return new Selection(ranges, primIndex)
80}
81
82export function simpleSelection(anchor, head) {
83 return new Selection([new Range(anchor, head || anchor)], 0)

Callers 8

computeSelAfterChangeFunction · 0.90
Doc.jsFile · 0.90
extendSelectionsFunction · 0.90
replaceOneSelectionFunction · 0.90
filterSelectionChangeFunction · 0.90
skipAtomicInSelectionFunction · 0.90
leftButtonSelectFunction · 0.90
extendToFunction · 0.90

Calls 7

cmpFunction · 0.90
indexOfFunction · 0.90
minPosFunction · 0.90
maxPosFunction · 0.90
fromMethod · 0.80
toMethod · 0.80
emptyMethod · 0.80

Tested by

no test coverage detected