Add metadata to screenLines returned by splitTokens

This commit is contained in:
Nathan Sobo
2012-02-09 10:18:37 -07:00
parent bbedfeadc8
commit 93bce8ccdf
2 changed files with 64 additions and 57 deletions

View File

@@ -34,23 +34,24 @@ class LineWrapper
for row in [start..end]
@buildWrappedLineForBufferRow(row)
splitTokens: (tokens) ->
splitTokens: (tokens, startColumn = 0) ->
return [] unless tokens.length
length = 0
textLength = 0
screenLine = []
while tokens.length
nextToken = tokens[0]
if length + nextToken.value.length > @maxLength
tokenFragments = @splitBoundaryToken(nextToken, @maxLength - length)
if textLength + nextToken.value.length > @maxLength
tokenFragments = @splitBoundaryToken(nextToken, @maxLength - textLength)
[token1, token2] = tokenFragments
tokens[0..0] = _.compact(tokenFragments)
break unless token1
nextToken = tokens.shift()
length += nextToken.value.length
textLength += nextToken.value.length
screenLine.push nextToken
[screenLine].concat @splitTokens(tokens)
_.extend(screenLine, { startColumn, textLength, endColumn: startColumn + textLength })
[screenLine].concat @splitTokens(tokens, screenLine.endColumn)
splitBoundaryToken: (token, boundaryIndex) ->
{ value } = token