diff --git a/lib/bracket-matcher-view.coffee b/lib/bracket-matcher-view.coffee index f6cf075..b2387a9 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..55a6db6 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": false, + "description": "Highlight the line number of the matching bracket." } } } diff --git a/spec/bracket-matcher-spec.coffee b/spec/bracket-matcher-spec.coffee index d8106db..dee04f1 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,19 +20,29 @@ describe "bracket matching", -> editor = atom.workspace.getActiveTextEditor() editorElement = atom.views.getView(editor) buffer = editor.getBuffer() + 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 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() @@ -188,6 +198,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() diff --git a/styles/bracket-matcher.atom-text-editor.less b/styles/bracket-matcher.atom-text-editor.less index a9e2c4b..739fdc2 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: @text-color-subtle +} \ No newline at end of file