blob: 3472b40b898185f0abe1e72ff8195f20bc53463f [file] [log] [blame]
Bram Moolenaar8e956362019-08-25 23:08:17 +02001" Tests for popup windows for text properties
2
3source check.vim
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004CheckFeature popupwin
Bram Moolenaar8e956362019-08-25 23:08:17 +02005CheckFeature textprop
6
7source screendump.vim
8CheckScreendump
9
10func Test_textprop_popup()
11 let lines =<< trim END
12 call setline(1, range(1, 100))
13 call setline(50, 'some text to work with')
14 50
15 normal zz
16 set scrolloff=0
Bram Moolenaara37cb552019-11-16 20:03:31 +010017 call prop_type_add('popupMarker', #{highlight: 'DiffAdd', bufnr: bufnr('%')})
Bram Moolenaar8e956362019-08-25 23:08:17 +020018 call prop_add(50, 11, #{
19 \ length: 7,
20 \ type: 'popupMarker',
Bram Moolenaara37cb552019-11-16 20:03:31 +010021 \ bufnr: bufnr('%'),
Bram Moolenaar8e956362019-08-25 23:08:17 +020022 \ })
23 let winid = popup_create('the text', #{
24 \ pos: 'botleft',
25 \ textprop: 'popupMarker',
26 \ border: [],
27 \ padding: [0,1,0,1],
28 \ close: 'click',
29 \ })
30 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +010031 call writefile(lines, 'XtestTextpropPopup', 'D')
Bram Moolenaar8e956362019-08-25 23:08:17 +020032 let buf = RunVimInTerminal('-S XtestTextpropPopup', #{rows: 10})
33 call VerifyScreenDump(buf, 'Test_popup_textprop_01', {})
34
35 call term_sendkeys(buf, "zt")
36 call VerifyScreenDump(buf, 'Test_popup_textprop_02', {})
37
38 call term_sendkeys(buf, "zzIawe\<Esc>")
39 call VerifyScreenDump(buf, 'Test_popup_textprop_03', {})
40
41 call term_sendkeys(buf, "0dw")
42 call VerifyScreenDump(buf, 'Test_popup_textprop_04', {})
43
44 call term_sendkeys(buf, "Oinserted\<Esc>")
45 call VerifyScreenDump(buf, 'Test_popup_textprop_05', {})
46
47 call term_sendkeys(buf, "k2dd")
48 call VerifyScreenDump(buf, 'Test_popup_textprop_06', {})
49
Bram Moolenaar1fb08312019-08-29 20:02:11 +020050 call term_sendkeys(buf, "4\<C-E>")
51 call VerifyScreenDump(buf, 'Test_popup_textprop_07', {})
52
Bram Moolenaar8e956362019-08-25 23:08:17 +020053 " clean up
54 call StopVimInTerminal(buf)
Bram Moolenaar8e956362019-08-25 23:08:17 +020055endfunc
56
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +020057func Test_textprop_popup_corners()
58 let lines =<< trim END
59 call setline(1, range(1, 100))
60 call setline(50, 'now working with some longer text here')
61 50
62 normal zz
63 set scrolloff=0
64 call prop_type_add('popupMarker', #{highlight: 'DiffAdd'})
65 call prop_add(50, 23, #{
66 \ length: 6,
67 \ type: 'popupMarker',
68 \ })
69 let winid = popup_create('bottom left', #{
70 \ pos: 'botleft',
71 \ textprop: 'popupMarker',
Bram Moolenaara37cb552019-11-16 20:03:31 +010072 \ textpropwin: win_getid(),
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +020073 \ padding: [0,1,0,1],
74 \ })
75 let winid = popup_create('bottom right', #{
76 \ pos: 'botright',
77 \ textprop: 'popupMarker',
78 \ border: [],
79 \ padding: [0,1,0,1],
80 \ })
81 let winid = popup_create('top left', #{
82 \ pos: 'topleft',
83 \ textprop: 'popupMarker',
84 \ border: [],
85 \ padding: [0,1,0,1],
86 \ })
87 let winid = popup_create('top right', #{
88 \ pos: 'topright',
89 \ textprop: 'popupMarker',
90 \ padding: [0,1,0,1],
91 \ })
92 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +010093 call writefile(lines, 'XtestTextpropPopupCorners', 'D')
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +020094 let buf = RunVimInTerminal('-S XtestTextpropPopupCorners', #{rows: 12})
95 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_1', {})
96
97 call term_sendkeys(buf, "0dw")
98 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_2', {})
99
100 call term_sendkeys(buf, "46Goextra\<Esc>")
101 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_3', {})
102
103 call term_sendkeys(buf, "u")
Bram Moolenaar57441d62019-08-28 22:38:07 +0200104 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +0200105 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_4', {})
106
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200107 call term_sendkeys(buf, ":vsplit foo\<CR>")
108 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_5', {})
109
110 call term_sendkeys(buf, ":only!\<CR>")
111 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_6', {})
112
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +0200113 " clean up
114 call StopVimInTerminal(buf)
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +0200115endfunc
116
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200117func Test_textprop_popup_offsets()
118 let lines =<< trim END
119 call setline(1, range(1, 100))
120 call setline(50, 'now working with some longer text here')
121 50
122 normal zz
123 set scrolloff=0
124 call prop_type_add('popupMarker', #{highlight: 'DiffAdd'})
125 call prop_add(50, 23, #{
126 \ length: 6,
127 \ type: 'popupMarker',
128 \ })
129 let winid = popup_create('bottom left', #{
130 \ pos: 'botleft',
131 \ line: -1,
132 \ col: 2,
133 \ textprop: 'popupMarker',
134 \ padding: [0,1,0,1],
135 \ })
136 let winid = popup_create('bottom right', #{
137 \ pos: 'botright',
138 \ line: -1,
139 \ col: -2,
140 \ textprop: 'popupMarker',
141 \ border: [],
142 \ padding: [0,1,0,1],
143 \ })
144 let winid = popup_create('top left', #{
145 \ pos: 'topleft',
146 \ line: 1,
147 \ col: 2,
148 \ textprop: 'popupMarker',
149 \ border: [],
150 \ padding: [0,1,0,1],
151 \ })
152 let winid = popup_create('top right', #{
153 \ pos: 'topright',
154 \ line: 1,
155 \ col: -2,
156 \ textprop: 'popupMarker',
157 \ padding: [0,1,0,1],
158 \ })
159 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +0100160 call writefile(lines, 'XtestTextpropPopupOffset', 'D')
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200161 let buf = RunVimInTerminal('-S XtestTextpropPopupOffset', #{rows: 12})
162 call VerifyScreenDump(buf, 'Test_popup_textprop_off_1', {})
163
164 " test that removing the text property closes the popups
165 call term_sendkeys(buf, ":call prop_clear(50)\<CR>")
166 call VerifyScreenDump(buf, 'Test_popup_textprop_off_2', {})
167
168 " clean up
169 call StopVimInTerminal(buf)
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200170endfunc
171
Bram Moolenaar8e956362019-08-25 23:08:17 +0200172
173" vim: shiftwidth=2 sts=2