mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-02 20:07:25 +03:00
Async-tokenize remaining buffer changes that exceed chunk size
This commit is contained in:
parent
7ead4d7390
commit
dc60017c02
@ -262,6 +262,18 @@ describe "TokenizedBuffer", ->
|
||||
delete event.bufferChange
|
||||
expect(event).toEqual(start: 5, end: 7, delta: 0)
|
||||
|
||||
describe "when there is an insertion that is larger than the chunk size", ->
|
||||
it "tokenizes the initial chunk synchronously, then tokenizes the remaining lines in the background", ->
|
||||
commentBlock = _.multiplyString("// a comment\n", tokenizedBuffer.chunkSize + 2)
|
||||
buffer.insert([0,0], commentBlock)
|
||||
expect(tokenizedBuffer.lineForScreenRow(0).ruleStack?).toBeTruthy()
|
||||
expect(tokenizedBuffer.lineForScreenRow(4).ruleStack?).toBeTruthy()
|
||||
expect(tokenizedBuffer.lineForScreenRow(5).ruleStack?).toBeFalsy()
|
||||
|
||||
advanceClock()
|
||||
expect(tokenizedBuffer.lineForScreenRow(5).ruleStack?).toBeTruthy()
|
||||
expect(tokenizedBuffer.lineForScreenRow(6).ruleStack?).toBeTruthy()
|
||||
|
||||
describe ".findOpeningBracket(closingBufferPosition)", ->
|
||||
it "returns the position of the matching bracket, skipping any nested brackets", ->
|
||||
expect(tokenizedBuffer.findOpeningBracket([9, 2])).toEqual [1, 29]
|
||||
|
@ -107,7 +107,7 @@ class TokenizedBuffer
|
||||
else
|
||||
@screenLines[start..end] = @buildPlaceholderScreenLinesForRows(start, end + delta, stack)
|
||||
|
||||
unless _.isEqual(@stackForRow(end + delta), previousStack)
|
||||
if @stackForRow(end + delta) and not _.isEqual(@stackForRow(end + delta), previousStack)
|
||||
@invalidateRow(end + delta + 1)
|
||||
|
||||
@trigger "change", { start, end, delta, bufferChange: e }
|
||||
@ -122,11 +122,22 @@ class TokenizedBuffer
|
||||
|
||||
buildTokenizedScreenLinesForRows: (startRow, endRow, startingStack) ->
|
||||
ruleStack = startingStack
|
||||
for row in [startRow..endRow]
|
||||
screenLine = @buildTokenizedScreenLineForRow(row, ruleStack)
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user