Permalink
Browse files

Improve es5 strict mode compatibility.

In es5 strict mode "function" could only be a top-level statement.
  • Loading branch information...
1 parent d37d3db commit a7e00f580ded53aaf0f887339f88b7569a07aa11 @eustas eustas committed with marijnh Feb 5, 2013
Showing with 17 additions and 18 deletions.
  1. +17 −18 lib/util/search.js
View
@@ -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();) {
@@ -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()));
}
});
});

0 comments on commit a7e00f5

Please sign in to comment.