MCPcopy
hub / github.com/hokein/electron-sample-apps / updateLinesNoUndo

Function updateLinesNoUndo

mini-code-editor/cm/lib/codemirror.js:669–766  ·  view source on GitHub ↗
(from, to, newText, selFrom, selTo)

Source from the content-addressed store, hash-verified

667 function redo() {unredoHelper(history.undone, history.done);}
668
669 function updateLinesNoUndo(from, to, newText, selFrom, selTo) {
670 if (suppressEdits) return;
671 var recomputeMaxLength = false, maxLineLength = maxLine.length;
672 if (!options.lineWrapping)
673 doc.iter(from.line, to.line + 1, function(line) {
674 if (!line.hidden && line.text.length == maxLineLength) {recomputeMaxLength = true; return true;}
675 });
676 if (from.line != to.line || newText.length > 1) gutterDirty = true;
677
678 var nlines = to.line - from.line, firstLine = getLine(from.line), lastLine = getLine(to.line);
679 // First adjust the line structure, taking some care to leave highlighting intact.
680 if (from.ch == 0 && to.ch == 0 && newText[newText.length - 1] == "") {
681 // This is a whole-line replace. Treated specially to make
682 // sure line objects move the way they are supposed to.
683 var added = [], prevLine = null;
684 if (from.line) {
685 prevLine = getLine(from.line - 1);
686 prevLine.fixMarkEnds(lastLine);
687 } else lastLine.fixMarkStarts();
688 for (var i = 0, e = newText.length - 1; i < e; ++i)
689 added.push(Line.inheritMarks(newText[i], prevLine));
690 if (nlines) doc.remove(from.line, nlines, callbacks);
691 if (added.length) doc.insert(from.line, added);
692 } else if (firstLine == lastLine) {
693 if (newText.length == 1)
694 firstLine.replace(from.ch, to.ch, newText[0]);
695 else {
696 lastLine = firstLine.split(to.ch, newText[newText.length-1]);
697 firstLine.replace(from.ch, null, newText[0]);
698 firstLine.fixMarkEnds(lastLine);
699 var added = [];
700 for (var i = 1, e = newText.length - 1; i < e; ++i)
701 added.push(Line.inheritMarks(newText[i], firstLine));
702 added.push(lastLine);
703 doc.insert(from.line + 1, added);
704 }
705 } else if (newText.length == 1) {
706 firstLine.replace(from.ch, null, newText[0]);
707 lastLine.replace(null, to.ch, "");
708 firstLine.append(lastLine);
709 doc.remove(from.line + 1, nlines, callbacks);
710 } else {
711 var added = [];
712 firstLine.replace(from.ch, null, newText[0]);
713 lastLine.replace(null, to.ch, newText[newText.length-1]);
714 firstLine.fixMarkEnds(lastLine);
715 for (var i = 1, e = newText.length - 1; i < e; ++i)
716 added.push(Line.inheritMarks(newText[i], firstLine));
717 if (nlines > 1) doc.remove(from.line + 1, nlines - 1, callbacks);
718 doc.insert(from.line + 1, added);
719 }
720 if (options.lineWrapping) {
721 var perLine = Math.max(5, scroller.clientWidth / charWidth() - 3);
722 doc.iter(from.line, from.line + newText.length, function(line) {
723 if (line.hidden) return;
724 var guess = Math.ceil(line.text.length / perLine) || 1;
725 if (guess != line.height) updateLineHeight(line, guess);
726 });

Callers 2

updateLinesFunction · 0.85
unredoHelperFunction · 0.85

Calls 9

getLineFunction · 0.85
charWidthFunction · 0.85
updateLineHeightFunction · 0.85
highlightLinesFunction · 0.85
startWorkerFunction · 0.85
setSelectionFunction · 0.85
updateLineFunction · 0.85
textHeightFunction · 0.85
paddingTopFunction · 0.85

Tested by

no test coverage detected