Skip to content

Commit 195de2a

Browse files
committed
fix slow regexp in c9search when line contains \u2028 or \u2029
1 parent 7c6d99c commit 195de2a

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

lib/ace/mode/c9search_highlight_rules.js

+28-11
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,26 @@ var C9SearchHighlightRules = function() {
4949
"start" : [
5050
{
5151
tokenNames : ["c9searchresults.constant.numeric", "c9searchresults.text", "c9searchresults.text", "c9searchresults.keyword"],
52-
regex : "(^\\s+[0-9]+)(:\\s)(.+)",
52+
regex : /(^\s+[0-9]+)(:)(\d*\s?)([^\r\n]+)/,
5353
onMatch : function(val, state, stack) {
5454
var values = this.splitRegex.exec(val);
5555
var types = this.tokenNames;
5656
var tokens = [{
5757
type: types[0],
5858
value: values[1]
59-
},{
59+
}, {
6060
type: types[1],
6161
value: values[2]
6262
}];
6363

64+
if (values[3]) {
65+
if (values[3] == " ")
66+
tokens[1] = { type: types[1], value: values[2] + " " };
67+
else
68+
tokens.push({ type: types[1], value: values[3] });
69+
}
6470
var regex = stack[1];
65-
var str = values[3];
71+
var str = values[4];
6672

6773
var m;
6874
var last = 0;
@@ -85,11 +91,7 @@ var C9SearchHighlightRules = function() {
8591
}
8692
},
8793
{
88-
token : ["string", "text"], // single line
89-
regex : "(\\S.*)(:$)"
90-
},
91-
{
92-
regex : "Searching for .*$",
94+
regex : "^Searching for [^\\r\\n]*$",
9395
onMatch: function(val, state, stack) {
9496
var parts = val.split("\x01");
9597
if (parts.length < 3)
@@ -168,11 +170,26 @@ var C9SearchHighlightRules = function() {
168170
}
169171
},
170172
{
171-
regex : "\\d+",
172-
token: "constant.numeric"
173+
regex : "^(?=Found \\d+ matches)",
174+
token : "text",
175+
next : "numbers"
176+
},
177+
{
178+
token : "string", // single line
179+
regex : "^\\S:?[^:]+",
180+
next : "numbers"
173181
}
174-
]
182+
],
183+
numbers:[{
184+
regex : "\\d+",
185+
token : "constant.numeric"
186+
}, {
187+
regex : "$",
188+
token : "text",
189+
next : "start"
190+
}]
175191
};
192+
this.normalizeRules();
176193
};
177194

178195
oop.inherits(C9SearchHighlightRules, TextHighlightRules);

tool/mode_creator.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function run() {
203203
src = src.replace("define(", 'define("' + path +'", ["require","exports","module",' + deps +'],');
204204
try {
205205
eval(src);
206-
require(["ace/mode/new"], function(e) {
206+
require([path], function(e) {
207207
try {
208208
continueRun(e);
209209
} catch(e) {
@@ -228,7 +228,8 @@ var continueRun = function(rules) {
228228
}
229229
currentRules = new rules().getRules();
230230
var Tokenizer = DebugTokenizer;
231-
231+
var Mode = require(editor2.session.$mode.$id).Mode;
232+
editor2.session.$mode = new Mode();
232233
var tk = new Tokenizer(currentRules);
233234
editor2.session.$mode.$tokenizer = tk;
234235
editor2.session.bgTokenizer.setTokenizer(tk);

0 commit comments

Comments
 (0)