From 6b10fcc2f85306399e1485ff2380dd87af71ec3f Mon Sep 17 00:00:00 2001 From: David Graham & Nathan Sobo Date: Wed, 9 Apr 2014 13:49:27 -0600 Subject: [PATCH] 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. --- src/editor-view.coffee | 4 +--- src/token.coffee | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/editor-view.coffee b/src/editor-view.coffee index 1da0e223d..d1fcbcc29 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -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 diff --git a/src/token.coffee b/src/token.coffee index 17699f8f8..f42c5a9cc 100644 --- a/src/token.coffee +++ b/src/token.coffee @@ -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