From 640bf6dc8d5d5822648cd89265dd355e2d9f6294 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 23 Nov 2012 10:37:14 -0700 Subject: [PATCH] Refactor background tokenization --- src/app/tokenized-buffer.coffee | 49 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/app/tokenized-buffer.coffee b/src/app/tokenized-buffer.coffee index d585d4bb2..510223eb0 100644 --- a/src/app/tokenized-buffer.coffee +++ b/src/app/tokenized-buffer.coffee @@ -70,24 +70,44 @@ class TokenizedBuffer lastRow = @getLastRow() continue if invalidRow > lastRow - filledRegion = false row = invalidRow loop previousStack = @stackForRow(row) @screenLines[row] = @buildTokenizedScreenLineForRow(row, @stackForRow(row - 1)) - @validateRow(row) if --rowsRemaining == 0 + filledRegion = false break if row == lastRow or _.isEqual(@stackForRow(row), previousStack) filledRegion = true break row++ - @trigger "change", { start: invalidRow, end: row, delta: 0} + @validateRow(row) @invalidateRow(row + 1) unless filledRegion + @trigger "change", { start: invalidRow, end: row, delta: 0 } @tokenizeInBackground() + firstInvalidRow: -> + @invalidRows[0] + + validateRow: (row) -> + @invalidRows.shift() while @invalidRows[0] <= row + + invalidateRow: (row) -> + @invalidRows.push(row) + @invalidRows.sort (a, b) -> a - b + @tokenizeInBackground() + + updateInvalidRows: (start, end, delta) -> + @invalidRows = @invalidRows.map (row) -> + if row < start + row + else if start <= row <= end + end + delta + 1 + else if row > end + row + delta + buildPlaceholderScreenLinesForRows: (startRow, endRow) -> @buildPlaceholderScreenLineForRow(row) for row in [startRow..endRow] @@ -188,29 +208,6 @@ class TokenizedBuffer getLastRow: -> @buffer.getLastRow() - firstInvalidRow: -> - @invalidRows[0] - - invalidateRow: (row) -> - @invalidRows.push(row) - @invalidRows.sort (a, b) -> a - b - @tokenizeInBackground() - - validateRow: (row) -> - @invalidRows.shift() if @invalidRows[0] == row - - updateInvalidRows: (start, end, delta) -> - updatedRows = [] - for row in @invalidRows - if row < start - updatedRows.push(row) - else if start <= row <= end - updatedRows.push(end + delta + 1) - else if row > end - updatedRows.push(row + delta) - - @invalidRows = updatedRows - logLines: (start=0, end=@buffer.getLastRow()) -> for row in [start..end] line = @lineForScreenRow(row).text