(doc, change)
| 5157 | // spans partially within the change. Returns an array of span |
| 5158 | // arrays with one element for each line in (after) the change. |
| 5159 | function stretchSpansOverChange(doc, change) { |
| 5160 | var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans; |
| 5161 | var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans; |
| 5162 | if (!oldFirst && !oldLast) return null; |
| 5163 | |
| 5164 | var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0; |
| 5165 | // Get the spans that 'stick out' on both sides |
| 5166 | var first = markedSpansBefore(oldFirst, startCh, isInsert); |
| 5167 | var last = markedSpansAfter(oldLast, endCh, isInsert); |
| 5168 | |
| 5169 | // Next, merge those two ends |
| 5170 | var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0); |
| 5171 | if (first) { |
| 5172 | // Fix up .to properties of first |
| 5173 | for (var i = 0; i < first.length; ++i) { |
| 5174 | var span = first[i]; |
| 5175 | if (span.to == null) { |
| 5176 | var found = getMarkedSpanFor(last, span.marker); |
| 5177 | if (!found) span.to = startCh; |
| 5178 | else if (sameLine) span.to = found.to == null ? null : found.to + offset; |
| 5179 | } |
| 5180 | } |
| 5181 | } |
| 5182 | if (last) { |
| 5183 | // Fix up .from in last (or move them into first in case of sameLine) |
| 5184 | for (var i = 0; i < last.length; ++i) { |
| 5185 | var span = last[i]; |
| 5186 | if (span.to != null) span.to += offset; |
| 5187 | if (span.from == null) { |
| 5188 | var found = getMarkedSpanFor(first, span.marker); |
| 5189 | if (!found) { |
| 5190 | span.from = offset; |
| 5191 | if (sameLine) (first || (first = [])).push(span); |
| 5192 | } |
| 5193 | } else { |
| 5194 | span.from += offset; |
| 5195 | if (sameLine) (first || (first = [])).push(span); |
| 5196 | } |
| 5197 | } |
| 5198 | } |
| 5199 | // Make sure we didn't create any zero-length spans |
| 5200 | if (first) first = clearEmptySpans(first); |
| 5201 | if (last && last != first) last = clearEmptySpans(last); |
| 5202 | |
| 5203 | var newMarkers = [first]; |
| 5204 | if (!sameLine) { |
| 5205 | // Fill gap with whole-line-spans |
| 5206 | var gap = change.text.length - 2, gapMarkers; |
| 5207 | if (gap > 0 && first) |
| 5208 | for (var i = 0; i < first.length; ++i) |
| 5209 | if (first[i].to == null) |
| 5210 | (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i].marker, null, null)); |
| 5211 | for (var i = 0; i < gap; ++i) |
| 5212 | newMarkers.push(gapMarkers); |
| 5213 | newMarkers.push(last); |
| 5214 | } |
| 5215 | return newMarkers; |
| 5216 | } |
no test coverage detected