Skip to content
Snippets Groups Projects
Commit 0634f2e4 authored by Marijn Haverbeke's avatar Marijn Haverbeke
Browse files

Fix several bugs in search code

parent 4ff1fc03
No related branches found
No related tags found
No related merge requests found
......@@ -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();
......
......@@ -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;
......@@ -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},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment