Skip to content

Commit

Permalink
Merge pull request ajaxorg#591 from okonomiyaki3000/master
Browse files Browse the repository at this point in the history
Numer of items replaced
  • Loading branch information
fjakobs committed Apr 11, 2012
2 parents 59ddc64 + 68a812c commit 32c88cf
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/ace/editor.js
Expand Up @@ -1151,12 +1151,17 @@ var Editor = function(renderer, session) {
this.$search.set(options);

var range = this.$search.find(this.session);
var 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) {
Expand All @@ -1165,19 +1170,25 @@ var Editor = function(renderer, session) {
}

var ranges = this.$search.findAll(this.session);
var 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) {
Expand Down

0 comments on commit 32c88cf

Please sign in to comment.