       it "does not change the text", ->
         editor.insertText("\"woah(")
         editor.selectAll()
-        editorView.trigger "bracket-matcher:remove-brackets-from-selection"
+        atom.commands.dispatch(editorElement, "bracket-matcher:remove-brackets-from-selection")
         expect(editor.buffer.getText()).toBe "\"woah("
 
     describe "when selecting a matching pair of brackets", ->

      it "moves the cursor to after the ending pair", ->
        editor.moveToEndOfLine()
        editor.moveLeft()
        editorView.trigger "bracket-matcher:go-to-matching-bracket"
        expect(editor.getCursorBufferPosition()).toEqual [12, 1]

    describe "when the cursor is after the starting pair", ->
      it "moves the cursor to before the ending pair", ->
        editor.moveToEndOfLine()
        editorView.trigger "bracket-matcher:go-to-matching-bracket"
        expect(editor.getCursorBufferPosition()).toEqual [12, 0]

    describe "when the cursor is before the ending pair", ->
      it "moves the cursor to after the starting pair", ->
        editor.setCursorBufferPosition([12, 0])
        editorView.trigger "bracket-matcher:go-to-matching-bracket"
        expect(editor.getCursorBufferPosition()).toEqual [0, 29]

    describe "when the cursor is after the ending pair", ->
      it "moves the cursor to before the starting pair", ->
        editor.setCursorBufferPosition([12, 1])
        editorView.trigger "bracket-matcher:go-to-matching-bracket"
        expect(editor.getCursorBufferPosition()).toEqual [0, 28]

    describe "when the cursor is not adjacent to a pair", ->
      describe "when within a `{}` pair", ->
        it "moves the cursor to before the enclosing brace", ->
          editor.setCursorBufferPosition([11, 2])
          editorView.trigger "bracket-matcher:go-to-matching-bracket"
          expect(editor.getCursorBufferPosition()).toEqual [0, 28]

      describe "when within a `()` pair", ->
        it "moves the cursor to before the enclosing brace", ->
          editor.setCursorBufferPosition([2, 14])
          editorView.trigger "bracket-matcher:go-to-matching-bracket"
          expect(editor.getCursorBufferPosition()).toEqual [2, 7]

      describe 'in HTML/XML files', ->


      runs ->
        editorView = atom.workspaceView.getActiveView()
        editorElement = editorView.element
        {editor} = editorView
        {buffer} = editor

    it 'closes the first unclosed tag', ->
      editor.setCursorBufferPosition([5,14])
      atom.commands.dispatch(editorElement, 'bracket-matcher:close-tag')

      expect(editor.getCursorBufferPosition()).toEqual [5, 18]
      expect(editor.getTextInRange([[5,14], [5,18]])).toEqual '</a>'

    it 'closes the following unclosed tags if called repeatedly', ->
      editor.setCursorBufferPosition([5,14])
      atom.commands.dispatch(editorElement, 'bracket-matcher:close-tag')
      atom.commands.dispatch(editorElement, 'bracket-matcher:close-tag')

      expect(editor.getCursorBufferPosition()).toEqual [5, 22]
      expect(editor.getTextInRange([[5,18], [5,22]])).toEqual '</p>'

    it 'does not close any tag if no unclosed tag can be found at the insertion point', ->
      editor.setCursorBufferPosition([5,14])
      atom.commands.dispatch(editorElement, 'bracket-matcher:close-tag')

      #closing all currently open tags
      atom.commands.dispatch(editorElement, 'bracket-matcher:close-tag')
      editor.setCursorBufferPosition([13,11])
      atom.commands.dispatch(editorElement, 'bracket-matcher:close-tag')
      atom.commands.dispatch(editorElement, 'bracket-matcher:close-tag')
      editor.setCursorBufferPosition([15,0])
      atom.commands.dispatch(editorElement, 'bracket-matcher:close-tag')
      atom.commands.dispatch(editorElement, 'bracket-matcher:close-tag')

      # positioning on an already closed tag
      editor.setCursorBufferPosition([11,9])
      atom.commands.dispatch(editorElement, 'bracket-matcher:close-tag')
      expect(editor.getCursorBufferPosition()).toEqual [11,9]

    it 'does not get confused in case of nested identical tags -- tag not closing', ->
      editor.setCursorBufferPosition([13,11])
      atom.commands.dispatch(editorElement, 'bracket-matcher:close-tag')
      atom.commands.dispatch(editorElement, 'bracket-matcher:close-tag')

      expect(editor.getCursorBufferPosition()).toEqual [13,16]

    it 'does not get confused in case of nested identical tags -- tag closing', ->
      editor.setCursorBufferPosition([13,11])
      atom.commands.dispatch(editorElement, 'bracket-matcher:close-tag')

      expect(editor.getCursorBufferPosition()).toEqual [13,16]
      expect(editor.getTextInRange([[13,10], [13,16]])).toEqual '</div>'

      atom.commands.dispatch(editorElement, 'bracket-matcher:close-tag')

      expect(editor.getCursorBufferPosition()).toEqual [13,16]
