Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/bracket-matcher-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) ->
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
20 changes: 19 additions & 1 deletion spec/bracket-matcher-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe "bracket matching", ->
[editorElement, editor, buffer] = []
[editorElement, editor, buffer, gutter] = []

beforeEach ->
atom.config.set 'bracket-matcher.autocompleteBrackets', true
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions styles/bracket-matcher.atom-text-editor.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
border-bottom: 1px dotted lime;
position: absolute;
}

.line-number.bracket-matcher {
background-color: @text-color-subtle
}