MCPcopy Index your code
hub / github.com/DHTMLX/gantt / stretchSpansOverChange

Function stretchSpansOverChange

samples/common/codehighlight/codemirror.js:1364–1422  ·  view source on GitHub ↗
(doc, change)

Source from the content-addressed store, hash-verified

1362 // spans partially within the change. Returns an array of span
1363 // arrays with one element for each line in (after) the change.
1364 function stretchSpansOverChange(doc, change) {
1365 if (change.full) { return null }
1366 var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
1367 var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
1368 if (!oldFirst && !oldLast) { return null }
1369
1370 var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
1371 // Get the spans that 'stick out' on both sides
1372 var first = markedSpansBefore(oldFirst, startCh, isInsert);
1373 var last = markedSpansAfter(oldLast, endCh, isInsert);
1374
1375 // Next, merge those two ends
1376 var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
1377 if (first) {
1378 // Fix up .to properties of first
1379 for (var i = 0; i < first.length; ++i) {
1380 var span = first[i];
1381 if (span.to == null) {
1382 var found = getMarkedSpanFor(last, span.marker);
1383 if (!found) { span.to = startCh; }
1384 else if (sameLine) { span.to = found.to == null ? null : found.to + offset; }
1385 }
1386 }
1387 }
1388 if (last) {
1389 // Fix up .from in last (or move them into first in case of sameLine)
1390 for (var i$1 = 0; i$1 < last.length; ++i$1) {
1391 var span$1 = last[i$1];
1392 if (span$1.to != null) { span$1.to += offset; }
1393 if (span$1.from == null) {
1394 var found$1 = getMarkedSpanFor(first, span$1.marker);
1395 if (!found$1) {
1396 span$1.from = offset;
1397 if (sameLine) { (first || (first = [])).push(span$1); }
1398 }
1399 } else {
1400 span$1.from += offset;
1401 if (sameLine) { (first || (first = [])).push(span$1); }
1402 }
1403 }
1404 }
1405 // Make sure we didn't create any zero-length spans
1406 if (first) { first = clearEmptySpans(first); }
1407 if (last && last != first) { last = clearEmptySpans(last); }
1408
1409 var newMarkers = [first];
1410 if (!sameLine) {
1411 // Fill gap with whole-line-spans
1412 var gap = change.text.length - 2, gapMarkers;
1413 if (gap > 0 && first)
1414 { for (var i$2 = 0; i$2 < first.length; ++i$2)
1415 { if (first[i$2].to == null)
1416 { (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null)); } } }
1417 for (var i$3 = 0; i$3 < gap; ++i$3)
1418 { newMarkers.push(gapMarkers); }
1419 newMarkers.push(last);
1420 }
1421 return newMarkers

Callers 2

mergeOldSpansFunction · 0.85
makeChangeInnerFunction · 0.85

Calls 8

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

Tested by

no test coverage detected