         false
 
     _.adviseBefore editor, 'insertNewline', =>
-      selection = editor.getSelection()
       return if editor.hasMultipleCursors()
       return unless editor.getSelection().isEmpty()
 
-      if @selectionIsWrappedByMatchingBrackets(selection)
+      cursorBufferPosition = editor.getCursorBufferPosition()
+      previousCharacter = editor.getTextInBufferRange([cursorBufferPosition.add([0, -1]), cursorBufferPosition])
+      nextCharacter = editor.getTextInBufferRange([cursorBufferPosition, cursorBufferPosition.add([0,1])])
+      if @pairedCharacters[previousCharacter] is nextCharacter
         editor.transact =>
           editor.insertText "\n\n"
           editor.moveCursorUp()

        false

    _.adviseBefore editor, 'backspace', =>
      selection = editor.getSelection()
      return if editor.hasMultipleCursors()
      return unless selection.isEmpty()

      if @selectionIsWrappedByMatchingBrackets(selection)
        editor.transact =>
          editor.moveCursorLeft()
          editor.delete()

    @closeCharacter == string

  selectionIsWrappedByMatchingBrackets: (selection) ->
    return false if selection.isEmpty()
    selectedText = selection.getText()
    firstCharacter = selectedText[0]
    lastCharacter = selectedText[ selectedText.length - 1 ]
