Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 7ff5d47

Browse files
author
Bryant Ung
authored
Merge pull request #290 from seattlevine/highlight-matching-line
Highlight matching line
2 parents b46c4ec + 7f1e652 commit 7ff5d47

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

lib/bracket-matcher-view.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ MAX_ROWS_TO_SCAN_BACKWARD_TRAVERSAL = Object.freeze(Point(-MAX_ROWS_TO_SCAN, 0))
1313
module.exports =
1414
class BracketMatcherView
1515
constructor: (@editor, editorElement, @matchManager) ->
16+
@gutter = @editor.gutterWithName('line-number')
1617
@subscriptions = new CompositeDisposable
1718
@tagFinder = new TagFinder(@editor)
1819
@pairHighlighted = false
@@ -187,6 +188,8 @@ class BracketMatcherView
187188
createMarker: (bufferRange) ->
188189
marker = @editor.markBufferRange(bufferRange)
189190
@editor.decorateMarker(marker, type: 'highlight', class: 'bracket-matcher', deprecatedRegionClass: 'bracket-matcher')
191+
if atom.config.get('bracket-matcher.highlightMatchingLineNumber', scope: @editor.getRootScopeDescriptor()) and @gutter
192+
@gutter.decorateMarker(marker, type: 'highlight', class: 'bracket-matcher', deprecatedRegionClass: 'bracket-matcher')
190193
marker
191194

192195
findCurrentPair: (isInverse) ->

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
"type": "boolean",
5757
"default": true,
5858
"description": "Wrap selected text in brackets or quotes when the editor contains selections and the opening bracket or quote is typed."
59+
},
60+
"highlightMatchingLineNumber": {
61+
"type": "boolean",
62+
"default": false,
63+
"description": "Highlight the line number of the matching bracket."
5964
}
6065
}
6166
}

spec/bracket-matcher-spec.coffee

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
describe "bracket matching", ->
2-
[editorElement, editor, buffer] = []
2+
[editorElement, editor, buffer, gutter] = []
33

44
beforeEach ->
55
atom.config.set 'bracket-matcher.autocompleteBrackets', true
@@ -20,19 +20,29 @@ describe "bracket matching", ->
2020
editor = atom.workspace.getActiveTextEditor()
2121
editorElement = atom.views.getView(editor)
2222
buffer = editor.getBuffer()
23+
gutter = editor.gutterWithName('line-number')
2324

2425
describe "matching bracket highlighting", ->
26+
beforeEach ->
27+
atom.config.set 'bracket-matcher.highlightMatchingLineNumber', true
28+
2529
expectNoHighlights = ->
2630
decorations = editor.getHighlightDecorations().filter (decoration) -> decoration.properties.class is 'bracket-matcher'
2731
expect(decorations.length).toBe 0
2832

2933
expectHighlights = (startBufferPosition, endBufferPosition) ->
3034
decorations = editor.getHighlightDecorations().filter (decoration) -> decoration.properties.class is 'bracket-matcher'
35+
gutterDecorations = editor.getLineNumberDecorations().filter (gutterDecoration) -> gutterDecoration.properties.class is 'bracket-matcher'
36+
3137
expect(decorations.length).toBe 2
38+
expect(gutterDecorations.length).toBe 2
3239

3340
expect(decorations[0].marker.getStartBufferPosition()).toEqual startBufferPosition
3441
expect(decorations[1].marker.getStartBufferPosition()).toEqual endBufferPosition
3542

43+
expect(gutterDecorations[0].marker.getStartBufferPosition()).toEqual startBufferPosition
44+
expect(gutterDecorations[1].marker.getStartBufferPosition()).toEqual endBufferPosition
45+
3646
describe "when the cursor is before a starting pair", ->
3747
it "highlights the starting pair and ending pair", ->
3848
editor.moveToEndOfLine()
@@ -234,6 +244,14 @@ describe "bracket matching", ->
234244
editor.getLastCursor().destroy()
235245
expectHighlights([0, 28], [12, 0])
236246

247+
describe "when highlightMatchingLineNumber config is disabled", ->
248+
it "does not highlight the gutter", ->
249+
atom.config.set('bracket-matcher.highlightMatchingLineNumber', false)
250+
editor.moveToEndOfLine()
251+
editor.moveLeft()
252+
gutterDecorations = editor.getLineNumberDecorations().filter (gutterDecoration) -> gutterDecoration.properties.class is 'bracket-matcher'
253+
expect(gutterDecorations.length).toBe 0
254+
237255
describe "when the cursor moves off (clears) a selection next to a starting or ending pair", ->
238256
it "highlights the starting pair and ending pair", ->
239257
editor.moveToEndOfLine()

styles/bracket-matcher.atom-text-editor.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
border-bottom: 1px dotted lime;
33
position: absolute;
44
}
5+
6+
.line-number.bracket-matcher {
7+
background-color: @text-color-subtle
8+
}

0 commit comments

Comments
 (0)