Skip to content

Commit

Permalink
Treat all whitespace lines as not having leading whitespace
Browse files Browse the repository at this point in the history
Instead it's treated as all trailing whitespace, as it was originally.
  • Loading branch information
Nathan Sobo committed Apr 22, 2014
1 parent e3eb51c commit 28dd7d4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions spec/tokenized-buffer-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@ describe "TokenizedBuffer", ->
expect(tokenizedBuffer.lineForScreenRow(5).tokens[3].hasLeadingWhitespace).toBe true
expect(tokenizedBuffer.lineForScreenRow(5).tokens[4].hasLeadingWhitespace).toBe false

# Lines that are *only* whitespace are considered to have leading whitespace
# Lines that are *only* whitespace are not considered to have leading whitespace
buffer.insert([10, 0], ' ')
expect(tokenizedBuffer.lineForScreenRow(10).tokens[0].hasLeadingWhitespace).toBe true
expect(tokenizedBuffer.lineForScreenRow(10).tokens[0].hasLeadingWhitespace).toBe false

it "sets ::hasTrailingWhitespace to true on tokens that have trailing whitespace", ->
buffer.insert([0, Infinity], ' ')
Expand Down
4 changes: 2 additions & 2 deletions src/token.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Token
leadingHtml = ''
trailingHtml = ''

if @hasLeadingWhitespace and not @hasTrailingWhitespace and match = LeadingWhitespaceRegex.exec(@value)
if @hasLeadingWhitespace and match = LeadingWhitespaceRegex.exec(@value)
classes = 'leading-whitespace'
classes += ' indent-guide' if hasIndentGuide
classes += ' invisible-character' if invisibles.space
Expand All @@ -156,7 +156,7 @@ class Token

if @hasTrailingWhitespace and match = TrailingWhitespaceRegex.exec(@value)
classes = 'trailing-whitespace'
classes += ' indent-guide' if hasIndentGuide and @hasLeadingWhitespace
classes += ' indent-guide' if hasIndentGuide and not @hasLeadingWhitespace
classes += ' invisible-character' if invisibles.space

match[0] = match[0].replace(CharacterRegex, invisibles.space) if invisibles.space
Expand Down
2 changes: 1 addition & 1 deletion src/tokenized-line.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class TokenizedLine
outputTokens

markLeadingAndTrailingWhitespaceTokens: ->
firstNonWhitespacePosition = @text.search(/\S|$/)
firstNonWhitespacePosition = @text.search(/\S/)
firstTrailingWhitespacePosition = @text.search(/\s*$/)
lineIsWhitespaceOnly = firstTrailingWhitespacePosition is 0
position = 0
Expand Down

0 comments on commit 28dd7d4

Please sign in to comment.