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

Function removeReadOnlyRanges

lib/web/CodeMirror/src/line/spans.js:144–170  ·  view source on GitHub ↗
(doc, from, to)

Source from the content-addressed store, hash-verified

142
143// Used to 'clip' out readOnly ranges when making a change.
144export function removeReadOnlyRanges(doc, from, to) {
145 let markers = null
146 doc.iter(from.line, to.line + 1, line => {
147 if (line.markedSpans) for (let i = 0; i < line.markedSpans.length; ++i) {
148 let mark = line.markedSpans[i].marker
149 if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
150 (markers || (markers = [])).push(mark)
151 }
152 })
153 if (!markers) return null
154 let parts = [{from: from, to: to}]
155 for (let i = 0; i < markers.length; ++i) {
156 let mk = markers[i], m = mk.find(0)
157 for (let j = 0; j < parts.length; ++j) {
158 let p = parts[j]
159 if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) continue
160 let newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to)
161 if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
162 newParts.push({from: p.from, to: m.from})
163 if (dto > 0 || !mk.inclusiveRight && !dto)
164 newParts.push({from: m.to, to: p.to})
165 parts.splice.apply(parts, newParts)
166 j += newParts.length - 3
167 }
168 }
169 return parts
170}
171
172// Connect or disconnect spans from a line.
173export function detachMarkedSpans(line) {

Callers 1

makeChangeFunction · 0.90

Calls 5

indexOfFunction · 0.90
cmpFunction · 0.90
applyMethod · 0.65
pushMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected