Skip to content

Commit

Permalink
Merge pull request ajaxorg#1473 from ajaxorg/bgTokenizer
Browse files Browse the repository at this point in the history
bgTokenizer worker should not redraw unnecessarily
  • Loading branch information
Ruben Daniels committed Jul 6, 2013
2 parents 95e0f2f + 069bbda commit 62653ea
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions lib/ace/background_tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,37 @@ var BackgroundTokenizer = function(tokenizer, editor) {
if (!self.running) { return; }

var workerStart = new Date();
var startLine = self.currentLine;
var currentLine = self.currentLine;
var endLine = -1;
var doc = self.doc;

var processedLines = 0;
while (self.lines[currentLine])
currentLine++;

var startLine = currentLine;

var len = doc.getLength();
while (self.currentLine < len) {
self.$tokenizeRow(self.currentLine);
while (self.lines[self.currentLine])
self.currentLine++;
var processedLines = 0;
self.running = false;
while (currentLine < len) {
self.$tokenizeRow(currentLine);
endLine = currentLine;
do {
currentLine++;
} while (self.lines[currentLine]);

// only check every 5 lines
processedLines ++;
if ((processedLines % 5 == 0) && (new Date() - workerStart) > 20) {
self.fireUpdateEvent(startLine, self.currentLine-1);
if ((processedLines % 5 == 0) && (new Date() - workerStart) > 20) {
self.running = setTimeout(self.$worker, 20);
self.currentLine = currentLine;
return;
}
}

self.running = false;

self.fireUpdateEvent(startLine, len - 1);
self.currentLine = currentLine;

if (startLine <= endLine)
self.fireUpdateEvent(startLine, endLine);
};
};

Expand Down

0 comments on commit 62653ea

Please sign in to comment.