forked from atom/vim-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
motions-spec.coffee
2048 lines (1648 loc) · 71.6 KB
/
motions-spec.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
helpers = require './spec-helper'
describe "Motions", ->
[editor, editorElement, parentElement, vimState] = []
beforeEach ->
vimMode = atom.packages.loadPackage('vim-mode')
vimMode.activateResources()
helpers.getEditorElement (element) ->
editorElement = element
editor = editorElement.getModel()
vimState = editorElement.vimState
vimState.activateNormalMode()
vimState.resetNormalMode()
keydown = (key, options={}) ->
options.element ?= editorElement
helpers.keydown(key, options)
normalModeInputKeydown = (key, opts = {}) ->
theEditor = opts.editor or editor
theEditor.normalModeInputView.editorElement.getModel().setText(key)
submitNormalModeInputText = (text) ->
inputEditor = editor.normalModeInputView.editorElement
inputEditor.getModel().setText(text)
atom.commands.dispatch(inputEditor, "core:confirm")
describe "simple motions", ->
beforeEach ->
editor.setText("12345\nabcd\nABCDE")
editor.setCursorScreenPosition([1, 1])
describe "the h keybinding", ->
describe "as a motion", ->
it "moves the cursor left, but not to the previous line", ->
keydown('h')
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
keydown('h')
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
it "moves the cursor to the previous line if wrapLeftRightMotion is true", ->
atom.config.set('vim-mode.wrapLeftRightMotion', true)
keydown('h')
keydown('h')
expect(editor.getCursorScreenPosition()).toEqual [0, 4]
describe "as a selection", ->
it "selects the character to the left", ->
keydown('y')
keydown('h')
expect(vimState.getRegister('"').text).toBe 'a'
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
describe "the j keybinding", ->
it "moves the cursor down, but not to the end of the last line", ->
keydown('j')
expect(editor.getCursorScreenPosition()).toEqual [2, 1]
keydown('j')
expect(editor.getCursorScreenPosition()).toEqual [2, 1]
it "moves the cursor to the end of the line, not past it", ->
editor.setCursorScreenPosition([0, 4])
keydown('j')
expect(editor.getCursorScreenPosition()).toEqual [1, 3]
it "remembers the position it column it was in after moving to shorter line", ->
editor.setCursorScreenPosition([0, 4])
keydown('j')
expect(editor.getCursorScreenPosition()).toEqual [1, 3]
keydown('j')
expect(editor.getCursorScreenPosition()).toEqual [2, 4]
describe "when visual mode", ->
beforeEach ->
keydown('v')
expect(editor.getCursorScreenPosition()).toEqual [1, 2]
it "moves the cursor down", ->
keydown('j')
expect(editor.getCursorScreenPosition()).toEqual [2, 2]
it "doesn't go over after the last line", ->
keydown('j')
expect(editor.getCursorScreenPosition()).toEqual [2, 2]
it "selects the text while moving", ->
keydown('j')
expect(editor.getSelectedText()).toBe "bcd\nAB"
describe "the k keybinding", ->
it "moves the cursor up, but not to the beginning of the first line", ->
keydown('k')
expect(editor.getCursorScreenPosition()).toEqual [0, 1]
keydown('k')
expect(editor.getCursorScreenPosition()).toEqual [0, 1]
describe "the l keybinding", ->
beforeEach -> editor.setCursorScreenPosition([1, 2])
it "moves the cursor right, but not to the next line", ->
keydown('l')
expect(editor.getCursorScreenPosition()).toEqual [1, 3]
keydown('l')
expect(editor.getCursorScreenPosition()).toEqual [1, 3]
it "moves the cursor to the next line if wrapLeftRightMotion is true", ->
atom.config.set('vim-mode.wrapLeftRightMotion', true)
keydown('l')
keydown('l')
expect(editor.getCursorScreenPosition()).toEqual [2, 0]
describe "on a blank line", ->
it "doesn't move the cursor", ->
editor.setText("\n\n\n")
editor.setCursorBufferPosition([1, 0])
keydown('l')
expect(editor.getCursorBufferPosition()).toEqual [1, 0]
describe "the w keybinding", ->
beforeEach -> editor.setText("ab cde1+- \n xyz\n\nzip")
describe "as a motion", ->
beforeEach -> editor.setCursorScreenPosition([0, 0])
it "moves the cursor to the beginning of the next word", ->
keydown('w')
expect(editor.getCursorScreenPosition()).toEqual [0, 3]
keydown('w')
expect(editor.getCursorScreenPosition()).toEqual [0, 7]
keydown('w')
expect(editor.getCursorScreenPosition()).toEqual [1, 1]
keydown('w')
expect(editor.getCursorScreenPosition()).toEqual [2, 0]
keydown('w')
expect(editor.getCursorScreenPosition()).toEqual [3, 0]
keydown('w')
expect(editor.getCursorScreenPosition()).toEqual [3, 2]
# When the cursor gets to the EOF, it should stay there.
keydown('w')
expect(editor.getCursorScreenPosition()).toEqual [3, 2]
it "moves the cursor to the end of the word if last word in file", ->
editor.setText("abc")
editor.setCursorScreenPosition([0, 0])
keydown('w')
expect(editor.getCursorScreenPosition()).toEqual([0, 2])
describe "as a selection", ->
describe "within a word", ->
beforeEach ->
editor.setCursorScreenPosition([0, 0])
keydown('y')
keydown('w')
it "selects to the end of the word", ->
expect(vimState.getRegister('"').text).toBe 'ab '
describe "between words", ->
beforeEach ->
editor.setCursorScreenPosition([0, 2])
keydown('y')
keydown('w')
it "selects the whitespace", ->
expect(vimState.getRegister('"').text).toBe ' '
describe "the W keybinding", ->
beforeEach -> editor.setText("cde1+- ab \n xyz\n\nzip")
describe "as a motion", ->
beforeEach -> editor.setCursorScreenPosition([0, 0])
it "moves the cursor to the beginning of the next word", ->
keydown('W', shift: true)
expect(editor.getCursorScreenPosition()).toEqual [0, 7]
keydown('W', shift: true)
expect(editor.getCursorScreenPosition()).toEqual [1, 1]
keydown('W', shift: true)
expect(editor.getCursorScreenPosition()).toEqual [2, 0]
keydown('W', shift: true)
expect(editor.getCursorScreenPosition()).toEqual [3, 0]
describe "as a selection", ->
describe "within a word", ->
it "selects to the end of the whole word", ->
editor.setCursorScreenPosition([0, 0])
keydown('y')
keydown('W', shift: true)
expect(vimState.getRegister('"').text).toBe 'cde1+- '
it "continues past blank lines", ->
editor.setCursorScreenPosition([2, 0])
keydown('d')
keydown('W', shift: true)
expect(editor.getText()).toBe "cde1+- ab \n xyz\nzip"
expect(vimState.getRegister('"').text).toBe '\n'
it "doesn't go past the end of the file", ->
editor.setCursorScreenPosition([3, 0])
keydown('d')
keydown('W', shift: true)
expect(editor.getText()).toBe "cde1+- ab \n xyz\n\n"
expect(vimState.getRegister('"').text).toBe 'zip'
describe "the e keybinding", ->
beforeEach -> editor.setText("ab cde1+- \n xyz\n\nzip")
describe "as a motion", ->
beforeEach -> editor.setCursorScreenPosition([0, 0])
it "moves the cursor to the end of the current word", ->
keydown('e')
expect(editor.getCursorScreenPosition()).toEqual [0, 1]
keydown('e')
expect(editor.getCursorScreenPosition()).toEqual [0, 6]
keydown('e')
expect(editor.getCursorScreenPosition()).toEqual [0, 8]
keydown('e')
expect(editor.getCursorScreenPosition()).toEqual [1, 3]
keydown('e')
expect(editor.getCursorScreenPosition()).toEqual [3, 2]
describe "as selection", ->
describe "within a word", ->
beforeEach ->
editor.setCursorScreenPosition([0, 0])
keydown('y')
keydown('e')
it "selects to the end of the current word", ->
expect(vimState.getRegister('"').text).toBe 'ab'
describe "between words", ->
beforeEach ->
editor.setCursorScreenPosition([0, 2])
keydown('y')
keydown('e')
it "selects to the end of the next word", ->
expect(vimState.getRegister('"').text).toBe ' cde1'
describe "the E keybinding", ->
beforeEach -> editor.setText("ab cde1+- \n xyz \n\nzip\n")
describe "as a motion", ->
beforeEach -> editor.setCursorScreenPosition([0, 0])
it "moves the cursor to the end of the current word", ->
keydown('E', shift: true)
expect(editor.getCursorScreenPosition()).toEqual [0, 1]
keydown('E', shift: true)
expect(editor.getCursorScreenPosition()).toEqual [0, 9]
keydown('E', shift: true)
expect(editor.getCursorScreenPosition()).toEqual [1, 3]
keydown('E', shift: true)
expect(editor.getCursorScreenPosition()).toEqual [3, 2]
keydown('E', shift: true)
expect(editor.getCursorScreenPosition()).toEqual [4, 0]
describe "as selection", ->
describe "within a word", ->
beforeEach ->
editor.setCursorScreenPosition([0, 0])
keydown('y')
keydown('E', shift: true)
it "selects to the end of the current word", ->
expect(vimState.getRegister('"').text).toBe 'ab'
describe "between words", ->
beforeEach ->
editor.setCursorScreenPosition([0, 2])
keydown('y')
keydown('E', shift: true)
it "selects to the end of the next word", ->
expect(vimState.getRegister('"').text).toBe ' cde1+-'
describe "press more than once", ->
beforeEach ->
editor.setCursorScreenPosition([0, 0])
keydown('v')
keydown('E', shift: true)
keydown('E', shift: true)
keydown('y')
it "selects to the end of the current word", ->
expect(vimState.getRegister('"').text).toBe 'ab cde1+-'
describe "the ) keybinding", ->
beforeEach ->
editor.setText "This is a sentence. This is a second sentence.\nThis is a third sentence.\n\nThis sentence is past the paragraph boundary."
editor.setCursorBufferPosition [0, 0]
describe "as a motion", ->
it "moves the cursor to the beginning of the next sentence", ->
keydown ')'
expect(editor.getCursorBufferPosition()).toEqual [0, 20]
keydown ')'
expect(editor.getCursorBufferPosition()).toEqual [1, 0]
keydown ')'
expect(editor.getCursorBufferPosition()).toEqual [2, 0]
describe "as a selection", ->
beforeEach ->
keydown('y')
keydown(')')
it 'selects to the start of the next sentence', ->
expect(vimState.getRegister('"').text).toBe "This is a sentence. "
describe "the ( keybinding", ->
beforeEach ->
editor.setText "This first sentence is in its own paragraph.\n\nThis is a sentence. This is a second sentence.\nThis is a third sentence"
editor.setCursorBufferPosition [3, 0]
describe "as a motion", ->
it "moves the cursor to the beginning of the previous sentence", ->
keydown '('
expect(editor.getCursorBufferPosition()).toEqual [2, 20]
keydown '('
expect(editor.getCursorBufferPosition()).toEqual [2, 0]
keydown '('
expect(editor.getCursorBufferPosition()).toEqual [1, 0]
describe "as a selection", ->
beforeEach ->
keydown('y')
keydown('(')
it 'selects to the end of the previous sentence', ->
expect(vimState.getRegister('"').text).toBe "This is a second sentence.\n"
describe "the } keybinding", ->
beforeEach ->
editor.setText("abcde\n\nfghij\nhijk\n xyz \n\nzip\n\n \nthe end")
editor.setCursorScreenPosition([0, 0])
describe "as a motion", ->
it "moves the cursor to the end of the paragraph", ->
keydown('}')
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
keydown('}')
expect(editor.getCursorScreenPosition()).toEqual [5, 0]
keydown('}')
expect(editor.getCursorScreenPosition()).toEqual [7, 0]
keydown('}')
expect(editor.getCursorScreenPosition()).toEqual [9, 6]
describe "as a selection", ->
beforeEach ->
keydown('y')
keydown('}')
it 'selects to the end of the current paragraph', ->
expect(vimState.getRegister('"').text).toBe "abcde\n"
describe "the { keybinding", ->
beforeEach ->
editor.setText("abcde\n\nfghij\nhijk\n xyz \n\nzip\n\n \nthe end")
editor.setCursorScreenPosition([9, 0])
describe "as a motion", ->
it "moves the cursor to the beginning of the paragraph", ->
keydown('{')
expect(editor.getCursorScreenPosition()).toEqual [7, 0]
keydown('{')
expect(editor.getCursorScreenPosition()).toEqual [5, 0]
keydown('{')
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
keydown('{')
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
describe "as a selection", ->
beforeEach ->
editor.setCursorScreenPosition([7, 0])
keydown('y')
keydown('{')
it 'selects to the beginning of the current paragraph', ->
expect(vimState.getRegister('"').text).toBe "\nzip\n"
describe "the b keybinding", ->
beforeEach -> editor.setText(" ab cde1+- \n xyz\n\nzip }\n last")
describe "as a motion", ->
beforeEach -> editor.setCursorScreenPosition([4, 1])
it "moves the cursor to the beginning of the previous word", ->
keydown('b')
expect(editor.getCursorScreenPosition()).toEqual [3, 4]
keydown('b')
expect(editor.getCursorScreenPosition()).toEqual [3, 0]
keydown('b')
expect(editor.getCursorScreenPosition()).toEqual [2, 0]
keydown('b')
expect(editor.getCursorScreenPosition()).toEqual [1, 1]
keydown('b')
expect(editor.getCursorScreenPosition()).toEqual [0, 8]
keydown('b')
expect(editor.getCursorScreenPosition()).toEqual [0, 4]
keydown('b')
expect(editor.getCursorScreenPosition()).toEqual [0, 1]
# Go to start of the file, after moving past the first word
keydown('b')
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
# Stay at the start of the file
keydown('b')
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
describe "as a selection", ->
describe "within a word", ->
beforeEach ->
editor.setCursorScreenPosition([0, 2])
keydown('y')
keydown('b')
it "selects to the beginning of the current word", ->
expect(vimState.getRegister('"').text).toBe 'a'
expect(editor.getCursorScreenPosition()).toEqual [0, 1]
describe "between words", ->
beforeEach ->
editor.setCursorScreenPosition([0, 4])
keydown('y')
keydown('b')
it "selects to the beginning of the last word", ->
expect(vimState.getRegister('"').text).toBe 'ab '
expect(editor.getCursorScreenPosition()).toEqual [0, 1]
describe "the B keybinding", ->
beforeEach -> editor.setText("cde1+- ab \n\t xyz-123\n\n zip")
describe "as a motion", ->
beforeEach -> editor.setCursorScreenPosition([4, 1])
it "moves the cursor to the beginning of the previous word", ->
keydown('B', shift: true)
expect(editor.getCursorScreenPosition()).toEqual [3, 1]
keydown('B', shift: true)
expect(editor.getCursorScreenPosition()).toEqual [2, 0]
keydown('B', shift: true)
expect(editor.getCursorScreenPosition()).toEqual [1, 3]
keydown('B', shift: true)
expect(editor.getCursorScreenPosition()).toEqual [0, 7]
keydown('B', shift: true)
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
describe "as a selection", ->
it "selects to the beginning of the whole word", ->
editor.setCursorScreenPosition([1, 9])
keydown('y')
keydown('B', shift: true)
expect(vimState.getRegister('"').text).toBe 'xyz-12'
it "doesn't go past the beginning of the file", ->
editor.setCursorScreenPosition([0, 0])
vimState.setRegister('"', text: 'abc')
keydown('y')
keydown('B', shift: true)
expect(vimState.getRegister('"').text).toBe 'abc'
describe "the ^ keybinding", ->
beforeEach ->
editor.setText(" abcde")
describe "from the beginning of the line", ->
beforeEach -> editor.setCursorScreenPosition([0, 0])
describe "as a motion", ->
beforeEach -> keydown('^')
it "moves the cursor to the first character of the line", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 2]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('^')
it 'selects to the first character of the line', ->
expect(editor.getText()).toBe 'abcde'
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
describe "from the first character of the line", ->
beforeEach -> editor.setCursorScreenPosition([0, 2])
describe "as a motion", ->
beforeEach -> keydown('^')
it "stays put", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 2]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('^')
it "does nothing", ->
expect(editor.getText()).toBe ' abcde'
expect(editor.getCursorScreenPosition()).toEqual [0, 2]
describe "from the middle of a word", ->
beforeEach -> editor.setCursorScreenPosition([0, 4])
describe "as a motion", ->
beforeEach -> keydown('^')
it "moves the cursor to the first character of the line", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 2]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('^')
it 'selects to the first character of the line', ->
expect(editor.getText()).toBe ' cde'
expect(editor.getCursorScreenPosition()).toEqual [0, 2]
describe "the 0 keybinding", ->
beforeEach ->
editor.setText(" abcde")
editor.setCursorScreenPosition([0, 4])
describe "as a motion", ->
beforeEach -> keydown('0')
it "moves the cursor to the first column", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('0')
it 'selects to the first column of the line', ->
expect(editor.getText()).toBe 'cde'
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
describe "the $ keybinding", ->
beforeEach ->
editor.setText(" abcde\n\n1234567890")
editor.setCursorScreenPosition([0, 4])
describe "as a motion from empty line", ->
beforeEach -> editor.setCursorScreenPosition([1, 0])
it "moves the cursor to the end of the line", ->
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
describe "as a motion", ->
beforeEach -> keydown('$')
# FIXME: See atom/vim-mode#2
it "moves the cursor to the end of the line", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 6]
it "should remain in the last column when moving down", ->
keydown('j')
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
keydown('j')
expect(editor.getCursorScreenPosition()).toEqual [2, 9]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('$')
it "selects to the beginning of the lines", ->
expect(editor.getText()).toBe " ab\n\n1234567890"
expect(editor.getCursorScreenPosition()).toEqual [0, 3]
describe "the 0 keybinding", ->
beforeEach ->
editor.setText(" a\n")
editor.setCursorScreenPosition([0, 2])
describe "as a motion", ->
beforeEach -> keydown('0')
it "moves the cursor to the beginning of the line", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
describe "the - keybinding", ->
beforeEach ->
editor.setText("abcdefg\n abc\n abc\n")
describe "from the middle of a line", ->
beforeEach -> editor.setCursorScreenPosition([1, 3])
describe "as a motion", ->
beforeEach -> keydown('-')
it "moves the cursor to the first character of the previous line", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('-')
it "deletes the current and previous line", ->
expect(editor.getText()).toBe " abc\n"
# commented out because the column is wrong due to a bug in `k`; re-enable when `k` is fixed
#expect(editor.getCursorScreenPosition()).toEqual [0, 3]
describe "from the first character of a line indented the same as the previous one", ->
beforeEach -> editor.setCursorScreenPosition([2, 2])
describe "as a motion", ->
beforeEach -> keydown('-')
it "moves to the first character of the previous line (directly above)", ->
expect(editor.getCursorScreenPosition()).toEqual [1, 2]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('-')
it "selects to the first character of the previous line (directly above)", ->
expect(editor.getText()).toBe "abcdefg\n"
# commented out because the column is wrong due to a bug in `k`; re-enable when `k` is fixed
#expect(editor.getCursorScreenPosition()).toEqual [0, 2]
describe "from the beginning of a line preceded by an indented line", ->
beforeEach -> editor.setCursorScreenPosition([2, 0])
describe "as a motion", ->
beforeEach -> keydown('-')
it "moves the cursor to the first character of the previous line", ->
expect(editor.getCursorScreenPosition()).toEqual [1, 2]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('-')
it "selects to the first character of the previous line", ->
expect(editor.getText()).toBe "abcdefg\n"
# commented out because the column is wrong due to a bug in `k`; re-enable when `k` is fixed
#expect(editor.getCursorScreenPosition()).toEqual [0, 0]
describe "with a count", ->
beforeEach ->
editor.setText("1\n2\n3\n4\n5\n6\n")
editor.setCursorScreenPosition([4, 0])
describe "as a motion", ->
beforeEach ->
keydown('3')
keydown('-')
it "moves the cursor to the first character of that many lines previous", ->
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('3')
keydown('-')
it "deletes the current line plus that many previous lines", ->
expect(editor.getText()).toBe "1\n6\n"
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
describe "the + keybinding", ->
beforeEach ->
editor.setText(" abc\n abc\nabcdefg\n")
describe "from the middle of a line", ->
beforeEach -> editor.setCursorScreenPosition([1, 3])
describe "as a motion", ->
beforeEach -> keydown('+')
it "moves the cursor to the first character of the next line", ->
expect(editor.getCursorScreenPosition()).toEqual [2, 0]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('+')
it "deletes the current and next line", ->
expect(editor.getText()).toBe " abc\n"
# commented out because the column is wrong due to a bug in `j`; re-enable when `j` is fixed
#expect(editor.getCursorScreenPosition()).toEqual [0, 3]
describe "from the first character of a line indented the same as the next one", ->
beforeEach -> editor.setCursorScreenPosition([0, 2])
describe "as a motion", ->
beforeEach -> keydown('+')
it "moves to the first character of the next line (directly below)", ->
expect(editor.getCursorScreenPosition()).toEqual [1, 2]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('+')
it "selects to the first character of the next line (directly below)", ->
expect(editor.getText()).toBe "abcdefg\n"
# commented out because the column is wrong due to a bug in `j`; re-enable when `j` is fixed
#expect(editor.getCursorScreenPosition()).toEqual [0, 2]
describe "from the beginning of a line followed by an indented line", ->
beforeEach -> editor.setCursorScreenPosition([0, 0])
describe "as a motion", ->
beforeEach -> keydown('+')
it "moves the cursor to the first character of the next line", ->
expect(editor.getCursorScreenPosition()).toEqual [1, 2]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('+')
it "selects to the first character of the next line", ->
expect(editor.getText()).toBe "abcdefg\n"
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
describe "with a count", ->
beforeEach ->
editor.setText("1\n2\n3\n4\n5\n6\n")
editor.setCursorScreenPosition([1, 0])
describe "as a motion", ->
beforeEach ->
keydown('3')
keydown('+')
it "moves the cursor to the first character of that many lines following", ->
expect(editor.getCursorScreenPosition()).toEqual [4, 0]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('3')
keydown('+')
it "deletes the current line plus that many following lines", ->
expect(editor.getText()).toBe "1\n6\n"
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
describe "the _ keybinding", ->
beforeEach ->
editor.setText(" abc\n abc\nabcdefg\n")
describe "from the middle of a line", ->
beforeEach -> editor.setCursorScreenPosition([1, 3])
describe "as a motion", ->
beforeEach -> keydown('_')
it "moves the cursor to the first character of the current line", ->
expect(editor.getCursorScreenPosition()).toEqual [1, 2]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('_')
it "deletes the current line", ->
expect(editor.getText()).toBe " abc\nabcdefg\n"
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
describe "with a count", ->
beforeEach ->
editor.setText("1\n2\n3\n4\n5\n6\n")
editor.setCursorScreenPosition([1, 0])
describe "as a motion", ->
beforeEach ->
keydown('3')
keydown('_')
it "moves the cursor to the first character of that many lines following", ->
expect(editor.getCursorScreenPosition()).toEqual [3, 0]
describe "as a selection", ->
beforeEach ->
keydown('d')
keydown('3')
keydown('_')
it "deletes the current line plus that many following lines", ->
expect(editor.getText()).toBe "1\n5\n6\n"
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
describe "the enter keybinding", ->
keydownCodeForEnter = '\r' # 'enter' does not work
startingText = " abc\n abc\nabcdefg\n"
describe "from the middle of a line", ->
startingCursorPosition = [1, 3]
describe "as a motion", ->
it "acts the same as the + keybinding", ->
# do it with + and save the results
editor.setText(startingText)
editor.setCursorScreenPosition(startingCursorPosition)
keydown('+')
referenceCursorPosition = editor.getCursorScreenPosition()
# do it again with enter and compare the results
editor.setText(startingText)
editor.setCursorScreenPosition(startingCursorPosition)
keydown(keydownCodeForEnter)
expect(editor.getCursorScreenPosition()).toEqual referenceCursorPosition
describe "as a selection", ->
it "acts the same as the + keybinding", ->
# do it with + and save the results
editor.setText(startingText)
editor.setCursorScreenPosition(startingCursorPosition)
keydown('d')
keydown('+')
referenceText = editor.getText()
referenceCursorPosition = editor.getCursorScreenPosition()
# do it again with enter and compare the results
editor.setText(startingText)
editor.setCursorScreenPosition(startingCursorPosition)
keydown('d')
keydown(keydownCodeForEnter)
expect(editor.getText()).toEqual referenceText
expect(editor.getCursorScreenPosition()).toEqual referenceCursorPosition
describe "the gg keybinding", ->
beforeEach ->
editor.setText(" 1abc\n 2\n3\n")
editor.setCursorScreenPosition([0, 2])
describe "as a motion", ->
describe "in normal mode", ->
beforeEach ->
keydown('g')
keydown('g')
it "moves the cursor to the beginning of the first line", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
describe "in linewise visual mode", ->
beforeEach ->
editor.setCursorScreenPosition([1, 0])
vimState.activateVisualMode('linewise')
keydown('g')
keydown('g')
it "selects to the first line in the file", ->
expect(editor.getSelectedText()).toBe " 1abc\n 2\n"
it "moves the cursor to a specified line", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
describe "in characterwise visual mode", ->
beforeEach ->
editor.setCursorScreenPosition([1, 1])
vimState.activateVisualMode()
keydown('g')
keydown('g')
it "selects to the first line in the file", ->
expect(editor.getSelectedText()).toBe "1abc\n 2"
it "moves the cursor to a specified line", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 1]
describe "as a repeated motion", ->
describe "in normal mode", ->
beforeEach ->
keydown('2')
keydown('g')
keydown('g')
it "moves the cursor to a specified line", ->
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
describe "in linewise visual motion", ->
beforeEach ->
editor.setCursorScreenPosition([2, 0])
vimState.activateVisualMode('linewise')
keydown('2')
keydown('g')
keydown('g')
it "selects to a specified line", ->
expect(editor.getSelectedText()).toBe " 2\n3\n"
it "moves the cursor to a specified line", ->
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
describe "in characterwise visual motion", ->
beforeEach ->
editor.setCursorScreenPosition([2, 0])
vimState.activateVisualMode()
keydown('2')
keydown('g')
keydown('g')
it "selects to a first character of specified line", ->
expect(editor.getSelectedText()).toBe "2\n3"
it "moves the cursor to a specified line", ->
expect(editor.getCursorScreenPosition()).toEqual [1, 1]
describe "the g_ keybinding", ->
beforeEach ->
editor.setText("1 \n 2 \n 3abc\n ")
describe "as a motion", ->
it "moves the cursor to the last nonblank character", ->
editor.setCursorScreenPosition([1, 0])
keydown('g')
keydown('_')
expect(editor.getCursorScreenPosition()).toEqual [1, 4]
it "will move the cursor to the beginning of the line if necessary", ->
editor.setCursorScreenPosition([0, 2])
keydown('g')
keydown('_')
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
describe "as a repeated motion", ->
it "moves the cursor downward and outward", ->
editor.setCursorScreenPosition([0, 0])
keydown('2')
keydown('g')
keydown('_')
expect(editor.getCursorScreenPosition()).toEqual [1, 4]
describe "as a selection", ->
it "selects the current line excluding whitespace", ->
editor.setCursorScreenPosition([1, 2])
vimState.activateVisualMode()
keydown('2')
keydown('g')
keydown('_')
expect(editor.getSelectedText()).toEqual " 2 \n 3abc"
describe "the G keybinding", ->
beforeEach ->