1 helpers = require './spec-helper'
3 describe "Insert mode commands", ->
4 [editor, editorElement, vimState] = []
7 vimMode = atom.packages.loadPackage('vim-mode')
8 vimMode.activateResources()
10 helpers.getEditorElement (element) ->
11 editorElement = element
12 editor = editorElement.getModel()
13 vimState = editorElement.vimState
14 vimState.activateNormalMode()
15 vimState.resetNormalMode()
17 keydown = (key, options={}) ->
18 options.element ?= editorElement
19 helpers.keydown(key, options)
21 describe "Copy from line above/below", ->
23 editor.setText("12345\n\nabcd\nefghi")
24 editor.setCursorBufferPosition([1, 0])
25 editor.addCursorAtBufferPosition([3, 0])
28 describe "the ctrl-y command", ->
29 it "copies from the line above", ->
30 keydown 'y', ctrl: true
31 expect(editor.getText()).toBe '12345\n1\nabcd\naefghi'
34 keydown 'y', ctrl: true
35 expect(editor.getText()).toBe '12345\n1 3\nabcd\na cefghi'
37 it "does nothing if there's nothing above the cursor", ->
38 editor.insertText 'fill'
39 keydown 'y', ctrl: true
40 expect(editor.getText()).toBe '12345\nfill5\nabcd\nfillefghi'
42 keydown 'y', ctrl: true
43 expect(editor.getText()).toBe '12345\nfill5\nabcd\nfillefghi'
45 it "does nothing on the first line", ->
46 editor.setCursorBufferPosition([0, 2])
47 editor.addCursorAtBufferPosition([3, 2])
49 expect(editor.getText()).toBe '12a345\n\nabcd\nefaghi'
50 keydown 'y', ctrl: true
51 expect(editor.getText()).toBe '12a345\n\nabcd\nefadghi'
53 describe "the ctrl-e command", ->
55 atom.keymaps.add "test",
56 'atom-text-editor.vim-mode.insert-mode':
57 'ctrl-e': 'vim-mode:copy-from-line-below'
59 it "copies from the line below", ->
60 keydown 'e', ctrl: true
61 expect(editor.getText()).toBe '12345\na\nabcd\nefghi'
64 keydown 'e', ctrl: true
65 expect(editor.getText()).toBe '12345\na c\nabcd\n efghi'
67 it "does nothing if there's nothing below the cursor", ->
68 editor.insertText 'foo'
69 keydown 'e', ctrl: true
70 expect(editor.getText()).toBe '12345\nfood\nabcd\nfooefghi'
72 keydown 'e', ctrl: true
73 expect(editor.getText()).toBe '12345\nfood\nabcd\nfooefghi'