From 62b4787843aa83eb165f499eb60555653aee2dc0 Mon Sep 17 00:00:00 2001 From: reujab Date: Sat, 2 Dec 2017 20:37:19 -0500 Subject: [PATCH 1/3] added alwaysSkipClosingPairs --- lib/bracket-matcher.coffee | 4 ++-- package.json | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/bracket-matcher.coffee b/lib/bracket-matcher.coffee index eccbded..e21d7d3 100644 --- a/lib/bracket-matcher.coffee +++ b/lib/bracket-matcher.coffee @@ -54,11 +54,11 @@ 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)) + if (bracketMarker = _.find(@bracketMarkers, (marker) -> marker.isValid() and marker.getBufferRange().end.isEqual(cursorBufferPosition))) or @getScopedSetting("bracket-matcher.alwaysSkipClosingPairs") skipOverExistingClosingBracket = true if skipOverExistingClosingBracket - bracketMarker.destroy() + bracketMarker?.destroy() _.remove(@bracketMarkers, bracketMarker) @editor.moveRight() false diff --git a/package.json b/package.json index 11e00a5..e0d7637 100644 --- a/package.json +++ b/package.json @@ -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." } } } From 0d09c8cb18057c89e7e1fb8abf861a6430063bd4 Mon Sep 17 00:00:00 2001 From: reujab Date: Sat, 2 Dec 2017 21:45:18 -0500 Subject: [PATCH 2/3] added tests for alwaysSkipClosingPairs --- spec/bracket-matcher-spec.coffee | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/bracket-matcher-spec.coffee b/spec/bracket-matcher-spec.coffee index c2731f0..4a6cc0f 100644 --- a/spec/bracket-matcher-spec.coffee +++ b/spec/bracket-matcher-spec.coffee @@ -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 "()" From 87248184284db7f559200ef231e363fe47bf43df Mon Sep 17 00:00:00 2001 From: reujab Date: Mon, 4 Dec 2017 20:46:45 -0500 Subject: [PATCH 3/3] split conditional into two statements --- lib/bracket-matcher.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/bracket-matcher.coffee b/lib/bracket-matcher.coffee index e21d7d3..bc8fc36 100644 --- a/lib/bracket-matcher.coffee +++ b/lib/bracket-matcher.coffee @@ -54,7 +54,8 @@ 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))) or @getScopedSetting("bracket-matcher.alwaysSkipClosingPairs") + bracketMarker = _.find(@bracketMarkers, (marker) -> marker.isValid() and marker.getBufferRange().end.isEqual(cursorBufferPosition)) + if bracketMarker or @getScopedSetting("bracket-matcher.alwaysSkipClosingPairs") skipOverExistingClosingBracket = true if skipOverExistingClosingBracket