Cleanup TokenizedBuffer

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-12-11 17:16:34 -08:00
parent d0a213b2b1
commit ab96129ef6

View File

@@ -98,20 +98,32 @@ class TokenizedBuffer
delta = newRange.end.row - oldRange.end.row
@updateInvalidRows(start, end, delta)
previousEndStack = @stackForRow(end) # used in spill detection below
@screenLines[start..end] = @buildScreenLinesForRows(start, end + delta, @stackForRow(start - 1))
newEndStack = @stackForRow(end + delta)
previousStack = @stackForRow(end) # used in spill detection below
stack = @stackForRow(start - 1)
if stack? or start == 0
@screenLines[start..end] = @buildTokenizedScreenLinesForRows(start, end + delta, stack)
else
@screenLines[start..end] = @buildPlaceholderScreenLinesForRows(start, end + delta, stack)
if @stackForRow(end + delta) and not _.isEqual(@stackForRow(end + delta), previousStack)
if newEndStack and not _.isEqual(newEndStack, previousEndStack)
@invalidateRow(end + delta + 1)
@trigger "change", { start, end, delta, bufferChange: e }
buildScreenLinesForRows: (startRow, endRow, startingStack) ->
ruleStack = startingStack
stopTokenizingAt = startRow + @chunkSize
screenLines = for row in [startRow..endRow]
if (ruleStack or row == 0) and row < stopTokenizingAt
screenLine = @buildTokenizedScreenLineForRow(row, ruleStack)
ruleStack = screenLine.ruleStack
else
screenLine = @buildPlaceholderScreenLineForRow(row)
screenLine
if endRow >= stopTokenizingAt
@invalidateRow(stopTokenizingAt)
@tokenizeInBackground()
screenLines
buildPlaceholderScreenLinesForRows: (startRow, endRow) ->
@buildPlaceholderScreenLineForRow(row) for row in [startRow..endRow]
@@ -120,24 +132,6 @@ class TokenizedBuffer
tokens = [new Token(value: line, scopes: [@languageMode.grammar.scopeName])]
new ScreenLine({tokens, @tabLength})
buildTokenizedScreenLinesForRows: (startRow, endRow, startingStack) ->
ruleStack = startingStack
lastRowToTokenize = startRow + @chunkSize - 1
screenLines = for row in [startRow..endRow]
if row <= lastRowToTokenize
screenLine = @buildTokenizedScreenLineForRow(row, ruleStack)
else
screenLine = @buildPlaceholderScreenLineForRow(row)
ruleStack = screenLine.ruleStack
screenLine
if endRow > lastRowToTokenize
@invalidateRow(lastRowToTokenize + 1)
@tokenizeInBackground()
screenLines
buildTokenizedScreenLineForRow: (row, ruleStack) ->
line = @buffer.lineForRow(row)
{ tokens, ruleStack } = @languageMode.tokenizeLine(line, ruleStack)