MCPcopy
hub / github.com/witheve/Eve / stretchSpansOverChange

Function stretchSpansOverChange

src/codemirror.js:6392–6450  ·  view source on GitHub ↗
(doc, change)

Source from the content-addressed store, hash-verified

6390 // spans partially within the change. Returns an array of span
6391 // arrays with one element for each line in (after) the change.
6392 function stretchSpansOverChange(doc, change) {
6393 if (change.full) return null;
6394 var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
6395 var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
6396 if (!oldFirst && !oldLast) return null;
6397
6398 var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
6399 // Get the spans that 'stick out' on both sides
6400 var first = markedSpansBefore(oldFirst, startCh, isInsert);
6401 var last = markedSpansAfter(oldLast, endCh, isInsert);
6402
6403 // Next, merge those two ends
6404 var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
6405 if (first) {
6406 // Fix up .to properties of first
6407 for (var i = 0; i < first.length; ++i) {
6408 var span = first[i];
6409 if (span.to == null) {
6410 var found = getMarkedSpanFor(last, span.marker);
6411 if (!found) span.to = startCh;
6412 else if (sameLine) span.to = found.to == null ? null : found.to + offset;
6413 }
6414 }
6415 }
6416 if (last) {
6417 // Fix up .from in last (or move them into first in case of sameLine)
6418 for (var i = 0; i < last.length; ++i) {
6419 var span = last[i];
6420 if (span.to != null) span.to += offset;
6421 if (span.from == null) {
6422 var found = getMarkedSpanFor(first, span.marker);
6423 if (!found) {
6424 span.from = offset;
6425 if (sameLine) (first || (first = [])).push(span);
6426 }
6427 } else {
6428 span.from += offset;
6429 if (sameLine) (first || (first = [])).push(span);
6430 }
6431 }
6432 }
6433 // Make sure we didn't create any zero-length spans
6434 if (first) first = clearEmptySpans(first);
6435 if (last && last != first) last = clearEmptySpans(last);
6436
6437 var newMarkers = [first];
6438 if (!sameLine) {
6439 // Fill gap with whole-line-spans
6440 var gap = change.text.length - 2, gapMarkers;
6441 if (gap > 0 && first)
6442 for (var i = 0; i < first.length; ++i)
6443 if (first[i].to == null)
6444 (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i].marker, null, null));
6445 for (var i = 0; i < gap; ++i)
6446 newMarkers.push(gapMarkers);
6447 newMarkers.push(last);
6448 }
6449 return newMarkers;

Callers 2

makeChangeInnerFunction · 0.85
mergeOldSpansFunction · 0.85

Calls 7

isLineFunction · 0.85
getLineFunction · 0.85
markedSpansBeforeFunction · 0.85
markedSpansAfterFunction · 0.85
lstFunction · 0.85
getMarkedSpanForFunction · 0.85
clearEmptySpansFunction · 0.85

Tested by

no test coverage detected