Merge pull request #591 from okonomiyaki3000/master

Numer of items replaced
This commit is contained in:
Fabian Jakobs 2012-04-11 09:13:11 -07:00
commit 32c88cfb77

View file

@ -1151,12 +1151,17 @@ var Editor = function(renderer, session) {
this.$search.set(options); this.$search.set(options);
var range = this.$search.find(this.session); var range = this.$search.find(this.session);
var replaced = 0;
if (!range) if (!range)
return; return replaced;
this.$tryReplace(range, replacement); if(this.$tryReplace(range, replacement)) {
replaced = 1;
}
if (range !== null) if (range !== null)
this.selection.setSelectionRange(range); this.selection.setSelectionRange(range);
return replaced;
}; };
this.replaceAll = function(replacement, options) { this.replaceAll = function(replacement, options) {
@ -1165,19 +1170,25 @@ var Editor = function(renderer, session) {
} }
var ranges = this.$search.findAll(this.session); var ranges = this.$search.findAll(this.session);
var replaced = 0;
if (!ranges.length) if (!ranges.length)
return; return replaced;
var selection = this.getSelectionRange(); var selection = this.getSelectionRange();
this.clearSelection(); this.clearSelection();
this.selection.moveCursorTo(0, 0); this.selection.moveCursorTo(0, 0);
this.$blockScrolling += 1; this.$blockScrolling += 1;
for (var i = ranges.length - 1; i >= 0; --i) for (var i = ranges.length - 1; i >= 0; --i) {
this.$tryReplace(ranges[i], replacement); if(this.$tryReplace(ranges[i], replacement)) {
replaced++;
}
}
this.selection.setSelectionRange(selection); this.selection.setSelectionRange(selection);
this.$blockScrolling -= 1; this.$blockScrolling -= 1;
return replaced;
}; };
this.$tryReplace = function(range, replacement) { this.$tryReplace = function(range, replacement) {