mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Tokenize empty lines with a changed indent level synchronously
This commit is contained in:
committed by
Ben Ogle
parent
de2930fe99
commit
4642d96f39
@@ -157,32 +157,29 @@ class TokenizedBuffer extends Model
|
||||
end = oldRange.end.row
|
||||
delta = newRange.end.row - oldRange.end.row
|
||||
|
||||
@invalidateSurroundingChangedWhitespaceRows(start, end)
|
||||
@updateInvalidRows(start, end, delta)
|
||||
previousEndStack = @stackForRow(end) # used in spill detection below
|
||||
newTokenizedLines = @buildTokenizedLinesForRows(start, end + delta, @stackForRow(start - 1))
|
||||
_.spliceWithArray(@tokenizedLines, start, end - start + 1, newTokenizedLines)
|
||||
newEndStack = @stackForRow(end + delta)
|
||||
|
||||
start = @retokenizeWhitespaceRowsIfIndentLevelChanged(start - 1, -1)
|
||||
end = @retokenizeWhitespaceRowsIfIndentLevelChanged(newRange.end.row + 1, 1) - delta
|
||||
|
||||
newEndStack = @stackForRow(end + delta)
|
||||
if newEndStack and not _.isEqual(newEndStack, previousEndStack)
|
||||
@invalidateRow(end + delta + 1)
|
||||
|
||||
@emit "changed", { start, end, delta, bufferChange: e }
|
||||
|
||||
invalidateSurroundingChangedWhitespaceRows: (startRow, endRow) ->
|
||||
# Indent levels might change when something else in the buffer changes.
|
||||
# If they do, invalidate those rows.
|
||||
@invalidateChangedWhitespaceRows(startRow - 1, -1)
|
||||
@invalidateChangedWhitespaceRows(endRow + 1, 1)
|
||||
|
||||
invalidateChangedWhitespaceRows: (row, increment) ->
|
||||
retokenizeWhitespaceRowsIfIndentLevelChanged: (row, increment) ->
|
||||
line = @tokenizedLines[row]
|
||||
if line?.isOnlyWhitespace() and @indentLevelForRow(row) != line.indentLevel
|
||||
if line?.isOnlyWhitespace() and @indentLevelForRow(row) isnt line.indentLevel
|
||||
while line?.isOnlyWhitespace()
|
||||
@invalidateRow(row)
|
||||
@tokenizedLines[row] = @buildTokenizedTokenizedLineForRow(row, @stackForRow(row - 1))
|
||||
row += increment
|
||||
line = @tokenizedLines[row]
|
||||
return
|
||||
|
||||
row - increment
|
||||
|
||||
buildTokenizedLinesForRows: (startRow, endRow, startingStack) ->
|
||||
ruleStack = startingStack
|
||||
|
||||
Reference in New Issue
Block a user