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

Commit

Permalink
Merge pull request #335 from reujab/master
Browse files Browse the repository at this point in the history
Added option to always skip over pair in front of cursor
  • Loading branch information
Wliu authored Dec 5, 2017
2 parents a592c90 + 8724818 commit 32817b8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/bracket-matcher.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ class BracketMatcher

skipOverExistingClosingBracket = false
if @isClosingBracket(text) and nextCharacter is text and not hasEscapeCharacterBeforeCursor
if bracketMarker = _.find(@bracketMarkers, (marker) -> marker.isValid() and marker.getBufferRange().end.isEqual(cursorBufferPosition))
bracketMarker = _.find(@bracketMarkers, (marker) -> marker.isValid() and marker.getBufferRange().end.isEqual(cursorBufferPosition))
if bracketMarker or @getScopedSetting("bracket-matcher.alwaysSkipClosingPairs")
skipOverExistingClosingBracket = true

if skipOverExistingClosingBracket
bracketMarker.destroy()
bracketMarker?.destroy()
_.remove(@bracketMarkers, bracketMarker)
@editor.moveRight()
false
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
"type": "boolean",
"default": false,
"description": "Highlight the line number of the matching bracket."
},
"alwaysSkipClosingPairs": {
"type": "boolean",
"default": false,
"description": "Always skip closing pairs in front of the cursor."
}
}
}
23 changes: 23 additions & 0 deletions spec/bracket-matcher-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1454,3 +1454,26 @@ describe "bracket matching", ->
expect(editor.getCursorBufferPosition().row).toEqual 1
expect(editor.getCursorBufferPosition().column).toEqual 0
expect(editor.getTextInRange([[1, 0], [1, Infinity]])).toEqual ''

describe "skipping closed brackets", ->
beforeEach ->
editor.buffer.setText("")

it "skips over brackets", ->
editor.insertText("(")
expect(editor.buffer.getText()).toBe "()"
editor.insertText(")")
expect(editor.buffer.getText()).toBe "()"

it "does not skip over brackets that have already been skipped", ->
editor.insertText("()")
editor.moveLeft()
editor.insertText(")")
expect(editor.buffer.getText()).toBe "())"

it "does skip over brackets that have already been skipped when alwaysSkipClosingPairs is set", ->
atom.config.set("bracket-matcher.alwaysSkipClosingPairs", true)
editor.insertText("()")
editor.moveLeft()
editor.insertText(")")
expect(editor.buffer.getText()).toBe "()"

0 comments on commit 32817b8

Please sign in to comment.