Return token objects from tokensForScreenRow

Include the text of each token alongside its array of scopes.

Signed-off-by: Nathan Sobo <nathan@github.com>
This commit is contained in:
Max Brunsfeld
2016-07-26 12:39:41 -07:00
committed by Nathan Sobo
parent 20b54505f3
commit 455d3213ed
2 changed files with 66 additions and 16 deletions

View File

@@ -809,8 +809,22 @@ class TextEditor extends Model
return
tokensForScreenRow: (screenRow) ->
for tagCode in @screenLineForScreenRow(screenRow).tagCodes when @displayLayer.isOpenTagCode(tagCode)
@displayLayer.tagForCode(tagCode)
tokens = []
lineTextIndex = 0
currentTokenScopes = []
{lineText, tagCodes} = @screenLineForScreenRow(screenRow)
for tagCode in tagCodes
if @displayLayer.isOpenTagCode(tagCode)
currentTokenScopes.push(@displayLayer.tagForCode(tagCode))
else if @displayLayer.isCloseTagCode(tagCode)
currentTokenScopes.pop()
else
tokens.push({
text: lineText.substr(lineTextIndex, tagCode)
scopes: currentTokenScopes.slice()
})
lineTextIndex += tagCode
tokens
screenLineForScreenRow: (screenRow) ->
return if screenRow < 0 or screenRow > @getLastScreenRow()