(from, to, newText, selFrom, selTo)
| 867 | function redo() {unredoHelper(history.undone, history.done);} |
| 868 | |
| 869 | function updateLinesNoUndo(from, to, newText, selFrom, selTo) { |
| 870 | if (suppressEdits) return; |
| 871 | var recomputeMaxLength = false, maxLineLength = maxLine.length; |
| 872 | if (!options.lineWrapping) |
| 873 | doc.iter(from.line, to.line + 1, function(line) { |
| 874 | if (!line.hidden && line.text.length == maxLineLength) {recomputeMaxLength = true; return true;} |
| 875 | }); |
| 876 | if (from.line != to.line || newText.length > 1) gutterDirty = true; |
| 877 | |
| 878 | var nlines = to.line - from.line, firstLine = getLine(from.line), lastLine = getLine(to.line); |
| 879 | // First adjust the line structure, taking some care to leave highlighting intact. |
| 880 | if (from.ch == 0 && to.ch == 0 && newText[newText.length - 1] == "") { |
| 881 | // This is a whole-line replace. Treated specially to make |
| 882 | // sure line objects move the way they are supposed to. |
| 883 | var added = [], prevLine = null; |
| 884 | if (from.line) { |
| 885 | prevLine = getLine(from.line - 1); |
| 886 | prevLine.fixMarkEnds(lastLine); |
| 887 | } else lastLine.fixMarkStarts(); |
| 888 | for (var i = 0, e = newText.length - 1; i < e; ++i) |
| 889 | added.push(Line.inheritMarks(newText[i], prevLine)); |
| 890 | if (nlines) doc.remove(from.line, nlines, callbacks); |
| 891 | if (added.length) doc.insert(from.line, added); |
| 892 | } else if (firstLine == lastLine) { |
| 893 | if (newText.length == 1) |
| 894 | firstLine.replace(from.ch, to.ch, newText[0]); |
| 895 | else { |
| 896 | lastLine = firstLine.split(to.ch, newText[newText.length-1]); |
| 897 | firstLine.replace(from.ch, null, newText[0]); |
| 898 | firstLine.fixMarkEnds(lastLine); |
| 899 | var added = []; |
| 900 | for (var i = 1, e = newText.length - 1; i < e; ++i) |
| 901 | added.push(Line.inheritMarks(newText[i], firstLine)); |
| 902 | added.push(lastLine); |
| 903 | doc.insert(from.line + 1, added); |
| 904 | } |
| 905 | } else if (newText.length == 1) { |
| 906 | firstLine.replace(from.ch, null, newText[0]); |
| 907 | lastLine.replace(null, to.ch, ""); |
| 908 | firstLine.append(lastLine); |
| 909 | doc.remove(from.line + 1, nlines, callbacks); |
| 910 | } else { |
| 911 | var added = []; |
| 912 | firstLine.replace(from.ch, null, newText[0]); |
| 913 | lastLine.replace(null, to.ch, newText[newText.length-1]); |
| 914 | firstLine.fixMarkEnds(lastLine); |
| 915 | for (var i = 1, e = newText.length - 1; i < e; ++i) |
| 916 | added.push(Line.inheritMarks(newText[i], firstLine)); |
| 917 | if (nlines > 1) doc.remove(from.line + 1, nlines - 1, callbacks); |
| 918 | doc.insert(from.line + 1, added); |
| 919 | } |
| 920 | if (options.lineWrapping) { |
| 921 | var perLine = Math.max(5, scroller.clientWidth / charWidth() - 3); |
| 922 | doc.iter(from.line, from.line + newText.length, function(line) { |
| 923 | if (line.hidden) return; |
| 924 | var guess = Math.ceil(line.text.length / perLine) || 1; |
| 925 | if (guess != line.height) updateLineHeight(line, guess); |
| 926 | }); |
no test coverage detected