From 2ebe0dc57e9c993cef7b2e139a4e975d59d5d620 Mon Sep 17 00:00:00 2001 From: esdoppio Date: Mon, 25 Jul 2016 11:41:39 +0800 Subject: [PATCH 1/2] Test for cases where braces should not be inserted --- spec/bracket-matcher-spec.coffee | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/spec/bracket-matcher-spec.coffee b/spec/bracket-matcher-spec.coffee index e896597..536749c 100644 --- a/spec/bracket-matcher-spec.coffee +++ b/spec/bracket-matcher-spec.coffee @@ -874,6 +874,33 @@ describe "bracket matching", -> editor.undo() expect(editor.getText()).toBe 'foo = ""' + it "should not insert curly braces right before doubly quoted string", -> + editor.insertText "foo = " + editor.insertText '"' + editor.moveLeft() + editor.insertText "#" + expect(editor.getText()).toBe 'foo = #""' + + it "should not insert curly braces right after double quoted string", -> + editor.insertText "foo = " + editor.moveLeft() + editor.insertText '"' + editor.moveRight() + editor.insertText "#" + expect(editor.getText()).toBe 'foo = ""# ' + + it "should not insert curly braces right before doubly quoted string at the beginning of a line", -> + editor.insertText '"' + editor.moveLeft() + editor.insertText "#" + expect(editor.getText()).toBe '#""' + + it "should not insert curly braces right after doubly quoted string at the end of a line", -> + editor.insertText '"' + editor.moveRight() + editor.insertText "#" + expect(editor.getText()).toBe '""#' + it "should not insert curly braces inside singly quoted string", -> editor.insertText "foo = " editor.insertText "'" From 4d46aabe3b21f90ed0c90efabc7811df3d359442 Mon Sep 17 00:00:00 2001 From: esdoppio Date: Mon, 25 Jul 2016 12:04:04 +0800 Subject: [PATCH 2/2] :bug: Patch isCursorOnInterpolatedString The problem lies in the fact that "scopes at cursor" is actually the scopes of the character on the right, so to determine if the cursor is on an interpolated string, the character on the other side of the cursor should also be checked, with two exceptions: when the cursor is at the beginning or end of a line. This patch aims to be clean, but not perfect: ** In some rare situations, such as when typing `#` at the beginning or end of a line within a multi-line interpolated string, it won't expand to `#{}`. ** --- lib/bracket-matcher.coffee | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/bracket-matcher.coffee b/lib/bracket-matcher.coffee index 7326026..bd742d4 100644 --- a/lib/bracket-matcher.coffee +++ b/lib/bracket-matcher.coffee @@ -198,7 +198,13 @@ class BracketMatcher 'comment.documentation.heredoc.elixir' ] @interpolatedStringSelector = SelectorCache.get(segments.join(' | ')) - @interpolatedStringSelector.matches(@editor.getLastCursor().getScopeDescriptor().getScopesArray()) + + lastCursor = @editor.getLastCursor() + + return false if lastCursor.isAtBeginningOfLine() or lastCursor.isAtEndOfLine() + + @interpolatedStringSelector.matches(lastCursor.getScopeDescriptor().getScopesArray()) and + @interpolatedStringSelector.matches(@editor.scopeDescriptorForBufferPosition([lastCursor.getBufferRow(), lastCursor.getBufferColumn() - 1]).getScopesArray()) getInvertedPairedCharacters: -> return @invertedPairedCharacters if @invertedPairedCharacters