Skip to content

Commit

Permalink
Fix several bugs in search code
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Jul 31, 2012
1 parent 4ff1fc0 commit 0634f2e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/util/search.js
Expand Up @@ -40,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 = getSearchCursor(cm, query); cursor.findNext();)
for (var cursor = getSearchCursor(cm, state.query); cursor.findNext();)
state.marked.push(cm.markText(cursor.from(), cursor.to(), "CodeMirror-searching"));
}
state.posFrom = state.posTo = cm.getCursor();
Expand Down
7 changes: 3 additions & 4 deletions lib/util/searchcursor.js
Expand Up @@ -15,9 +15,8 @@
if (reverse) {
var line = cm.getLine(pos.line).slice(0, pos.ch), match = line.match(query), start = 0;
while (match) {
var ind = line.indexOf(match[0]);
start += ind;
line = line.slice(ind + 1);
start += match.index;
line = line.slice(match.index);
var newmatch = line.match(query);
if (newmatch) match = newmatch;
else break;
Expand All @@ -26,7 +25,7 @@
}
else {
var line = cm.getLine(pos.line).slice(pos.ch), match = line.match(query),
start = match && pos.ch + line.indexOf(match[0]);
start = match && pos.ch + match.index;
}
if (match)
return {from: {line: pos.line, ch: start},
Expand Down

0 comments on commit 0634f2e

Please sign in to comment.