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:
parent
6db9e31ab6
commit
45f27b3fae
1 changed files with 10 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue