Rely on token's knowledge of its own leading/trailing whitespace status

Previously, we were determining this at render time. But its baked into
the state of tokens when TokenizedLines are constructed now so we no
longer need to compute it when rendering.
This commit is contained in:
David Graham & Nathan Sobo
2014-04-09 13:49:27 -06:00
committed by Nathan Sobo
parent cf27826156
commit 6b10fcc2f8
2 changed files with 5 additions and 7 deletions

View File

@@ -1488,10 +1488,8 @@ class EditorView extends View
position = 0
for token in tokens
@updateScopeStack(line, scopeStack, token.scopes)
hasLeadingWhitespace = position < firstNonWhitespacePosition
hasTrailingWhitespace = position + token.value.length > firstTrailingWhitespacePosition
hasIndentGuide = not mini and showIndentGuide and (hasLeadingWhitespace or lineIsWhitespaceOnly)
line.push(token.getValueAsHtml({invisibles, hasLeadingWhitespace, hasTrailingWhitespace, hasIndentGuide}))
line.push(token.getValueAsHtml({invisibles, hasIndentGuide}))
position += token.value.length
@popScope(line, scopeStack) while scopeStack.length > 0

View File

@@ -129,7 +129,7 @@ class Token
scopeClasses = scope.split('.')
_.isSubset(targetClasses, scopeClasses)
getValueAsHtml: ({invisibles, hasLeadingWhitespace, hasTrailingWhitespace, hasIndentGuide})->
getValueAsHtml: ({invisibles, hasIndentGuide})->
invisibles ?= {}
if @isHardTab
classes = 'hard-tab'
@@ -144,7 +144,7 @@ class Token
leadingHtml = ''
trailingHtml = ''
if hasLeadingWhitespace 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
@@ -154,9 +154,9 @@ class Token
startIndex = match[0].length
if hasTrailingWhitespace and match = TrailingWhitespaceRegex.exec(@value)
if @hasTrailingWhitespace and match = TrailingWhitespaceRegex.exec(@value)
classes = 'trailing-whitespace'
classes += ' indent-guide' if hasIndentGuide and not 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