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

Function removeReadOnlyRanges

static/mergely/lib/codemirror.js:6466–6492  ·  view source on GitHub ↗
(doc, from, to)

Source from the content-addressed store, hash-verified

6464
6465 // Used to 'clip' out readOnly ranges when making a change.
6466 function removeReadOnlyRanges(doc, from, to) {
6467 var markers = null;
6468 doc.iter(from.line, to.line + 1, function(line) {
6469 if (line.markedSpans) for (var i = 0; i < line.markedSpans.length; ++i) {
6470 var mark = line.markedSpans[i].marker;
6471 if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
6472 (markers || (markers = [])).push(mark);
6473 }
6474 });
6475 if (!markers) return null;
6476 var parts = [{from: from, to: to}];
6477 for (var i = 0; i < markers.length; ++i) {
6478 var mk = markers[i], m = mk.find(0);
6479 for (var j = 0; j < parts.length; ++j) {
6480 var p = parts[j];
6481 if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) continue;
6482 var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to);
6483 if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
6484 newParts.push({from: p.from, to: m.from});
6485 if (dto > 0 || !mk.inclusiveRight && !dto)
6486 newParts.push({from: m.to, to: p.to});
6487 parts.splice.apply(parts, newParts);
6488 j += newParts.length - 1;
6489 }
6490 }
6491 return parts;
6492 }
6493
6494 // Connect or disconnect spans from a line.
6495 function detachMarkedSpans(line) {

Callers 1

makeChangeFunction · 0.70

Calls 2

indexOfFunction · 0.70
cmpFunction · 0.50

Tested by

no test coverage detected