MCPcopy
hub / github.com/csev/py4e / updateDoc

Function updateDoc

tools/pythonauto/static/codemirror/codemirror.js:4740–4785  ·  view source on GitHub ↗
(doc, change, markedSpans, selAfter, estimateHeight)

Source from the content-addressed store, hash-verified

4738 // DOCUMENT DATA STRUCTURE
4739
4740 function updateDoc(doc, change, markedSpans, selAfter, estimateHeight) {
4741 function spansFor(n) {return markedSpans ? markedSpans[n] : null;}
4742 function update(line, text, spans) {
4743 updateLine(line, text, spans, estimateHeight);
4744 signalLater(line, "change", line, change);
4745 }
4746
4747 var from = change.from, to = change.to, text = change.text;
4748 var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
4749 var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
4750
4751 // First adjust the line structure
4752 if (from.ch == 0 && to.ch == 0 && lastText == "" &&
4753 (!doc.cm || doc.cm.options.wholeLineUpdateBefore)) {
4754 // This is a whole-line replace. Treated specially to make
4755 // sure line objects move the way they are supposed to.
4756 for (var i = 0, e = text.length - 1, added = []; i < e; ++i)
4757 added.push(new Line(text[i], spansFor(i), estimateHeight));
4758 update(lastLine, lastLine.text, lastSpans);
4759 if (nlines) doc.remove(from.line, nlines);
4760 if (added.length) doc.insert(from.line, added);
4761 } else if (firstLine == lastLine) {
4762 if (text.length == 1) {
4763 update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
4764 } else {
4765 for (var added = [], i = 1, e = text.length - 1; i < e; ++i)
4766 added.push(new Line(text[i], spansFor(i), estimateHeight));
4767 added.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight));
4768 update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
4769 doc.insert(from.line + 1, added);
4770 }
4771 } else if (text.length == 1) {
4772 update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
4773 doc.remove(from.line + 1, nlines);
4774 } else {
4775 update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
4776 update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
4777 for (var i = 1, e = text.length - 1, added = []; i < e; ++i)
4778 added.push(new Line(text[i], spansFor(i), estimateHeight));
4779 if (nlines > 1) doc.remove(from.line + 1, nlines - 1);
4780 doc.insert(from.line + 1, added);
4781 }
4782
4783 signalLater(doc, "change", doc, change);
4784 setSelection(doc, selAfter.anchor, selAfter.head, null, true);
4785 }
4786
4787 function LeafChunk(lines) {
4788 this.lines = lines;

Callers 3

makeChangeSingleDocFunction · 0.70
codemirror.jsFile · 0.70

Calls 8

sliceMethod · 0.80
getLineFunction · 0.70
lstFunction · 0.70
spansForFunction · 0.70
updateFunction · 0.70
signalLaterFunction · 0.70
setSelectionFunction · 0.70
insertMethod · 0.45

Tested by

no test coverage detected