From 0e04fff0ea80fa5cbe96b8354db38bd334aea83a Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 16 Jul 2012 16:04:05 -0700 Subject: upgrade to codemirror 2.3 Signed-off-by: Ananya Sen Conflicts: js/code-editor/codemirror-ninja/theme/lesser-dark-ninja.css Signed-off-by: Ananya Sen --- imports/codemirror/lib/util/search.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'imports/codemirror/lib/util/search.js') diff --git a/imports/codemirror/lib/util/search.js b/imports/codemirror/lib/util/search.js index 63ebca9b..c5a2bccf 100644 --- a/imports/codemirror/lib/util/search.js +++ b/imports/codemirror/lib/util/search.js @@ -14,6 +14,10 @@ function getSearchState(cm) { return cm._searchState || (cm._searchState = new SearchState()); } + function getSearchCursor(cm, query, pos) { + // Heuristic: if the query string is all lowercase, do a case insensitive search. + return cm.getSearchCursor(query, pos, typeof query == "string" && query == query.toLowerCase()); + } function dialog(cm, text, shortText, f) { if (cm.openDialog) cm.openDialog(text, f); else f(prompt(shortText, "")); @@ -23,11 +27,11 @@ else if (confirm(shortText)) fs[0](); } function parseQuery(query) { - var isRE = query.match(/^\/(.*)\/$/); - return isRE ? new RegExp(isRE[1]) : query; + var isRE = query.match(/^\/(.*)\/([a-z]*)$/); + return isRE ? new RegExp(isRE[1], isRE[2].indexOf("i") == -1 ? "" : "i") : query; } var queryDialog = - 'Search: (Use /re/ syntax for regexp search)'; + 'Search: (Use /re/ syntax for regexp search)'; function doSearch(cm, rev) { var state = getSearchState(cm); if (state.query) return findNext(cm, rev); @@ -36,7 +40,7 @@ if (!query || state.query) return; state.query = parseQuery(query); if (cm.lineCount() < 2000) { // This is too expensive on big documents. - for (var cursor = cm.getSearchCursor(query); cursor.findNext();) + for (var cursor = getSearchCursor(cm, query); cursor.findNext();) state.marked.push(cm.markText(cursor.from(), cursor.to(), "CodeMirror-searching")); } state.posFrom = state.posTo = cm.getCursor(); @@ -46,9 +50,9 @@ } function findNext(cm, rev) {cm.operation(function() { var state = getSearchState(cm); - var cursor = cm.getSearchCursor(state.query, rev ? state.posFrom : state.posTo); + var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo); if (!cursor.find(rev)) { - cursor = cm.getSearchCursor(state.query, rev ? {line: cm.lineCount() - 1} : {line: 0, ch: 0}); + cursor = getSearchCursor(cm, state.query, rev ? {line: cm.lineCount() - 1} : {line: 0, ch: 0}); if (!cursor.find(rev)) return; } cm.setSelection(cursor.from(), cursor.to()); @@ -63,8 +67,8 @@ })} var replaceQueryDialog = - 'Replace: (Use /re/ syntax for regexp search)'; - var replacementQueryDialog = 'With: '; + 'Replace: (Use /re/ syntax for regexp search)'; + var replacementQueryDialog = 'With: '; var doReplaceConfirm = "Replace? "; function replace(cm, all) { dialog(cm, replaceQueryDialog, "Replace:", function(query) { @@ -72,23 +76,23 @@ query = parseQuery(query); dialog(cm, replacementQueryDialog, "Replace with:", function(text) { if (all) { - cm.operation(function() { - for (var cursor = cm.getSearchCursor(query); cursor.findNext();) { + cm.compoundChange(function() { cm.operation(function() { + for (var cursor = getSearchCursor(cm, query); cursor.findNext();) { if (typeof query != "string") { var match = cm.getRange(cursor.from(), cursor.to()).match(query); cursor.replace(text.replace(/\$(\d)/, function(w, i) {return match[i];})); } else cursor.replace(text); } - }); + })}); } else { clearSearch(cm); - var cursor = cm.getSearchCursor(query, cm.getCursor()); + var cursor = getSearchCursor(cm, query, cm.getCursor()); function advance() { var start = cursor.from(), match; if (!(match = cursor.findNext())) { - cursor = cm.getSearchCursor(query); + cursor = getSearchCursor(cm, query); if (!(match = cursor.findNext()) || - (cursor.from().line == start.line && cursor.from().ch == start.ch)) return; + (start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return; } cm.setSelection(cursor.from(), cursor.to()); confirmDialog(cm, doReplaceConfirm, "Replace?", -- cgit v1.2.3