From b281737838e3b915a0269f5b178f5e7166cffe07 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 16 Sep 2014 17:42:34 -0700 Subject: [PATCH 1/4] Add leading/trailing classes to hard tab tokens Previously the leading-whitespace and trailing-whitespace classes were never added to tokens that were hard tabs. --- spec/editor-component-spec.coffee | 26 ++++++++++++++++++++++++++ src/token.coffee | 2 ++ 2 files changed, 28 insertions(+) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index 86f70e9d1..0690528bb 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -197,6 +197,32 @@ describe "EditorComponent", -> nextAnimationFrame() expect(linesNode.style.backgroundColor).toBe 'rgb(255, 0, 0)' + it "applies .trailing-whitespace for lines with trailing spaces and/or tabs", -> + editor.setText('a ') + nextAnimationFrame() + + leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) + expect(leafNodes[0].classList.contains('trailing-whitespace')).toBe true + + editor.setText('a\t') + nextAnimationFrame() + + leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) + expect(leafNodes[0].classList.contains('trailing-whitespace')).toBe true + + it "applies .leading-whitespace for lines with trailing spaces and/or tabs", -> + editor.setText(' a') + nextAnimationFrame() + + leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) + expect(leafNodes[0].classList.contains('leading-whitespace')).toBe true + + editor.setText('\ta') + nextAnimationFrame() + + leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) + expect(leafNodes[0].classList.contains('leading-whitespace')).toBe true + describe "when showInvisibles is enabled", -> invisibles = null diff --git a/src/token.coffee b/src/token.coffee index fabf33de8..5366f33cc 100644 --- a/src/token.coffee +++ b/src/token.coffee @@ -153,6 +153,8 @@ class Token getValueAsHtml: ({hasIndentGuide}) -> if @isHardTab classes = 'hard-tab' + classes += ' leading-whitespace' if @hasLeadingWhitespace() + classes += ' trailing-whitespace' if @hasTrailingWhitespace() classes += ' indent-guide' if hasIndentGuide classes += ' invisible-character' if @hasInvisibleCharacters html = "#{@escapeString(@value)}" From 18f54e67803719b9847170330c4af6a7c7e4b427 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 16 Sep 2014 17:46:25 -0700 Subject: [PATCH 2/4] :lipstick: Put leading spec first --- spec/editor-component-spec.coffee | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index 0690528bb..f52e4a0a5 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -197,6 +197,19 @@ describe "EditorComponent", -> nextAnimationFrame() expect(linesNode.style.backgroundColor).toBe 'rgb(255, 0, 0)' + it "applies .leading-whitespace for lines with leading spaces and/or tabs", -> + editor.setText(' a') + nextAnimationFrame() + + leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) + expect(leafNodes[0].classList.contains('leading-whitespace')).toBe true + + editor.setText('\ta') + nextAnimationFrame() + + leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) + expect(leafNodes[0].classList.contains('leading-whitespace')).toBe true + it "applies .trailing-whitespace for lines with trailing spaces and/or tabs", -> editor.setText('a ') nextAnimationFrame() @@ -210,19 +223,6 @@ describe "EditorComponent", -> leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) expect(leafNodes[0].classList.contains('trailing-whitespace')).toBe true - it "applies .leading-whitespace for lines with trailing spaces and/or tabs", -> - editor.setText(' a') - nextAnimationFrame() - - leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) - expect(leafNodes[0].classList.contains('leading-whitespace')).toBe true - - editor.setText('\ta') - nextAnimationFrame() - - leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) - expect(leafNodes[0].classList.contains('leading-whitespace')).toBe true - describe "when showInvisibles is enabled", -> invisibles = null From 348f865cab168995d4a83d0d0525e7beeaba3d07 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 17 Sep 2014 09:47:40 -0700 Subject: [PATCH 3/4] Add spec for all whitespace lines --- spec/editor-component-spec.coffee | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index f52e4a0a5..3a9e2a904 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -211,6 +211,18 @@ describe "EditorComponent", -> expect(leafNodes[0].classList.contains('leading-whitespace')).toBe true it "applies .trailing-whitespace for lines with trailing spaces and/or tabs", -> + editor.setText(' ') + nextAnimationFrame() + + leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) + expect(leafNodes[0].classList.contains('trailing-whitespace')).toBe true + + editor.setText('\t') + nextAnimationFrame() + + leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) + expect(leafNodes[0].classList.contains('trailing-whitespace')).toBe true + editor.setText('a ') nextAnimationFrame() From 36f60c517efaebff390c9c10e9102d0aab381b1f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 17 Sep 2014 09:50:51 -0700 Subject: [PATCH 4/4] Assert other whitespace class is not present --- spec/editor-component-spec.coffee | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index 3a9e2a904..f8bc55742 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -203,12 +203,14 @@ describe "EditorComponent", -> leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) expect(leafNodes[0].classList.contains('leading-whitespace')).toBe true + expect(leafNodes[0].classList.contains('trailing-whitespace')).toBe false editor.setText('\ta') nextAnimationFrame() leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) expect(leafNodes[0].classList.contains('leading-whitespace')).toBe true + expect(leafNodes[0].classList.contains('trailing-whitespace')).toBe false it "applies .trailing-whitespace for lines with trailing spaces and/or tabs", -> editor.setText(' ') @@ -216,24 +218,28 @@ describe "EditorComponent", -> leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) expect(leafNodes[0].classList.contains('trailing-whitespace')).toBe true + expect(leafNodes[0].classList.contains('leading-whitespace')).toBe false editor.setText('\t') nextAnimationFrame() leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) expect(leafNodes[0].classList.contains('trailing-whitespace')).toBe true + expect(leafNodes[0].classList.contains('leading-whitespace')).toBe false editor.setText('a ') nextAnimationFrame() leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) expect(leafNodes[0].classList.contains('trailing-whitespace')).toBe true + expect(leafNodes[0].classList.contains('leading-whitespace')).toBe false editor.setText('a\t') nextAnimationFrame() leafNodes = getLeafNodes(component.lineNodeForScreenRow(0)) expect(leafNodes[0].classList.contains('trailing-whitespace')).toBe true + expect(leafNodes[0].classList.contains('leading-whitespace')).toBe false describe "when showInvisibles is enabled", -> invisibles = null