 
       editor.getBuffer().setText("abc\n  012\n")
       editor.setCursorScreenPosition([1, 2])
+      keydown('o')
 
     it "switches to insert and adds a newline above the current one", ->
-      keydown('o')
-
       expect(editor.getText()).toBe "abc\n  012\n  \n"
       expect(editor).toHaveClass 'insert-mode'
       expect(editor.getCursorScreenPosition()).toEqual [2, 2]

    beforeEach ->
      editor.getBuffer().setText("012\n")

    it "switches to insert mode and shifts to the right", ->
      editor.setCursorScreenPosition([0, 0])

      keydown('a')

      expect(editor.getCursorScreenPosition()).toEqual [0, 1]
      expect(editor).toHaveClass 'insert-mode'

    it "doesn't linewrap", ->
      editor.setCursorScreenPosition([0, 3])

      keydown('a')

      expect(editor.getCursorScreenPosition()).toEqual [0, 3]

  describe "the J keybinding", ->
    beforeEach ->
      editor.getBuffer().setText("012\n    456\n")
      editor.setCursorScreenPosition([0, 1])

    it "deletes the contents until the end of the line", ->
      keydown('J', shift: true)

      expect(editor.getText()).toBe "012 456\n"

    describe "undo behavior", ->
      it "handles repeats", ->
        editor.setText("12345\nabcde\nABCDE\nQWERT")
        editor.setCursorScreenPosition([1, 1])

        keydown('2')
        keydown('J', shift: true)

        keydown('u')

        expect(editor.getText()).toBe "12345\nabcde\nABCDE\nQWERT"

  describe "the > keybinding", ->
    describe "when followed by a >", ->
      it "indents the current line", ->
        editor.setText("12345\nabcde\nABCDE")
        editor.setCursorScreenPosition([1, 1])

        keydown('>')
        keydown('>')

        expect(editor.getText()).toBe "12345\n  abcde\nABCDE"
        expect(editor.getCursorScreenPosition()).toEqual [1, 2]

      it "indents multiple lines at once", ->
        editor.setText("12345\nabcde\nABCDE")
        editor.setCursorScreenPosition([0, 0])

        keydown('3')
        keydown('>')
        keydown('>')

        expect(editor.getText()).toBe "  12345\n  abcde\n  ABCDE"
        expect(editor.getCursorScreenPosition()).toEqual [0, 2]

        keydown('u')
        expect(editor.getText()).toBe "12345\nabcde\nABCDE"

  describe "the < keybinding", ->
    describe "when followed by a <", ->
      it "indents the current line", ->
        expect(editor.setText("12345\n  abcde\nABCDE"))
        editor.setCursorScreenPosition([1, 2])

        keydown('<')
        keydown('<')
        expect(editor.getText()).toBe "12345\nabcde\nABCDE"
        expect(editor.getCursorScreenPosition()).toEqual [1, 0]

      it "indents multiple lines at once", ->
        editor.setText("  12345\n  abcde\n  ABCDE")
        editor.setCursorScreenPosition([0, 0])

        keydown('3')
        keydown('<')
        keydown('<')
        expect(editor.getText()).toBe "12345\nabcde\nABCDE"
        expect(editor.getCursorScreenPosition()).toEqual [0, 0]

        keydown('u')
        expect(editor.getText()).toBe "  12345\n  abcde\n  ABCDE"

        expect(editor).not.toHaveClass 'command-mode'
        expect(editor).toHaveClass 'insert-mode'

  describe "the C keybinding", ->
    beforeEach ->
      editor.getBuffer().setText("012\n")
      editor.setCursorScreenPosition([0, 1])
      keydown('C', shift: true)

    it "deletes the contents until the end of the line and enters insert mode", ->
      expect(editor.getText()).toBe "0\n"
      expect(editor.getCursorScreenPosition()).toEqual [0, 1]
      expect(editor).not.toHaveClass 'command-mode'
