When splitting lines, keep leading whitespace on current line.

If we detect leading whitespace, we replace the next token with the
result of splitting the next token into two tokens, one containing any
leading whitespace and one with the rest. Then the leading whitespace
is added to the current line. When the second half of the split is
processed, it no longer has leading whitespace and is split to the next
line.
This commit is contained in:
Nathan Sobo
2012-02-08 19:15:00 -07:00
parent 21e05f7218
commit 34922a18fe
2 changed files with 31 additions and 5 deletions

View File

@@ -40,13 +40,26 @@ class LineWrapper
length = 0
screenLine = []
while tokens.length
break if length + tokens[0].value.length > @maxLength
token = tokens.shift()
length += token.value.length
screenLine.push token
nextToken = tokens[0]
if length + nextToken.value.length > @maxLength
# keep any leading whitespace on current line
if match = /\b/.exec(nextToken.value)
if match.index > 0
tokens[0..0] = @splitTokenAt(nextToken, match.index)
else
break
nextToken = tokens.shift()
length += nextToken.value.length
screenLine.push nextToken
[screenLine].concat @splitTokens(tokens)
splitTokenAt: (token, index) ->
{ type, value} = token
value1 = value.substring(0, index)
value2 = value.substring(index)
[{value: value1, type }, {value: value2, type}]
buildWrappedLineForBufferRow: (bufferRow) ->
wordRegex = getWordRegex()
line = @buffer.getLine(bufferRow)