-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
test_popupwin.vim
4183 lines (3593 loc) · 125 KB
/
test_popupwin.vim
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
" Tests for popup windows
source check.vim
CheckFeature popupwin
source screendump.vim
source term_util.vim
func Test_simple_popup()
CheckScreendump
let lines =<< trim END
call setline(1, range(1, 100))
hi PopupColor1 ctermbg=lightblue
hi PopupColor2 ctermbg=lightcyan
hi EndOfBuffer ctermbg=lightgrey
hi Comment ctermfg=red
call prop_type_add('comment', #{highlight: 'Comment'})
let winid = popup_create('hello there', #{line: 3, col: 11, minwidth: 20, highlight: 'PopupColor1'})
let winid2 = popup_create(['another one', 'another two', 'another three'], #{line: 3, col: 25, minwidth: 20})
call setwinvar(winid2, '&wincolor', 'PopupColor2')
END
call writefile(lines, 'XtestPopup', 'D')
let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
call VerifyScreenDump(buf, 'Test_popupwin_01', {})
" Add a tabpage
call term_sendkeys(buf, ":tabnew\<CR>")
call term_sendkeys(buf, ":let popupwin = popup_create(["
\ .. "#{text: 'other tab'},"
\ .. "#{text: 'a comment line', props: [#{"
\ .. "col: 3, length: 7, minwidth: 20, type: 'comment'"
\ .. "}]},"
\ .. "], #{line: 4, col: 9, minwidth: 20})\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_02', {})
" switch back to first tabpage
call term_sendkeys(buf, "gt")
call VerifyScreenDump(buf, 'Test_popupwin_03', {})
" close that tabpage
call term_sendkeys(buf, ":quit!\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_04', {})
" set 'columns' to a small value, size must be recomputed
call term_sendkeys(buf, ":let cols = &columns\<CR>")
call term_sendkeys(buf, ":set columns=12\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_04a', {})
call term_sendkeys(buf, ":let &columns = cols\<CR>")
" resize popup, show empty line at bottom
call term_sendkeys(buf, ":call popup_move(popupwin, #{minwidth: 15, maxwidth: 25, minheight: 3, maxheight: 5})\<CR>")
call term_sendkeys(buf, ":redraw\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_05', {})
" show not fitting line at bottom
call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>")
call term_sendkeys(buf, ":redraw\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_06', {})
" move popup over ruler
call term_sendkeys(buf, ":set cmdheight=2\<CR>")
call term_sendkeys(buf, ":call popup_move(popupwin, #{line: 7, col: 55})\<CR>")
call term_sendkeys(buf, ":\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_07', {})
" clear all popups after moving the cursor a bit, so that ruler is updated
call term_sendkeys(buf, "axxx\<Esc>")
call TermWait(buf)
call term_sendkeys(buf, "0")
call TermWait(buf)
call term_sendkeys(buf, ":call popup_clear()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_08', {})
" clean up
call StopVimInTerminal(buf)
endfunc
func Test_popup_with_border_and_padding()
CheckScreendump
for iter in range(0, 1)
let lines =<< trim END
call setline(1, range(1, 100))
call popup_create('hello border', #{line: 2, col: 3, border: []})
call popup_create('hello padding', #{line: 2, col: 23, padding: []})
call popup_create('hello both', #{line: 2, col: 43, border: [], padding: [], highlight: 'Normal'})
call popup_create('border TL', #{line: 6, col: 3, border: [1, 0, 0, 4]})
call popup_create('paddings', #{line: 6, col: 23, padding: range(1, 4)})
call popup_create('wrapped longer text', #{line: 8, col: 55, padding: [0, 3, 0, 3], border: [0, 1, 0, 1]})
call popup_create('right aligned text', #{line: 11, col: 56, wrap: 0, padding: [0, 3, 0, 3], border: [0, 1, 0, 1]})
call popup_create('X', #{line: 2, col: 73})
call popup_create('X', #{line: 3, col: 74})
call popup_create('X', #{line: 4, col: 75})
call popup_create('X', #{line: 5, col: 76})
END
call insert(lines, iter == 1 ? '' : 'set enc=latin1')
call writefile(lines, 'XtestPopupBorder', 'D')
let buf = RunVimInTerminal('-S XtestPopupBorder', #{rows: 15})
call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {})
call StopVimInTerminal(buf)
endfor
let lines =<< trim END
call setline(1, range(1, 100))
hi BlueColor ctermbg=lightblue
hi TopColor ctermbg=253
hi RightColor ctermbg=245
hi BottomColor ctermbg=240
hi LeftColor ctermbg=248
call popup_create('hello border', #{line: 2, col: 3, border: [], borderhighlight: ['BlueColor']})
call popup_create(['hello border', 'and more'], #{line: 2, col: 23, border: [], borderhighlight: ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']})
call popup_create(['hello border', 'lines only'], #{line: 2, col: 43, border: [], borderhighlight: ['BlueColor'], borderchars: ['x']})
call popup_create(['hello border', 'with corners'], #{line: 2, col: 60, border: [], borderhighlight: ['BlueColor'], borderchars: ['x', '#']})
let winid = popup_create(['hello border', 'with numbers'], #{line: 6, col: 3, border: [], borderhighlight: ['BlueColor'], borderchars: ['0', '1', '2', '3', '4', '5', '6', '7']})
call popup_create(['hello border', 'just blanks'], #{line: 7, col: 23, border: [], borderhighlight: ['BlueColor'], borderchars: [' ']})
func MultiByte()
call popup_create(['hello'], #{line: 8, col: 43, border: [], borderchars: ['─', '│', '─', '│', '┌', '┐', '┘', '└']})
endfunc
END
call writefile(lines, 'XtestPopupBorder', 'D')
let buf = RunVimInTerminal('-S XtestPopupBorder', #{rows: 12})
call VerifyScreenDump(buf, 'Test_popupwin_22', {})
" check that changing borderchars triggers a redraw
call term_sendkeys(buf, ":call popup_setoptions(winid, #{borderchars: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']})\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_23', {})
" check multi-byte border only with 'ambiwidth' single
if &ambiwidth == 'single'
call term_sendkeys(buf, ":call MultiByte()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_24', {})
endif
call StopVimInTerminal(buf)
let with_border_or_padding = #{
\ line: 2,
\ core_line: 3,
\ col: 3,
\ core_col: 4,
\ width: 14,
\ core_width: 12,
\ height: 3,
\ core_height: 1,
\ firstline: 1,
\ lastline: 1,
\ scrollbar: 0,
\ visible: 1}
let winid = popup_create('hello border', #{line: 2, col: 3, border: []})",
call assert_equal(with_border_or_padding, winid->popup_getpos())
let options = popup_getoptions(winid)
call assert_equal([], options.border)
call assert_false(has_key(options, "padding"))
let winid = popup_create('hello padding', #{line: 2, col: 3, padding: []})
let with_border_or_padding.width = 15
let with_border_or_padding.core_width = 13
call assert_equal(with_border_or_padding, popup_getpos(winid))
let options = popup_getoptions(winid)
call assert_false(has_key(options, "border"))
call assert_equal([], options.padding)
call popup_setoptions(winid, #{
\ padding: [1, 2, 3, 4],
\ border: [4, 0, 7, 8],
\ borderhighlight: ['Top', 'Right', 'Bottom', 'Left'],
\ borderchars: ['1', '^', '2', '>', '3', 'v', '4', '<'],
\ })
let options = popup_getoptions(winid)
call assert_equal([1, 0, 1, 1], options.border)
call assert_equal([1, 2, 3, 4], options.padding)
call assert_equal(['Top', 'Right', 'Bottom', 'Left'], options.borderhighlight)
call assert_equal(['1', '^', '2', '>', '3', 'v', '4', '<'], options.borderchars)
" Check that popup_setoptions() takes the output of popup_getoptions()
call popup_setoptions(winid, options)
call assert_equal(options, popup_getoptions(winid))
" Check that range() doesn't crash
call popup_setoptions(winid, #{
\ padding: range(1, 4),
\ border: range(5, 8),
\ borderhighlight: range(4),
\ borderchars: range(8),
\ })
let winid = popup_create('hello both', #{line: 3, col: 8, border: [], padding: []})
call assert_equal(#{
\ line: 3,
\ core_line: 5,
\ col: 8,
\ core_col: 10,
\ width: 14,
\ core_width: 10,
\ height: 5,
\ scrollbar: 0,
\ core_height: 1,
\ firstline: 1,
\ lastline: 1,
\ visible: 1}, popup_getpos(winid))
call popup_clear()
endfunc
func Test_popup_with_syntax_win_execute()
CheckScreendump
let lines =<< trim END
call setline(1, range(1, 100))
hi PopupColor ctermbg=lightblue
let winid = popup_create([
\ '#include <stdio.h>',
\ 'int main(void)',
\ '{',
\ ' printf(123);',
\ '}',
\], #{line: 3, col: 25, highlight: 'PopupColor'})
call win_execute(winid, 'set syntax=cpp')
END
call writefile(lines, 'XtestPopup', 'D')
let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
call VerifyScreenDump(buf, 'Test_popupwin_10', {})
" clean up
call StopVimInTerminal(buf)
endfunc
func Test_popup_with_syntax_setbufvar()
CheckScreendump
let lines =<< trim END
call setline(1, range(1, 100))
hi PopupColor ctermbg=lightgrey
let winid = popup_create([
\ '#include <stdio.h>',
\ 'int main(void)',
\ '{',
\ "\tprintf(567);",
\ '}',
\], #{line: 3, col: 21, highlight: 'PopupColor'})
call setbufvar(winbufnr(winid), '&syntax', 'cpp')
END
call writefile(lines, 'XtestPopup', 'D')
let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
call VerifyScreenDump(buf, 'Test_popupwin_11', {})
" clean up
call StopVimInTerminal(buf)
endfunc
func Test_popup_with_matches()
CheckScreendump
let lines =<< trim END
call setline(1, ['111 222 333', '444 555 666'])
let winid = popup_create([
\ '111 222 333',
\ '444 555 666',
\], #{line: 3, col: 10, border: []})
set hlsearch
hi VeryBlue ctermfg=blue guifg=blue
/666
call matchadd('ErrorMsg', '111')
call matchadd('VeryBlue', '444')
call win_execute(winid, "call matchadd('ErrorMsg', '111')")
call win_execute(winid, "call matchadd('VeryBlue', '555')")
END
call writefile(lines, 'XtestPopupMatches', 'D')
let buf = RunVimInTerminal('-S XtestPopupMatches', #{rows: 10})
call VerifyScreenDump(buf, 'Test_popupwin_matches', {})
" clean up
call StopVimInTerminal(buf)
endfunc
func Test_popup_all_corners()
CheckScreendump
let lines =<< trim END
call setline(1, repeat([repeat('-', 60)], 15))
set so=0
normal 2G3|r#
let winid1 = popup_create(['first', 'second'], #{
\ line: 'cursor+1',
\ col: 'cursor',
\ pos: 'topleft',
\ border: [],
\ padding: [],
\ })
normal 24|r@
let winid1 = popup_create(['First', 'SeconD'], #{
\ line: 'cursor+1',
\ col: 'cursor',
\ pos: 'topright',
\ border: [],
\ padding: [],
\ })
normal 9G27|r%
let winid1 = popup_create(['fiRSt', 'seCOnd'], #{
\ line: 'cursor-1',
\ col: 'cursor',
\ pos: 'botleft',
\ border: [],
\ padding: [],
\ })
normal 48|r&
let winid1 = popup_create(['FIrsT', 'SEcoND'], #{
\ line: 'cursor-1',
\ col: 'cursor',
\ pos: 'botright',
\ border: [],
\ padding: [],
\ })
normal 1G51|r*
let winid1 = popup_create(['one', 'two'], #{
\ line: 'cursor-1',
\ col: 'cursor',
\ pos: 'botleft',
\ border: [],
\ padding: [],
\ })
END
call writefile(lines, 'XtestPopupCorners', 'D')
let buf = RunVimInTerminal('-S XtestPopupCorners', #{rows: 12})
call VerifyScreenDump(buf, 'Test_popupwin_corners', {})
" clean up
call StopVimInTerminal(buf)
endfunc
func Test_popup_nospace()
CheckScreendump
let lines =<< trim END
call setline(1, repeat([repeat('-', 60)], 15))
set so=0
" cursor in a line in top half, using "botleft" with popup that
" does fit
normal 5G2|r@
let winid1 = popup_create(['one', 'two'], #{
\ line: 'cursor-1',
\ col: 'cursor',
\ pos: 'botleft',
\ border: [],
\ })
" cursor in a line in top half, using "botleft" with popup that
" doesn't fit: gets truncated
normal 5G9|r#
let winid1 = popup_create(['one', 'two', 'tee'], #{
\ line: 'cursor-1',
\ col: 'cursor',
\ pos: 'botleft',
\ posinvert: 0,
\ border: [],
\ })
" cursor in a line in top half, using "botleft" with popup that
" doesn't fit and 'posinvert' set: flips to below.
normal 5G16|r%
let winid1 = popup_create(['one', 'two', 'tee'], #{
\ line: 'cursor-1',
\ col: 'cursor',
\ pos: 'botleft',
\ border: [],
\ })
" cursor in a line in bottom half, using "botleft" with popup that
" doesn't fit: does not flip.
normal 8G23|r*
let winid1 = popup_create(['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'], #{
\ line: 'cursor-1',
\ col: 'cursor',
\ pos: 'botleft',
\ border: [],
\ })
" cursor in a line in bottom half, using "topleft" with popup that
" does fit
normal 8G30|r@
let winid1 = popup_create(['one', 'two'], #{
\ line: 'cursor+1',
\ col: 'cursor',
\ pos: 'topleft',
\ border: [],
\ })
" cursor in a line in top half, using "topleft" with popup that
" doesn't fit: truncated
normal 8G37|r#
let winid1 = popup_create(['one', 'two', 'tee'], #{
\ line: 'cursor+1',
\ col: 'cursor',
\ pos: 'topleft',
\ posinvert: 0,
\ border: [],
\ })
" cursor in a line in top half, using "topleft" with popup that
" doesn't fit and "posinvert" set: flips to above.
normal 8G44|r%
let winid1 = popup_create(['one', 'two', 'tee', 'fou', 'fiv'], #{
\ line: 'cursor+1',
\ col: 'cursor',
\ pos: 'topleft',
\ border: [],
\ })
" cursor in a line in top half, using "topleft" with popup that
" doesn't fit: does not flip.
normal 5G51|r*
let winid1 = popup_create(['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'], #{
\ line: 'cursor+1',
\ col: 'cursor',
\ pos: 'topleft',
\ border: [],
\ })
END
call writefile(lines, 'XtestPopupNospace', 'D')
let buf = RunVimInTerminal('-S XtestPopupNospace', #{rows: 12})
call VerifyScreenDump(buf, 'Test_popupwin_nospace', {})
" clean up
call StopVimInTerminal(buf)
endfunc
func Test_popup_firstline_dump()
CheckScreendump
let lines =<< trim END
call setline(1, range(1, 20))
let winid = popup_create(['1111', '222222', '33333', '44', '5', '666666', '77777', '888', '9999999999999999'], #{
\ maxheight: 4,
\ firstline: 3,
\ })
END
call writefile(lines, 'XtestPopupFirstline', 'D')
let buf = RunVimInTerminal('-S XtestPopupFirstline', #{rows: 10})
call VerifyScreenDump(buf, 'Test_popupwin_firstline_1', {})
call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: -1})\<CR>")
call term_sendkeys(buf, ":\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_firstline_2', {})
" clean up
call StopVimInTerminal(buf)
endfunc
func Test_popup_firstline()
let winid = popup_create(['1111', '222222', '33333', '44444'], #{
\ maxheight: 2,
\ firstline: 3,
\ })
call assert_equal(3, popup_getoptions(winid).firstline)
call popup_setoptions(winid, #{firstline: 1})
call assert_equal(1, popup_getoptions(winid).firstline)
eval winid->popup_close()
let winid = popup_create(['xxx']->repeat(50), #{
\ maxheight: 3,
\ firstline: 11,
\ })
redraw
call assert_equal(11, popup_getoptions(winid).firstline)
call assert_equal(11, popup_getpos(winid).firstline)
" check line() works with popup window
call assert_equal(11, line('.', winid))
call assert_equal(50, line('$', winid))
call assert_equal(0, line('$', 123456))
" Normal command changes what is displayed but not "firstline"
call win_execute(winid, "normal! \<c-y>")
call assert_equal(11, popup_getoptions(winid).firstline)
call assert_equal(10, popup_getpos(winid).firstline)
" Making some property change applies "firstline" again
call popup_setoptions(winid, #{line: 4})
call assert_equal(11, popup_getoptions(winid).firstline)
call assert_equal(11, popup_getpos(winid).firstline)
" Remove "firstline" property and scroll
call popup_setoptions(winid, #{firstline: 0})
call win_execute(winid, "normal! \<c-y>")
call assert_equal(0, popup_getoptions(winid).firstline)
call assert_equal(10, popup_getpos(winid).firstline)
" Making some property change has no side effect
call popup_setoptions(winid, #{line: 3})
call assert_equal(0, popup_getoptions(winid).firstline)
call assert_equal(10, popup_getpos(winid).firstline)
call popup_close(winid)
" CTRL-D scrolls down half a page
let winid = popup_create(['xxx']->repeat(50), #{
\ maxheight: 8,
\ })
redraw
call assert_equal(1, popup_getpos(winid).firstline)
call win_execute(winid, "normal! \<C-D>")
call assert_equal(5, popup_getpos(winid).firstline)
call win_execute(winid, "normal! \<C-D>")
call assert_equal(9, popup_getpos(winid).firstline)
call win_execute(winid, "normal! \<C-U>")
call assert_equal(5, popup_getpos(winid).firstline)
call win_execute(winid, "normal! \<C-F>")
call assert_equal(11, popup_getpos(winid).firstline)
call win_execute(winid, "normal! \<C-B>")
call assert_equal(5, popup_getpos(winid).firstline)
call popup_close(winid)
" Popup with less elements than the maximum height and negative firstline:
" check that the popup height is correctly computed.
let winid = popup_create(['xxx']->repeat(4), #{
\ firstline: -1,
\ maxheight: 6,
\ })
let pos = popup_getpos(winid)
call assert_equal(3, pos.width)
call assert_equal(4, pos.height)
call popup_close(winid)
endfunc
func Test_popup_firstline_cursorline()
let winid = popup_create(['1111', '222222', '33333', '44444'], #{
\ maxheight: 2,
\ firstline: 3,
\ cursorline: 1,
\ })
call assert_equal(3, popup_getoptions(winid).firstline)
call assert_equal(3, getwininfo(winid)[0].topline)
call assert_equal(3, getcurpos(winid)[1])
call popup_close(winid)
endfunc
func Test_popup_noscrolloff()
set scrolloff=5
let winid = popup_create(['xxx']->repeat(50), #{
\ maxheight: 5,
\ firstline: 11,
\ })
redraw
call assert_equal(11, popup_getoptions(winid).firstline)
call assert_equal(11, popup_getpos(winid).firstline)
call popup_setoptions(winid, #{firstline: 0})
call win_execute(winid, "normal! \<c-y>")
call assert_equal(0, popup_getoptions(winid).firstline)
call assert_equal(10, popup_getpos(winid).firstline)
call popup_close(winid)
endfunc
func Test_popup_drag()
CheckScreendump
" create a popup that covers the command line
let lines =<< trim END
call setline(1, range(1, 20))
split
vsplit
$wincmd w
vsplit
1wincmd w
let winid = popup_create(['1111', '222222', '33333'], #{
\ drag: 1,
\ resize: 1,
\ border: [],
\ line: &lines - 4,
\ })
func Dragit()
map <silent> <F3> :call test_setmouse(&lines - 4, &columns / 2)<CR>
map <silent> <F4> :call test_setmouse(&lines - 8, &columns / 2 - 20)<CR>
call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
endfunc
func Resize()
map <silent> <F5> :call test_setmouse(6, 21)<CR>
map <silent> <F6> :call test_setmouse(7, 25)<CR>
call feedkeys("\<F5>\<LeftMouse>\<F6>\<LeftDrag>\<LeftRelease>", "xt")
endfunc
func ClickAndDrag()
map <silent> <F3> :call test_setmouse(5, 2)<CR>
map <silent> <F4> :call test_setmouse(3, 14)<CR>
map <silent> <F5> :call test_setmouse(3, 18)<CR>
call feedkeys("\<F3>\<LeftMouse>\<LeftRelease>", "xt")
call feedkeys("\<F4>\<LeftMouse>\<F5>\<LeftDrag>\<LeftRelease>", "xt")
endfunc
func DragAllStart()
call popup_clear()
call popup_create('hello', #{line: 3, col: 5, dragall: 1})
endfunc
func DragAllDrag()
map <silent> <F3> :call test_setmouse(3, 5)<CR>
map <silent> <F4> :call test_setmouse(5, 36)<CR>
call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
endfunc
END
call writefile(lines, 'XtestPopupDrag', 'D')
let buf = RunVimInTerminal('-S XtestPopupDrag', #{rows: 10})
call VerifyScreenDump(buf, 'Test_popupwin_drag_01', {})
call term_sendkeys(buf, ":call Dragit()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_drag_02', {})
call term_sendkeys(buf, ":call Resize()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_drag_03', {})
" dragging works after click on a status line
call term_sendkeys(buf, ":call ClickAndDrag()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_drag_04', {})
" dragging without border
call term_sendkeys(buf, ":call DragAllStart()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_drag_05', {})
call term_sendkeys(buf, ":call DragAllDrag()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_drag_06', {})
" clean up
call StopVimInTerminal(buf)
endfunc
func Test_popup_drag_minwidth()
CheckScreendump
" create a popup that does not fit
let lines =<< trim END
call range(40)
\ ->map({_,i -> string(i)})
\ ->popup_create({
\ 'drag': 1,
\ 'wrap': 0,
\ 'border': [],
\ 'scrollbar': 1,
\ 'minwidth': 100,
\ 'filter': {w, k -> k ==# 'q' ? len([popup_close(w)]) : 0},
\ })
func DragitDown()
map <silent> <F3> :call test_setmouse(1, 10)<CR>
map <silent> <F4> :call test_setmouse(5, 40)<CR>
call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
endfunc
func DragitUp()
map <silent> <F3> :call test_setmouse(5, 40)<CR>
map <silent> <F4> :call test_setmouse(4, 40)<CR>
map <silent> <F5> :call test_setmouse(3, 40)<CR>
call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<F5>\<LeftDrag>\<LeftRelease>", "xt")
endfunc
END
call writefile(lines, 'XtestPopupDrag', 'D')
let buf = RunVimInTerminal('-S XtestPopupDrag', #{rows: 10})
call VerifyScreenDump(buf, 'Test_popupwin_drag_minwidth_1', {})
call term_sendkeys(buf, ":call DragitDown()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_drag_minwidth_2', {})
call term_sendkeys(buf, ":call DragitUp()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_drag_minwidth_3', {})
call term_sendkeys(buf, 'q')
" clean up
call StopVimInTerminal(buf)
endfunc
func Test_popup_drag_termwin()
CheckUnix
CheckScreendump
CheckFeature terminal
" create a popup that covers the terminal window
let lines =<< trim END
set foldmethod=marker
call setline(1, range(100))
for nr in range(7)
call setline(nr * 12 + 1, "fold {{{")
call setline(nr * 12 + 11, "end }}}")
endfor
%foldclose
set shell=/bin/sh noruler
unlet $PROMPT_COMMAND
let $PS1 = 'vim> '
terminal ++rows=4
$wincmd w
let winid = popup_create(['1111', '2222'], #{
\ drag: 1,
\ resize: 1,
\ border: [],
\ line: 3,
\ })
func DragitLeft()
call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
endfunc
func DragitDown()
call feedkeys("\<F4>\<LeftMouse>\<F5>\<LeftDrag>\<LeftRelease>", "xt")
endfunc
func DragitDownLeft()
call feedkeys("\<F5>\<LeftMouse>\<F6>\<LeftDrag>\<LeftRelease>", "xt")
endfunc
map <silent> <F3> :call test_setmouse(3, &columns / 2)<CR>
map <silent> <F4> :call test_setmouse(3, &columns / 2 - 20)<CR>
map <silent> <F5> :call test_setmouse(12, &columns / 2)<CR>
map <silent> <F6> :call test_setmouse(12, &columns / 2 - 20)<CR>
END
call writefile(lines, 'XtestPopupTerm', 'D')
let buf = RunVimInTerminal('-S XtestPopupTerm', #{rows: 16})
call VerifyScreenDump(buf, 'Test_popupwin_term_01', {})
call term_sendkeys(buf, ":call DragitLeft()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_term_02', {})
call term_sendkeys(buf, ":call DragitDown()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_term_03', {})
call term_sendkeys(buf, ":call DragitDownLeft()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_term_04', {})
" clean up
call StopVimInTerminal(buf)
endfunc
func Test_popup_close_with_mouse()
CheckScreendump
let lines =<< trim END
call setline(1, range(1, 20))
" With border, can click on X
let winid = popup_create('foobar', #{
\ close: 'button',
\ border: [],
\ line: 1,
\ col: 1,
\ })
func CloseMsg(id, result)
echomsg 'Popup closed with ' .. a:result
endfunc
let winid = popup_create('notification', #{
\ close: 'click',
\ line: 3,
\ col: 15,
\ callback: 'CloseMsg',
\ })
let winid = popup_create('no border here', #{
\ close: 'button',
\ line: 5,
\ col: 3,
\ })
let winid = popup_create('only padding', #{
\ close: 'button',
\ padding: [],
\ line: 5,
\ col: 23,
\ })
func CloseWithX()
call feedkeys("\<F3>\<LeftMouse>\<LeftRelease>", "xt")
endfunc
map <silent> <F3> :call test_setmouse(1, len('foobar') + 2)<CR>
func CloseWithClick()
call feedkeys("\<F4>\<LeftMouse>\<LeftRelease>", "xt")
endfunc
map <silent> <F4> :call test_setmouse(3, 17)<CR>
func CreateWithMenuFilter()
let winid = popup_create('barfoo', #{
\ close: 'button',
\ filter: 'popup_filter_menu',
\ border: [],
\ line: 1,
\ col: 40,
\ })
endfunc
END
call writefile(lines, 'XtestPopupClose', 'D')
let buf = RunVimInTerminal('-S XtestPopupClose', #{rows: 10})
call VerifyScreenDump(buf, 'Test_popupwin_close_01', {})
call term_sendkeys(buf, ":call CloseWithX()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_close_02', {})
call term_sendkeys(buf, ":call CloseWithClick()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_close_03', {})
call term_sendkeys(buf, ":call CreateWithMenuFilter()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_close_04', {})
" We have to send the actual mouse code, feedkeys() would be caught the
" filter.
call term_sendkeys(buf, "\<Esc>[<0;47;1M")
call VerifyScreenDump(buf, 'Test_popupwin_close_05', {})
" clean up
call StopVimInTerminal(buf)
endfunction
func Test_popup_menu_wrap()
CheckScreendump
let lines =<< trim END
call setline(1, range(1, 20))
call popup_create([
\ 'one',
\ 'asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfas',
\ 'three',
\ 'four',
\ ], #{
\ pos: "botleft",
\ border: [],
\ padding: [0,1,0,1],
\ maxheight: 3,
\ cursorline: 1,
\ filter: 'popup_filter_menu',
\ })
END
call writefile(lines, 'XtestPopupWrap', 'D')
let buf = RunVimInTerminal('-S XtestPopupWrap', #{rows: 10})
call VerifyScreenDump(buf, 'Test_popupwin_wrap_1', {})
call term_sendkeys(buf, "jj")
call VerifyScreenDump(buf, 'Test_popupwin_wrap_2', {})
" clean up
call term_sendkeys(buf, "\<Esc>")
call StopVimInTerminal(buf)
endfunction
func Test_popup_with_mask()
CheckScreendump
let lines =<< trim END
call setline(1, repeat([join(range(1, 42), '')], 13))
hi PopupColor ctermbg=lightgrey
let winid = popup_create([
\ 'some text',
\ 'another line',
\], #{
\ line: 1,
\ col: 10,
\ posinvert: 0,
\ wrap: 0,
\ fixed: 1,
\ scrollbar: v:false,
\ zindex: 90,
\ padding: [],
\ highlight: 'PopupColor',
\ mask: [[1,1,1,1], [-5,-1,4,4], [7,9,2,3], [2,4,3,3]]})
call popup_create([
\ 'xxxxxxxxx',
\ 'yyyyyyyyy',
\], #{
\ line: 3,
\ col: 18,
\ zindex: 20})
let winidb = popup_create([
\ 'just one line',
\], #{
\ line: 7,
\ col: 10,
\ posinvert: 0,
\ wrap: 0,
\ fixed: 1,
\ scrollbar: v:false,
\ close: 'button',
\ zindex: 90,
\ padding: [],
\ border: [],
\ mask: [[1,2,1,1], [-5,-1,4,4], [7,9,2,3], [3,5,5,5],[-7,-4,5,5]]})
END
call writefile(lines, 'XtestPopupMask', 'D')
let buf = RunVimInTerminal('-S XtestPopupMask', #{rows: 13})
call VerifyScreenDump(buf, 'Test_popupwin_mask_1', {})
call term_sendkeys(buf, ":call popup_move(winid, #{col: 11, line: 2})\<CR>")
call term_sendkeys(buf, ":call popup_move(winidb, #{col: 12})\<CR>")
call term_sendkeys(buf, ":\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_mask_2', {})
call term_sendkeys(buf, ":call popup_move(winid, #{col: 65, line: 2})\<CR>")
call term_sendkeys(buf, ":call popup_move(winidb, #{col: 63})\<CR>")
call term_sendkeys(buf, ":\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_mask_3', {})
call term_sendkeys(buf, ":call popup_move(winid, #{pos: 'topright', col: 12, line: 2})\<CR>")
call term_sendkeys(buf, ":call popup_move(winidb, #{pos: 'topright', col: 12})\<CR>")
call term_sendkeys(buf, ":\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_mask_4', {})
call term_sendkeys(buf, ":call popup_move(winid, #{pos: 'topright', col: 12, line: 11})\<CR>")
call term_sendkeys(buf, ":call popup_move(winidb, #{pos: 'topleft', col: 42, line: 11})\<CR>")
call term_sendkeys(buf, ":\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_mask_5', {})
" clean up
call StopVimInTerminal(buf)
" this was causing a crash
call popup_create('test', #{mask: [[0, 0, 0, 0]]})
call popup_clear()
" this was causing an internal error
enew
set nowrap
call repeat('x', &columns)->setline(1)
call prop_type_add('textprop', {})
call prop_add(1, 1, #{length: &columns, type: 'textprop'})
vsplit
let opts = popup_create('', #{textprop: 'textprop'})
\ ->popup_getoptions()
\ ->extend(#{mask: [[1, 1, 1, 1]]})
call popup_create('', opts)
redraw
close!
bwipe!
call prop_type_delete('textprop')
call popup_clear()
set wrap&
endfunc
func Test_popup_select()
CheckScreendump
CheckFeature clipboard_working
" create a popup with some text to be selected
let lines =<< trim END
set clipboard=autoselect
call setline(1, range(1, 20))
let winid = popup_create(['the word', 'some more', 'several words here', 'invisible', '5', '6', '7'], #{
\ drag: 1,
\ border: [],
\ line: 3,
\ col: 10,
\ maxheight: 3,
\ })
func Select1()
call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
endfunc
map <silent> <F3> :call test_setmouse(4, 15)<CR>
map <silent> <F4> :call test_setmouse(6, 23)<CR>
END
call writefile(lines, 'XtestPopupSelect', 'D')
let buf = RunVimInTerminal('-S XtestPopupSelect', #{rows: 10})
call term_sendkeys(buf, ":call Select1()\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_select_01', {})
call term_sendkeys(buf, ":call popup_close(winid)\<CR>")
call term_sendkeys(buf, "\"*p")
" clean the command line, sometimes it still shows a command
call term_sendkeys(buf, ":\<esc>")
call VerifyScreenDump(buf, 'Test_popupwin_select_02', {})
" clean up
call StopVimInTerminal(buf)
endfunc
func Test_popup_in_tab()
" default popup is local to tab, not visible when in other tab
let winid = popup_create("text", {})
let bufnr = winbufnr(winid)
call assert_equal(1, popup_getpos(winid).visible)
call assert_equal(0, popup_getoptions(winid).tabpage)
tabnew
call assert_equal(0, popup_getpos(winid).visible)
call assert_equal(1, popup_getoptions(winid).tabpage)
quit
call assert_equal(1, popup_getpos(winid).visible)
call assert_equal(1, bufexists(bufnr))
call popup_clear()
" buffer is gone now
call assert_equal(0, bufexists(bufnr))
" global popup is visible in any tab
let winid = popup_create("text", #{tabpage: -1})
call assert_equal(1, popup_getpos(winid).visible)
call assert_equal(-1, popup_getoptions(winid).tabpage)
tabnew
call assert_equal(1, popup_getpos(winid).visible)
call assert_equal(-1, popup_getoptions(winid).tabpage)
quit
call assert_equal(1, popup_getpos(winid).visible)
call popup_clear()
" create popup in other tab
tabnew
let winid = popup_create("text", #{tabpage: 1})
call assert_equal(0, popup_getpos(winid).visible)
call assert_equal(1, popup_getoptions(winid).tabpage)
quit
call assert_equal(1, popup_getpos(winid).visible)
call assert_equal(0, popup_getoptions(winid).tabpage)
call popup_clear()
endfunc
func Test_popup_valid_arguments()
call assert_equal(0, len(popup_list()))
" Zero value is like the property wasn't there
let winid = popup_create("text", #{col: 0})
let pos = popup_getpos(winid)
call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col)