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

Function stretchSpansOverChange

GUI/codemirror/lib/codemirror.js:5202–5259  ·  view source on GitHub ↗
(doc, change)

Source from the content-addressed store, hash-verified

5200 // spans partially within the change. Returns an array of span
5201 // arrays with one element for each line in (after) the change.
5202 function stretchSpansOverChange(doc, change) {
5203 var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
5204 var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
5205 if (!oldFirst && !oldLast) return null;
5206
5207 var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
5208 // Get the spans that 'stick out' on both sides
5209 var first = markedSpansBefore(oldFirst, startCh, isInsert);
5210 var last = markedSpansAfter(oldLast, endCh, isInsert);
5211
5212 // Next, merge those two ends
5213 var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
5214 if (first) {
5215 // Fix up .to properties of first
5216 for (var i = 0; i < first.length; ++i) {
5217 var span = first[i];
5218 if (span.to == null) {
5219 var found = getMarkedSpanFor(last, span.marker);
5220 if (!found) span.to = startCh;
5221 else if (sameLine) span.to = found.to == null ? null : found.to + offset;
5222 }
5223 }
5224 }
5225 if (last) {
5226 // Fix up .from in last (or move them into first in case of sameLine)
5227 for (var i = 0; i < last.length; ++i) {
5228 var span = last[i];
5229 if (span.to != null) span.to += offset;
5230 if (span.from == null) {
5231 var found = getMarkedSpanFor(first, span.marker);
5232 if (!found) {
5233 span.from = offset;
5234 if (sameLine) (first || (first = [])).push(span);
5235 }
5236 } else {
5237 span.from += offset;
5238 if (sameLine) (first || (first = [])).push(span);
5239 }
5240 }
5241 }
5242 // Make sure we didn't create any zero-length spans
5243 if (first) first = clearEmptySpans(first);
5244 if (last && last != first) last = clearEmptySpans(last);
5245
5246 var newMarkers = [first];
5247 if (!sameLine) {
5248 // Fill gap with whole-line-spans
5249 var gap = change.text.length - 2, gapMarkers;
5250 if (gap > 0 && first)
5251 for (var i = 0; i < first.length; ++i)
5252 if (first[i].to == null)
5253 (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i].marker, null, null));
5254 for (var i = 0; i < gap; ++i)
5255 newMarkers.push(gapMarkers);
5256 newMarkers.push(last);
5257 }
5258 return newMarkers;
5259 }

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…