Skip to content

Commit e204732

Browse files
committed
[search addon] Fix highlighting around \b markers in regexp search
Issue #2475
1 parent 76525ac commit e204732

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
@@ -8,21 +8,21 @@
88

99
(function() {
1010
function searchOverlay(query, caseInsensitive) {
11-
var startChar;
12-
if (typeof query == "string") {
13-
startChar = query.charAt(0);
14-
query = new RegExp("^" + query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"),
15-
caseInsensitive ? "i" : "");
16-
} else {
17-
query = new RegExp("^(?:" + query.source + ")", query.ignoreCase ? "i" : "");
18-
}
11+
if (typeof query == "string")
12+
query = new RegExp(query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), caseInsensitive ? "gi" : "g");
13+
else if (!query.global)
14+
query = new RegExp(query.source, query.ignoreCase ? "gi" : "g");
15+
1916
return {token: function(stream) {
20-
if (stream.match(query)) return "searching";
21-
while (!stream.eol()) {
22-
stream.next();
23-
if (startChar && !caseInsensitive)
24-
stream.skipTo(startChar) || stream.skipToEnd();
25-
if (stream.match(query, false)) break;
17+
query.lastIndex = stream.pos;
18+
var match = query.exec(stream.string);
19+
if (match && match.index == stream.pos) {
20+
stream.pos += match[0].length;
21+
return "searching";
22+
} else if (match) {
23+
stream.pos = match.index;
24+
} else {
25+
stream.skipToEnd();
2626
}
2727
}};
2828
}

0 commit comments

Comments
 (0)