Always seek to specified position in TokenizedBufferIterator

Fixes #10350

Signed-off-by: Antonio Scandurra <as-cii@github.com>
This commit is contained in:
Nathan Sobo
2016-08-02 12:19:45 -06:00
committed by Antonio Scandurra
parent ed5ad3cee7
commit 2b5f1bda46
3 changed files with 145 additions and 86 deletions

View File

@@ -18,24 +18,31 @@ class TokenizedBufferIterator
@currentLineLength = currentLine.text.length
@containingTags = @currentLineOpenTags.map (id) => @grammarRegistry.scopeForId(id)
currentColumn = 0
for tag, index in @currentTags
if tag >= 0
if currentColumn >= position.column and @isAtTagBoundary()
if currentColumn is position.column
@tagIndex = index
break
else
currentColumn += tag
@containingTags.pop() while @closeTags.shift()
@containingTags.push(tag) while tag = @openTags.shift()
else
scopeName = @grammarRegistry.scopeForId(tag)
if tag % 2 is 0
if @openTags.length > 0
@containingTags.push(openTag) while openTag = @openTags.shift()
if currentColumn > position.column
@tagIndex = index
break
else
@closeTags.push(scopeName)
else
else
scopeName = @grammarRegistry.scopeForId(tag)
if tag % 2 is 0 # close tag
if @openTags.length > 0
if currentColumn is position.column
@tagIndex = index
break
else
@containingTags.pop() while @closeTags.shift()
@containingTags.push(openTag) while openTag = @openTags.shift()
@closeTags.push(scopeName)
else # open tag
@openTags.push(scopeName)
@tagIndex ?= @currentTags.length