prevent higlight_word from freezing the browser on long lines

This commit is contained in:
nightwing 2012-10-27 22:19:55 +04:00
commit a334a64691

View file

@ -42,6 +42,9 @@ var SearchHighlight = function(regExp, clazz, type) {
};
(function() {
// needed to prevent long lines from freezing the browser
this.MAX_RANGES = 500;
this.setRegexp = function(regExp) {
if (this.regExp+"" == regExp+"")
return;
@ -58,6 +61,8 @@ var SearchHighlight = function(regExp, clazz, type) {
var ranges = this.cache[i];
if (ranges == null) {
ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
if (ranges.length > this.MAX_RANGES)
ranges = ranges.slice(0, this.MAX_RANGES);
ranges = ranges.map(function(match) {
return new Range(i, match.offset, i, match.offset + match.length);
});