(doc, change)
| 6365 | // spans partially within the change. Returns an array of span |
| 6366 | // arrays with one element for each line in (after) the change. |
| 6367 | function stretchSpansOverChange(doc, change) { |
| 6368 | if (change.full) return null; |
| 6369 | var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans; |
| 6370 | var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans; |
| 6371 | if (!oldFirst && !oldLast) return null; |
| 6372 | |
| 6373 | var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0; |
| 6374 | // Get the spans that 'stick out' on both sides |
| 6375 | var first = markedSpansBefore(oldFirst, startCh, isInsert); |
| 6376 | var last = markedSpansAfter(oldLast, endCh, isInsert); |
| 6377 | |
| 6378 | // Next, merge those two ends |
| 6379 | var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0); |
| 6380 | if (first) { |
| 6381 | // Fix up .to properties of first |
| 6382 | for (var i = 0; i < first.length; ++i) { |
| 6383 | var span = first[i]; |
| 6384 | if (span.to == null) { |
| 6385 | var found = getMarkedSpanFor(last, span.marker); |
| 6386 | if (!found) span.to = startCh; |
| 6387 | else if (sameLine) span.to = found.to == null ? null : found.to + offset; |
| 6388 | } |
| 6389 | } |
| 6390 | } |
| 6391 | if (last) { |
| 6392 | // Fix up .from in last (or move them into first in case of sameLine) |
| 6393 | for (var i = 0; i < last.length; ++i) { |
| 6394 | var span = last[i]; |
| 6395 | if (span.to != null) span.to += offset; |
| 6396 | if (span.from == null) { |
| 6397 | var found = getMarkedSpanFor(first, span.marker); |
| 6398 | if (!found) { |
| 6399 | span.from = offset; |
| 6400 | if (sameLine) (first || (first = [])).push(span); |
| 6401 | } |
| 6402 | } else { |
| 6403 | span.from += offset; |
| 6404 | if (sameLine) (first || (first = [])).push(span); |
| 6405 | } |
| 6406 | } |
| 6407 | } |
| 6408 | // Make sure we didn't create any zero-length spans |
| 6409 | if (first) first = clearEmptySpans(first); |
| 6410 | if (last && last != first) last = clearEmptySpans(last); |
| 6411 | |
| 6412 | var newMarkers = [first]; |
| 6413 | if (!sameLine) { |
| 6414 | // Fill gap with whole-line-spans |
| 6415 | var gap = change.text.length - 2, gapMarkers; |
| 6416 | if (gap > 0 && first) |
| 6417 | for (var i = 0; i < first.length; ++i) |
| 6418 | if (first[i].to == null) |
| 6419 | (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i].marker, null, null)); |
| 6420 | for (var i = 0; i < gap; ++i) |
| 6421 | newMarkers.push(gapMarkers); |
| 6422 | newMarkers.push(last); |
| 6423 | } |
| 6424 | return newMarkers; |
no test coverage detected