Only mark trailing whitespace on the last segment of a soft-wrapped line

This commit is contained in:
David Graham & Nathan Sobo
2014-04-09 13:07:02 -06:00
committed by Nathan Sobo
parent b4af0a79d0
commit 5e38add177
2 changed files with 11 additions and 1 deletions

View File

@@ -500,3 +500,12 @@ describe "TokenizedBuffer", ->
# Lines that are *only* whitespace are considered to have trailing whitespace
buffer.insert([10, 0], ' ')
expect(tokenizedBuffer.lineForScreenRow(10).tokens[0].hasTrailingWhitespace).toBe true
it "only marks trailing whitespace on the last segment of a soft-wrapped line", ->
buffer.insert([0, Infinity], ' ')
tokenizedLine = tokenizedBuffer.lineForScreenRow(0)
[segment1, segment2] = tokenizedLine.softWrapAt(16)
expect(segment1.tokens[5].value).toBe ' '
expect(segment1.tokens[5].hasTrailingWhitespace).toBe false
expect(segment2.tokens[6].value).toBe ' '
expect(segment2.tokens[6].hasTrailingWhitespace).toBe true

View File

@@ -125,7 +125,8 @@ class TokenizedLine
position = 0
for token, i in @tokens
token.hasLeadingWhitespace = position < firstNonWhitespacePosition
token.hasTrailingWhitespace = position + token.value.length > firstTrailingWhitespacePosition
# Only the *last* segment of a soft-wrapped line can have trailing whitespace
token.hasTrailingWhitespace = @lineEnding? and (position + token.value.length > firstTrailingWhitespacePosition)
position += token.value.length
isComment: ->