Tab characters render as atomic tokens containing spaces

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-04-05 15:22:57 -06:00
parent 4550f017c3
commit 84ba78c55d
6 changed files with 55 additions and 10 deletions

View File

@@ -56,8 +56,12 @@ class Highlighter
tokenizer = @buffer.getMode().getTokenizer()
line = @buffer.lineForRow(row)
{tokens, state} = tokenizer.getLineTokens(line, state)
tokens = tokens.map (tokenProperties) -> new Token(tokenProperties)
new ScreenLineFragment(tokens, line, [1, 0], [1, 0], { state })
tokenObjects = []
for tokenProperties in tokens
token = new Token(tokenProperties)
tokenObjects.push(token.breakOutTabCharacters()...)
text = _.pluck(tokenObjects, 'value').join('')
new ScreenLineFragment(tokenObjects, text, [1, 0], [1, 0], { state })
lineForScreenRow: (row) ->
@screenLines[row]

View File

@@ -45,19 +45,21 @@ class ScreenLineFragment
new ScreenLineFragment(tokens, text, screenDelta, bufferDelta, {state: other.state})
clipColumn: (column, { skipAtomicTokens }) ->
column = Math.min(column, @text.length)
textLength = @text.length
column = Math.min(column, textLength)
currentColumn = 0
for token in @tokens
nextColumn = token.value.length + currentColumn
break if nextColumn >= column
currentColumn = nextColumn
tokenStartColumn = currentColumn
tokenEndColumn = tokenStartColumn + token.value.length
break if tokenEndColumn > column
currentColumn = tokenEndColumn
if token?.isAtomic
if skipAtomicTokens and column > currentColumn
nextColumn
if skipAtomicTokens and column > tokenStartColumn
tokenEndColumn
else
currentColumn
tokenStartColumn
else
column

View File

@@ -13,3 +13,13 @@ class Token
value1 = @value.substring(0, splitIndex)
value2 = @value.substring(splitIndex)
[new Token(value: value1, type: @type), new Token(value: value2, type: @type)]
breakOutTabCharacters: ->
for substring in @value.match(/([^\t]+|\t)/g)
if substring == '\t'
@buildTabToken()
else
new Token(value: substring, type: @type)
buildTabToken: ->
new Token(value: atom.tabText, type: @type, isAtomic: true)