   isQuote: (string) ->
     /'|"/.test(string)
 
+  getInvertedPairedCharacters: ->
+    return @invertedPairedCharacters if @invertedPairedCharacters
+
+    @invertedPairedCharacters = {}
+    for open, close of @pairedCharacters
+      @invertedPairedCharacters[close] = open
+    @invertedPairedCharacters
+
   isOpeningBracket: (string) ->
-    @startPairMatches[string]?
+    @pairedCharacters[string]?
 
   isClosingBracket: (string) ->
-    @endPairMatches[string]?
+    @getInvertedPairedCharacters()[string]?

      cursorBufferPosition = editSession.getCursorBufferPosition()
      previousCharacter = editSession.getTextInBufferRange([cursorBufferPosition.add([0, -1]), cursorBufferPosition])
      nextCharacter = editSession.getTextInBufferRange([cursorBufferPosition, cursorBufferPosition.add([0,1])])
      if @startPairMatches[previousCharacter] is nextCharacter
        editSession.transact =>
          editSession.moveCursorLeft()
          editSession.delete()


module.exports =
class BracketMatcher extends AtomPackage
  pairedCharacters:
    '(': ')'
    '[': ']'
    '{': '}'
    '"': '"'
    "'": "'"

  startPairMatches:
    '(': ')'
    '[': ']'
    '{': '}'

  endPairMatches:
    ')': '('
    ']': '['
    '}': '{'

  pairHighlighted: false

