From ba202f3b1fe89cc1ba24c098afab8b3e0b16d849 Mon Sep 17 00:00:00 2001 From: Mike Levine Date: Wed, 7 Jun 2017 09:01:36 -0700 Subject: [PATCH 1/6] Highlight matching line --- lib/bracket-matcher-view.coffee | 3 +++ package.json | 5 +++++ spec/bracket-matcher-spec.coffee | 9 ++++++++- styles/bracket-matcher.atom-text-editor.less | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/bracket-matcher-view.coffee b/lib/bracket-matcher-view.coffee index f6cf075..d148398 100644 --- a/lib/bracket-matcher-view.coffee +++ b/lib/bracket-matcher-view.coffee @@ -14,6 +14,7 @@ MAX_ROWS_TO_SCAN_BACKWARD_TRAVERSAL = Object.freeze(Point(-MAX_ROWS_TO_SCAN, 0)) module.exports = class BracketMatcherView constructor: (@editor, editorElement, @matchManager) -> + @gutter = @editor.gutterWithName('line-number') @subscriptions = new CompositeDisposable @tagFinder = new TagFinder(@editor) @pairHighlighted = false @@ -188,6 +189,8 @@ class BracketMatcherView createMarker: (bufferRange) -> marker = @editor.markBufferRange(bufferRange) @editor.decorateMarker(marker, type: 'highlight', class: 'bracket-matcher', deprecatedRegionClass: 'bracket-matcher') + if atom.config.get('bracket-matcher.highlightMatchingLineNumber', scope: @editor.getRootScopeDescriptor()) and @gutter + @gutter.decorateMarker(marker, type: 'highlight', class: 'bracket-matcher', deprecatedRegionClass: 'bracket-matcher') marker findCurrentPair: (matches) -> diff --git a/package.json b/package.json index e638dc1..7149a53 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,11 @@ "type": "boolean", "default": true, "description": "Wrap selected text in brackets or quotes when the editor contains selections and the opening bracket or quote is typed." + }, + "highlightMatchingLineNumber": { + "type": "boolean", + "default": true, + "description": "If the line number gutter is visible, highlight the line number of the matching bracket" } } } diff --git a/spec/bracket-matcher-spec.coffee b/spec/bracket-matcher-spec.coffee index d8106db..3f71268 100644 --- a/spec/bracket-matcher-spec.coffee +++ b/spec/bracket-matcher-spec.coffee @@ -1,5 +1,5 @@ describe "bracket matching", -> - [editorElement, editor, buffer] = [] + [editorElement, editor, buffer, gutter] = [] beforeEach -> atom.config.set 'bracket-matcher.autocompleteBrackets', true @@ -20,6 +20,7 @@ describe "bracket matching", -> editor = atom.workspace.getActiveTextEditor() editorElement = atom.views.getView(editor) buffer = editor.getBuffer() + gutter = editor.gutterWithName('line-number') describe "matching bracket highlighting", -> expectNoHighlights = -> @@ -28,11 +29,17 @@ describe "bracket matching", -> expectHighlights = (startBufferPosition, endBufferPosition) -> decorations = editor.getHighlightDecorations().filter (decoration) -> decoration.properties.class is 'bracket-matcher' + gutterDecorations = editor.getLineNumberDecorations().filter (gutterDecoration) -> gutterDecoration.properties.class is 'bracket-matcher' + expect(decorations.length).toBe 2 + expect(gutterDecorations.length).toBe 2 expect(decorations[0].marker.getStartBufferPosition()).toEqual startBufferPosition expect(decorations[1].marker.getStartBufferPosition()).toEqual endBufferPosition + expect(gutterDecorations[0].marker.getStartBufferPosition()).toEqual startBufferPosition + expect(gutterDecorations[1].marker.getStartBufferPosition()).toEqual endBufferPosition + describe "when the cursor is before a starting pair", -> it "highlights the starting pair and ending pair", -> editor.moveToEndOfLine() diff --git a/styles/bracket-matcher.atom-text-editor.less b/styles/bracket-matcher.atom-text-editor.less index a9e2c4b..c3f8c7e 100644 --- a/styles/bracket-matcher.atom-text-editor.less +++ b/styles/bracket-matcher.atom-text-editor.less @@ -2,3 +2,7 @@ border-bottom: 1px dotted lime; position: absolute; } + +.line-number.bracket-matcher { + background-color: #888888 +} \ No newline at end of file From 895528408fc3f7048a8f3245f8a80aac86265956 Mon Sep 17 00:00:00 2001 From: Mike Levine Date: Wed, 7 Jun 2017 09:39:13 -0700 Subject: [PATCH 2/6] 2 space indents --- lib/bracket-matcher-view.coffee | 2 +- package.json | 6 +++--- styles/bracket-matcher.atom-text-editor.less | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/bracket-matcher-view.coffee b/lib/bracket-matcher-view.coffee index d148398..b2387a9 100644 --- a/lib/bracket-matcher-view.coffee +++ b/lib/bracket-matcher-view.coffee @@ -190,7 +190,7 @@ class BracketMatcherView marker = @editor.markBufferRange(bufferRange) @editor.decorateMarker(marker, type: 'highlight', class: 'bracket-matcher', deprecatedRegionClass: 'bracket-matcher') if atom.config.get('bracket-matcher.highlightMatchingLineNumber', scope: @editor.getRootScopeDescriptor()) and @gutter - @gutter.decorateMarker(marker, type: 'highlight', class: 'bracket-matcher', deprecatedRegionClass: 'bracket-matcher') + @gutter.decorateMarker(marker, type: 'highlight', class: 'bracket-matcher', deprecatedRegionClass: 'bracket-matcher') marker findCurrentPair: (matches) -> diff --git a/package.json b/package.json index 7149a53..e8834af 100644 --- a/package.json +++ b/package.json @@ -58,9 +58,9 @@ "description": "Wrap selected text in brackets or quotes when the editor contains selections and the opening bracket or quote is typed." }, "highlightMatchingLineNumber": { - "type": "boolean", - "default": true, - "description": "If the line number gutter is visible, highlight the line number of the matching bracket" + "type": "boolean", + "default": true, + "description": "If the line number gutter is visible, highlight the line number of the matching bracket" } } } diff --git a/styles/bracket-matcher.atom-text-editor.less b/styles/bracket-matcher.atom-text-editor.less index c3f8c7e..76ff10d 100644 --- a/styles/bracket-matcher.atom-text-editor.less +++ b/styles/bracket-matcher.atom-text-editor.less @@ -4,5 +4,5 @@ } .line-number.bracket-matcher { - background-color: #888888 + background-color: #888888 } \ No newline at end of file From e93de5fa2cae0c04b09fcebc8f8e571f85c0ef3b Mon Sep 17 00:00:00 2001 From: Mike Levine Date: Wed, 7 Jun 2017 11:22:17 -0700 Subject: [PATCH 3/6] use standard color for highlight --- styles/bracket-matcher.atom-text-editor.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/styles/bracket-matcher.atom-text-editor.less b/styles/bracket-matcher.atom-text-editor.less index 76ff10d..739fdc2 100644 --- a/styles/bracket-matcher.atom-text-editor.less +++ b/styles/bracket-matcher.atom-text-editor.less @@ -4,5 +4,5 @@ } .line-number.bracket-matcher { - background-color: #888888 + background-color: @text-color-subtle } \ No newline at end of file From bcea1b6f00ca41d63f8e44a2bf505a4f0659bcb2 Mon Sep 17 00:00:00 2001 From: Mike Levine Date: Wed, 7 Jun 2017 16:01:27 -0700 Subject: [PATCH 4/6] Added test for highlightMatchingLineNumber false --- spec/bracket-matcher-spec.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/bracket-matcher-spec.coffee b/spec/bracket-matcher-spec.coffee index 3f71268..1349535 100644 --- a/spec/bracket-matcher-spec.coffee +++ b/spec/bracket-matcher-spec.coffee @@ -195,6 +195,14 @@ describe "bracket matching", -> editor.getLastCursor().destroy() expectHighlights([0, 28], [12, 0]) + describe "when highlightMatchingLineNumber config is disabled", -> + it "does not highlight the gutter", -> + atom.config.set('bracket-matcher.highlightMatchingLineNumber', false) + editor.moveToEndOfLine() + editor.moveLeft() + gutterDecorations = editor.getLineNumberDecorations().filter (gutterDecoration) -> gutterDecoration.properties.class is 'bracket-matcher' + expect(gutterDecorations.length).toBe 0 + describe "when the cursor moves off (clears) a selection next to a starting or ending pair", -> it "highlights the starting pair and ending pair", -> editor.moveToEndOfLine() From c25a55b766e9a325666a7c9a5e4f40d2be3642db Mon Sep 17 00:00:00 2001 From: Mike Levine Date: Fri, 1 Sep 2017 20:41:13 -0700 Subject: [PATCH 5/6] Default highlightMatchingLineNumber to false --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e8834af..55a6db6 100644 --- a/package.json +++ b/package.json @@ -59,8 +59,8 @@ }, "highlightMatchingLineNumber": { "type": "boolean", - "default": true, - "description": "If the line number gutter is visible, highlight the line number of the matching bracket" + "default": false, + "description": "Highlight the line number of the matching bracket." } } } From 7f1e652e73ae802dd4ca0b256a2ab94c78d515fc Mon Sep 17 00:00:00 2001 From: Mike Levine Date: Tue, 5 Sep 2017 09:48:44 -0700 Subject: [PATCH 6/6] Fix tests: set bracket-matcher.highlightMatchingLineNumber to true --- spec/bracket-matcher-spec.coffee | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/bracket-matcher-spec.coffee b/spec/bracket-matcher-spec.coffee index 1349535..dee04f1 100644 --- a/spec/bracket-matcher-spec.coffee +++ b/spec/bracket-matcher-spec.coffee @@ -23,6 +23,9 @@ describe "bracket matching", -> gutter = editor.gutterWithName('line-number') describe "matching bracket highlighting", -> + beforeEach -> + atom.config.set 'bracket-matcher.highlightMatchingLineNumber', true + expectNoHighlights = -> decorations = editor.getHighlightDecorations().filter (decoration) -> decoration.properties.class is 'bracket-matcher' expect(decorations.length).toBe 0