Add indent guide to whitespace lines

The whitespace in lines that have no non-whitespace
text is treated as trailing whitespace so add the
indent guide to the trailing whitespace tokens when the
line is 100% whitespace.
This commit is contained in:
Kevin Sawicki
2013-02-20 15:40:44 -08:00
parent 1db21c91cc
commit 2457e7f5b2
3 changed files with 19 additions and 7 deletions

View File

@@ -1201,16 +1201,14 @@ class Editor extends View
else
firstNonWhitespacePosition = screenLine.text.search(/\S/)
firstTrailingWhitespacePosition = screenLine.text.search(/\s*$/)
lineIsWhitespaceOnly = firstTrailingWhitespacePosition is 0
position = 0
for token in screenLine.tokens
updateScopeStack(token.scopes)
line.push(token.getValueAsHtml(
invisibles: invisibles
hasLeadingWhitespace: position < firstNonWhitespacePosition
hasTrailingWhitespace: position + token.value.length > firstTrailingWhitespacePosition
hasIndentGuide: @showIndentGuide
))
hasLeadingWhitespace = position < firstNonWhitespacePosition
hasTrailingWhitespace = position + token.value.length > firstTrailingWhitespacePosition
hasIndentGuide = @showIndentGuide and (hasLeadingWhitespace or lineIsWhitespaceOnly)
line.push(token.getValueAsHtml({invisibles, hasLeadingWhitespace, hasTrailingWhitespace, hasIndentGuide}))
position += token.value.length
popScope() while scopeStack.length > 0

View File

@@ -92,6 +92,7 @@ class Token
html = html.replace /[ ]+$/, (match) ->
classes = []
classes.push('invisible') if invisibles.space
classes.push('indent-guide') if hasIndentGuide
classes.push('trailing-whitespace')
match = match.replace(/./g, invisibles.space) if invisibles.space
"<span class='#{classes.join(' ')}'>#{match}</span>"