1 helpers = require './spec-helper'
2 settings = require '../lib/settings'
4 describe "Operators", ->
5 [editor, editorElement, vimState] = []
8 vimMode = atom.packages.loadPackage('vim-mode')
9 vimMode.activateResources()
11 helpers.getEditorElement (element) ->
12 editorElement = element
13 editor = editorElement.getModel()
14 vimState = editorElement.vimState
15 vimState.activateNormalMode()
16 vimState.resetNormalMode()
18 keydown = (key, options={}) ->
19 options.element ?= editorElement
20 helpers.keydown(key, options)
22 normalModeInputKeydown = (key, opts = {}) ->
23 editor.normalModeInputView.editorElement.getModel().setText(key)
25 describe "cancelling operations", ->
26 it "throws an error when no operation is pending", ->
27 # cancel operation pushes an empty input operation
28 # doing this without a pending operation would throw an exception
29 expect(-> vimState.pushOperations(new Input(''))).toThrow()
31 it "cancels and cleans up properly", ->
32 # make sure normalModeInputView is created
34 expect(vimState.isOperatorPending()).toBe true
35 editor.normalModeInputView.viewModel.cancel()
37 expect(vimState.isOperatorPending()).toBe false
38 expect(editor.normalModeInputView).toBe undefined
40 describe "the x keybinding", ->
41 describe "on a line with content", ->
42 describe "without vim-mode.wrapLeftRightMotion", ->
44 editor.setText("abc\n012345\n\nxyz")
45 editor.setCursorScreenPosition([1, 4])
47 it "deletes a character", ->
49 expect(editor.getText()).toBe 'abc\n01235\n\nxyz'
50 expect(editor.getCursorScreenPosition()).toEqual [1, 4]
51 expect(vimState.getRegister('"').text).toBe '4'
54 expect(editor.getText()).toBe 'abc\n0123\n\nxyz'
55 expect(editor.getCursorScreenPosition()).toEqual [1, 3]
56 expect(vimState.getRegister('"').text).toBe '5'
59 expect(editor.getText()).toBe 'abc\n012\n\nxyz'
60 expect(editor.getCursorScreenPosition()).toEqual [1, 2]
61 expect(vimState.getRegister('"').text).toBe '3'
64 expect(editor.getText()).toBe 'abc\n01\n\nxyz'
65 expect(editor.getCursorScreenPosition()).toEqual [1, 1]
66 expect(vimState.getRegister('"').text).toBe '2'
69 expect(editor.getText()).toBe 'abc\n0\n\nxyz'
70 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
71 expect(vimState.getRegister('"').text).toBe '1'
74 expect(editor.getText()).toBe 'abc\n\n\nxyz'
75 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
76 expect(vimState.getRegister('"').text).toBe '0'
78 it "deletes multiple characters with a count", ->
81 expect(editor.getText()).toBe 'abc\n0123\n\nxyz'
82 expect(editor.getCursorScreenPosition()).toEqual [1, 3]
83 expect(vimState.getRegister('"').text).toBe '45'
85 editor.setCursorScreenPosition([0, 1])
88 expect(editor.getText()).toBe 'a\n0123\n\nxyz'
89 expect(editor.getCursorScreenPosition()).toEqual [0, 0]
90 expect(vimState.getRegister('"').text).toBe 'bc'
92 describe "with multiple cursors", ->
94 editor.setText "abc\n012345\n\nxyz"
95 editor.setCursorScreenPosition [1, 4]
96 editor.addCursorAtBufferPosition [0, 1]
98 it "is undone as one operation", ->
100 expect(editor.getText()).toBe "ac\n01235\n\nxyz"
102 expect(editor.getText()).toBe "abc\n012345\n\nxyz"
104 describe "with vim-mode.wrapLeftRightMotion", ->
106 editor.setText("abc\n012345\n\nxyz")
107 editor.setCursorScreenPosition([1, 4])
108 atom.config.set('vim-mode.wrapLeftRightMotion', true)
110 it "deletes a character", ->
111 # copy of the earlier test because wrapLeftRightMotion should not affect it
113 expect(editor.getText()).toBe 'abc\n01235\n\nxyz'
114 expect(editor.getCursorScreenPosition()).toEqual [1, 4]
115 expect(vimState.getRegister('"').text).toBe '4'
118 expect(editor.getText()).toBe 'abc\n0123\n\nxyz'
119 expect(editor.getCursorScreenPosition()).toEqual [1, 3]
120 expect(vimState.getRegister('"').text).toBe '5'
123 expect(editor.getText()).toBe 'abc\n012\n\nxyz'
124 expect(editor.getCursorScreenPosition()).toEqual [1, 2]
125 expect(vimState.getRegister('"').text).toBe '3'
128 expect(editor.getText()).toBe 'abc\n01\n\nxyz'
129 expect(editor.getCursorScreenPosition()).toEqual [1, 1]
130 expect(vimState.getRegister('"').text).toBe '2'
133 expect(editor.getText()).toBe 'abc\n0\n\nxyz'
134 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
135 expect(vimState.getRegister('"').text).toBe '1'
138 expect(editor.getText()).toBe 'abc\n\n\nxyz'
139 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
140 expect(vimState.getRegister('"').text).toBe '0'
142 it "deletes multiple characters and newlines with a count", ->
143 atom.config.set('vim-mode.wrapLeftRightMotion', true)
146 expect(editor.getText()).toBe 'abc\n0123\n\nxyz'
147 expect(editor.getCursorScreenPosition()).toEqual [1, 3]
148 expect(vimState.getRegister('"').text).toBe '45'
150 editor.setCursorScreenPosition([0, 1])
153 expect(editor.getText()).toBe 'a0123\n\nxyz'
154 expect(editor.getCursorScreenPosition()).toEqual [0, 1]
155 expect(vimState.getRegister('"').text).toBe 'bc\n'
159 expect(editor.getText()).toBe 'ayz'
160 expect(editor.getCursorScreenPosition()).toEqual [0, 1]
161 expect(vimState.getRegister('"').text).toBe '0123\n\nx'
163 describe "on an empty line", ->
165 editor.setText("abc\n012345\n\nxyz")
166 editor.setCursorScreenPosition([2, 0])
168 it "deletes nothing on an empty line when vim-mode.wrapLeftRightMotion is false", ->
169 atom.config.set('vim-mode.wrapLeftRightMotion', false)
171 expect(editor.getText()).toBe "abc\n012345\n\nxyz"
172 expect(editor.getCursorScreenPosition()).toEqual [2, 0]
174 it "deletes an empty line when vim-mode.wrapLeftRightMotion is true", ->
175 atom.config.set('vim-mode.wrapLeftRightMotion', true)
177 expect(editor.getText()).toBe "abc\n012345\nxyz"
178 expect(editor.getCursorScreenPosition()).toEqual [2, 0]
180 describe "the X keybinding", ->
181 describe "on a line with content", ->
183 editor.setText("ab\n012345")
184 editor.setCursorScreenPosition([1, 2])
186 it "deletes a character", ->
187 keydown('X', shift: true)
188 expect(editor.getText()).toBe 'ab\n02345'
189 expect(editor.getCursorScreenPosition()).toEqual [1, 1]
190 expect(vimState.getRegister('"').text).toBe '1'
192 keydown('X', shift: true)
193 expect(editor.getText()).toBe 'ab\n2345'
194 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
195 expect(vimState.getRegister('"').text).toBe '0'
197 keydown('X', shift: true)
198 expect(editor.getText()).toBe 'ab\n2345'
199 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
200 expect(vimState.getRegister('"').text).toBe '0'
202 atom.config.set('vim-mode.wrapLeftRightMotion', true)
203 keydown('X', shift: true)
204 expect(editor.getText()).toBe 'ab2345'
205 expect(editor.getCursorScreenPosition()).toEqual [0, 2]
206 expect(vimState.getRegister('"').text).toBe '\n'
208 describe "on an empty line", ->
210 editor.setText("012345\n\nabcdef")
211 editor.setCursorScreenPosition([1, 0])
213 it "deletes nothing when vim-mode.wrapLeftRightMotion is false", ->
214 atom.config.set('vim-mode.wrapLeftRightMotion', false)
215 keydown('X', shift: true)
216 expect(editor.getText()).toBe "012345\n\nabcdef"
217 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
219 it "deletes the newline when wrapLeftRightMotion is true", ->
220 atom.config.set('vim-mode.wrapLeftRightMotion', true)
221 keydown('X', shift: true)
222 expect(editor.getText()).toBe "012345\nabcdef"
223 expect(editor.getCursorScreenPosition()).toEqual [0, 5]
225 describe "the s keybinding", ->
227 editor.setText('012345')
228 editor.setCursorScreenPosition([0, 1])
230 it "deletes the character to the right and enters insert mode", ->
232 expect(editorElement.classList.contains('insert-mode')).toBe(true)
233 expect(editor.getText()).toBe '02345'
234 expect(editor.getCursorScreenPosition()).toEqual [0, 1]
235 expect(vimState.getRegister('"').text).toBe '1'
237 it "is repeatable", ->
238 editor.setCursorScreenPosition([0, 0])
241 editor.insertText("ab")
243 expect(editor.getText()).toBe 'ab345'
244 editor.setCursorScreenPosition([0, 2])
246 expect(editor.getText()).toBe 'abab'
249 editor.setCursorScreenPosition([0, 0])
252 editor.insertText("ab")
254 expect(editor.getText()).toBe 'ab345'
256 expect(editor.getText()).toBe '012345'
257 expect(editor.getSelectedText()).toBe ''
259 describe "in visual mode", ->
265 it "deletes the selected characters and enters insert mode", ->
266 expect(editorElement.classList.contains('insert-mode')).toBe(true)
267 expect(editor.getText()).toBe '0345'
268 expect(editor.getCursorScreenPosition()).toEqual [0, 1]
269 expect(vimState.getRegister('"').text).toBe '12'
271 describe "the S keybinding", ->
273 editor.setText("12345\nabcde\nABCDE")
274 editor.setCursorScreenPosition([1, 3])
276 it "deletes the entire line and enters insert mode", ->
277 keydown('S', shift: true)
278 expect(editorElement.classList.contains('insert-mode')).toBe(true)
279 expect(editor.getText()).toBe "12345\n\nABCDE"
280 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
281 expect(vimState.getRegister('"').text).toBe "abcde\n"
282 expect(vimState.getRegister('"').type).toBe 'linewise'
284 it "is repeatable", ->
285 keydown('S', shift: true)
286 editor.insertText("abc")
288 expect(editor.getText()).toBe "12345\nabc\nABCDE"
289 editor.setCursorScreenPosition([2, 3])
291 expect(editor.getText()).toBe "12345\nabc\nabc\n"
294 keydown('S', shift: true)
295 editor.insertText("abc")
297 expect(editor.getText()).toBe "12345\nabc\nABCDE"
299 expect(editor.getText()).toBe "12345\nabcde\nABCDE"
300 expect(editor.getSelectedText()).toBe ''
302 it "works when the cursor's goal column is greater than its current column", ->
303 editor.setText("\n12345")
304 editor.setCursorBufferPosition([1, Infinity])
306 keydown("S", shift: true)
307 expect(editor.getText()).toBe("\n12345")
309 # Can't be tested without setting grammar of test buffer
310 xit "respects indentation", ->
312 describe "the d keybinding", ->
313 it "enters operator-pending mode", ->
315 expect(editorElement.classList.contains('operator-pending-mode')).toBe(true)
316 expect(editorElement.classList.contains('normal-mode')).toBe(false)
318 describe "when followed by a d", ->
319 it "deletes the current line and exits operator-pending mode", ->
320 editor.setText("12345\nabcde\n\nABCDE")
321 editor.setCursorScreenPosition([1, 1])
326 expect(editor.getText()).toBe "12345\n\nABCDE"
327 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
328 expect(vimState.getRegister('"').text).toBe "abcde\n"
329 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
330 expect(editorElement.classList.contains('normal-mode')).toBe(true)
332 it "deletes the last line", ->
333 editor.setText("12345\nabcde\nABCDE")
334 editor.setCursorScreenPosition([2, 1])
339 expect(editor.getText()).toBe "12345\nabcde\n"
340 expect(editor.getCursorScreenPosition()).toEqual [2, 0]
342 it "leaves the cursor on the first nonblank character", ->
343 editor.setText("12345\n abcde\n")
344 editor.setCursorScreenPosition([0, 4])
349 expect(editor.getText()).toBe " abcde\n"
350 expect(editor.getCursorScreenPosition()).toEqual [0, 2]
352 describe "undo behavior", ->
354 editor.setText("12345\nabcde\nABCDE\nQWERT")
355 editor.setCursorScreenPosition([1, 1])
357 it "undoes both lines", ->
364 expect(editor.getText()).toBe "12345\nabcde\nABCDE\nQWERT"
365 expect(editor.getSelectedText()).toBe ''
367 describe "with multiple cursors", ->
369 editor.setCursorBufferPosition([1, 1])
370 editor.addCursorAtBufferPosition([0, 0])
372 it "is undone as one operation", ->
378 expect(editor.getText()).toBe "12345\nabcde\nABCDE\nQWERT"
379 expect(editor.getSelectedText()).toBe ''
381 describe "when followed by a w", ->
382 it "deletes the next word until the end of the line and exits operator-pending mode", ->
383 editor.setText("abcd efg\nabc")
384 editor.setCursorScreenPosition([0, 5])
389 # Incompatibility with VIM. In vim, `w` behaves differently as an
390 # operator than as a motion; it stops at the end of a line.expect(editor.getText()).toBe "abcd abc"
391 expect(editor.getText()).toBe "abcd abc"
392 expect(editor.getCursorScreenPosition()).toEqual [0, 5]
394 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
395 expect(editorElement.classList.contains('normal-mode')).toBe(true)
397 it "deletes to the beginning of the next word", ->
398 editor.setText('abcd efg')
399 editor.setCursorScreenPosition([0, 2])
404 expect(editor.getText()).toBe 'abefg'
405 expect(editor.getCursorScreenPosition()).toEqual [0, 2]
407 editor.setText('one two three four')
408 editor.setCursorScreenPosition([0, 0])
414 expect(editor.getText()).toBe 'four'
415 expect(editor.getCursorScreenPosition()).toEqual [0, 0]
417 describe "when followed by an iw", ->
418 it "deletes the containing word", ->
419 editor.setText("12345 abcde ABCDE")
420 editor.setCursorScreenPosition([0, 9])
423 expect(editorElement.classList.contains('operator-pending-mode')).toBe(true)
427 expect(editor.getText()).toBe "12345 ABCDE"
428 expect(editor.getCursorScreenPosition()).toEqual [0, 6]
429 expect(vimState.getRegister('"').text).toBe "abcde"
430 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
431 expect(editorElement.classList.contains('normal-mode')).toBe(true)
433 describe "when followed by a j", ->
434 originalText = "12345\nabcde\nABCDE\n"
437 editor.setText(originalText)
439 describe "on the beginning of the file", ->
440 it "deletes the next two lines", ->
441 editor.setCursorScreenPosition([0, 0])
444 expect(editor.getText()).toBe("ABCDE\n")
446 describe "on the end of the file", ->
447 it "deletes nothing", ->
448 editor.setCursorScreenPosition([4, 0])
451 expect(editor.getText()).toBe(originalText)
453 describe "on the middle of second line", ->
454 it "deletes the last two lines", ->
455 editor.setCursorScreenPosition([1, 2])
458 expect(editor.getText()).toBe("12345\n")
460 describe "when followed by an k", ->
461 originalText = "12345\nabcde\nABCDE"
464 editor.setText(originalText)
466 describe "on the end of the file", ->
467 it "deletes the bottom two lines", ->
468 editor.setCursorScreenPosition([2, 4])
471 expect(editor.getText()).toBe("12345\n")
473 describe "on the beginning of the file", ->
474 xit "deletes nothing", ->
475 editor.setCursorScreenPosition([0, 0])
478 expect(editor.getText()).toBe(originalText)
480 describe "when on the middle of second line", ->
481 it "deletes the first two lines", ->
482 editor.setCursorScreenPosition([1, 2])
485 expect(editor.getText()).toBe("ABCDE")
487 describe "when followed by a G", ->
489 originalText = "12345\nabcde\nABCDE"
490 editor.setText(originalText)
492 describe "on the beginning of the second line", ->
493 it "deletes the bottom two lines", ->
494 editor.setCursorScreenPosition([1, 0])
496 keydown('G', shift: true)
497 expect(editor.getText()).toBe("12345\n")
499 describe "on the middle of the second line", ->
500 it "deletes the bottom two lines", ->
501 editor.setCursorScreenPosition([1, 2])
503 keydown('G', shift: true)
504 expect(editor.getText()).toBe("12345\n")
506 describe "when followed by a goto line G", ->
508 originalText = "12345\nabcde\nABCDE"
509 editor.setText(originalText)
511 describe "on the beginning of the second line", ->
512 it "deletes the bottom two lines", ->
513 editor.setCursorScreenPosition([1, 0])
516 keydown('G', shift: true)
517 expect(editor.getText()).toBe("12345\nABCDE")
519 describe "on the middle of the second line", ->
520 it "deletes the bottom two lines", ->
521 editor.setCursorScreenPosition([1, 2])
524 keydown('G', shift: true)
525 expect(editor.getText()).toBe("12345\nABCDE")
527 describe "when followed by a t)", ->
528 describe "with the entire line yanked before", ->
530 editor.setText("test (xyz)")
531 editor.setCursorScreenPosition([0, 6])
533 it "deletes until the closing parenthesis", ->
538 normalModeInputKeydown(')')
539 expect(editor.getText()).toBe("test ()")
540 expect(editor.getCursorScreenPosition()).toEqual [0, 6]
542 describe "with multiple cursors", ->
543 it "deletes each selection", ->
544 editor.setText("abcd\n1234\nABCD\n")
545 editor.setCursorBufferPosition([0, 1])
546 editor.addCursorAtBufferPosition([1, 2])
547 editor.addCursorAtBufferPosition([2, 3])
552 expect(editor.getText()).toBe "a\n12\nABC"
553 expect(editor.getCursorBufferPositions()).toEqual [
559 it "doesn't delete empty selections", ->
560 editor.setText("abcd\nabc\nabd")
561 editor.setCursorBufferPosition([0, 0])
562 editor.addCursorAtBufferPosition([1, 0])
563 editor.addCursorAtBufferPosition([2, 0])
567 normalModeInputKeydown('d')
569 expect(editor.getText()).toBe "d\nabc\nd"
570 expect(editor.getCursorBufferPositions()).toEqual [
576 describe "the D keybinding", ->
578 editor.getBuffer().setText("012\n")
579 editor.setCursorScreenPosition([0, 1])
580 keydown('D', shift: true)
582 it "deletes the contents until the end of the line", ->
583 expect(editor.getText()).toBe "0\n"
585 describe "the c keybinding", ->
587 editor.setText("12345\nabcde\nABCDE")
589 describe "when followed by a c", ->
590 describe "with autoindent", ->
592 editor.setText("12345\n abcde\nABCDE")
593 editor.setCursorScreenPosition([1, 1])
594 spyOn(editor, 'shouldAutoIndent').andReturn(true)
595 spyOn(editor, 'autoIndentBufferRow').andCallFake (line) ->
597 spyOn(editor.languageMode, 'suggestedIndentForLineAtBufferRow').andCallFake -> 1
599 it "deletes the current line and enters insert mode", ->
600 editor.setCursorScreenPosition([1, 1])
605 expect(editor.getText()).toBe "12345\n \nABCDE"
606 expect(editor.getCursorScreenPosition()).toEqual [1, 2]
607 expect(editorElement.classList.contains('normal-mode')).toBe(false)
608 expect(editorElement.classList.contains('insert-mode')).toBe(true)
610 it "is repeatable", ->
613 editor.insertText("abc")
615 expect(editor.getText()).toBe "12345\n abc\nABCDE"
616 editor.setCursorScreenPosition([2, 3])
618 expect(editor.getText()).toBe "12345\n abc\n abc\n"
623 editor.insertText("abc")
625 expect(editor.getText()).toBe "12345\n abc\nABCDE"
627 expect(editor.getText()).toBe "12345\n abcde\nABCDE"
628 expect(editor.getSelectedText()).toBe ''
630 describe "when the cursor is on the last line", ->
631 it "deletes the line's content and enters insert mode on the last line", ->
632 editor.setCursorScreenPosition([2, 1])
637 expect(editor.getText()).toBe "12345\nabcde\n\n"
638 expect(editor.getCursorScreenPosition()).toEqual [2, 0]
639 expect(editorElement.classList.contains('normal-mode')).toBe(false)
640 expect(editorElement.classList.contains('insert-mode')).toBe(true)
642 describe "when the cursor is on the only line", ->
643 it "deletes the line's content and enters insert mode", ->
644 editor.setText("12345")
645 editor.setCursorScreenPosition([0, 2])
650 expect(editor.getText()).toBe ""
651 expect(editor.getCursorScreenPosition()).toEqual [0, 0]
652 expect(editorElement.classList.contains('normal-mode')).toBe(false)
653 expect(editorElement.classList.contains('insert-mode')).toBe(true)
655 describe "when followed by i w", ->
656 it "undo's and redo's completely", ->
657 editor.setCursorScreenPosition([1, 1])
662 expect(editor.getText()).toBe "12345\n\nABCDE"
663 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
664 expect(editorElement.classList.contains('insert-mode')).toBe(true)
666 # Just cannot get "typing" to work correctly in test.
667 editor.setText("12345\nfg\nABCDE")
669 expect(editorElement.classList.contains('normal-mode')).toBe(true)
670 expect(editor.getText()).toBe "12345\nfg\nABCDE"
673 expect(editor.getText()).toBe "12345\nabcde\nABCDE"
674 keydown('r', ctrl: true)
675 expect(editor.getText()).toBe "12345\nfg\nABCDE"
677 describe "when followed by a w", ->
678 it "changes the word", ->
679 editor.setText("word1 word2 word3")
680 editor.setCursorBufferPosition([0, "word1 w".length])
686 expect(editor.getText()).toBe "word1 w word3"
688 describe "when followed by a G", ->
690 originalText = "12345\nabcde\nABCDE"
691 editor.setText(originalText)
693 describe "on the beginning of the second line", ->
694 it "deletes the bottom two lines", ->
695 editor.setCursorScreenPosition([1, 0])
697 keydown('G', shift: true)
699 expect(editor.getText()).toBe("12345\n\n")
701 describe "on the middle of the second line", ->
702 it "deletes the bottom two lines", ->
703 editor.setCursorScreenPosition([1, 2])
705 keydown('G', shift: true)
707 expect(editor.getText()).toBe("12345\n\n")
709 describe "when followed by a %", ->
711 editor.setText("12345(67)8\nabc(d)e\nA()BCDE")
713 describe "before brackets or on the first one", ->
715 editor.setCursorScreenPosition([0, 1])
716 editor.addCursorAtScreenPosition([1, 1])
717 editor.addCursorAtScreenPosition([2, 1])
720 editor.insertText('x')
722 it "replaces inclusively until matching bracket", ->
723 expect(editor.getText()).toBe("1x8\naxe\nAxBCDE")
724 expect(vimState.mode).toBe "insert"
726 it "undoes correctly with u", ->
728 expect(vimState.mode).toBe "normal"
730 expect(editor.getText()).toBe("12345(67)8\nabc(d)e\nA()BCDE")
732 describe "inside brackets or on the ending one", ->
733 it "replaces inclusively backwards until matching bracket", ->
734 editor.setCursorScreenPosition([0, 6])
735 editor.addCursorAtScreenPosition([1, 5])
736 editor.addCursorAtScreenPosition([2, 2])
739 editor.insertText('x')
740 expect(editor.getText()).toBe("12345x7)8\nabcxe\nAxBCDE")
741 expect(vimState.mode).toBe "insert"
743 describe "after or without brackets", ->
744 it "deletes nothing", ->
745 editor.setText("12345(67)8\nabc(d)e\nABCDE")
746 editor.setCursorScreenPosition([0, 9])
747 editor.addCursorAtScreenPosition([2, 2])
750 expect(editor.getText()).toBe("12345(67)8\nabc(d)e\nABCDE")
751 expect(vimState.mode).toBe "normal"
753 describe "repetition with .", ->
755 editor.setCursorScreenPosition([0, 1])
758 editor.insertText('x')
761 it "repeats correctly before a bracket", ->
762 editor.setCursorScreenPosition([1, 0])
764 expect(editor.getText()).toBe("1x8\nxe\nA()BCDE")
765 expect(vimState.mode).toBe "normal"
767 it "repeats correctly on the opening bracket", ->
768 editor.setCursorScreenPosition([1, 3])
770 expect(editor.getText()).toBe("1x8\nabcxe\nA()BCDE")
771 expect(vimState.mode).toBe "normal"
773 it "repeats correctly inside brackets", ->
774 editor.setCursorScreenPosition([1, 4])
776 expect(editor.getText()).toBe("1x8\nabcx)e\nA()BCDE")
777 expect(vimState.mode).toBe "normal"
779 it "repeats correctly on the closing bracket", ->
780 editor.setCursorScreenPosition([1, 5])
782 expect(editor.getText()).toBe("1x8\nabcxe\nA()BCDE")
783 expect(vimState.mode).toBe "normal"
785 it "does nothing when repeated after a bracket", ->
786 editor.setCursorScreenPosition([2, 3])
788 expect(editor.getText()).toBe("1x8\nabc(d)e\nA()BCDE")
789 expect(vimState.mode).toBe "normal"
791 describe "when followed by a goto line G", ->
793 editor.setText "12345\nabcde\nABCDE"
795 describe "on the beginning of the second line", ->
796 it "deletes all the text on the line", ->
797 editor.setCursorScreenPosition([1, 0])
800 keydown('G', shift: true)
802 expect(editor.getText()).toBe("12345\n\nABCDE")
804 describe "on the middle of the second line", ->
805 it "deletes all the text on the line", ->
806 editor.setCursorScreenPosition([1, 2])
809 keydown('G', shift: true)
811 expect(editor.getText()).toBe("12345\n\nABCDE")
813 describe "in visual mode", ->
815 editor.setText "123456789\nabcde\nfghijklmnopq\nuvwxyz"
816 editor.setCursorScreenPosition [1, 1]
818 describe "with characterwise selection on a single line", ->
819 it "repeats with .", ->
824 editor.insertText "ab"
826 expect(editor.getText()).toBe "123456789\naabe\nfghijklmnopq\nuvwxyz"
828 editor.setCursorScreenPosition [0, 1]
830 expect(editor.getText()).toBe "1ab56789\naabe\nfghijklmnopq\nuvwxyz"
832 it "repeats shortened with . near the end of the line", ->
833 editor.setCursorScreenPosition [0, 2]
838 editor.insertText "ab"
840 expect(editor.getText()).toBe "12ab89\nabcde\nfghijklmnopq\nuvwxyz"
842 editor.setCursorScreenPosition [1, 3]
844 expect(editor.getText()).toBe "12ab89\nabcab\nfghijklmnopq\nuvwxyz"
846 it "repeats shortened with . near the end of the line regardless of whether motion wrapping is enabled", ->
847 atom.config.set('vim-mode.wrapLeftRightMotion', true)
848 editor.setCursorScreenPosition [0, 2]
853 editor.insertText "ab"
855 expect(editor.getText()).toBe "12ab89\nabcde\nfghijklmnopq\nuvwxyz"
857 editor.setCursorScreenPosition [1, 3]
859 # this differs from VIM, which would eat the \n before fghij...
860 expect(editor.getText()).toBe "12ab89\nabcab\nfghijklmnopq\nuvwxyz"
862 describe "is repeatable with characterwise selection over multiple lines", ->
863 it "repeats with .", ->
869 editor.insertText "x"
871 expect(editor.getText()).toBe "123456789\naxklmnopq\nuvwxyz"
873 editor.setCursorScreenPosition [0, 1]
875 expect(editor.getText()).toBe "1xnopq\nuvwxyz"
877 it "repeats shortened with . near the end of the line", ->
878 # this behaviour is unlike VIM, see #737
884 editor.insertText "x"
886 expect(editor.getText()).toBe "123456789\naxnopq\nuvwxyz"
888 editor.setCursorScreenPosition [0, 1]
890 expect(editor.getText()).toBe "1x\nuvwxyz"
892 describe "is repeatable with linewise selection", ->
893 describe "with one line selected", ->
894 it "repeats with .", ->
895 keydown 'V', shift: true
897 editor.insertText "x"
899 expect(editor.getText()).toBe "123456789\nx\nfghijklmnopq\nuvwxyz"
901 editor.setCursorScreenPosition [0, 7]
903 expect(editor.getText()).toBe "x\nx\nfghijklmnopq\nuvwxyz"
905 editor.setCursorScreenPosition [2, 0]
907 expect(editor.getText()).toBe "x\nx\nx\nuvwxyz"
909 describe "with multiple lines selected", ->
910 it "repeats with .", ->
911 keydown 'V', shift: true
914 editor.insertText "x"
916 expect(editor.getText()).toBe "123456789\nx\nuvwxyz"
918 editor.setCursorScreenPosition [0, 7]
920 expect(editor.getText()).toBe "x\nuvwxyz"
922 it "repeats shortened with . near the end of the file", ->
923 keydown 'V', shift: true
926 editor.insertText "x"
928 expect(editor.getText()).toBe "123456789\nx\nuvwxyz"
930 editor.setCursorScreenPosition [1, 7]
932 expect(editor.getText()).toBe "123456789\nx\n"
934 xdescribe "is repeatable with block selection", ->
935 # there is no block selection yet
937 describe "the C keybinding", ->
939 editor.getBuffer().setText("012\n")
940 editor.setCursorScreenPosition([0, 1])
941 keydown('C', shift: true)
943 it "deletes the contents until the end of the line and enters insert mode", ->
944 expect(editor.getText()).toBe "0\n"
945 expect(editor.getCursorScreenPosition()).toEqual [0, 1]
946 expect(editorElement.classList.contains('normal-mode')).toBe(false)
947 expect(editorElement.classList.contains('insert-mode')).toBe(true)
949 describe "the y keybinding", ->
951 editor.getBuffer().setText("012 345\nabc\ndefg\n")
952 editor.setCursorScreenPosition([0, 4])
953 vimState.setRegister('"', text: '345')
955 describe "when selected lines in visual linewise mode", ->
957 keydown('V', shift: true)
961 it "is in linewise motion", ->
962 expect(vimState.getRegister('"').type).toEqual "linewise"
964 it "saves the lines to the default register", ->
965 expect(vimState.getRegister('"').text).toBe "012 345\nabc\n"
967 it "places the cursor at the beginning of the selection", ->
968 expect(editor.getCursorBufferPositions()).toEqual([[0, 0]])
970 describe "when followed by a second y ", ->
975 it "saves the line to the default register", ->
976 expect(vimState.getRegister('"').text).toBe "012 345\n"
978 it "leaves the cursor at the starting position", ->
979 expect(editor.getCursorScreenPosition()).toEqual [0, 4]
981 describe "when useClipboardAsDefaultRegister enabled", ->
982 it "writes to clipboard", ->
983 atom.config.set 'vim-mode.useClipboardAsDefaultRegister', true
986 expect(atom.clipboard.read()).toBe '012 345\n'
988 describe "when followed with a repeated y", ->
994 it "copies n lines, starting from the current", ->
995 expect(vimState.getRegister('"').text).toBe "012 345\nabc\n"
997 it "leaves the cursor at the starting position", ->
998 expect(editor.getCursorScreenPosition()).toEqual [0, 4]
1000 describe "with a register", ->
1007 it "saves the line to the a register", ->
1008 expect(vimState.getRegister('a').text).toBe "012 345\n"
1010 it "appends the line to the A register", ->
1012 keydown('A', shift: true)
1015 expect(vimState.getRegister('a').text).toBe "012 345\n012 345\n"
1017 describe "with a forward motion", ->
1022 it "saves the selected text to the default register", ->
1023 expect(vimState.getRegister('"').text).toBe '345'
1025 it "leaves the cursor at the starting position", ->
1026 expect(editor.getCursorScreenPosition()).toEqual [0, 4]
1028 it "does not yank when motion fails", ->
1031 normalModeInputKeydown('x')
1032 expect(vimState.getRegister('"').text).toBe '345'
1034 describe "with a text object", ->
1035 it "moves the cursor to the beginning of the text object", ->
1036 editor.setCursorBufferPosition([0, 5])
1040 expect(editor.getCursorBufferPositions()).toEqual([[0, 4]])
1042 describe "with a left motion", ->
1047 it "saves the left letter to the default register", ->
1048 expect(vimState.getRegister('"').text).toBe " "
1050 it "moves the cursor position to the left", ->
1051 expect(editor.getCursorScreenPosition()).toEqual [0, 3]
1053 describe "with a down motion", ->
1058 it "saves both full lines to the default register", ->
1059 expect(vimState.getRegister('"').text).toBe "012 345\nabc\n"
1061 it "leaves the cursor at the starting position", ->
1062 expect(editor.getCursorScreenPosition()).toEqual [0, 4]
1064 describe "with an up motion", ->
1066 editor.setCursorScreenPosition([2, 2])
1070 it "saves both full lines to the default register", ->
1071 expect(vimState.getRegister('"').text).toBe "abc\ndefg\n"
1073 it "puts the cursor on the first line and the original column", ->
1074 expect(editor.getCursorScreenPosition()).toEqual [1, 2]
1076 describe "when followed by a G", ->
1078 originalText = "12345\nabcde\nABCDE"
1079 editor.setText(originalText)
1081 describe "on the beginning of the second line", ->
1082 it "deletes the bottom two lines", ->
1083 editor.setCursorScreenPosition([1, 0])
1085 keydown('G', shift: true)
1086 keydown('P', shift: true)
1087 expect(editor.getText()).toBe("12345\nabcde\nABCDE\nabcde\nABCDE")
1089 describe "on the middle of the second line", ->
1090 it "deletes the bottom two lines", ->
1091 editor.setCursorScreenPosition([1, 2])
1093 keydown('G', shift: true)
1094 keydown('P', shift: true)
1095 expect(editor.getText()).toBe("12345\nabcde\nABCDE\nabcde\nABCDE")
1097 describe "when followed by a goto line G", ->
1099 originalText = "12345\nabcde\nABCDE"
1100 editor.setText(originalText)
1102 describe "on the beginning of the second line", ->
1103 it "deletes the bottom two lines", ->
1104 editor.setCursorScreenPosition([1, 0])
1107 keydown('G', shift: true)
1108 keydown('P', shift: true)
1109 expect(editor.getText()).toBe("12345\nabcde\nabcde\nABCDE")
1111 describe "on the middle of the second line", ->
1112 it "deletes the bottom two lines", ->
1113 editor.setCursorScreenPosition([1, 2])
1116 keydown('G', shift: true)
1117 keydown('P', shift: true)
1118 expect(editor.getText()).toBe("12345\nabcde\nabcde\nABCDE")
1120 describe "with multiple cursors", ->
1121 it "moves each cursor and copies the last selection's text", ->
1122 editor.setText " abcd\n 1234"
1123 editor.setCursorBufferPosition([0, 0])
1124 editor.addCursorAtBufferPosition([1, 5])
1129 expect(vimState.getRegister('"').text).toBe '123'
1130 expect(editor.getCursorBufferPositions()).toEqual [[0, 0], [1, 2]]
1132 describe "in a long file", ->
1134 editor.setHeight(400)
1135 editor.setLineHeightInPixels(10)
1136 editor.setDefaultCharWidth(10)
1140 editor.setText(text)
1142 describe "yanking many lines forward", ->
1143 it "does not scroll the window", ->
1144 editor.setCursorBufferPosition [40, 1]
1145 previousScrollTop = editor.getScrollTop()
1152 keydown('G', shift: true)
1154 expect(editor.getScrollTop()).toEqual(previousScrollTop)
1155 expect(editor.getCursorBufferPosition()).toEqual [40, 1]
1156 expect(vimState.getRegister('"').text.split('\n').length).toBe 121
1158 describe "yanking many lines backwards", ->
1159 it "scrolls the window", ->
1160 editor.setCursorBufferPosition [140, 1]
1161 previousScrollTop = editor.getScrollTop()
1167 keydown('G', shift: true)
1169 expect(editor.getScrollTop()).toNotEqual previousScrollTop
1170 expect(editor.getCursorBufferPosition()).toEqual [59, 1]
1171 expect(vimState.getRegister('"').text.split('\n').length).toBe 83
1173 describe "the yy keybinding", ->
1174 describe "on a single line file", ->
1176 editor.getBuffer().setText "exclamation!\n"
1177 editor.setCursorScreenPosition [0, 0]
1179 it "copies the entire line and pastes it correctly", ->
1184 expect(vimState.getRegister('"').text).toBe "exclamation!\n"
1185 expect(editor.getText()).toBe "exclamation!\nexclamation!\n"
1187 describe "on a single line file with no newline", ->
1189 editor.getBuffer().setText "no newline!"
1190 editor.setCursorScreenPosition [0, 0]
1192 it "copies the entire line and pastes it correctly", ->
1197 expect(vimState.getRegister('"').text).toBe "no newline!\n"
1198 expect(editor.getText()).toBe "no newline!\nno newline!"
1200 it "copies the entire line and pastes it respecting count and new lines", ->
1206 expect(vimState.getRegister('"').text).toBe "no newline!\n"
1207 expect(editor.getText()).toBe "no newline!\nno newline!\nno newline!"
1209 describe "the Y keybinding", ->
1211 editor.getBuffer().setText "012 345\nabc\n"
1212 editor.setCursorScreenPosition [0, 4]
1214 it "saves the line to the default register", ->
1215 keydown('Y', shift: true)
1217 expect(vimState.getRegister('"').text).toBe "012 345\n"
1218 expect(editor.getCursorScreenPosition()).toEqual [0, 4]
1220 describe "the p keybinding", ->
1221 describe "with character contents", ->
1223 editor.getBuffer().setText "012\n"
1224 editor.setCursorScreenPosition [0, 0]
1225 vimState.setRegister('"', text: '345')
1226 vimState.setRegister('a', text: 'a')
1227 atom.clipboard.write "clip"
1229 describe "from the default register", ->
1230 beforeEach -> keydown('p')
1232 it "inserts the contents", ->
1233 expect(editor.getText()).toBe "034512\n"
1234 expect(editor.getCursorScreenPosition()).toEqual [0, 3]
1236 describe "at the end of a line", ->
1238 editor.setCursorScreenPosition [0, 2]
1241 it "positions cursor correctly", ->
1242 expect(editor.getText()).toBe "012345\n"
1243 expect(editor.getCursorScreenPosition()).toEqual [0, 5]
1245 describe "when useClipboardAsDefaultRegister enabled", ->
1246 it "inserts contents from clipboard", ->
1247 atom.config.set 'vim-mode.useClipboardAsDefaultRegister', true
1249 expect(editor.getText()).toBe "0clip12\n"
1251 describe "from a specified register", ->
1257 it "inserts the contents of the 'a' register", ->
1258 expect(editor.getText()).toBe "0a12\n"
1259 expect(editor.getCursorScreenPosition()).toEqual [0, 1]
1261 describe "at the end of a line", ->
1262 it "inserts before the current line's newline", ->
1263 editor.setText("abcde\none two three")
1264 editor.setCursorScreenPosition([1, 4])
1272 expect(editor.getText()).toBe "abcdetwo three\none "
1274 describe "with a selection", ->
1276 editor.selectRight()
1279 it "replaces the current selection", ->
1280 expect(editor.getText()).toBe "34512\n"
1281 expect(editor.getCursorScreenPosition()).toEqual [0, 2]
1283 describe "with linewise contents", ->
1284 describe "on a single line", ->
1286 editor.getBuffer().setText("012")
1287 editor.setCursorScreenPosition([0, 1])
1288 vimState.setRegister('"', text: " 345\n", type: 'linewise')
1290 it "inserts the contents of the default register", ->
1293 expect(editor.getText()).toBe "012\n 345"
1294 expect(editor.getCursorScreenPosition()).toEqual [1, 1]
1296 it "replaces the current selection", ->
1297 editor.selectRight()
1300 expect(editor.getText()).toBe "0 345\n2"
1301 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
1303 describe "on multiple lines", ->
1305 editor.getBuffer().setText("012\n 345")
1306 vimState.setRegister('"', text: " 456\n", type: 'linewise')
1308 it "inserts the contents of the default register at middle line", ->
1309 editor.setCursorScreenPosition([0, 1])
1312 expect(editor.getText()).toBe "012\n 456\n 345"
1313 expect(editor.getCursorScreenPosition()).toEqual [1, 1]
1315 it "inserts the contents of the default register at end of line", ->
1316 editor.setCursorScreenPosition([1, 1])
1319 expect(editor.getText()).toBe "012\n 345\n 456"
1320 expect(editor.getCursorScreenPosition()).toEqual [2, 1]
1322 describe "with multiple linewise contents", ->
1324 editor.getBuffer().setText("012\nabc")
1325 editor.setCursorScreenPosition([1, 0])
1326 vimState.setRegister('"', text: " 345\n 678\n", type: 'linewise')
1329 it "inserts the contents of the default register", ->
1330 expect(editor.getText()).toBe "012\nabc\n 345\n 678"
1331 expect(editor.getCursorScreenPosition()).toEqual [2, 1]
1333 describe "pasting twice", ->
1335 editor.setText("12345\nabcde\nABCDE\nQWERT")
1336 editor.setCursorScreenPosition([1, 1])
1337 vimState.setRegister('"', text: '123')
1341 it "inserts the same line twice", ->
1342 expect(editor.getText()).toBe "12345\nab123123cde\nABCDE\nQWERT"
1344 describe "when undone", ->
1348 it "removes both lines", ->
1349 expect(editor.getText()).toBe "12345\nabcde\nABCDE\nQWERT"
1351 describe "the P keybinding", ->
1352 describe "with character contents", ->
1354 editor.getBuffer().setText("012\n")
1355 editor.setCursorScreenPosition([0, 0])
1356 vimState.setRegister('"', text: '345')
1357 vimState.setRegister('a', text: 'a')
1358 keydown('P', shift: true)
1360 it "inserts the contents of the default register above", ->
1361 expect(editor.getText()).toBe "345012\n"
1362 expect(editor.getCursorScreenPosition()).toEqual [0, 2]
1364 describe "the O keybinding", ->
1366 spyOn(editor, 'shouldAutoIndent').andReturn(true)
1367 spyOn(editor, 'autoIndentBufferRow').andCallFake (line) ->
1370 editor.getBuffer().setText(" abc\n 012\n")
1371 editor.setCursorScreenPosition([1, 1])
1373 it "switches to insert and adds a newline above the current one", ->
1374 keydown('O', shift: true)
1375 expect(editor.getText()).toBe " abc\n \n 012\n"
1376 expect(editor.getCursorScreenPosition()).toEqual [1, 2]
1377 expect(editorElement.classList.contains('insert-mode')).toBe(true)
1379 it "is repeatable", ->
1380 editor.getBuffer().setText(" abc\n 012\n 4spaces\n")
1381 editor.setCursorScreenPosition([1, 1])
1382 keydown('O', shift: true)
1383 editor.insertText "def"
1385 expect(editor.getText()).toBe " abc\n def\n 012\n 4spaces\n"
1386 editor.setCursorScreenPosition([1, 1])
1388 expect(editor.getText()).toBe " abc\n def\n def\n 012\n 4spaces\n"
1389 editor.setCursorScreenPosition([4, 1])
1391 expect(editor.getText()).toBe " abc\n def\n def\n 012\n def\n 4spaces\n"
1393 it "is undoable", ->
1394 keydown('O', shift: true)
1395 editor.insertText "def"
1397 expect(editor.getText()).toBe " abc\n def\n 012\n"
1399 expect(editor.getText()).toBe " abc\n 012\n"
1401 describe "the o keybinding", ->
1403 spyOn(editor, 'shouldAutoIndent').andReturn(true)
1404 spyOn(editor, 'autoIndentBufferRow').andCallFake (line) ->
1407 editor.getBuffer().setText("abc\n 012\n")
1408 editor.setCursorScreenPosition([1, 2])
1410 it "switches to insert and adds a newline above the current one", ->
1412 expect(editor.getText()).toBe "abc\n 012\n \n"
1413 expect(editorElement.classList.contains('insert-mode')).toBe(true)
1414 expect(editor.getCursorScreenPosition()).toEqual [2, 2]
1416 # This works in practice, but the editor doesn't respect the indentation
1417 # rules without a syntax grammar. Need to set the editor's grammar
1419 xit "is repeatable", ->
1420 editor.getBuffer().setText(" abc\n 012\n 4spaces\n")
1421 editor.setCursorScreenPosition([1, 1])
1423 editor.insertText "def"
1425 expect(editor.getText()).toBe " abc\n 012\n def\n 4spaces\n"
1427 expect(editor.getText()).toBe " abc\n 012\n def\n def\n 4spaces\n"
1428 editor.setCursorScreenPosition([4, 1])
1430 expect(editor.getText()).toBe " abc\n def\n def\n 012\n 4spaces\n def\n"
1432 it "is undoable", ->
1434 editor.insertText "def"
1436 expect(editor.getText()).toBe "abc\n 012\n def\n"
1438 expect(editor.getText()).toBe "abc\n 012\n"
1440 describe "the a keybinding", ->
1442 editor.getBuffer().setText("012\n")
1444 describe "at the beginning of the line", ->
1446 editor.setCursorScreenPosition([0, 0])
1449 it "switches to insert mode and shifts to the right", ->
1450 expect(editor.getCursorScreenPosition()).toEqual [0, 1]
1451 expect(editorElement.classList.contains('insert-mode')).toBe(true)
1453 describe "at the end of the line", ->
1455 editor.setCursorScreenPosition([0, 3])
1458 it "doesn't linewrap", ->
1459 expect(editor.getCursorScreenPosition()).toEqual [0, 3]
1461 describe "the A keybinding", ->
1463 editor.getBuffer().setText("11\n22\n")
1465 describe "at the beginning of a line", ->
1466 it "switches to insert mode at the end of the line", ->
1467 editor.setCursorScreenPosition([0, 0])
1468 keydown('A', shift: true)
1470 expect(editorElement.classList.contains('insert-mode')).toBe(true)
1471 expect(editor.getCursorScreenPosition()).toEqual [0, 2]
1473 it "repeats always as insert at the end of the line", ->
1474 editor.setCursorScreenPosition([0, 0])
1475 keydown('A', shift: true)
1476 editor.insertText("abc")
1478 editor.setCursorScreenPosition([1, 0])
1481 expect(editor.getText()).toBe "11abc\n22abc\n"
1482 expect(editorElement.classList.contains('insert-mode')).toBe(false)
1483 expect(editor.getCursorScreenPosition()).toEqual [1, 4]
1485 describe "the I keybinding", ->
1487 editor.getBuffer().setText("11\n 22\n")
1489 describe "at the end of a line", ->
1490 it "switches to insert mode at the beginning of the line", ->
1491 editor.setCursorScreenPosition([0, 2])
1492 keydown('I', shift: true)
1494 expect(editorElement.classList.contains('insert-mode')).toBe(true)
1495 expect(editor.getCursorScreenPosition()).toEqual [0, 0]
1497 it "switches to insert mode after leading whitespace", ->
1498 editor.setCursorScreenPosition([1, 4])
1499 keydown('I', shift: true)
1501 expect(editorElement.classList.contains('insert-mode')).toBe(true)
1502 expect(editor.getCursorScreenPosition()).toEqual [1, 2]
1504 it "repeats always as insert at the first character of the line", ->
1505 editor.setCursorScreenPosition([0, 2])
1506 keydown('I', shift: true)
1507 editor.insertText("abc")
1509 expect(editor.getCursorScreenPosition()).toEqual [0, 2]
1510 editor.setCursorScreenPosition([1, 4])
1513 expect(editor.getText()).toBe "abc11\n abc22\n"
1514 expect(editorElement.classList.contains('insert-mode')).toBe(false)
1515 expect(editor.getCursorScreenPosition()).toEqual [1, 4]
1517 describe "the J keybinding", ->
1519 editor.getBuffer().setText("012\n 456\n")
1520 editor.setCursorScreenPosition([0, 1])
1522 describe "without repeating", ->
1523 beforeEach -> keydown('J', shift: true)
1525 it "joins the contents of the current line with the one below it", ->
1526 expect(editor.getText()).toBe "012 456\n"
1528 describe "with repeating", ->
1530 editor.setText("12345\nabcde\nABCDE\nQWERT")
1531 editor.setCursorScreenPosition([1, 1])
1533 keydown('J', shift: true)
1535 describe "undo behavior", ->
1536 beforeEach -> keydown('u')
1538 it "handles repeats", ->
1539 expect(editor.getText()).toBe "12345\nabcde\nABCDE\nQWERT"
1541 describe "the > keybinding", ->
1543 editor.setText("12345\nabcde\nABCDE")
1545 describe "on the last line", ->
1547 editor.setCursorScreenPosition([2, 0])
1549 describe "when followed by a >", ->
1554 it "indents the current line", ->
1555 expect(editor.getText()).toBe "12345\nabcde\n ABCDE"
1556 expect(editor.getCursorScreenPosition()).toEqual [2, 2]
1558 describe "on the first line", ->
1560 editor.setCursorScreenPosition([0, 0])
1562 describe "when followed by a >", ->
1567 it "indents the current line", ->
1568 expect(editor.getText()).toBe " 12345\nabcde\nABCDE"
1569 expect(editor.getCursorScreenPosition()).toEqual [0, 2]
1571 describe "when followed by a repeating >", ->
1577 it "indents multiple lines at once", ->
1578 expect(editor.getText()).toBe " 12345\n abcde\n ABCDE"
1579 expect(editor.getCursorScreenPosition()).toEqual [0, 2]
1581 describe "undo behavior", ->
1582 beforeEach -> keydown('u')
1584 it "outdents all three lines", ->
1585 expect(editor.getText()).toBe "12345\nabcde\nABCDE"
1587 describe "in visual mode linewise", ->
1589 editor.setCursorScreenPosition([0, 0])
1590 keydown('v', shift: true)
1593 describe "single indent multiple lines", ->
1597 it "indents both lines once and exits visual mode", ->
1598 expect(editorElement.classList.contains('normal-mode')).toBe(true)
1599 expect(editor.getText()).toBe " 12345\n abcde\nABCDE"
1600 expect(editor.getSelectedBufferRanges()).toEqual [ [[0, 2], [0, 2]] ]
1602 it "allows repeating the operation", ->
1604 expect(editor.getText()).toBe " 12345\n abcde\nABCDE"
1606 describe "multiple indent multiple lines", ->
1611 it "indents both lines twice and exits visual mode", ->
1612 expect(editorElement.classList.contains('normal-mode')).toBe(true)
1613 expect(editor.getText()).toBe " 12345\n abcde\nABCDE"
1614 expect(editor.getSelectedBufferRanges()).toEqual [ [[0, 4], [0, 4]] ]
1616 describe "with multiple selections", ->
1618 editor.setCursorScreenPosition([1, 3])
1621 editor.addCursorAtScreenPosition([0, 0])
1623 it "indents the lines and keeps the cursors", ->
1625 expect(editor.getText()).toBe " 12345\n abcde\n ABCDE"
1626 expect(editor.getCursorScreenPositions()).toEqual [[1, 2], [0, 2]]
1628 describe "the < keybinding", ->
1630 editor.setText(" 12345\n abcde\nABCDE")
1631 editor.setCursorScreenPosition([0, 0])
1633 describe "when followed by a <", ->
1638 it "outdents the current line", ->
1639 expect(editor.getText()).toBe " 12345\n abcde\nABCDE"
1640 expect(editor.getCursorScreenPosition()).toEqual [0, 2]
1642 describe "when followed by a repeating <", ->
1648 it "outdents multiple lines at once", ->
1649 expect(editor.getText()).toBe " 12345\n abcde\nABCDE"
1650 expect(editor.getCursorScreenPosition()).toEqual [0, 2]
1652 describe "undo behavior", ->
1653 beforeEach -> keydown('u')
1655 it "indents both lines", ->
1656 expect(editor.getText()).toBe " 12345\n abcde\nABCDE"
1658 describe "in visual mode linewise", ->
1660 keydown('v', shift: true)
1663 describe "single outdent multiple lines", ->
1667 it "outdents the current line and exits visual mode", ->
1668 expect(editorElement.classList.contains('normal-mode')).toBe(true)
1669 expect(editor.getText()).toBe " 12345\n abcde\nABCDE"
1670 expect(editor.getSelectedBufferRanges()).toEqual [ [[0, 2], [0, 2]] ]
1672 it "allows repeating the operation", ->
1674 expect(editor.getText()).toBe "12345\nabcde\nABCDE"
1676 describe "multiple outdent multiple lines", ->
1681 it "outdents both lines twice and exits visual mode", ->
1682 expect(editorElement.classList.contains('normal-mode')).toBe(true)
1683 expect(editor.getText()).toBe "12345\nabcde\nABCDE"
1684 expect(editor.getSelectedBufferRanges()).toEqual [ [[0, 0], [0, 0]] ]
1686 describe "the = keybinding", ->
1691 atom.packages.activatePackage('language-javascript')
1693 oldGrammar = editor.getGrammar()
1694 editor.setText("foo\n bar\n baz")
1695 editor.setCursorScreenPosition([1, 0])
1697 describe "when used in a scope that supports auto-indent", ->
1699 jsGrammar = atom.grammars.grammarForScopeName('source.js')
1700 editor.setGrammar(jsGrammar)
1703 editor.setGrammar(oldGrammar)
1705 describe "when followed by a =", ->
1710 it "indents the current line", ->
1711 expect(editor.indentationForBufferRow(1)).toBe 0
1713 describe "when followed by a G", ->
1715 editor.setCursorScreenPosition([0, 0])
1717 keydown('G', shift: true)
1719 it "uses the default count", ->
1720 expect(editor.indentationForBufferRow(1)).toBe 0
1721 expect(editor.indentationForBufferRow(2)).toBe 0
1723 describe "when followed by a repeating =", ->
1729 it "autoindents multiple lines at once", ->
1730 expect(editor.getText()).toBe "foo\nbar\nbaz"
1731 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
1733 describe "undo behavior", ->
1734 beforeEach -> keydown('u')
1736 it "indents both lines", ->
1737 expect(editor.getText()).toBe "foo\n bar\n baz"
1739 describe "the . keybinding", ->
1741 editor.setText("12\n34\n56\n78")
1742 editor.setCursorScreenPosition([0, 0])
1744 it "repeats the last operation", ->
1750 expect(editor.getText()).toBe ""
1752 it "composes with motions", ->
1758 expect(editor.getText()).toBe "78"
1760 describe "the r keybinding", ->
1762 editor.setText("12\n34\n\n")
1763 editor.setCursorBufferPosition([0, 0])
1764 editor.addCursorAtBufferPosition([1, 0])
1766 it "replaces a single character", ->
1768 normalModeInputKeydown('x')
1769 expect(editor.getText()).toBe 'x2\nx4\n\n'
1771 it "does nothing when cancelled", ->
1773 expect(editorElement.classList.contains('operator-pending-mode')).toBe(true)
1775 expect(editor.getText()).toBe '12\n34\n\n'
1776 expect(editorElement.classList.contains('normal-mode')).toBe(true)
1778 it "replaces a single character with a line break", ->
1780 atom.commands.dispatch(editor.normalModeInputView.editorElement, 'core:confirm')
1781 expect(editor.getText()).toBe '\n2\n\n4\n\n'
1782 expect(editor.getCursorBufferPositions()).toEqual [[1, 0], [3, 0]]
1784 it "composes properly with motions", ->
1787 normalModeInputKeydown('x')
1788 expect(editor.getText()).toBe 'xx\nxx\n\n'
1790 it "does nothing on an empty line", ->
1791 editor.setCursorBufferPosition([2, 0])
1793 normalModeInputKeydown('x')
1794 expect(editor.getText()).toBe '12\n34\n\n'
1796 it "does nothing if asked to replace more characters than there are on a line", ->
1799 normalModeInputKeydown('x')
1800 expect(editor.getText()).toBe '12\n34\n\n'
1802 describe "when in visual mode", ->
1807 it "replaces the entire selection with the given character", ->
1809 normalModeInputKeydown('x')
1810 expect(editor.getText()).toBe 'xx\nxx\n\n'
1812 it "leaves the cursor at the beginning of the selection", ->
1814 normalModeInputKeydown('x')
1815 expect(editor.getCursorBufferPositions()).toEqual [[0, 0], [1, 0]]
1817 describe 'with accented characters', ->
1818 buildIMECompositionEvent = (event, {data, target}={}) ->
1819 event = new Event(event)
1821 Object.defineProperty(event, 'target', get: -> target)
1824 buildTextInputEvent = ({data, target}) ->
1825 event = new Event('textInput')
1827 Object.defineProperty(event, 'target', get: -> target)
1830 it 'works with IME composition', ->
1832 normalModeEditor = editor.normalModeInputView.editorElement
1833 jasmine.attachToDOM(normalModeEditor)
1834 domNode = normalModeEditor.component.domNode
1835 inputNode = domNode.querySelector('.hidden-input')
1836 domNode.dispatchEvent(buildIMECompositionEvent('compositionstart', target: inputNode))
1837 domNode.dispatchEvent(buildIMECompositionEvent('compositionupdate', data: 's', target: inputNode))
1838 expect(normalModeEditor.getModel().getText()).toEqual 's'
1839 domNode.dispatchEvent(buildIMECompositionEvent('compositionupdate', data: 'sd', target: inputNode))
1840 expect(normalModeEditor.getModel().getText()).toEqual 'sd'
1841 domNode.dispatchEvent(buildIMECompositionEvent('compositionend', target: inputNode))
1842 domNode.dispatchEvent(buildTextInputEvent(data: '速度', target: inputNode))
1843 expect(editor.getText()).toBe '速度2\n速度4\n\n'
1845 describe 'the m keybinding', ->
1847 editor.setText('12\n34\n56\n')
1848 editor.setCursorBufferPosition([0, 1])
1850 it 'marks a position', ->
1852 normalModeInputKeydown('a')
1853 expect(vimState.getMark('a')).toEqual [0, 1]
1855 describe 'the ~ keybinding', ->
1857 editor.setText('aBc\nXyZ')
1858 editor.setCursorBufferPosition([0, 0])
1859 editor.addCursorAtBufferPosition([1, 0])
1861 it 'toggles the case and moves right', ->
1863 expect(editor.getText()).toBe 'ABc\nxyZ'
1864 expect(editor.getCursorScreenPositions()).toEqual [[0, 1], [1, 1]]
1867 expect(editor.getText()).toBe 'Abc\nxYZ'
1868 expect(editor.getCursorScreenPositions()).toEqual [[0, 2], [1, 2]]
1871 expect(editor.getText()).toBe 'AbC\nxYz'
1872 expect(editor.getCursorScreenPositions()).toEqual [[0, 2], [1, 2]]
1874 it 'takes a count', ->
1878 expect(editor.getText()).toBe 'AbC\nxYz'
1879 expect(editor.getCursorScreenPositions()).toEqual [[0, 2], [1, 2]]
1881 describe "in visual mode", ->
1882 it "toggles the case of the selected text", ->
1883 editor.setCursorBufferPosition([0, 0])
1884 keydown("V", shift: true)
1886 expect(editor.getText()).toBe 'AbC\nXyZ'
1888 describe "with g and motion", ->
1889 it "toggles the case of text", ->
1890 editor.setCursorBufferPosition([0, 0])
1895 expect(editor.getText()).toBe 'Abc\nXyZ'
1897 it "uses default count", ->
1898 editor.setCursorBufferPosition([0, 0])
1901 keydown("G", shift: true)
1902 expect(editor.getText()).toBe 'AbC\nxYz'
1904 describe 'the U keybinding', ->
1906 editor.setText('aBc\nXyZ')
1907 editor.setCursorBufferPosition([0, 0])
1909 it "makes text uppercase with g and motion", ->
1911 keydown("U", shift: true)
1913 expect(editor.getText()).toBe 'ABc\nXyZ'
1916 keydown("U", shift: true)
1918 expect(editor.getText()).toBe 'ABC\nXyZ'
1920 editor.setCursorBufferPosition([1, 0])
1922 keydown("U", shift: true)
1924 expect(editor.getText()).toBe 'ABC\nXYZ'
1925 expect(editor.getCursorScreenPosition()).toEqual [1, 2]
1927 it "uses default count", ->
1928 editor.setCursorBufferPosition([0, 0])
1930 keydown("U", shift: true)
1931 keydown("G", shift: true)
1932 expect(editor.getText()).toBe 'ABC\nXYZ'
1934 it "makes the selected text uppercase in visual mode", ->
1935 keydown("V", shift: true)
1936 keydown("U", shift: true)
1937 expect(editor.getText()).toBe 'ABC\nXyZ'
1939 describe 'the u keybinding', ->
1941 editor.setText('aBc\nXyZ')
1942 editor.setCursorBufferPosition([0, 0])
1944 it "makes text lowercase with g and motion", ->
1948 expect(editor.getText()).toBe 'abc\nXyZ'
1949 expect(editor.getCursorScreenPosition()).toEqual [0, 2]
1951 it "uses default count", ->
1952 editor.setCursorBufferPosition([0, 0])
1955 keydown("G", shift: true)
1956 expect(editor.getText()).toBe 'abc\nxyz'
1958 it "makes the selected text lowercase in visual mode", ->
1959 keydown("V", shift: true)
1961 expect(editor.getText()).toBe 'abc\nXyZ'
1963 describe "the i keybinding", ->
1965 editor.setText('123\n4567')
1966 editor.setCursorBufferPosition([0, 0])
1967 editor.addCursorAtBufferPosition([1, 0])
1969 it "allows undoing an entire batch of typing", ->
1971 editor.insertText("abcXX")
1975 expect(editor.getText()).toBe "abc123\nabc4567"
1978 editor.insertText "d"
1979 editor.insertText "e"
1980 editor.insertText "f"
1982 expect(editor.getText()).toBe "abdefc123\nabdefc4567"
1985 expect(editor.getText()).toBe "abc123\nabc4567"
1988 expect(editor.getText()).toBe "123\n4567"
1990 it "allows repeating typing", ->
1992 editor.insertText("abcXX")
1996 expect(editor.getText()).toBe "abc123\nabc4567"
1999 expect(editor.getText()).toBe "ababcc123\nababcc4567"
2002 expect(editor.getText()).toBe "abababccc123\nabababccc4567"
2004 describe 'with nonlinear input', ->
2007 editor.setCursorBufferPosition [0, 0]
2009 it 'deals with auto-matched brackets', ->
2011 # this sequence simulates what the bracket-matcher package does
2012 # when the user types (a)b<enter>
2013 editor.insertText '()'
2015 editor.insertText 'a'
2017 editor.insertText 'b\n'
2019 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
2022 expect(editor.getText()).toBe '(a)b\n(a)b\n'
2023 expect(editor.getCursorScreenPosition()).toEqual [2, 0]
2025 it 'deals with autocomplete', ->
2027 # this sequence simulates autocompletion of 'add' to 'addFoo'
2028 editor.insertText 'a'
2029 editor.insertText 'd'
2030 editor.insertText 'd'
2031 editor.setTextInBufferRange [[0, 0], [0, 3]], 'addFoo'
2033 expect(editor.getCursorScreenPosition()).toEqual [0, 5]
2034 expect(editor.getText()).toBe 'addFoo'
2037 expect(editor.getText()).toBe 'addFoaddFooo'
2038 expect(editor.getCursorScreenPosition()).toEqual [0, 10]
2040 describe 'the a keybinding', ->
2043 editor.setCursorBufferPosition([0, 0])
2045 it "can be undone in one go", ->
2047 editor.insertText("abc")
2049 expect(editor.getText()).toBe "abc"
2051 expect(editor.getText()).toBe ""
2053 it "repeats correctly", ->
2055 editor.insertText("abc")
2057 expect(editor.getText()).toBe "abc"
2058 expect(editor.getCursorScreenPosition()).toEqual [0, 2]
2060 expect(editor.getText()).toBe "abcabc"
2061 expect(editor.getCursorScreenPosition()).toEqual [0, 5]
2063 describe "the ctrl-a/ctrl-x keybindings", ->
2065 atom.config.set 'vim-mode.numberRegex', settings.config.numberRegex.default
2066 editor.setText('123\nab45\ncd-67ef\nab-5\na-bcdef')
2067 editor.setCursorBufferPosition [0, 0]
2068 editor.addCursorAtBufferPosition [1, 0]
2069 editor.addCursorAtBufferPosition [2, 0]
2070 editor.addCursorAtBufferPosition [3, 3]
2071 editor.addCursorAtBufferPosition [4, 0]
2073 describe "increasing numbers", ->
2074 it "increases the next number", ->
2075 keydown('a', ctrl: true)
2076 expect(editor.getCursorBufferPositions()).toEqual [[0, 2], [1, 3], [2, 4], [3, 3], [4, 0]]
2077 expect(editor.getText()).toBe '124\nab46\ncd-66ef\nab-4\na-bcdef'
2078 expect(atom.beep).not.toHaveBeenCalled()
2080 it "repeats with .", ->
2081 keydown 'a', ctrl: true
2083 expect(editor.getCursorBufferPositions()).toEqual [[0, 2], [1, 3], [2, 4], [3, 3], [4, 0]]
2084 expect(editor.getText()).toBe '125\nab47\ncd-65ef\nab-3\na-bcdef'
2085 expect(atom.beep).not.toHaveBeenCalled()
2087 it "can have a count", ->
2089 keydown 'a', ctrl: true
2090 expect(editor.getCursorBufferPositions()).toEqual [[0, 2], [1, 3], [2, 4], [3, 2], [4, 0]]
2091 expect(editor.getText()).toBe '128\nab50\ncd-62ef\nab0\na-bcdef'
2092 expect(atom.beep).not.toHaveBeenCalled()
2094 it "can make a negative number positive, change number of digits", ->
2097 keydown 'a', ctrl: true
2098 expect(editor.getCursorBufferPositions()).toEqual [[0, 2], [1, 4], [2, 3], [3, 3], [4, 0]]
2099 expect(editor.getText()).toBe '222\nab144\ncd32ef\nab94\na-bcdef'
2100 expect(atom.beep).not.toHaveBeenCalled()
2102 it "does nothing when cursor is after the number", ->
2103 editor.setCursorBufferPosition [2, 5]
2104 keydown 'a', ctrl: true
2105 expect(editor.getCursorBufferPositions()).toEqual [[2, 5]]
2106 expect(editor.getText()).toBe '123\nab45\ncd-67ef\nab-5\na-bcdef'
2107 expect(atom.beep).toHaveBeenCalled()
2109 it "does nothing on an empty line", ->
2110 editor.setText('\n')
2111 editor.setCursorBufferPosition [0, 0]
2112 editor.addCursorAtBufferPosition [1, 0]
2113 keydown 'a', ctrl: true
2114 expect(editor.getCursorBufferPositions()).toEqual [[0, 0], [1, 0]]
2115 expect(editor.getText()).toBe '\n'
2116 expect(atom.beep).toHaveBeenCalled()
2118 it "honours the vim-mode:numberRegex setting", ->
2119 editor.setText('123\nab45\ncd -67ef\nab-5\na-bcdef')
2120 editor.setCursorBufferPosition [0, 0]
2121 editor.addCursorAtBufferPosition [1, 0]
2122 editor.addCursorAtBufferPosition [2, 0]
2123 editor.addCursorAtBufferPosition [3, 3]
2124 editor.addCursorAtBufferPosition [4, 0]
2125 atom.config.set('vim-mode.numberRegex', '(?:\\B-)?[0-9]+')
2126 keydown('a', ctrl: true)
2127 expect(editor.getCursorBufferPositions()).toEqual [[0, 2], [1, 3], [2, 5], [3, 3], [4, 0]]
2128 expect(editor.getText()).toBe '124\nab46\ncd -66ef\nab-6\na-bcdef'
2129 expect(atom.beep).not.toHaveBeenCalled()
2131 describe "decreasing numbers", ->
2132 it "decreases the next number", ->
2133 keydown('x', ctrl: true)
2134 expect(editor.getCursorBufferPositions()).toEqual [[0, 2], [1, 3], [2, 4], [3, 3], [4, 0]]
2135 expect(editor.getText()).toBe '122\nab44\ncd-68ef\nab-6\na-bcdef'
2136 expect(atom.beep).not.toHaveBeenCalled()
2138 it "repeats with .", ->
2139 keydown 'x', ctrl: true
2141 expect(editor.getCursorBufferPositions()).toEqual [[0, 2], [1, 3], [2, 4], [3, 3], [4, 0]]
2142 expect(editor.getText()).toBe '121\nab43\ncd-69ef\nab-7\na-bcdef'
2143 expect(atom.beep).not.toHaveBeenCalled()
2145 it "can have a count", ->
2147 keydown 'x', ctrl: true
2148 expect(editor.getCursorBufferPositions()).toEqual [[0, 2], [1, 3], [2, 4], [3, 4], [4, 0]]
2149 expect(editor.getText()).toBe '118\nab40\ncd-72ef\nab-10\na-bcdef'
2150 expect(atom.beep).not.toHaveBeenCalled()
2152 it "can make a positive number negative, change number of digits", ->
2155 keydown 'x', ctrl: true
2156 expect(editor.getCursorBufferPositions()).toEqual [[0, 1], [1, 4], [2, 5], [3, 5], [4, 0]]
2157 expect(editor.getText()).toBe '24\nab-54\ncd-166ef\nab-104\na-bcdef'
2158 expect(atom.beep).not.toHaveBeenCalled()
2160 it "does nothing when cursor is after the number", ->
2161 editor.setCursorBufferPosition [2, 5]
2162 keydown 'x', ctrl: true
2163 expect(editor.getCursorBufferPositions()).toEqual [[2, 5]]
2164 expect(editor.getText()).toBe '123\nab45\ncd-67ef\nab-5\na-bcdef'
2165 expect(atom.beep).toHaveBeenCalled()
2167 it "does nothing on an empty line", ->
2168 editor.setText('\n')
2169 editor.setCursorBufferPosition [0, 0]
2170 editor.addCursorAtBufferPosition [1, 0]
2171 keydown 'x', ctrl: true
2172 expect(editor.getCursorBufferPositions()).toEqual [[0, 0], [1, 0]]
2173 expect(editor.getText()).toBe '\n'
2174 expect(atom.beep).toHaveBeenCalled()
2176 it "honours the vim-mode:numberRegex setting", ->
2177 editor.setText('123\nab45\ncd -67ef\nab-5\na-bcdef')
2178 editor.setCursorBufferPosition [0, 0]
2179 editor.addCursorAtBufferPosition [1, 0]
2180 editor.addCursorAtBufferPosition [2, 0]
2181 editor.addCursorAtBufferPosition [3, 3]
2182 editor.addCursorAtBufferPosition [4, 0]
2183 atom.config.set('vim-mode.numberRegex', '(?:\\B-)?[0-9]+')
2184 keydown('x', ctrl: true)
2185 expect(editor.getCursorBufferPositions()).toEqual [[0, 2], [1, 3], [2, 5], [3, 3], [4, 0]]
2186 expect(editor.getText()).toBe '122\nab44\ncd -68ef\nab-4\na-bcdef'
2187 expect(atom.beep).not.toHaveBeenCalled()
2189 describe 'the R keybinding', ->
2191 editor.setText('12345\n67890')
2192 editor.setCursorBufferPosition([0, 2])
2194 it "enters replace mode and replaces characters", ->
2195 keydown "R", shift: true
2196 expect(editorElement.classList.contains('insert-mode')).toBe true
2197 expect(editorElement.classList.contains('replace-mode')).toBe true
2199 editor.insertText "ab"
2202 expect(editor.getText()).toBe "12ab5\n67890"
2203 expect(editor.getCursorScreenPosition()).toEqual [0, 3]
2204 expect(editorElement.classList.contains('insert-mode')).toBe false
2205 expect(editorElement.classList.contains('replace-mode')).toBe false
2206 expect(editorElement.classList.contains('normal-mode')).toBe true
2208 it "continues beyond end of line as insert", ->
2209 keydown "R", shift: true
2210 expect(editorElement.classList.contains('insert-mode')).toBe true
2211 expect(editorElement.classList.contains('replace-mode')).toBe true
2213 editor.insertText "abcde"
2216 expect(editor.getText()).toBe "12abcde\n67890"
2218 it "treats backspace as undo", ->
2219 editor.insertText "foo"
2220 keydown "R", shift: true
2222 editor.insertText "a"
2223 editor.insertText "b"
2224 expect(editor.getText()).toBe "12fooab5\n67890"
2226 keydown 'backspace', raw: true
2227 expect(editor.getText()).toBe "12fooa45\n67890"
2229 editor.insertText "c"
2231 expect(editor.getText()).toBe "12fooac5\n67890"
2233 keydown 'backspace', raw: true
2234 keydown 'backspace', raw: true
2236 expect(editor.getText()).toBe "12foo345\n67890"
2237 expect(editor.getSelectedText()).toBe ""
2239 keydown 'backspace', raw: true
2240 expect(editor.getText()).toBe "12foo345\n67890"
2241 expect(editor.getSelectedText()).toBe ""
2243 it "can be repeated", ->
2244 keydown "R", shift: true
2245 editor.insertText "ab"
2247 editor.setCursorBufferPosition([1, 2])
2249 expect(editor.getText()).toBe "12ab5\n67ab0"
2250 expect(editor.getCursorScreenPosition()).toEqual [1, 3]
2252 editor.setCursorBufferPosition([0, 4])
2254 expect(editor.getText()).toBe "12abab\n67ab0"
2255 expect(editor.getCursorScreenPosition()).toEqual [0, 5]
2257 it "can be interrupted by arrow keys and behave as insert for repeat", ->
2258 # FIXME don't know how to test this (also, depends on PR #568)
2260 it "repeats correctly when backspace was used in the text", ->
2261 keydown "R", shift: true
2262 editor.insertText "a"
2263 keydown 'backspace', raw: true
2264 editor.insertText "b"
2266 editor.setCursorBufferPosition([1, 2])
2268 expect(editor.getText()).toBe "12b45\n67b90"
2269 expect(editor.getCursorScreenPosition()).toEqual [1, 2]
2271 editor.setCursorBufferPosition([0, 4])
2273 expect(editor.getText()).toBe "12b4b\n67b90"
2274 expect(editor.getCursorScreenPosition()).toEqual [0, 4]
2276 it "doesn't replace a character if newline is entered", ->
2277 keydown "R", shift: true
2278 expect(editorElement.classList.contains('insert-mode')).toBe true
2279 expect(editorElement.classList.contains('replace-mode')).toBe true
2281 editor.insertText "\n"
2284 expect(editor.getText()).toBe "12\n345\n67890"