From 9bdc78df2eb83bafb17ee304d1d149689d91d1fa Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 9 Apr 2014 17:20:22 -0600 Subject: [PATCH] Correctly render lines containing only whitespace --- spec/editor-component-spec.coffee | 12 ++++++++++++ src/token.coffee | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index 09d280b69..402a14f50 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -82,6 +82,18 @@ describe "EditorComponent", -> expect(line2LeafNodes[2].textContent).toBe ' ' expect(line2LeafNodes[2].classList.contains('indent-guide')).toBe true + it "renders indent guides correctly on lines containing only whitespace", -> + editor.getBuffer().insert([1, Infinity], '\n ') + lines = node.querySelectorAll('.line') + line2LeafNodes = getLeafNodes(lines[2]) + expect(line2LeafNodes.length).toBe 3 + expect(line2LeafNodes[0].textContent).toBe ' ' + expect(line2LeafNodes[0].classList.contains('indent-guide')).toBe true + expect(line2LeafNodes[1].textContent).toBe ' ' + expect(line2LeafNodes[1].classList.contains('indent-guide')).toBe true + expect(line2LeafNodes[2].textContent).toBe ' ' + expect(line2LeafNodes[2].classList.contains('indent-guide')).toBe true + getLeafNodes = (node) -> if node.children.length > 0 flatten(toArray(node.children).map(getLeafNodes)) diff --git a/src/token.coffee b/src/token.coffee index f42c5a9cc..aabd60bdb 100644 --- a/src/token.coffee +++ b/src/token.coffee @@ -144,7 +144,7 @@ class Token leadingHtml = '' trailingHtml = '' - if @hasLeadingWhitespace and match = LeadingWhitespaceRegex.exec(@value) + if @hasLeadingWhitespace and not @hasTrailingWhitespace and match = LeadingWhitespaceRegex.exec(@value) classes = 'leading-whitespace' classes += ' indent-guide' if hasIndentGuide classes += ' invisible-character' if invisibles.space @@ -156,7 +156,7 @@ class Token if @hasTrailingWhitespace and match = TrailingWhitespaceRegex.exec(@value) classes = 'trailing-whitespace' - classes += ' indent-guide' if hasIndentGuide and not @hasLeadingWhitespace + classes += ' indent-guide' if hasIndentGuide and @hasLeadingWhitespace classes += ' invisible-character' if invisibles.space match[0] = match[0].replace(CharacterRegex, invisibles.space) if invisibles.space