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

Function updateDoc

samples/common/codehighlight/codemirror.js:4714–4763  ·  view source on GitHub ↗
(doc, change, markedSpans, estimateHeight)

Source from the content-addressed store, hash-verified

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) {

Callers 3

makeChangeSingleDocFunction · 0.85
DocFunction · 0.85

Calls 8

getLineFunction · 0.85
lstFunction · 0.85
spansForFunction · 0.85
linesForFunction · 0.85
isWholeLineUpdateFunction · 0.85
updateFunction · 0.85
signalLaterFunction · 0.85
insertMethod · 0.80

Tested by

no test coverage detected