Don't perform a replace operation in Document.replace if there is nothing to replace. Increases performance in wrapMode if inserting many lines

This commit is contained in:
Julian Viereck 2011-01-11 16:13:03 +08:00 committed by Fabian Jakobs
commit 45f27b3fae

View file

@ -675,6 +675,16 @@ var Document = function(text, mode) {
},
this.replace = function(range, text) {
// Shortcut: Nothing to replace in this case.
if (text.length == 0 && range.isEmpty()) {
return range.start;
} else
// Shortcut: If the text we want to insert is the same as it is already
// in the document, we don't have to replace anything.
if (text == this.getTextRange(range)) {
return range.end;
}
this.$remove(range);
if (text) {
var end = this.$insert(range.start, text);