Skip to content

Commit

Permalink
Improve es5 strict mode compatibility.
Browse files Browse the repository at this point in the history
In es5 strict mode "function" could only be a top-level statement.
  • Loading branch information
eustas authored and marijnh committed Feb 5, 2013
1 parent d37d3db commit a7e00f5
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions lib/util/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@
if (!query) return;
query = parseQuery(query);
dialog(cm, replacementQueryDialog, "Replace with:", function(text) {
function advance(cursor) {
var start = cursor.from(), match;
if (!(match = cursor.findNext())) {
cursor = getSearchCursor(cm, query);
if (!(match = cursor.findNext()) ||
(start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
}
cm.setSelection(cursor.from(), cursor.to());
confirmDialog(cm, doReplaceConfirm, "Replace?",
[function() {doReplace(cursor, match);}, function() {advance(cursor);}]);
}
function doReplace(cursor, match) {
cursor.replace(typeof query == "string" ? text :
text.replace(/\$(\d)/, function(w, i) {return match[i];}));
advance(cursor);
}
if (all) {
cm.compoundChange(function() { cm.operation(function() {
for (var cursor = getSearchCursor(cm, query); cursor.findNext();) {
Expand All @@ -86,24 +102,7 @@
});});
} else {
clearSearch(cm);
var cursor = getSearchCursor(cm, query, cm.getCursor());
function advance() {
var start = cursor.from(), match;
if (!(match = cursor.findNext())) {
cursor = getSearchCursor(cm, query);
if (!(match = cursor.findNext()) ||
(start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
}
cm.setSelection(cursor.from(), cursor.to());
confirmDialog(cm, doReplaceConfirm, "Replace?",
[function() {doReplace(match);}, advance]);
}
function doReplace(match) {
cursor.replace(typeof query == "string" ? text :
text.replace(/\$(\d)/, function(w, i) {return match[i];}));
advance();
}
advance();
advance(getSearchCursor(cm, query, cm.getCursor()));
}
});
});
Expand Down

0 comments on commit a7e00f5

Please sign in to comment.