replace and replaceAll will return the number of items replaced
This commit is contained in:
parent
581668441a
commit
f79c2d8ce2
1 changed files with 18 additions and 7 deletions
|
|
@ -1093,13 +1093,18 @@ var Editor = function(renderer, session) {
|
|||
if (options)
|
||||
this.$search.set(options);
|
||||
|
||||
var range = this.$search.find(this.session);
|
||||
var range = this.$search.find(this.session),
|
||||
replaced = 0;
|
||||
if (!range)
|
||||
return;
|
||||
return replaced;
|
||||
|
||||
this.$tryReplace(range, replacement);
|
||||
if(this.$tryReplace(range, replacement)) {
|
||||
replaced = 1;
|
||||
}
|
||||
if (range !== null)
|
||||
this.selection.setSelectionRange(range);
|
||||
|
||||
return replaced;
|
||||
};
|
||||
|
||||
this.replaceAll = function(replacement, options) {
|
||||
|
|
@ -1107,20 +1112,26 @@ var Editor = function(renderer, session) {
|
|||
this.$search.set(options);
|
||||
}
|
||||
|
||||
var ranges = this.$search.findAll(this.session);
|
||||
var ranges = this.$search.findAll(this.session),
|
||||
replaced = 0;
|
||||
if (!ranges.length)
|
||||
return;
|
||||
return replaced;
|
||||
|
||||
var selection = this.getSelectionRange();
|
||||
this.clearSelection();
|
||||
this.selection.moveCursorTo(0, 0);
|
||||
|
||||
this.$blockScrolling += 1;
|
||||
for (var i = ranges.length - 1; i >= 0; --i)
|
||||
this.$tryReplace(ranges[i], replacement);
|
||||
for (var i = ranges.length - 1; i >= 0; --i) {
|
||||
if(this.$tryReplace(ranges[i], replacement)) {
|
||||
replaced++;
|
||||
}
|
||||
}
|
||||
|
||||
this.selection.setSelectionRange(selection);
|
||||
this.$blockScrolling -= 1;
|
||||
|
||||
return replaced;
|
||||
};
|
||||
|
||||
this.$tryReplace = function(range, replacement) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue