Skip to content

Commit 7b51bfb

Browse files
committed
[search addon] Fix highlighting around \b markers in regexp search
Issue #2475
1 parent c8bb745 commit 7b51bfb

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

addon/search/search.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616
})(function(CodeMirror) {
1717
"use strict";
1818
function searchOverlay(query, caseInsensitive) {
19-
var startChar;
20-
if (typeof query == "string") {
21-
startChar = query.charAt(0);
22-
query = new RegExp("^" + query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"),
23-
caseInsensitive ? "i" : "");
24-
} else {
25-
query = new RegExp("^(?:" + query.source + ")", query.ignoreCase ? "i" : "");
26-
}
19+
if (typeof query == "string")
20+
query = new RegExp(query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), caseInsensitive ? "gi" : "g");
21+
else if (!query.global)
22+
query = new RegExp(query.source, query.ignoreCase ? "gi" : "g");
23+
2724
return {token: function(stream) {
28-
if (stream.match(query)) return "searching";
29-
while (!stream.eol()) {
30-
stream.next();
31-
if (startChar && !caseInsensitive)
32-
stream.skipTo(startChar) || stream.skipToEnd();
33-
if (stream.match(query, false)) break;
25+
query.lastIndex = stream.pos;
26+
var match = query.exec(stream.string);
27+
if (match && match.index == stream.pos) {
28+
stream.pos += match[0].length;
29+
return "searching";
30+
} else if (match) {
31+
stream.pos = match.index;
32+
} else {
33+
stream.skipToEnd();
3434
}
3535
}};
3636
}

0 commit comments

Comments
 (0)