MCPcopy Index your code
hub / github.com/csev/py4e / stretchSpansOverChange

Function stretchSpansOverChange

tools/pythonauto/static/codemirror/codemirror.js:4105–4162  ·  view source on GitHub ↗
(doc, change)

Source from the content-addressed store, hash-verified

4103 }
4104
4105 function stretchSpansOverChange(doc, change) {
4106 var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
4107 var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
4108 if (!oldFirst && !oldLast) return null;
4109
4110 var startCh = change.from.ch, endCh = change.to.ch, isInsert = posEq(change.from, change.to);
4111 // Get the spans that 'stick out' on both sides
4112 var first = markedSpansBefore(oldFirst, startCh, isInsert);
4113 var last = markedSpansAfter(oldLast, endCh, isInsert);
4114
4115 // Next, merge those two ends
4116 var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
4117 if (first) {
4118 // Fix up .to properties of first
4119 for (var i = 0; i < first.length; ++i) {
4120 var span = first[i];
4121 if (span.to == null) {
4122 var found = getMarkedSpanFor(last, span.marker);
4123 if (!found) span.to = startCh;
4124 else if (sameLine) span.to = found.to == null ? null : found.to + offset;
4125 }
4126 }
4127 }
4128 if (last) {
4129 // Fix up .from in last (or move them into first in case of sameLine)
4130 for (var i = 0; i < last.length; ++i) {
4131 var span = last[i];
4132 if (span.to != null) span.to += offset;
4133 if (span.from == null) {
4134 var found = getMarkedSpanFor(first, span.marker);
4135 if (!found) {
4136 span.from = offset;
4137 if (sameLine) (first || (first = [])).push(span);
4138 }
4139 } else {
4140 span.from += offset;
4141 if (sameLine) (first || (first = [])).push(span);
4142 }
4143 }
4144 }
4145 // Make sure we didn't create any zero-length spans
4146 if (first) first = clearEmptySpans(first);
4147 if (last && last != first) last = clearEmptySpans(last);
4148
4149 var newMarkers = [first];
4150 if (!sameLine) {
4151 // Fill gap with whole-line-spans
4152 var gap = change.text.length - 2, gapMarkers;
4153 if (gap > 0 && first)
4154 for (var i = 0; i < first.length; ++i)
4155 if (first[i].to == null)
4156 (gapMarkers || (gapMarkers = [])).push({from: null, to: null, marker: first[i].marker});
4157 for (var i = 0; i < gap; ++i)
4158 newMarkers.push(gapMarkers);
4159 newMarkers.push(last);
4160 }
4161 return newMarkers;
4162 }

Callers 2

makeChangeNoReadonlyFunction · 0.70
mergeOldSpansFunction · 0.70

Calls 8

isLineFunction · 0.70
getLineFunction · 0.70
posEqFunction · 0.70
markedSpansBeforeFunction · 0.70
markedSpansAfterFunction · 0.70
lstFunction · 0.70
getMarkedSpanForFunction · 0.70
clearEmptySpansFunction · 0.70

Tested by

no test coverage detected