From 2e72790e72ff18d54ff17c0db52157bcac75070c Mon Sep 17 00:00:00 2001 From: Jason Woods Date: Sun, 1 Feb 2015 17:57:48 +0000 Subject: [PATCH 1/2] :bug: Fix ident guides missing on whitespace only lines with invis chars --- src/lines-component.coffee | 3 +-- src/tokenized-line.coffee | 10 +++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/lines-component.coffee b/src/lines-component.coffee index ff8827a21..6099de185 100644 --- a/src/lines-component.coffee +++ b/src/lines-component.coffee @@ -213,8 +213,7 @@ LinesComponent = React.createClass innerHTML = "" scopeStack = [] - firstTrailingWhitespacePosition = text.search(/\s*$/) - lineIsWhitespaceOnly = firstTrailingWhitespacePosition is 0 + lineIsWhitespaceOnly = line.isOnlyWhitespace() for token in tokens innerHTML += @updateScopeStack(scopeStack, token.scopes) hasIndentGuide = not editor.isMini() and showIndentGuide and (token.hasLeadingWhitespace() or (token.hasTrailingWhitespace() and lineIsWhitespaceOnly)) diff --git a/src/tokenized-line.coffee b/src/tokenized-line.coffee index 60eab31d9..2e9a6a7e7 100644 --- a/src/tokenized-line.coffee +++ b/src/tokenized-line.coffee @@ -9,6 +9,7 @@ idCounter = 1 module.exports = class TokenizedLine endOfLineInvisibles: null + lineIsWhitespaceOnly: false constructor: ({tokens, @lineEnding, @ruleStack, @startBufferColumn, @fold, @tabLength, @indentLevel, @invisibles}) -> @startBufferColumn ?= 0 @@ -146,7 +147,7 @@ class TokenizedLine markLeadingAndTrailingWhitespaceTokens: -> firstNonWhitespaceIndex = @text.search(NonWhitespaceRegex) firstTrailingWhitespaceIndex = @text.search(TrailingWhitespaceRegex) - lineIsWhitespaceOnly = firstTrailingWhitespaceIndex is 0 + @lineIsWhitespaceOnly = firstTrailingWhitespaceIndex is 0 index = 0 for token in @tokens if index < firstNonWhitespaceIndex @@ -202,12 +203,7 @@ class TokenizedLine false isOnlyWhitespace: -> - if @text == '' - true - else - for token in @tokens - return false unless token.isOnlyWhitespace() - true + @lineIsWhitespaceOnly tokenAtIndex: (index) -> @tokens[index] From 973d7ebf13469e763ec23cbe6b3340d96e60484e Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 3 Feb 2015 21:26:01 -0700 Subject: [PATCH 2/2] Add spec coverage for indent guides + invisibles on blank lines --- spec/text-editor-component-spec.coffee | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/text-editor-component-spec.coffee b/spec/text-editor-component-spec.coffee index 35c58512e..cc35b51b1 100644 --- a/spec/text-editor-component-spec.coffee +++ b/spec/text-editor-component-spec.coffee @@ -374,6 +374,22 @@ describe "TextEditorComponent", -> expect(line2LeafNodes[2].textContent).toBe ' ' expect(line2LeafNodes[2].classList.contains('indent-guide')).toBe true + it "renders indent guides correctly on lines containing only whitespace when invisibles are enabled", -> + atom.config.set 'editor.showInvisibles', true + atom.config.set 'editor.invisibles', space: '-', eol: 'x' + editor.getBuffer().insert([1, Infinity], '\n ') + nextAnimationFrame() + + line2LeafNodes = getLeafNodes(component.lineNodeForScreenRow(2)) + expect(line2LeafNodes.length).toBe 4 + 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 + expect(line2LeafNodes[3].textContent).toBe 'x' + it "does not render indent guides in trailing whitespace for lines containing non whitespace characters", -> editor.getBuffer().setText " hi " nextAnimationFrame()