mirror of
https://github.com/atom/atom.git
synced 2026-02-09 06:05:11 -05:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user