(doc, change, markedSpans, estimateHeight)
| 4712 | |
| 4713 | // Perform a change on the document data structure. |
| 4714 | function updateDoc(doc, change, markedSpans, estimateHeight) { |
| 4715 | function spansFor(n) {return markedSpans ? markedSpans[n] : null} |
| 4716 | function update(line, text, spans) { |
| 4717 | updateLine(line, text, spans, estimateHeight); |
| 4718 | signalLater(line, "change", line, change); |
| 4719 | } |
| 4720 | function linesFor(start, end) { |
| 4721 | var result = []; |
| 4722 | for (var i = start; i < end; ++i) |
| 4723 | { result.push(new Line(text[i], spansFor(i), estimateHeight)); } |
| 4724 | return result |
| 4725 | } |
| 4726 | |
| 4727 | var from = change.from, to = change.to, text = change.text; |
| 4728 | var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line); |
| 4729 | var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line; |
| 4730 | |
| 4731 | // Adjust the line structure |
| 4732 | if (change.full) { |
| 4733 | doc.insert(0, linesFor(0, text.length)); |
| 4734 | doc.remove(text.length, doc.size - text.length); |
| 4735 | } else if (isWholeLineUpdate(doc, change)) { |
| 4736 | // This is a whole-line replace. Treated specially to make |
| 4737 | // sure line objects move the way they are supposed to. |
| 4738 | var added = linesFor(0, text.length - 1); |
| 4739 | update(lastLine, lastLine.text, lastSpans); |
| 4740 | if (nlines) { doc.remove(from.line, nlines); } |
| 4741 | if (added.length) { doc.insert(from.line, added); } |
| 4742 | } else if (firstLine == lastLine) { |
| 4743 | if (text.length == 1) { |
| 4744 | update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans); |
| 4745 | } else { |
| 4746 | var added$1 = linesFor(1, text.length - 1); |
| 4747 | added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight)); |
| 4748 | update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0)); |
| 4749 | doc.insert(from.line + 1, added$1); |
| 4750 | } |
| 4751 | } else if (text.length == 1) { |
| 4752 | update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0)); |
| 4753 | doc.remove(from.line + 1, nlines); |
| 4754 | } else { |
| 4755 | update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0)); |
| 4756 | update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans); |
| 4757 | var added$2 = linesFor(1, text.length - 1); |
| 4758 | if (nlines > 1) { doc.remove(from.line + 1, nlines - 1); } |
| 4759 | doc.insert(from.line + 1, added$2); |
| 4760 | } |
| 4761 | |
| 4762 | signalLater(doc, "change", doc, change); |
| 4763 | } |
| 4764 | |
| 4765 | // Call f for all linked documents. |
| 4766 | function linkedDocs(doc, f, sharedHistOnly) { |
no test coverage detected