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

Added option to always skip over pair in front of cursor #335

Merged
merged 3 commits into from
Dec 5, 2017
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
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 "()"