Assign ::firstNonWhitespace/TrailingWhitespaceIndex in Token::split

Fixes #3277
This commit is contained in:
Nathan Sobo
2014-08-15 12:49:03 -06:00
parent 5975548cec
commit 6c52bcf20c
5 changed files with 52 additions and 36 deletions

View File

@@ -150,11 +150,9 @@ class TokenizedLine
index = 0
for token in @tokens
if index < firstNonWhitespaceIndex
token.hasLeadingWhitespace = true
token.firstNonWhitespaceIndex = Math.min(index + token.value.length, firstNonWhitespaceIndex - index)
# Only the *last* segment of a soft-wrapped line can have trailing whitespace
if @lineEnding? and (index + token.value.length > firstTrailingWhitespaceIndex)
token.hasTrailingWhitespace = true
token.firstTrailingWhitespaceIndex = Math.max(0, firstTrailingWhitespaceIndex - index)
index += token.value.length
@@ -170,12 +168,12 @@ class TokenizedLine
changedText = true
else
if invisibles.space
if token.hasLeadingWhitespace
if token.hasLeadingWhitespace()
token.value = token.value.replace LeadingWhitespaceRegex, (leadingWhitespace) ->
leadingWhitespace.replace RepeatedSpaceRegex, invisibles.space
token.hasInvisibleCharacters = true
changedText = true
if token.hasTrailingWhitespace
if token.hasTrailingWhitespace()
token.value = token.value.replace TrailingWhitespaceRegex, (leadingWhitespace) ->
leadingWhitespace.replace RepeatedSpaceRegex, invisibles.space
token.hasInvisibleCharacters = true