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

Make at least forward regexp search behave properly wrt $ and ^

parent 0634f2e4
No related branches found
No related tags found
Loading
......@@ -10,29 +10,32 @@
// It takes a position and a direction, and returns an object
// describing the next occurrence of the query, or null if no
// more matches were found.
if (typeof query != "string") // Regexp match
if (typeof query != "string") { // Regexp match
if (!query.global) query = new RegExp(query.source, query.ignoreCase ? "ig" : "g");
this.matches = function(reverse, pos) {
if (reverse) {
var line = cm.getLine(pos.line).slice(0, pos.ch), match = line.match(query), start = 0;
query.lastIndex = 0;
var line = cm.getLine(pos.line).slice(0, pos.ch), match = query.exec(line), start = 0;
while (match) {
start += match.index;
line = line.slice(match.index);
var newmatch = line.match(query);
query.lastIndex = 0;
var newmatch = query.exec(line);
if (newmatch) match = newmatch;
else break;
start++;
}
}
else {
var line = cm.getLine(pos.line).slice(pos.ch), match = line.match(query),
start = match && pos.ch + match.index;
} else {
query.lastIndex = pos.ch;
var line = cm.getLine(pos.line), match = query.exec(line),
start = match && match.index;
}
if (match)
return {from: {line: pos.line, ch: start},
to: {line: pos.line, ch: start + match[0].length},
match: match};
};
else { // String query
} else { // String query
if (caseFold) query = query.toLowerCase();
var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;};
var target = query.split("\n");
......
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