blob: cbfc7d2d7f3930b42ea639398a01bd318f2a075d [file] [log] [blame]
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001" Tests for popup windows
2
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02003source check.vim
4CheckFeature textprop
Bram Moolenaar4d784b22019-05-25 19:51:39 +02005
6source screendump.vim
7
8func Test_simple_popup()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02009 CheckScreendump
10
Bram Moolenaare7eb9272019-06-24 00:58:07 +020011 let lines =<< trim END
12 call setline(1, range(1, 100))
13 hi PopupColor1 ctermbg=lightblue
14 hi PopupColor2 ctermbg=lightcyan
15 hi Comment ctermfg=red
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020016 call prop_type_add('comment', #{highlight: 'Comment'})
17 let winid = popup_create('hello there', #{line: 3, col: 11, minwidth: 20, highlight: 'PopupColor1'})
18 let winid2 = popup_create(['another one', 'another two', 'another three'], #{line: 3, col: 25, minwidth: 20})
Bram Moolenaare7eb9272019-06-24 00:58:07 +020019 call setwinvar(winid2, '&wincolor', 'PopupColor2')
20 END
21 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020022 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaar4d784b22019-05-25 19:51:39 +020023 call VerifyScreenDump(buf, 'Test_popupwin_01', {})
24
Bram Moolenaarec583842019-05-26 14:11:23 +020025 " Add a tabpage
26 call term_sendkeys(buf, ":tabnew\<CR>")
Bram Moolenaar60cdb302019-05-27 21:54:10 +020027 call term_sendkeys(buf, ":let popupwin = popup_create(["
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020028 \ .. "#{text: 'other tab'},"
29 \ .. "#{text: 'a comment line', props: [#{"
Bram Moolenaard5abb4c2019-07-13 22:46:10 +020030 \ .. "col: 3, length: 7, minwidth: 20, type: 'comment'"
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020031 \ .. "}]},"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020032 \ .. "], #{line: 4, col: 9, minwidth: 20})\<CR>")
Bram Moolenaarec583842019-05-26 14:11:23 +020033 call VerifyScreenDump(buf, 'Test_popupwin_02', {})
34
35 " switch back to first tabpage
36 call term_sendkeys(buf, "gt")
37 call VerifyScreenDump(buf, 'Test_popupwin_03', {})
38
39 " close that tabpage
40 call term_sendkeys(buf, ":quit!\<CR>")
41 call VerifyScreenDump(buf, 'Test_popupwin_04', {})
42
Bram Moolenaar202d9822019-06-11 21:56:30 +020043 " set 'columns' to a small value, size must be recomputed
44 call term_sendkeys(buf, ":let cols = &columns\<CR>")
45 call term_sendkeys(buf, ":set columns=12\<CR>")
46 call VerifyScreenDump(buf, 'Test_popupwin_04a', {})
47 call term_sendkeys(buf, ":let &columns = cols\<CR>")
48
Bram Moolenaar17146962019-05-30 00:12:11 +020049 " resize popup, show empty line at bottom
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020050 call term_sendkeys(buf, ":call popup_move(popupwin, #{minwidth: 15, maxwidth: 25, minheight: 3, maxheight: 5})\<CR>")
Bram Moolenaar60cdb302019-05-27 21:54:10 +020051 call term_sendkeys(buf, ":redraw\<CR>")
52 call VerifyScreenDump(buf, 'Test_popupwin_05', {})
53
Bram Moolenaar17146962019-05-30 00:12:11 +020054 " show not fitting line at bottom
55 call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>")
56 call term_sendkeys(buf, ":redraw\<CR>")
57 call VerifyScreenDump(buf, 'Test_popupwin_06', {})
58
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020059 " move popup over ruler
60 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020061 call term_sendkeys(buf, ":call popup_move(popupwin, #{line: 7, col: 55})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +020062 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020063 call VerifyScreenDump(buf, 'Test_popupwin_07', {})
64
65 " clear all popups after moving the cursor a bit, so that ruler is updated
66 call term_sendkeys(buf, "axxx\<Esc>")
67 call term_wait(buf)
68 call term_sendkeys(buf, "0")
69 call term_wait(buf)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +020070 call term_sendkeys(buf, ":call popup_clear()\<CR>")
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020071 call VerifyScreenDump(buf, 'Test_popupwin_08', {})
72
Bram Moolenaar4d784b22019-05-25 19:51:39 +020073 " clean up
74 call StopVimInTerminal(buf)
75 call delete('XtestPopup')
76endfunc
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020077
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020078func Test_popup_with_border_and_padding()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +020079 CheckScreendump
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020080
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +020081 for iter in range(0, 1)
Bram Moolenaare7eb9272019-06-24 00:58:07 +020082 let lines =<< trim END
83 call setline(1, range(1, 100))
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020084 call popup_create('hello border', #{line: 2, col: 3, border: []})
85 call popup_create('hello padding', #{line: 2, col: 23, padding: []})
Bram Moolenaarc363fe12019-08-04 18:13:46 +020086 call popup_create('hello both', #{line: 2, col: 43, border: [], padding: [], highlight: 'Normal'})
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020087 call popup_create('border TL', #{line: 6, col: 3, border: [1, 0, 0, 4]})
88 call popup_create('paddings', #{line: 6, col: 23, padding: [1, 3, 2, 4]})
89 call popup_create('wrapped longer text', #{line: 8, col: 55, padding: [0, 3, 0, 3], border: [0, 1, 0, 1]})
90 call popup_create('right aligned text', #{line: 11, col: 56, wrap: 0, padding: [0, 3, 0, 3], border: [0, 1, 0, 1]})
Bram Moolenaare7eb9272019-06-24 00:58:07 +020091 END
92 call insert(lines, iter == 1 ? '' : 'set enc=latin1')
93 call writefile(lines, 'XtestPopupBorder')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020094 let buf = RunVimInTerminal('-S XtestPopupBorder', #{rows: 15})
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +020095 call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {})
96
97 call StopVimInTerminal(buf)
98 call delete('XtestPopupBorder')
99 endfor
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200100
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200101 let lines =<< trim END
102 call setline(1, range(1, 100))
103 hi BlueColor ctermbg=lightblue
104 hi TopColor ctermbg=253
105 hi RightColor ctermbg=245
106 hi BottomColor ctermbg=240
107 hi LeftColor ctermbg=248
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200108 call popup_create('hello border', #{line: 2, col: 3, border: [], borderhighlight: ['BlueColor']})
109 call popup_create(['hello border', 'and more'], #{line: 2, col: 23, border: [], borderhighlight: ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']})
110 call popup_create(['hello border', 'lines only'], #{line: 2, col: 43, border: [], borderhighlight: ['BlueColor'], borderchars: ['x']})
111 call popup_create(['hello border', 'with corners'], #{line: 2, col: 60, border: [], borderhighlight: ['BlueColor'], borderchars: ['x', '#']})
112 let winid = popup_create(['hello border', 'with numbers'], #{line: 6, col: 3, border: [], borderhighlight: ['BlueColor'], borderchars: ['0', '1', '2', '3', '4', '5', '6', '7']})
113 call popup_create(['hello border', 'just blanks'], #{line: 7, col: 23, border: [], borderhighlight: ['BlueColor'], borderchars: [' ']})
Bram Moolenaar3dabd712019-07-08 23:30:22 +0200114 func MultiByte()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200115 call popup_create(['hello'], #{line: 8, col: 43, border: [], borderchars: ['─', '│', '─', '│', '┌', '┐', '┘', '└']})
Bram Moolenaar3dabd712019-07-08 23:30:22 +0200116 endfunc
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200117 END
118 call writefile(lines, 'XtestPopupBorder')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200119 let buf = RunVimInTerminal('-S XtestPopupBorder', #{rows: 12})
Bram Moolenaar790498b2019-06-01 22:15:29 +0200120 call VerifyScreenDump(buf, 'Test_popupwin_22', {})
121
Bram Moolenaarad24a712019-06-17 20:05:45 +0200122 " check that changing borderchars triggers a redraw
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200123 call term_sendkeys(buf, ":call popup_setoptions(winid, #{borderchars: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']})\<CR>")
Bram Moolenaarad24a712019-06-17 20:05:45 +0200124 call VerifyScreenDump(buf, 'Test_popupwin_23', {})
125
Bram Moolenaar3dabd712019-07-08 23:30:22 +0200126 " check multi-byte border only with 'ambiwidth' single
127 if &ambiwidth == 'single'
128 call term_sendkeys(buf, ":call MultiByte()\<CR>")
129 call VerifyScreenDump(buf, 'Test_popupwin_24', {})
130 endif
131
Bram Moolenaar790498b2019-06-01 22:15:29 +0200132 call StopVimInTerminal(buf)
133 call delete('XtestPopupBorder')
134
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200135 let with_border_or_padding = #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200136 \ line: 2,
137 \ core_line: 3,
138 \ col: 3,
139 \ core_col: 4,
140 \ width: 14,
141 \ core_width: 12,
142 \ height: 3,
143 \ core_height: 1,
144 \ firstline: 1,
145 \ scrollbar: 0,
146 \ visible: 1}
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200147 let winid = popup_create('hello border', #{line: 2, col: 3, border: []})",
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200148 call assert_equal(with_border_or_padding, winid->popup_getpos())
Bram Moolenaarae943152019-06-16 22:54:14 +0200149 let options = popup_getoptions(winid)
150 call assert_equal([], options.border)
151 call assert_false(has_key(options, "padding"))
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200152
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200153 let winid = popup_create('hello padding', #{line: 2, col: 3, padding: []})
Bram Moolenaarae943152019-06-16 22:54:14 +0200154 let with_border_or_padding.width = 15
155 let with_border_or_padding.core_width = 13
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200156 call assert_equal(with_border_or_padding, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200157 let options = popup_getoptions(winid)
158 call assert_false(has_key(options, "border"))
159 call assert_equal([], options.padding)
160
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200161 call popup_setoptions(winid, #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200162 \ padding: [1, 2, 3, 4],
163 \ border: [4, 0, 7, 8],
164 \ borderhighlight: ['Top', 'Right', 'Bottom', 'Left'],
165 \ borderchars: ['1', '^', '2', '>', '3', 'v', '4', '<'],
Bram Moolenaarae943152019-06-16 22:54:14 +0200166 \ })
167 let options = popup_getoptions(winid)
168 call assert_equal([1, 0, 1, 1], options.border)
169 call assert_equal([1, 2, 3, 4], options.padding)
170 call assert_equal(['Top', 'Right', 'Bottom', 'Left'], options.borderhighlight)
171 call assert_equal(['1', '^', '2', '>', '3', 'v', '4', '<'], options.borderchars)
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200172
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200173 let winid = popup_create('hello both', #{line: 3, col: 8, border: [], padding: []})
174 call assert_equal(#{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200175 \ line: 3,
176 \ core_line: 5,
177 \ col: 8,
178 \ core_col: 10,
179 \ width: 14,
180 \ core_width: 10,
181 \ height: 5,
182 \ scrollbar: 0,
183 \ core_height: 1,
184 \ firstline: 1,
185 \ visible: 1}, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200186
187 call popup_clear()
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200188endfunc
189
Bram Moolenaarb4230122019-05-30 18:40:53 +0200190func Test_popup_with_syntax_win_execute()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200191 CheckScreendump
192
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200193 let lines =<< trim END
194 call setline(1, range(1, 100))
195 hi PopupColor ctermbg=lightblue
196 let winid = popup_create([
197 \ '#include <stdio.h>',
198 \ 'int main(void)',
199 \ '{',
200 \ ' printf(123);',
201 \ '}',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200202 \], #{line: 3, col: 25, highlight: 'PopupColor'})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200203 call win_execute(winid, 'set syntax=cpp')
204 END
205 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200206 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaarb4230122019-05-30 18:40:53 +0200207 call VerifyScreenDump(buf, 'Test_popupwin_10', {})
208
209 " clean up
210 call StopVimInTerminal(buf)
211 call delete('XtestPopup')
212endfunc
213
214func Test_popup_with_syntax_setbufvar()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200215 CheckScreendump
216
Bram Moolenaar402502d2019-05-30 22:07:36 +0200217 let lines =<< trim END
218 call setline(1, range(1, 100))
219 hi PopupColor ctermbg=lightgrey
220 let winid = popup_create([
221 \ '#include <stdio.h>',
222 \ 'int main(void)',
223 \ '{',
Bram Moolenaare089c3f2019-07-09 20:25:25 +0200224 \ "\tprintf(567);",
Bram Moolenaar402502d2019-05-30 22:07:36 +0200225 \ '}',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200226 \], #{line: 3, col: 21, highlight: 'PopupColor'})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200227 call setbufvar(winbufnr(winid), '&syntax', 'cpp')
228 END
229 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200230 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaarb4230122019-05-30 18:40:53 +0200231 call VerifyScreenDump(buf, 'Test_popupwin_11', {})
232
233 " clean up
234 call StopVimInTerminal(buf)
235 call delete('XtestPopup')
236endfunc
237
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200238func Test_popup_with_matches()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200239 CheckScreendump
240
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200241 let lines =<< trim END
242 call setline(1, ['111 222 333', '444 555 666'])
243 let winid = popup_create([
244 \ '111 222 333',
245 \ '444 555 666',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200246 \], #{line: 3, col: 10, border: []})
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200247 set hlsearch
248 /666
249 call matchadd('ErrorMsg', '111')
250 call matchadd('ErrorMsg', '444')
251 call win_execute(winid, "call matchadd('ErrorMsg', '111')")
252 call win_execute(winid, "call matchadd('ErrorMsg', '555')")
253 END
254 call writefile(lines, 'XtestPopupMatches')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200255 let buf = RunVimInTerminal('-S XtestPopupMatches', #{rows: 10})
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200256 call VerifyScreenDump(buf, 'Test_popupwin_matches', {})
257
258 " clean up
259 call StopVimInTerminal(buf)
260 call delete('XtestPopupMatches')
261endfunc
262
Bram Moolenaar399d8982019-06-02 15:34:29 +0200263func Test_popup_all_corners()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200264 CheckScreendump
265
Bram Moolenaar399d8982019-06-02 15:34:29 +0200266 let lines =<< trim END
267 call setline(1, repeat([repeat('-', 60)], 15))
268 set so=0
269 normal 2G3|r#
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200270 let winid1 = popup_create(['first', 'second'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200271 \ line: 'cursor+1',
272 \ col: 'cursor',
273 \ pos: 'topleft',
274 \ border: [],
275 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200276 \ })
277 normal 25|r@
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200278 let winid1 = popup_create(['First', 'SeconD'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200279 \ line: 'cursor+1',
280 \ col: 'cursor',
281 \ pos: 'topright',
282 \ border: [],
283 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200284 \ })
285 normal 9G29|r%
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200286 let winid1 = popup_create(['fiRSt', 'seCOnd'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200287 \ line: 'cursor-1',
288 \ col: 'cursor',
289 \ pos: 'botleft',
290 \ border: [],
291 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200292 \ })
293 normal 51|r&
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200294 let winid1 = popup_create(['FIrsT', 'SEcoND'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200295 \ line: 'cursor-1',
296 \ col: 'cursor',
297 \ pos: 'botright',
298 \ border: [],
299 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200300 \ })
301 END
302 call writefile(lines, 'XtestPopupCorners')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200303 let buf = RunVimInTerminal('-S XtestPopupCorners', #{rows: 12})
Bram Moolenaar399d8982019-06-02 15:34:29 +0200304 call VerifyScreenDump(buf, 'Test_popupwin_corners', {})
305
306 " clean up
307 call StopVimInTerminal(buf)
308 call delete('XtestPopupCorners')
309endfunc
310
Bram Moolenaar8d241042019-06-12 23:40:01 +0200311func Test_popup_firstline()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200312 CheckScreendump
313
Bram Moolenaar8d241042019-06-12 23:40:01 +0200314 let lines =<< trim END
315 call setline(1, range(1, 20))
Bram Moolenaar8c6173c2019-08-30 22:08:34 +0200316 let winid = popup_create(['1111', '222222', '33333', '44', '5', '666666', '77777', '888', '9999999999999999'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200317 \ maxheight: 4,
318 \ firstline: 3,
Bram Moolenaar8d241042019-06-12 23:40:01 +0200319 \ })
320 END
321 call writefile(lines, 'XtestPopupFirstline')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200322 let buf = RunVimInTerminal('-S XtestPopupFirstline', #{rows: 10})
Bram Moolenaar8c6173c2019-08-30 22:08:34 +0200323 call VerifyScreenDump(buf, 'Test_popupwin_firstline_1', {})
324
325 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: -1})\<CR>")
326 call term_sendkeys(buf, ":\<CR>")
327 call VerifyScreenDump(buf, 'Test_popupwin_firstline_2', {})
Bram Moolenaar8d241042019-06-12 23:40:01 +0200328
329 " clean up
330 call StopVimInTerminal(buf)
331 call delete('XtestPopupFirstline')
Bram Moolenaarae943152019-06-16 22:54:14 +0200332
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200333 let winid = popup_create(['1111', '222222', '33333', '44444'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200334 \ maxheight: 2,
335 \ firstline: 3,
Bram Moolenaarae943152019-06-16 22:54:14 +0200336 \ })
337 call assert_equal(3, popup_getoptions(winid).firstline)
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200338 call popup_setoptions(winid, #{firstline: 1})
Bram Moolenaarae943152019-06-16 22:54:14 +0200339 call assert_equal(1, popup_getoptions(winid).firstline)
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200340 eval winid->popup_close()
Bram Moolenaar9e67b6a2019-08-30 17:34:08 +0200341
342 let winid = popup_create(['xxx']->repeat(50), #{
343 \ maxheight: 3,
344 \ firstline: 11,
345 \ })
346 redraw
347 call assert_equal(11, popup_getoptions(winid).firstline)
348 call assert_equal(11, popup_getpos(winid).firstline)
Bram Moolenaar8e0a8e72019-09-02 22:56:24 +0200349 " check line() works with popup window
350 call assert_equal(11, line('.', winid))
351 call assert_equal(50, line('$', winid))
352 call assert_equal(0, line('$', 123456))
Bram Moolenaar9e67b6a2019-08-30 17:34:08 +0200353
354 " Normal command changes what is displayed but not "firstline"
355 call win_execute(winid, "normal! \<c-y>")
356 call assert_equal(11, popup_getoptions(winid).firstline)
357 call assert_equal(10, popup_getpos(winid).firstline)
358
359 " Making some property change applies "firstline" again
360 call popup_setoptions(winid, #{line: 4})
361 call assert_equal(11, popup_getoptions(winid).firstline)
362 call assert_equal(11, popup_getpos(winid).firstline)
363
364 " Remove "firstline" property and scroll
365 call popup_setoptions(winid, #{firstline: 0})
366 call win_execute(winid, "normal! \<c-y>")
367 call assert_equal(0, popup_getoptions(winid).firstline)
368 call assert_equal(10, popup_getpos(winid).firstline)
369
370 " Making some property change has no side effect
371 call popup_setoptions(winid, #{line: 3})
372 call assert_equal(0, popup_getoptions(winid).firstline)
373 call assert_equal(10, popup_getpos(winid).firstline)
Bram Moolenaarae943152019-06-16 22:54:14 +0200374
375 call popup_close(winid)
Bram Moolenaar8d241042019-06-12 23:40:01 +0200376endfunc
377
Bram Moolenaara112f2d2019-09-01 17:38:09 +0200378func Test_popup_noscrolloff()
379 set scrolloff=5
380 let winid = popup_create(['xxx']->repeat(50), #{
381 \ maxheight: 5,
382 \ firstline: 11,
383 \ })
384 redraw
385 call assert_equal(11, popup_getoptions(winid).firstline)
386 call assert_equal(11, popup_getpos(winid).firstline)
387
388 call popup_setoptions(winid, #{firstline: 0})
389 call win_execute(winid, "normal! \<c-y>")
390 call assert_equal(0, popup_getoptions(winid).firstline)
391 call assert_equal(10, popup_getpos(winid).firstline)
392
393 call popup_close(winid)
394endfunc
395
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200396func Test_popup_drag()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200397 CheckScreendump
398
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200399 " create a popup that covers the command line
400 let lines =<< trim END
401 call setline(1, range(1, 20))
Bram Moolenaar356375f2019-08-24 14:46:29 +0200402 split
403 vsplit
404 $wincmd w
405 vsplit
406 1wincmd w
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200407 let winid = popup_create(['1111', '222222', '33333'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200408 \ drag: 1,
Bram Moolenaar9bcb70c2019-08-01 21:11:05 +0200409 \ resize: 1,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200410 \ border: [],
411 \ line: &lines - 4,
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200412 \ })
413 func Dragit()
414 call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
415 endfunc
416 map <silent> <F3> :call test_setmouse(&lines - 4, &columns / 2)<CR>
Bram Moolenaar356375f2019-08-24 14:46:29 +0200417 map <silent> <F4> :call test_setmouse(&lines - 8, &columns / 2 - 20)<CR>
Bram Moolenaar9bcb70c2019-08-01 21:11:05 +0200418 func Resize()
419 call feedkeys("\<F5>\<LeftMouse>\<F6>\<LeftDrag>\<LeftRelease>", "xt")
420 endfunc
Bram Moolenaar356375f2019-08-24 14:46:29 +0200421 map <silent> <F5> :call test_setmouse(6, 21)<CR>
422 map <silent> <F6> :call test_setmouse(7, 25)<CR>
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200423 END
424 call writefile(lines, 'XtestPopupDrag')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200425 let buf = RunVimInTerminal('-S XtestPopupDrag', #{rows: 10})
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200426 call VerifyScreenDump(buf, 'Test_popupwin_drag_01', {})
427
428 call term_sendkeys(buf, ":call Dragit()\<CR>")
429 call VerifyScreenDump(buf, 'Test_popupwin_drag_02', {})
430
Bram Moolenaar9bcb70c2019-08-01 21:11:05 +0200431 call term_sendkeys(buf, ":call Resize()\<CR>")
432 call VerifyScreenDump(buf, 'Test_popupwin_drag_03', {})
433
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200434 " clean up
435 call StopVimInTerminal(buf)
436 call delete('XtestPopupDrag')
437endfunc
438
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200439func Test_popup_close_with_mouse()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200440 CheckScreendump
441
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200442 let lines =<< trim END
443 call setline(1, range(1, 20))
444 " With border, can click on X
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200445 let winid = popup_create('foobar', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200446 \ close: 'button',
447 \ border: [],
448 \ line: 1,
449 \ col: 1,
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200450 \ })
451 func CloseMsg(id, result)
452 echomsg 'Popup closed with ' .. a:result
453 endfunc
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200454 let winid = popup_create('notification', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200455 \ close: 'click',
456 \ line: 3,
457 \ col: 15,
458 \ callback: 'CloseMsg',
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200459 \ })
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200460 let winid = popup_create('no border here', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200461 \ close: 'button',
462 \ line: 5,
463 \ col: 3,
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200464 \ })
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200465 let winid = popup_create('only padding', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200466 \ close: 'button',
467 \ padding: [],
468 \ line: 5,
469 \ col: 23,
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200470 \ })
471 func CloseWithX()
472 call feedkeys("\<F3>\<LeftMouse>\<LeftRelease>", "xt")
473 endfunc
474 map <silent> <F3> :call test_setmouse(1, len('foobar') + 2)<CR>
475 func CloseWithClick()
476 call feedkeys("\<F4>\<LeftMouse>\<LeftRelease>", "xt")
477 endfunc
478 map <silent> <F4> :call test_setmouse(3, 17)<CR>
Bram Moolenaarf6396232019-08-24 19:36:00 +0200479 func CreateWithMenuFilter()
480 let winid = popup_create('barfoo', #{
481 \ close: 'button',
482 \ filter: 'popup_filter_menu',
483 \ border: [],
484 \ line: 1,
485 \ col: 40,
486 \ })
487 endfunc
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200488 END
489 call writefile(lines, 'XtestPopupClose')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200490 let buf = RunVimInTerminal('-S XtestPopupClose', #{rows: 10})
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200491 call VerifyScreenDump(buf, 'Test_popupwin_close_01', {})
492
493 call term_sendkeys(buf, ":call CloseWithX()\<CR>")
494 call VerifyScreenDump(buf, 'Test_popupwin_close_02', {})
495
496 call term_sendkeys(buf, ":call CloseWithClick()\<CR>")
497 call VerifyScreenDump(buf, 'Test_popupwin_close_03', {})
498
Bram Moolenaarf6396232019-08-24 19:36:00 +0200499 call term_sendkeys(buf, ":call CreateWithMenuFilter()\<CR>")
500 call VerifyScreenDump(buf, 'Test_popupwin_close_04', {})
501
502 " We have to send the actual mouse code, feedkeys() would be caught the
503 " filter.
504 call term_sendkeys(buf, "\<Esc>[<0;47;1M")
505 call VerifyScreenDump(buf, 'Test_popupwin_close_05', {})
506
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200507 " clean up
508 call StopVimInTerminal(buf)
509 call delete('XtestPopupClose')
510endfunction
511
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200512func Test_popup_with_mask()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200513 CheckScreendump
514
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200515 let lines =<< trim END
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200516 call setline(1, repeat([join(range(1, 42), '')], 13))
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200517 hi PopupColor ctermbg=lightgrey
518 let winid = popup_create([
519 \ 'some text',
520 \ 'another line',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200521 \], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200522 \ line: 1,
523 \ col: 10,
524 \ wrap: 0,
525 \ fixed: 1,
526 \ zindex: 90,
527 \ padding: [],
528 \ highlight: 'PopupColor',
529 \ mask: [[1,1,1,1], [-5,-1,4,4], [7,9,2,3], [2,4,3,3]]})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200530 call popup_create([
531 \ 'xxxxxxxxx',
532 \ 'yyyyyyyyy',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200533 \], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200534 \ line: 3,
535 \ col: 18,
536 \ zindex: 20})
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200537 let winidb = popup_create([
538 \ 'just one line',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200539 \], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200540 \ line: 7,
541 \ col: 10,
542 \ wrap: 0,
543 \ fixed: 1,
544 \ close: 'button',
545 \ zindex: 90,
546 \ padding: [],
547 \ border: [],
548 \ mask: [[1,2,1,1], [-5,-1,4,4], [7,9,2,3], [3,5,5,5],[-7,-4,5,5]]})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200549 END
550 call writefile(lines, 'XtestPopupMask')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200551 let buf = RunVimInTerminal('-S XtestPopupMask', #{rows: 13})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200552 call VerifyScreenDump(buf, 'Test_popupwin_mask_1', {})
553
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200554 call term_sendkeys(buf, ":call popup_move(winid, #{col: 11, line: 2})\<CR>")
555 call term_sendkeys(buf, ":call popup_move(winidb, #{col: 12})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200556 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200557 call VerifyScreenDump(buf, 'Test_popupwin_mask_2', {})
558
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200559 call term_sendkeys(buf, ":call popup_move(winid, #{col: 65, line: 2})\<CR>")
560 call term_sendkeys(buf, ":call popup_move(winidb, #{col: 63})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200561 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaard529ba52019-07-02 23:13:53 +0200562 call VerifyScreenDump(buf, 'Test_popupwin_mask_3', {})
563
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200564 call term_sendkeys(buf, ":call popup_move(winid, #{pos: 'topright', col: 12, line: 2})\<CR>")
565 call term_sendkeys(buf, ":call popup_move(winidb, #{pos: 'topright', col: 12})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200566 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaard529ba52019-07-02 23:13:53 +0200567 call VerifyScreenDump(buf, 'Test_popupwin_mask_4', {})
568
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200569 call term_sendkeys(buf, ":call popup_move(winid, #{pos: 'topright', col: 12, line: 11})\<CR>")
570 call term_sendkeys(buf, ":call popup_move(winidb, #{pos: 'topleft', col: 42, line: 11})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200571 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaarb4207472019-07-12 16:05:45 +0200572 call VerifyScreenDump(buf, 'Test_popupwin_mask_5', {})
573
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200574 " clean up
575 call StopVimInTerminal(buf)
576 call delete('XtestPopupMask')
577endfunc
578
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200579func Test_popup_select()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200580 CheckScreendump
581 CheckFeature clipboard_working
582
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200583 " create a popup with some text to be selected
584 let lines =<< trim END
Bram Moolenaar1755ec42019-06-15 13:13:54 +0200585 set clipboard=autoselect
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200586 call setline(1, range(1, 20))
Bram Moolenaar4dd751b2019-08-17 19:10:53 +0200587 let winid = popup_create(['the word', 'some more', 'several words here', 'invisible', '5', '6', '7'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200588 \ drag: 1,
589 \ border: [],
590 \ line: 3,
591 \ col: 10,
Bram Moolenaar4dd751b2019-08-17 19:10:53 +0200592 \ maxheight: 3,
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200593 \ })
594 func Select1()
595 call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
596 endfunc
597 map <silent> <F3> :call test_setmouse(4, 15)<CR>
598 map <silent> <F4> :call test_setmouse(6, 23)<CR>
599 END
600 call writefile(lines, 'XtestPopupSelect')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200601 let buf = RunVimInTerminal('-S XtestPopupSelect', #{rows: 10})
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200602 call term_sendkeys(buf, ":call Select1()\<CR>")
603 call VerifyScreenDump(buf, 'Test_popupwin_select_01', {})
604
605 call term_sendkeys(buf, ":call popup_close(winid)\<CR>")
606 call term_sendkeys(buf, "\"*p")
Bram Moolenaar8ccabf62019-07-12 18:12:51 +0200607 " clean the command line, sometimes it still shows a command
608 call term_sendkeys(buf, ":\<esc>")
609
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200610 call VerifyScreenDump(buf, 'Test_popupwin_select_02', {})
611
612 " clean up
613 call StopVimInTerminal(buf)
614 call delete('XtestPopupSelect')
615endfunc
616
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200617func Test_popup_in_tab()
618 " default popup is local to tab, not visible when in other tab
619 let winid = popup_create("text", {})
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200620 let bufnr = winbufnr(winid)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200621 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200622 call assert_equal(0, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200623 tabnew
624 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200625 call assert_equal(1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200626 quit
627 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200628
629 call assert_equal(1, bufexists(bufnr))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200630 call popup_clear()
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200631 " buffer is gone now
632 call assert_equal(0, bufexists(bufnr))
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200633
634 " global popup is visible in any tab
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200635 let winid = popup_create("text", #{tabpage: -1})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200636 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200637 call assert_equal(-1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200638 tabnew
639 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200640 call assert_equal(-1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200641 quit
642 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200643 call popup_clear()
Bram Moolenaara3fce622019-06-20 02:31:49 +0200644
645 " create popup in other tab
646 tabnew
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200647 let winid = popup_create("text", #{tabpage: 1})
Bram Moolenaara3fce622019-06-20 02:31:49 +0200648 call assert_equal(0, popup_getpos(winid).visible)
649 call assert_equal(1, popup_getoptions(winid).tabpage)
650 quit
651 call assert_equal(1, popup_getpos(winid).visible)
652 call assert_equal(0, popup_getoptions(winid).tabpage)
653 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200654endfunc
655
656func Test_popup_valid_arguments()
657 " Zero value is like the property wasn't there
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200658 let winid = popup_create("text", #{col: 0})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200659 let pos = popup_getpos(winid)
660 call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200661 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200662
663 " using cursor column has minimum value of 1
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200664 let winid = popup_create("text", #{col: 'cursor-100'})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200665 let pos = popup_getpos(winid)
666 call assert_equal(1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200667 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200668
669 " center
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200670 let winid = popup_create("text", #{pos: 'center'})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200671 let pos = popup_getpos(winid)
672 let around = (&columns - pos.width) / 2
673 call assert_inrange(around - 1, around + 1, pos.col)
674 let around = (&lines - pos.height) / 2
675 call assert_inrange(around - 1, around + 1, pos.line)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200676 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200677endfunc
678
679func Test_popup_invalid_arguments()
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +0200680 call assert_fails('call popup_create(666, {})', 'E86:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200681 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200682 call assert_fails('call popup_create("text", "none")', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200683 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200684
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200685 call assert_fails('call popup_create("text", #{col: "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200686 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200687 call assert_fails('call popup_create("text", #{col: "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200688 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200689 call assert_fails('call popup_create("text", #{col: "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200690 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200691 call assert_fails('call popup_create("text", #{col: "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200692 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200693
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200694 call assert_fails('call popup_create("text", #{line: "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200695 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200696 call assert_fails('call popup_create("text", #{line: "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200697 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200698 call assert_fails('call popup_create("text", #{line: "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200699 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200700 call assert_fails('call popup_create("text", #{line: "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200701 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200702
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200703 call assert_fails('call popup_create("text", #{pos: "there"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200704 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200705 call assert_fails('call popup_create("text", #{padding: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200706 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200707 call assert_fails('call popup_create("text", #{border: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200708 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200709 call assert_fails('call popup_create("text", #{borderhighlight: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200710 call popup_clear()
Bram Moolenaar403d0902019-07-17 21:37:32 +0200711 call assert_fails('call popup_create("text", #{borderhighlight: test_null_list()})', 'E714:')
712 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200713 call assert_fails('call popup_create("text", #{borderchars: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200714 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200715
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200716 call assert_fails('call popup_create([#{text: "text"}, 666], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200717 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200718 call assert_fails('call popup_create([#{text: "text", props: "none"}], {})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200719 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200720 call assert_fails('call popup_create([#{text: "text", props: ["none"]}], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200721 call popup_clear()
Bram Moolenaarcfdbc5a2019-07-17 21:27:52 +0200722 call assert_fails('call popup_create("text", #{mask: ["asdf"]})', 'E475:')
723 call popup_clear()
724 call assert_fails('call popup_create("text", #{mask: test_null_list()})', 'E475:')
Bram Moolenaar749fa0a2019-08-03 16:18:07 +0200725 call assert_fails('call popup_create("text", #{mapping: []})', 'E745:')
Bram Moolenaarcfdbc5a2019-07-17 21:27:52 +0200726 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200727endfunc
728
Bram Moolenaareea16992019-05-31 17:34:48 +0200729func Test_win_execute_closing_curwin()
730 split
731 let winid = popup_create('some text', {})
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200732 call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200733 call popup_clear()
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200734endfunc
735
736func Test_win_execute_not_allowed()
737 let winid = popup_create('some text', {})
738 call assert_fails('call win_execute(winid, "split")', 'E994:')
739 call assert_fails('call win_execute(winid, "vsplit")', 'E994:')
740 call assert_fails('call win_execute(winid, "close")', 'E994:')
741 call assert_fails('call win_execute(winid, "bdelete")', 'E994:')
Bram Moolenaar2d247842019-06-01 17:06:25 +0200742 call assert_fails('call win_execute(winid, "bwipe!")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200743 call assert_fails('call win_execute(winid, "tabnew")', 'E994:')
744 call assert_fails('call win_execute(winid, "tabnext")', 'E994:')
745 call assert_fails('call win_execute(winid, "next")', 'E994:')
746 call assert_fails('call win_execute(winid, "rewind")', 'E994:')
747 call assert_fails('call win_execute(winid, "buf")', 'E994:')
748 call assert_fails('call win_execute(winid, "edit")', 'E994:')
749 call assert_fails('call win_execute(winid, "enew")', 'E994:')
750 call assert_fails('call win_execute(winid, "wincmd x")', 'E994:')
751 call assert_fails('call win_execute(winid, "wincmd w")', 'E994:')
752 call assert_fails('call win_execute(winid, "wincmd t")', 'E994:')
753 call assert_fails('call win_execute(winid, "wincmd b")', 'E994:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200754 call popup_clear()
Bram Moolenaareea16992019-05-31 17:34:48 +0200755endfunc
756
Bram Moolenaar402502d2019-05-30 22:07:36 +0200757func Test_popup_with_wrap()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200758 CheckScreendump
759
Bram Moolenaar402502d2019-05-30 22:07:36 +0200760 let lines =<< trim END
761 call setline(1, range(1, 100))
762 let winid = popup_create(
763 \ 'a long line that wont fit',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200764 \ #{line: 3, col: 20, maxwidth: 10, wrap: 1})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200765 END
766 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200767 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200768 call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
769
770 " clean up
771 call StopVimInTerminal(buf)
772 call delete('XtestPopup')
773endfunc
774
775func Test_popup_without_wrap()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200776 CheckScreendump
777
Bram Moolenaar402502d2019-05-30 22:07:36 +0200778 let lines =<< trim END
779 call setline(1, range(1, 100))
780 let winid = popup_create(
781 \ 'a long line that wont fit',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200782 \ #{line: 3, col: 20, maxwidth: 10, wrap: 0})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200783 END
784 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200785 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200786 call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
787
788 " clean up
789 call StopVimInTerminal(buf)
790 call delete('XtestPopup')
791endfunc
792
Bram Moolenaar331bafd2019-07-20 17:46:05 +0200793func Test_popup_with_showbreak()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200794 CheckScreendump
795
Bram Moolenaar331bafd2019-07-20 17:46:05 +0200796 let lines =<< trim END
797 set showbreak=>>\
798 call setline(1, range(1, 20))
799 let winid = popup_dialog(
800 \ 'a long line here',
801 \ #{filter: 'popup_filter_yesno'})
802 END
803 call writefile(lines, 'XtestPopupShowbreak')
804 let buf = RunVimInTerminal('-S XtestPopupShowbreak', #{rows: 10})
805 call VerifyScreenDump(buf, 'Test_popupwin_showbreak', {})
806
807 " clean up
808 call term_sendkeys(buf, "y")
809 call StopVimInTerminal(buf)
810 call delete('XtestPopupShowbreak')
811endfunc
812
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200813func Test_popup_time()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200814 CheckFeature timers
815
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200816 topleft vnew
817 call setline(1, 'hello')
818
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200819 let winid = popup_create('world', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200820 \ line: 1,
821 \ col: 1,
822 \ minwidth: 20,
823 \ time: 500,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200824 \})
825 redraw
826 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
827 call assert_equal('world', line)
828
Bram Moolenaarb4f06282019-07-12 21:07:54 +0200829 call assert_equal(winid, popup_locate(1, 1))
830 call assert_equal(winid, popup_locate(1, 20))
831 call assert_equal(0, popup_locate(1, 21))
832 call assert_equal(0, popup_locate(2, 1))
833
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200834 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200835 redraw
Bram Moolenaar196b4662019-09-06 21:34:30 +0200836 let line = join(map(range(1, 5), '1->screenstring(v:val)'), '')
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200837 call assert_equal('hello', line)
838
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200839 call popup_create('on the command line', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200840 \ line: &lines,
841 \ col: 10,
842 \ minwidth: 20,
843 \ time: 500,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200844 \})
845 redraw
846 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
847 call assert_match('.*on the command line.*', line)
848
849 sleep 700m
850 redraw
851 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
852 call assert_notmatch('.*on the command line.*', line)
853
854 bwipe!
855endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200856
857func Test_popup_hide()
858 topleft vnew
859 call setline(1, 'hello')
860
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200861 let winid = popup_create('world', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200862 \ line: 1,
863 \ col: 1,
864 \ minwidth: 20,
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200865 \})
866 redraw
867 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
868 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200869 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200870 " buffer is still listed and active
871 call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200872
873 call popup_hide(winid)
874 redraw
875 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
876 call assert_equal('hello', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200877 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200878 " buffer is still listed but hidden
879 call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200880
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200881 eval winid->popup_show()
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200882 redraw
883 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
884 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200885 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200886
887
888 call popup_close(winid)
889 redraw
890 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
891 call assert_equal('hello', line)
892
893 " error is given for existing non-popup window
894 call assert_fails('call popup_hide(win_getid())', 'E993:')
895
896 " no error non-existing window
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200897 eval 1234234->popup_hide()
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200898 call popup_show(41234234)
899
900 bwipe!
901endfunc
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200902
903func Test_popup_move()
904 topleft vnew
905 call setline(1, 'hello')
906
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200907 let winid = popup_create('world', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200908 \ line: 1,
909 \ col: 1,
910 \ minwidth: 20,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200911 \})
912 redraw
913 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
914 call assert_equal('world ', line)
915
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200916 call popup_move(winid, #{line: 2, col: 2})
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200917 redraw
918 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
919 call assert_equal('hello ', line)
920 let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
921 call assert_equal('~world', line)
922
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200923 eval winid->popup_move(#{line: 1})
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200924 redraw
925 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
926 call assert_equal('hworld', line)
927
928 call popup_close(winid)
929
930 bwipe!
931endfunc
Bram Moolenaarbc133542019-05-29 20:26:46 +0200932
Bram Moolenaar402502d2019-05-30 22:07:36 +0200933func Test_popup_getpos()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200934 let winid = popup_create('hello', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200935 \ line: 2,
936 \ col: 3,
937 \ minwidth: 10,
938 \ minheight: 11,
Bram Moolenaarbc133542019-05-29 20:26:46 +0200939 \})
940 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200941 let res = popup_getpos(winid)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200942 call assert_equal(2, res.line)
943 call assert_equal(3, res.col)
944 call assert_equal(10, res.width)
945 call assert_equal(11, res.height)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200946 call assert_equal(1, res.visible)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200947
948 call popup_close(winid)
949endfunc
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200950
951func Test_popup_width_longest()
952 let tests = [
953 \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
954 \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
955 \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
956 \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
957 \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
958 \ ]
959
960 for test in tests
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200961 let winid = popup_create(test[0], #{line: 2, col: 3})
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200962 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200963 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200964 call assert_equal(test[1], position.width)
965 call popup_close(winid)
966 endfor
967endfunc
968
969func Test_popup_wraps()
970 let tests = [
971 \ ['nowrap', 6, 1],
972 \ ['a line that wraps once', 12, 2],
973 \ ['a line that wraps two times', 12, 3],
974 \ ]
975 for test in tests
976 let winid = popup_create(test[0],
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200977 \ #{line: 2, col: 3, maxwidth: 12})
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200978 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200979 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200980 call assert_equal(test[1], position.width)
981 call assert_equal(test[2], position.height)
982
983 call popup_close(winid)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200984 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200985 endfor
986endfunc
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200987
988func Test_popup_getoptions()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200989 let winid = popup_create('hello', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200990 \ line: 2,
991 \ col: 3,
992 \ minwidth: 10,
993 \ minheight: 11,
994 \ maxwidth: 20,
995 \ maxheight: 21,
996 \ zindex: 100,
997 \ time: 5000,
998 \ fixed: 1
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200999 \})
1000 redraw
1001 let res = popup_getoptions(winid)
1002 call assert_equal(2, res.line)
1003 call assert_equal(3, res.col)
1004 call assert_equal(10, res.minwidth)
1005 call assert_equal(11, res.minheight)
1006 call assert_equal(20, res.maxwidth)
1007 call assert_equal(21, res.maxheight)
1008 call assert_equal(100, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001009 call assert_equal(1, res.fixed)
Bram Moolenaarb8350ab2019-08-04 17:59:49 +02001010 call assert_equal(1, res.mapping)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001011 if has('timers')
1012 call assert_equal(5000, res.time)
1013 endif
1014 call popup_close(winid)
1015
1016 let winid = popup_create('hello', {})
1017 redraw
1018 let res = popup_getoptions(winid)
1019 call assert_equal(0, res.line)
1020 call assert_equal(0, res.col)
1021 call assert_equal(0, res.minwidth)
1022 call assert_equal(0, res.minheight)
1023 call assert_equal(0, res.maxwidth)
1024 call assert_equal(0, res.maxheight)
1025 call assert_equal(50, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001026 call assert_equal(0, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001027 if has('timers')
1028 call assert_equal(0, res.time)
1029 endif
1030 call popup_close(winid)
1031 call assert_equal({}, popup_getoptions(winid))
1032endfunc
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02001033
1034func Test_popup_option_values()
1035 new
1036 " window-local
1037 setlocal number
1038 setlocal nowrap
1039 " buffer-local
1040 setlocal omnifunc=Something
1041 " global/buffer-local
1042 setlocal path=/there
1043 " global/window-local
Bram Moolenaara112f2d2019-09-01 17:38:09 +02001044 setlocal statusline=2
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02001045
1046 let winid = popup_create('hello', {})
1047 call assert_equal(0, getwinvar(winid, '&number'))
1048 call assert_equal(1, getwinvar(winid, '&wrap'))
1049 call assert_equal('', getwinvar(winid, '&omnifunc'))
1050 call assert_equal(&g:path, getwinvar(winid, '&path'))
Bram Moolenaara112f2d2019-09-01 17:38:09 +02001051 call assert_equal(&g:statusline, getwinvar(winid, '&statusline'))
1052
1053 " 'scrolloff' is reset to zero
1054 call assert_equal(5, &scrolloff)
1055 call assert_equal(0, getwinvar(winid, '&scrolloff'))
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02001056
1057 call popup_close(winid)
1058 bwipe
1059endfunc
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001060
1061func Test_popup_atcursor()
1062 topleft vnew
1063 call setline(1, [
1064 \ 'xxxxxxxxxxxxxxxxx',
1065 \ 'xxxxxxxxxxxxxxxxx',
1066 \ 'xxxxxxxxxxxxxxxxx',
1067 \])
1068
1069 call cursor(2, 2)
1070 redraw
1071 let winid = popup_atcursor('vim', {})
1072 redraw
1073 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
1074 call assert_equal('xvimxxxxxxxxxxxxx', line)
1075 call popup_close(winid)
1076
1077 call cursor(3, 4)
1078 redraw
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001079 let winid = 'vim'->popup_atcursor({})
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001080 redraw
1081 let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
1082 call assert_equal('xxxvimxxxxxxxxxxx', line)
1083 call popup_close(winid)
1084
1085 call cursor(1, 1)
1086 redraw
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001087 let winid = popup_create('vim', #{
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001088 \ line: 'cursor+2',
1089 \ col: 'cursor+1',
1090 \})
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001091 redraw
1092 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '')
1093 call assert_equal('xvimxxxxxxxxxxxxx', line)
1094 call popup_close(winid)
1095
1096 call cursor(3, 3)
1097 redraw
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001098 let winid = popup_create('vim', #{
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001099 \ line: 'cursor-2',
1100 \ col: 'cursor-1',
1101 \})
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001102 redraw
1103 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
1104 call assert_equal('xvimxxxxxxxxxxxxx', line)
1105 call popup_close(winid)
1106
Bram Moolenaar402502d2019-05-30 22:07:36 +02001107 " just enough room above
1108 call cursor(3, 3)
1109 redraw
1110 let winid = popup_atcursor(['vim', 'is great'], {})
1111 redraw
1112 let pos = popup_getpos(winid)
1113 call assert_equal(1, pos.line)
1114 call popup_close(winid)
1115
1116 " not enough room above, popup goes below the cursor
1117 call cursor(3, 3)
1118 redraw
1119 let winid = popup_atcursor(['vim', 'is', 'great'], {})
1120 redraw
1121 let pos = popup_getpos(winid)
1122 call assert_equal(4, pos.line)
1123 call popup_close(winid)
1124
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +02001125 " cursor in first line, popup in line 2
1126 call cursor(1, 1)
1127 redraw
1128 let winid = popup_atcursor(['vim', 'is', 'great'], {})
1129 redraw
1130 let pos = popup_getpos(winid)
1131 call assert_equal(2, pos.line)
1132 call popup_close(winid)
1133
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001134 bwipe!
1135endfunc
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001136
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001137func Test_popup_beval()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001138 CheckScreendump
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001139
1140 let lines =<< trim END
1141 call setline(1, range(1, 20))
1142 call setline(5, 'here is some text to hover over')
1143 set balloonevalterm
1144 set balloonexpr=BalloonExpr()
1145 set balloondelay=100
1146 func BalloonExpr()
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001147 let s:winid = [v:beval_text]->popup_beval({})
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001148 return ''
1149 endfunc
1150 func Hover()
1151 call test_setmouse(5, 15)
1152 call feedkeys("\<MouseMove>\<Ignore>", "xt")
1153 sleep 100m
1154 endfunc
1155 func MoveOntoPopup()
1156 call test_setmouse(4, 17)
1157 call feedkeys("\<F4>\<MouseMove>\<Ignore>", "xt")
1158 endfunc
1159 func MoveAway()
1160 call test_setmouse(5, 13)
1161 call feedkeys("\<F5>\<MouseMove>\<Ignore>", "xt")
1162 endfunc
1163 END
1164 call writefile(lines, 'XtestPopupBeval')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001165 let buf = RunVimInTerminal('-S XtestPopupBeval', #{rows: 10})
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001166 call term_wait(buf, 100)
1167 call term_sendkeys(buf, 'j')
1168 call term_sendkeys(buf, ":call Hover()\<CR>")
1169 call VerifyScreenDump(buf, 'Test_popupwin_beval_1', {})
1170
1171 call term_sendkeys(buf, ":call MoveOntoPopup()\<CR>")
1172 call VerifyScreenDump(buf, 'Test_popupwin_beval_2', {})
1173
1174 call term_sendkeys(buf, ":call MoveAway()\<CR>")
1175 call VerifyScreenDump(buf, 'Test_popupwin_beval_3', {})
1176
1177 " clean up
1178 call StopVimInTerminal(buf)
1179 call delete('XtestPopupBeval')
1180endfunc
1181
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001182func Test_popup_filter()
1183 new
1184 call setline(1, 'some text')
1185
1186 func MyPopupFilter(winid, c)
1187 if a:c == 'e'
1188 let g:eaten = 'e'
1189 return 1
1190 endif
1191 if a:c == '0'
1192 let g:ignored = '0'
1193 return 0
1194 endif
1195 if a:c == 'x'
1196 call popup_close(a:winid)
1197 return 1
1198 endif
1199 return 0
1200 endfunc
1201
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001202 let winid = 'something'->popup_create(#{filter: 'MyPopupFilter'})
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001203 redraw
1204
1205 " e is consumed by the filter
1206 call feedkeys('e', 'xt')
1207 call assert_equal('e', g:eaten)
1208
1209 " 0 is ignored by the filter
1210 normal $
1211 call assert_equal(9, getcurpos()[2])
1212 call feedkeys('0', 'xt')
1213 call assert_equal('0', g:ignored)
1214 call assert_equal(1, getcurpos()[2])
1215
1216 " x closes the popup
1217 call feedkeys('x', 'xt')
1218 call assert_equal('e', g:eaten)
1219 call assert_equal(-1, winbufnr(winid))
1220
1221 delfunc MyPopupFilter
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001222 call popup_clear()
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001223endfunc
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001224
Bram Moolenaara42d9452019-06-15 21:46:30 +02001225func ShowDialog(key, result)
1226 let s:cb_res = 999
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001227 let winid = popup_dialog('do you want to quit (Yes/no)?', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001228 \ filter: 'popup_filter_yesno',
1229 \ callback: 'QuitCallback',
Bram Moolenaara42d9452019-06-15 21:46:30 +02001230 \ })
1231 redraw
1232 call feedkeys(a:key, "xt")
1233 call assert_equal(winid, s:cb_winid)
1234 call assert_equal(a:result, s:cb_res)
1235endfunc
1236
1237func Test_popup_dialog()
1238 func QuitCallback(id, res)
1239 let s:cb_winid = a:id
1240 let s:cb_res = a:res
1241 endfunc
1242
1243 let winid = ShowDialog("y", 1)
1244 let winid = ShowDialog("Y", 1)
1245 let winid = ShowDialog("n", 0)
1246 let winid = ShowDialog("N", 0)
1247 let winid = ShowDialog("x", 0)
1248 let winid = ShowDialog("X", 0)
1249 let winid = ShowDialog("\<Esc>", 0)
1250 let winid = ShowDialog("\<C-C>", -1)
1251
1252 delfunc QuitCallback
1253endfunc
1254
Bram Moolenaara730e552019-06-16 19:05:31 +02001255func ShowMenu(key, result)
1256 let s:cb_res = 999
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001257 let winid = popup_menu(['one', 'two', 'something else'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001258 \ callback: 'QuitCallback',
Bram Moolenaara730e552019-06-16 19:05:31 +02001259 \ })
1260 redraw
1261 call feedkeys(a:key, "xt")
1262 call assert_equal(winid, s:cb_winid)
1263 call assert_equal(a:result, s:cb_res)
1264endfunc
1265
1266func Test_popup_menu()
1267 func QuitCallback(id, res)
1268 let s:cb_winid = a:id
1269 let s:cb_res = a:res
1270 endfunc
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02001271 " mapping won't be used in popup
1272 map j k
Bram Moolenaara730e552019-06-16 19:05:31 +02001273
1274 let winid = ShowMenu(" ", 1)
1275 let winid = ShowMenu("j \<CR>", 2)
1276 let winid = ShowMenu("JjK \<CR>", 2)
1277 let winid = ShowMenu("jjjjjj ", 3)
1278 let winid = ShowMenu("kkk ", 1)
1279 let winid = ShowMenu("x", -1)
1280 let winid = ShowMenu("X", -1)
1281 let winid = ShowMenu("\<Esc>", -1)
1282 let winid = ShowMenu("\<C-C>", -1)
1283
1284 delfunc QuitCallback
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02001285 unmap j
Bram Moolenaara730e552019-06-16 19:05:31 +02001286endfunc
1287
1288func Test_popup_menu_screenshot()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001289 CheckScreendump
Bram Moolenaara730e552019-06-16 19:05:31 +02001290
1291 let lines =<< trim END
1292 call setline(1, range(1, 20))
1293 hi PopupSelected ctermbg=lightblue
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001294 call popup_menu(['one', 'two', 'another'], #{callback: 'MenuDone', title: ' make a choice from the list '})
Bram Moolenaara730e552019-06-16 19:05:31 +02001295 func MenuDone(id, res)
1296 echomsg "selected " .. a:res
1297 endfunc
1298 END
1299 call writefile(lines, 'XtestPopupMenu')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001300 let buf = RunVimInTerminal('-S XtestPopupMenu', #{rows: 10})
Bram Moolenaara730e552019-06-16 19:05:31 +02001301 call VerifyScreenDump(buf, 'Test_popupwin_menu_01', {})
1302
1303 call term_sendkeys(buf, "jj")
1304 call VerifyScreenDump(buf, 'Test_popupwin_menu_02', {})
1305
1306 call term_sendkeys(buf, " ")
1307 call VerifyScreenDump(buf, 'Test_popupwin_menu_03', {})
1308
1309 " clean up
1310 call StopVimInTerminal(buf)
1311 call delete('XtestPopupMenu')
1312endfunc
1313
Bram Moolenaarf914a332019-07-20 15:09:56 +02001314func Test_popup_menu_narrow()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001315 CheckScreendump
Bram Moolenaarf914a332019-07-20 15:09:56 +02001316
1317 let lines =<< trim END
1318 call setline(1, range(1, 20))
1319 hi PopupSelected ctermbg=green
1320 call popup_menu(['one', 'two', 'three'], #{callback: 'MenuDone'})
1321 func MenuDone(id, res)
1322 echomsg "selected " .. a:res
1323 endfunc
1324 END
1325 call writefile(lines, 'XtestPopupNarrowMenu')
1326 let buf = RunVimInTerminal('-S XtestPopupNarrowMenu', #{rows: 10})
1327 call VerifyScreenDump(buf, 'Test_popupwin_menu_04', {})
1328
1329 " clean up
1330 call term_sendkeys(buf, "x")
1331 call StopVimInTerminal(buf)
1332 call delete('XtestPopupNarrowMenu')
1333endfunc
1334
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001335func Test_popup_title()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001336 CheckScreendump
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001337
1338 " Create a popup without title or border, a line of padding will be added to
1339 " put the title on.
1340 let lines =<< trim END
1341 call setline(1, range(1, 20))
Bram Moolenaar5d458a72019-08-04 21:12:15 +02001342 let winid = popup_create(['one', 'two', 'another'], #{title: 'Title String'})
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001343 END
1344 call writefile(lines, 'XtestPopupTitle')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001345 let buf = RunVimInTerminal('-S XtestPopupTitle', #{rows: 10})
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001346 call VerifyScreenDump(buf, 'Test_popupwin_title', {})
1347
Bram Moolenaar5d458a72019-08-04 21:12:15 +02001348 call term_sendkeys(buf, ":call popup_setoptions(winid, #{maxwidth: 20, title: 'a very long title that is not going to fit'})\<CR>")
1349 call term_sendkeys(buf, ":\<CR>")
1350 call VerifyScreenDump(buf, 'Test_popupwin_longtitle_1', {})
1351
1352 call term_sendkeys(buf, ":call popup_setoptions(winid, #{border: []})\<CR>")
1353 call term_sendkeys(buf, ":\<CR>")
1354 call VerifyScreenDump(buf, 'Test_popupwin_longtitle_2', {})
1355
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001356 " clean up
1357 call StopVimInTerminal(buf)
1358 call delete('XtestPopupTitle')
Bram Moolenaarae943152019-06-16 22:54:14 +02001359
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001360 let winid = popup_create('something', #{title: 'Some Title'})
Bram Moolenaarae943152019-06-16 22:54:14 +02001361 call assert_equal('Some Title', popup_getoptions(winid).title)
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001362 call popup_setoptions(winid, #{title: 'Another Title'})
Bram Moolenaarae943152019-06-16 22:54:14 +02001363 call assert_equal('Another Title', popup_getoptions(winid).title)
1364
1365 call popup_clear()
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001366endfunc
1367
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001368func Test_popup_close_callback()
1369 func PopupDone(id, result)
1370 let g:result = a:result
1371 endfunc
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001372 let winid = popup_create('something', #{callback: 'PopupDone'})
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001373 redraw
1374 call popup_close(winid, 'done')
1375 call assert_equal('done', g:result)
1376endfunc
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001377
1378func Test_popup_empty()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001379 let winid = popup_create('', #{padding: [2,2,2,2]})
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001380 redraw
1381 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001382 call assert_equal(5, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001383 call assert_equal(5, pos.height)
1384
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001385 let winid = popup_create([], #{border: []})
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001386 redraw
1387 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001388 call assert_equal(3, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001389 call assert_equal(3, pos.height)
1390endfunc
Bram Moolenaar988c4332019-06-02 14:12:11 +02001391
1392func Test_popup_never_behind()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001393 CheckScreendump
1394
Bram Moolenaar988c4332019-06-02 14:12:11 +02001395 " +-----------------------------+
1396 " | | |
1397 " | | |
1398 " | | |
1399 " | line1 |
1400 " |------------line2------------|
1401 " | line3 |
1402 " | line4 |
1403 " | |
1404 " | |
1405 " +-----------------------------+
1406 let lines =<< trim END
Bram Moolenaar988c4332019-06-02 14:12:11 +02001407 split
1408 vsplit
1409 let info_window1 = getwininfo()[0]
1410 let line = info_window1['height']
1411 let col = info_window1['width']
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001412 call popup_create(['line1', 'line2', 'line3', 'line4'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001413 \ line : line,
1414 \ col : col,
Bram Moolenaar988c4332019-06-02 14:12:11 +02001415 \ })
1416 END
1417 call writefile(lines, 'XtestPopupBehind')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001418 let buf = RunVimInTerminal('-S XtestPopupBehind', #{rows: 10})
Bram Moolenaar988c4332019-06-02 14:12:11 +02001419 call term_sendkeys(buf, "\<C-W>w")
1420 call VerifyScreenDump(buf, 'Test_popupwin_behind', {})
1421
1422 " clean up
1423 call StopVimInTerminal(buf)
1424 call delete('XtestPopupBehind')
1425endfunc
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001426
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001427func s:VerifyPosition(p, msg, line, col, width, height)
1428 call assert_equal(a:line, popup_getpos(a:p).line, a:msg . ' (l)')
1429 call assert_equal(a:col, popup_getpos(a:p).col, a:msg . ' (c)')
1430 call assert_equal(a:width, popup_getpos(a:p).width, a:msg . ' (w)')
1431 call assert_equal(a:height, popup_getpos(a:p).height, a:msg . ' (h)')
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001432endfunc
1433
1434func Test_popup_position_adjust()
1435 " Anything placed past 2 cells from of the right of the screen is moved to the
1436 " left.
1437 "
1438 " When wrapping is disabled, we also shift to the left to display on the
1439 " screen, unless fixed is set.
1440
1441 " Entries for cases which don't vary based on wrapping.
1442 " Format is per tests described below
1443 let both_wrap_tests = [
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001444 \ ['a', 5, &columns, 5, &columns - 2, 1, 1],
1445 \ ['b', 5, &columns + 1, 5, &columns - 2, 1, 1],
1446 \ ['c', 5, &columns - 1, 5, &columns - 2, 1, 1],
1447 \ ['d', 5, &columns - 2, 5, &columns - 2, 1, 1],
1448 \ ['e', 5, &columns - 3, 5, &columns - 3, 1, 1],
1449 \
1450 \ ['aa', 5, &columns, 5, &columns - 2, 2, 1],
1451 \ ['bb', 5, &columns + 1, 5, &columns - 2, 2, 1],
1452 \ ['cc', 5, &columns - 1, 5, &columns - 2, 2, 1],
1453 \ ['dd', 5, &columns - 2, 5, &columns - 2, 2, 1],
1454 \ ['ee', 5, &columns - 3, 5, &columns - 3, 2, 1],
1455 \
1456 \ ['aaa', 5, &columns, 5, &columns - 2, 3, 1],
1457 \ ['bbb', 5, &columns + 1, 5, &columns - 2, 3, 1],
1458 \ ['ccc', 5, &columns - 1, 5, &columns - 2, 3, 1],
1459 \ ['ddd', 5, &columns - 2, 5, &columns - 2, 3, 1],
1460 \ ['eee', 5, &columns - 3, 5, &columns - 3, 3, 1],
1461 \ ]
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001462
1463 " these test groups are dicts with:
1464 " - comment: something to identify the group of tests by
1465 " - options: dict of options to merge with the row/col in tests
1466 " - tests: list of cases. Each one is a list with elements:
1467 " - text
1468 " - row
1469 " - col
1470 " - expected row
1471 " - expected col
1472 " - expected width
1473 " - expected height
1474 let tests = [
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001475 \ #{
1476 \ comment: 'left-aligned with wrapping',
1477 \ options: #{
1478 \ wrap: 1,
1479 \ pos: 'botleft',
1480 \ },
1481 \ tests: both_wrap_tests + [
1482 \ ['aaaa', 5, &columns, 4, &columns - 2, 3, 2],
1483 \ ['bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2],
1484 \ ['cccc', 5, &columns - 1, 4, &columns - 2, 3, 2],
1485 \ ['dddd', 5, &columns - 2, 4, &columns - 2, 3, 2],
1486 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1],
1487 \ ],
1488 \ },
1489 \ #{
1490 \ comment: 'left aligned without wrapping',
1491 \ options: #{
1492 \ wrap: 0,
1493 \ pos: 'botleft',
1494 \ },
1495 \ tests: both_wrap_tests + [
1496 \ ['aaaa', 5, &columns, 5, &columns - 3, 4, 1],
1497 \ ['bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1],
1498 \ ['cccc', 5, &columns - 1, 5, &columns - 3, 4, 1],
1499 \ ['dddd', 5, &columns - 2, 5, &columns - 3, 4, 1],
1500 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1],
1501 \ ],
1502 \ },
1503 \ #{
1504 \ comment: 'left aligned with fixed position',
1505 \ options: #{
1506 \ wrap: 0,
1507 \ fixed: 1,
1508 \ pos: 'botleft',
1509 \ },
1510 \ tests: both_wrap_tests + [
1511 \ ['aaaa', 5, &columns, 5, &columns - 2, 3, 1],
1512 \ ['bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1],
1513 \ ['cccc', 5, &columns - 1, 5, &columns - 2, 3, 1],
1514 \ ['dddd', 5, &columns - 2, 5, &columns - 2, 3, 1],
1515 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1],
1516 \ ],
1517 \ },
1518 \ ]
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001519
1520 for test_group in tests
1521 for test in test_group.tests
1522 let [ text, line, col, e_line, e_col, e_width, e_height ] = test
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001523 let options = #{
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001524 \ line: line,
1525 \ col: col,
1526 \ }
1527 call extend(options, test_group.options)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001528
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001529 let p = popup_create(text, options)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001530
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001531 let msg = string(extend(options, #{text: text}))
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001532 call s:VerifyPosition(p, msg, e_line, e_col, e_width, e_height)
1533 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001534 endfor
1535 endfor
1536
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001537 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001538 %bwipe!
1539endfunc
1540
Bram Moolenaar3397f742019-06-02 18:40:06 +02001541func Test_adjust_left_past_screen_width()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001542 " width of screen
1543 let X = join(map(range(&columns), {->'X'}), '')
1544
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001545 let p = popup_create(X, #{line: 1, col: 1, wrap: 0})
1546 call s:VerifyPosition(p, 'full width topleft', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001547
1548 redraw
1549 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1550 call assert_equal(X, line)
1551
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001552 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001553 redraw
1554
1555 " Same if placed on the right hand side
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001556 let p = popup_create(X, #{line: 1, col: &columns, wrap: 0})
1557 call s:VerifyPosition(p, 'full width topright', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001558
1559 redraw
1560 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1561 call assert_equal(X, line)
1562
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001563 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001564 redraw
1565
1566 " Extend so > window width
1567 let X .= 'x'
1568
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001569 let p = popup_create(X, #{line: 1, col: 1, wrap: 0})
1570 call s:VerifyPosition(p, 'full width + 1 topleft', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001571
1572 redraw
1573 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1574 call assert_equal(X[ : -2 ], line)
1575
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001576 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001577 redraw
1578
1579 " Shifted then truncated (the x is not visible)
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001580 let p = popup_create(X, #{line: 1, col: &columns - 3, wrap: 0})
1581 call s:VerifyPosition(p, 'full width + 1 topright', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001582
1583 redraw
1584 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1585 call assert_equal(X[ : -2 ], line)
1586
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001587 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001588 redraw
1589
1590 " Not shifted, just truncated
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001591 let p = popup_create(X,
1592 \ #{line: 1, col: 2, wrap: 0, fixed: 1})
1593 call s:VerifyPosition(p, 'full width + 1 fixed', 1, 2, &columns - 1, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001594
1595 redraw
1596 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1597 let e_line = ' ' . X[ 1 : -2 ]
1598 call assert_equal(e_line, line)
1599
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001600 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001601 redraw
1602
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001603 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001604 %bwipe!
Bram Moolenaar3397f742019-06-02 18:40:06 +02001605endfunc
1606
1607func Test_popup_moved()
1608 new
1609 call test_override('char_avail', 1)
1610 call setline(1, ['one word to move around', 'a WORD.and->some thing'])
1611
1612 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001613 let winid = popup_atcursor('text', #{moved: 'any'})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001614 redraw
1615 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001616 call assert_equal([1, 4, 4], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001617 " trigger the check for last_cursormoved by going into insert mode
1618 call feedkeys("li\<Esc>", 'xt')
1619 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001620 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001621
1622 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001623 let winid = popup_atcursor('text', #{moved: 'word'})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001624 redraw
1625 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001626 call assert_equal([1, 4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001627 call feedkeys("hi\<Esc>", 'xt')
1628 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001629 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001630
1631 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001632 let winid = popup_atcursor('text', #{moved: 'word'})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001633 redraw
1634 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001635 call assert_equal([1, 4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001636 call feedkeys("li\<Esc>", 'xt')
1637 call assert_equal(1, popup_getpos(winid).visible)
1638 call feedkeys("ei\<Esc>", 'xt')
1639 call assert_equal(1, popup_getpos(winid).visible)
1640 call feedkeys("eli\<Esc>", 'xt')
1641 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001642 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001643
Bram Moolenaar17627312019-06-02 19:53:44 +02001644 " WORD is the default
Bram Moolenaar3397f742019-06-02 18:40:06 +02001645 exe "normal gg0/WORD\<CR>"
Bram Moolenaar17627312019-06-02 19:53:44 +02001646 let winid = popup_atcursor('text', {})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001647 redraw
1648 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001649 call assert_equal([2, 2, 15], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001650 call feedkeys("eli\<Esc>", 'xt')
1651 call assert_equal(1, popup_getpos(winid).visible)
1652 call feedkeys("wi\<Esc>", 'xt')
1653 call assert_equal(1, popup_getpos(winid).visible)
1654 call feedkeys("Eli\<Esc>", 'xt')
1655 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001656 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001657
1658 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001659 let winid = popup_atcursor('text', #{moved: [5, 10]})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001660 redraw
1661 call assert_equal(1, popup_getpos(winid).visible)
1662 call feedkeys("eli\<Esc>", 'xt')
1663 call feedkeys("ei\<Esc>", 'xt')
1664 call assert_equal(1, popup_getpos(winid).visible)
1665 call feedkeys("eli\<Esc>", 'xt')
1666 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001667 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001668
1669 bwipe!
1670 call test_override('ALL', 0)
1671endfunc
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001672
1673func Test_notifications()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001674 CheckFeature timers
1675 CheckScreendump
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001676
Bram Moolenaar0fdddee2019-09-01 15:26:23 +02001677 let lines =<< trim END
1678 call setline(1, range(1, 20))
1679 hi Notification ctermbg=lightblue
1680 call popup_notification('first notification', {})
1681 END
1682 call writefile(lines, 'XtestNotifications')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001683 let buf = RunVimInTerminal('-S XtestNotifications', #{rows: 10})
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001684 call VerifyScreenDump(buf, 'Test_popupwin_notify_01', {})
1685
1686 " second one goes below the first one
Bram Moolenaardfa97f22019-06-15 14:31:55 +02001687 call term_sendkeys(buf, ":hi link PopupNotification Notification\<CR>")
1688 call term_sendkeys(buf, ":call popup_notification('another important notification', {})\<CR>")
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001689 call VerifyScreenDump(buf, 'Test_popupwin_notify_02', {})
1690
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001691 " clean up
1692 call StopVimInTerminal(buf)
1693 call delete('XtestNotifications')
1694endfunc
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001695
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001696func Test_popup_scrollbar()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001697 CheckScreendump
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001698
1699 let lines =<< trim END
1700 call setline(1, range(1, 20))
Bram Moolenaar8da41812019-06-26 18:04:54 +02001701 hi ScrollThumb ctermbg=blue
1702 hi ScrollBar ctermbg=red
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001703 let winid = popup_create(['one', 'two', 'three', 'four', 'five',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001704 \ 'six', 'seven', 'eight', 'nine'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001705 \ minwidth: 8,
1706 \ maxheight: 4,
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001707 \ })
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001708 func ScrollUp()
1709 call feedkeys("\<F3>\<ScrollWheelUp>", "xt")
1710 endfunc
1711 func ScrollDown()
1712 call feedkeys("\<F3>\<ScrollWheelDown>", "xt")
1713 endfunc
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001714 func ClickTop()
1715 call feedkeys("\<F4>\<LeftMouse>", "xt")
1716 endfunc
1717 func ClickBot()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001718 call popup_setoptions(g:winid, #{border: [], close: 'button'})
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001719 call feedkeys("\<F5>\<LeftMouse>", "xt")
1720 endfunc
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001721 map <silent> <F3> :call test_setmouse(5, 36)<CR>
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001722 map <silent> <F4> :call test_setmouse(4, 42)<CR>
1723 map <silent> <F5> :call test_setmouse(7, 42)<CR>
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001724 END
1725 call writefile(lines, 'XtestPopupScroll')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001726 let buf = RunVimInTerminal('-S XtestPopupScroll', #{rows: 10})
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001727 call VerifyScreenDump(buf, 'Test_popupwin_scroll_1', {})
1728
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001729 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 2})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +02001730 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001731 call VerifyScreenDump(buf, 'Test_popupwin_scroll_2', {})
1732
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001733 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 6})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +02001734 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001735 call VerifyScreenDump(buf, 'Test_popupwin_scroll_3', {})
1736
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001737 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 9})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +02001738 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001739 call VerifyScreenDump(buf, 'Test_popupwin_scroll_4', {})
1740
Bram Moolenaar9e67b6a2019-08-30 17:34:08 +02001741 call term_sendkeys(buf, ":call popup_setoptions(winid, #{scrollbarhighlight: 'ScrollBar', thumbhighlight: 'ScrollThumb', firstline: 5})\<CR>")
Bram Moolenaara112f2d2019-09-01 17:38:09 +02001742 " this scrolls two lines (half the window height)
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001743 call term_sendkeys(buf, ":call ScrollUp()\<CR>")
1744 call VerifyScreenDump(buf, 'Test_popupwin_scroll_5', {})
1745
1746 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
1747 call VerifyScreenDump(buf, 'Test_popupwin_scroll_6', {})
1748
1749 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
Bram Moolenaar13b47c32019-06-28 21:55:48 +02001750 " wait a bit, otherwise it fails sometimes (double click recognized?)
1751 sleep 100m
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001752 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
1753 call VerifyScreenDump(buf, 'Test_popupwin_scroll_7', {})
1754
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001755 call term_sendkeys(buf, ":call ClickTop()\<CR>")
1756 sleep 100m
1757 call term_sendkeys(buf, ":call ClickTop()\<CR>")
1758 call VerifyScreenDump(buf, 'Test_popupwin_scroll_8', {})
1759
1760 call term_sendkeys(buf, ":call ClickBot()\<CR>")
1761 call VerifyScreenDump(buf, 'Test_popupwin_scroll_9', {})
1762
Bram Moolenaar8c6173c2019-08-30 22:08:34 +02001763 " remove the minwidth and maxheight
1764 call term_sendkeys(buf, ":call popup_setoptions(winid, #{maxheight: 0, minwidth: 0})\<CR>")
1765 call VerifyScreenDump(buf, 'Test_popupwin_scroll_10', {})
1766
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001767 " clean up
1768 call StopVimInTerminal(buf)
1769 call delete('XtestPopupScroll')
1770endfunc
1771
Bram Moolenaar437a7462019-07-05 20:17:22 +02001772func Test_popup_fitting_scrollbar()
1773 " this was causing a crash, divide by zero
1774 let winid = popup_create([
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001775 \ 'one', 'two', 'longer line that wraps', 'four', 'five'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001776 \ scrollbar: 1,
1777 \ maxwidth: 10,
1778 \ maxheight: 5,
1779 \ firstline: 2})
Bram Moolenaar437a7462019-07-05 20:17:22 +02001780 redraw
1781 call popup_clear()
1782endfunc
1783
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001784func Test_popup_settext()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001785 CheckScreendump
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001786
1787 let lines =<< trim END
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001788 let opts = #{wrap: 0}
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001789 let p = popup_create('test', opts)
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001790 eval p->popup_settext('this is a text')
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001791 END
1792
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001793 call writefile(lines, 'XtestPopupSetText')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001794 let buf = RunVimInTerminal('-S XtestPopupSetText', #{rows: 10})
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001795 call VerifyScreenDump(buf, 'Test_popup_settext_01', {})
1796
1797 " Setting to empty string clears it
1798 call term_sendkeys(buf, ":call popup_settext(p, '')\<CR>")
1799 call VerifyScreenDump(buf, 'Test_popup_settext_02', {})
1800
1801 " Setting a list
1802 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
1803 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
1804
1805 " Shrinking with a list
1806 call term_sendkeys(buf, ":call popup_settext(p, ['a'])\<CR>")
1807 call VerifyScreenDump(buf, 'Test_popup_settext_04', {})
1808
1809 " Growing with a list
1810 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
1811 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
1812
1813 " Empty list clears
1814 call term_sendkeys(buf, ":call popup_settext(p, [])\<CR>")
1815 call VerifyScreenDump(buf, 'Test_popup_settext_05', {})
1816
1817 " Dicts
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001818 call term_sendkeys(buf, ":call popup_settext(p, [#{text: 'aaaa'}, #{text: 'bbbb'}, #{text: 'cccc'}])\<CR>")
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001819 call VerifyScreenDump(buf, 'Test_popup_settext_06', {})
1820
1821 " clean up
1822 call StopVimInTerminal(buf)
1823 call delete('XtestPopupSetText')
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001824endfunc
1825
1826func Test_popup_hidden()
1827 new
1828
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001829 let winid = popup_atcursor('text', #{hidden: 1})
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001830 redraw
1831 call assert_equal(0, popup_getpos(winid).visible)
1832 call popup_close(winid)
1833
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001834 let winid = popup_create('text', #{hidden: 1})
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001835 redraw
1836 call assert_equal(0, popup_getpos(winid).visible)
1837 call popup_close(winid)
1838
1839 func QuitCallback(id, res)
1840 let s:cb_winid = a:id
1841 let s:cb_res = a:res
1842 endfunc
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001843 let winid = 'make a choice'->popup_dialog(#{hidden: 1,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001844 \ filter: 'popup_filter_yesno',
1845 \ callback: 'QuitCallback',
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001846 \ })
1847 redraw
1848 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001849 call assert_equal(function('popup_filter_yesno'), popup_getoptions(winid).filter)
1850 call assert_equal(function('QuitCallback'), popup_getoptions(winid).callback)
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001851 exe "normal anot used by filter\<Esc>"
1852 call assert_equal('not used by filter', getline(1))
1853
1854 call popup_show(winid)
1855 call feedkeys('y', "xt")
1856 call assert_equal(1, s:cb_res)
1857
1858 bwipe!
1859 delfunc QuitCallback
1860endfunc
Bram Moolenaarae943152019-06-16 22:54:14 +02001861
1862" Test options not checked elsewhere
1863func Test_set_get_options()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001864 let winid = popup_create('some text', #{highlight: 'Beautiful'})
Bram Moolenaarae943152019-06-16 22:54:14 +02001865 let options = popup_getoptions(winid)
1866 call assert_equal(1, options.wrap)
1867 call assert_equal(0, options.drag)
1868 call assert_equal('Beautiful', options.highlight)
1869
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001870 call popup_setoptions(winid, #{wrap: 0, drag: 1, highlight: 'Another'})
Bram Moolenaarae943152019-06-16 22:54:14 +02001871 let options = popup_getoptions(winid)
1872 call assert_equal(0, options.wrap)
1873 call assert_equal(1, options.drag)
1874 call assert_equal('Another', options.highlight)
1875
1876 call popup_close(winid)
1877endfunc
Bram Moolenaar75a1a942019-06-20 03:45:36 +02001878
1879func Test_popupwin_garbage_collect()
1880 func MyPopupFilter(x, winid, c)
1881 " NOP
1882 endfunc
1883
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001884 let winid = popup_create('something', #{filter: function('MyPopupFilter', [{}])})
Bram Moolenaar75a1a942019-06-20 03:45:36 +02001885 call test_garbagecollect_now()
1886 redraw
Bram Moolenaar1bc353b2019-09-01 14:45:28 +02001887 " Must not crash caused by invalid memory access
Bram Moolenaar75a1a942019-06-20 03:45:36 +02001888 call feedkeys('j', 'xt')
1889 call assert_true(v:true)
1890
1891 call popup_close(winid)
1892 delfunc MyPopupFilter
1893endfunc
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02001894
Bram Moolenaar581ba392019-09-03 22:08:33 +02001895func Test_popupwin_filter_mode()
1896 func MyPopupFilter(winid, c)
1897 let s:typed = a:c
1898 if a:c == ':' || a:c == "\r" || a:c == 'v'
1899 " can start cmdline mode, get out, and start/stop Visual mode
1900 return 0
1901 endif
1902 return 1
1903 endfunc
1904
1905 " Normal, Visual and Insert mode
1906 let winid = popup_create('something', #{filter: 'MyPopupFilter', filtermode: 'nvi'})
1907 redraw
1908 call feedkeys('x', 'xt')
1909 call assert_equal('x', s:typed)
1910
1911 call feedkeys(":let g:foo = 'foo'\<CR>", 'xt')
1912 call assert_equal(':', s:typed)
1913 call assert_equal('foo', g:foo)
1914
1915 let @x = 'something'
1916 call feedkeys('v$"xy', 'xt')
1917 call assert_equal('y', s:typed)
1918 call assert_equal('something', @x) " yank command is filtered out
1919 call feedkeys('v', 'xt') " end Visual mode
1920
1921 call popup_close(winid)
1922
1923 " only Normal mode
1924 let winid = popup_create('something', #{filter: 'MyPopupFilter', filtermode: 'n'})
1925 redraw
1926 call feedkeys('x', 'xt')
1927 call assert_equal('x', s:typed)
1928
1929 call feedkeys(":let g:foo = 'foo'\<CR>", 'xt')
1930 call assert_equal(':', s:typed)
1931 call assert_equal('foo', g:foo)
1932
1933 let @x = 'something'
1934 call feedkeys('v$"xy', 'xt')
1935 call assert_equal('v', s:typed)
1936 call assert_notequal('something', @x)
1937
1938 call popup_close(winid)
1939
1940 " default: all modes
1941 let winid = popup_create('something', #{filter: 'MyPopupFilter'})
1942 redraw
1943 call feedkeys('x', 'xt')
1944 call assert_equal('x', s:typed)
1945
1946 let g:foo = 'bar'
1947 call feedkeys(":let g:foo = 'foo'\<CR>", 'xt')
1948 call assert_equal("\r", s:typed)
1949 call assert_equal('bar', g:foo)
1950
1951 let @x = 'something'
1952 call feedkeys('v$"xy', 'xt')
1953 call assert_equal('y', s:typed)
1954 call assert_equal('something', @x) " yank command is filtered out
1955 call feedkeys('v', 'xt') " end Visual mode
1956
1957 call popup_close(winid)
1958 delfunc MyPopupFilter
1959endfunc
1960
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02001961func Test_popupwin_with_buffer()
1962 call writefile(['some text', 'in a buffer'], 'XsomeFile')
1963 let buf = bufadd('XsomeFile')
1964 call assert_equal(0, bufloaded(buf))
Bram Moolenaar46451042019-08-24 15:50:46 +02001965
1966 setlocal number
1967 call setbufvar(buf, "&wrapmargin", 13)
1968
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02001969 let winid = popup_create(buf, {})
1970 call assert_notequal(0, winid)
1971 let pos = popup_getpos(winid)
1972 call assert_equal(2, pos.height)
1973 call assert_equal(1, bufloaded(buf))
Bram Moolenaar46451042019-08-24 15:50:46 +02001974
1975 " window-local option is set to default, buffer-local is not
1976 call assert_equal(0, getwinvar(winid, '&number'))
1977 call assert_equal(13, getbufvar(buf, '&wrapmargin'))
1978
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02001979 call popup_close(winid)
1980 call assert_equal({}, popup_getpos(winid))
1981 call assert_equal(1, bufloaded(buf))
1982 exe 'bwipe! ' .. buf
Bram Moolenaar46451042019-08-24 15:50:46 +02001983 setlocal nonumber
Bram Moolenaar7866b872019-07-01 22:21:01 +02001984
1985 edit test_popupwin.vim
1986 let winid = popup_create(bufnr(''), {})
1987 redraw
1988 call popup_close(winid)
Bram Moolenaar3940ec62019-07-05 21:53:24 +02001989 call delete('XsomeFile')
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02001990endfunc
Bram Moolenaare296e312019-07-03 23:20:18 +02001991
Bram Moolenaar934470e2019-09-01 23:27:05 +02001992func Test_popupwin_with_buffer_and_filter()
1993 new Xwithfilter
1994 call setline(1, range(100))
1995 let bufnr = bufnr()
1996 hide
1997
1998 func BufferFilter(win, key)
1999 if a:key == 'G'
2000 " recursive use of "G" does not cause problems.
2001 call win_execute(a:win, 'normal! G')
2002 return 1
2003 endif
2004 return 0
2005 endfunc
2006
2007 let winid = popup_create(bufnr, #{maxheight: 5, filter: 'BufferFilter'})
2008 call assert_equal(1, popup_getpos(winid).firstline)
2009 redraw
2010 call feedkeys("G", 'xt')
2011 call assert_equal(99, popup_getpos(winid).firstline)
2012
2013 call popup_close(winid)
2014 exe 'bwipe! ' .. bufnr
2015endfunc
2016
Bram Moolenaare296e312019-07-03 23:20:18 +02002017func Test_popupwin_width()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002018 let winid = popup_create(repeat(['short', 'long long long line', 'medium width'], 50), #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002019 \ maxwidth: 40,
2020 \ maxheight: 10,
Bram Moolenaare296e312019-07-03 23:20:18 +02002021 \ })
2022 for top in range(1, 20)
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002023 eval winid->popup_setoptions(#{firstline: top})
Bram Moolenaare296e312019-07-03 23:20:18 +02002024 redraw
2025 call assert_equal(19, popup_getpos(winid).width)
2026 endfor
2027 call popup_clear()
2028endfunc
Bram Moolenaar5ca1ac32019-07-04 15:39:28 +02002029
2030func Test_popupwin_buf_close()
2031 let buf = bufadd('Xtestbuf')
2032 call bufload(buf)
2033 call setbufline(buf, 1, ['just', 'some', 'lines'])
2034 let winid = popup_create(buf, {})
2035 redraw
2036 call assert_equal(3, popup_getpos(winid).height)
2037 let bufinfo = getbufinfo(buf)[0]
2038 call assert_equal(1, bufinfo.changed)
2039 call assert_equal(0, bufinfo.hidden)
2040 call assert_equal(0, bufinfo.listed)
2041 call assert_equal(1, bufinfo.loaded)
2042 call assert_equal([], bufinfo.windows)
2043 call assert_equal([winid], bufinfo.popups)
2044
2045 call popup_close(winid)
2046 call assert_equal({}, popup_getpos(winid))
2047 let bufinfo = getbufinfo(buf)[0]
2048 call assert_equal(1, bufinfo.changed)
2049 call assert_equal(1, bufinfo.hidden)
2050 call assert_equal(0, bufinfo.listed)
2051 call assert_equal(1, bufinfo.loaded)
2052 call assert_equal([], bufinfo.windows)
2053 call assert_equal([], bufinfo.popups)
2054 exe 'bwipe! ' .. buf
2055endfunc
Bram Moolenaar017c2692019-07-13 14:17:51 +02002056
2057func Test_popup_menu_with_maxwidth()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002058 CheckScreendump
Bram Moolenaar017c2692019-07-13 14:17:51 +02002059
2060 let lines =<< trim END
2061 call setline(1, range(1, 10))
2062 hi ScrollThumb ctermbg=blue
2063 hi ScrollBar ctermbg=red
2064 func PopupMenu(lines, line, col, scrollbar = 0)
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002065 return popup_menu(a:lines, #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002066 \ maxwidth: 10,
2067 \ maxheight: 3,
2068 \ pos : 'topleft',
2069 \ col : a:col,
2070 \ line : a:line,
2071 \ scrollbar : a:scrollbar,
Bram Moolenaar017c2692019-07-13 14:17:51 +02002072 \ })
2073 endfunc
2074 call PopupMenu(['x'], 1, 1)
2075 call PopupMenu(['123456789|'], 1, 16)
2076 call PopupMenu(['123456789|' .. ' '], 7, 1)
2077 call PopupMenu([repeat('123456789|', 100)], 7, 16)
2078 call PopupMenu(repeat(['123456789|' .. ' '], 5), 1, 33, 1)
2079 END
2080 call writefile(lines, 'XtestPopupMenuMaxWidth')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002081 let buf = RunVimInTerminal('-S XtestPopupMenuMaxWidth', #{rows: 13})
Bram Moolenaar017c2692019-07-13 14:17:51 +02002082 call VerifyScreenDump(buf, 'Test_popupwin_menu_maxwidth_1', {})
2083
2084 " close the menu popupwin.
2085 call term_sendkeys(buf, " ")
2086 call term_sendkeys(buf, " ")
2087 call term_sendkeys(buf, " ")
2088 call term_sendkeys(buf, " ")
2089 call term_sendkeys(buf, " ")
2090
2091 " clean up
2092 call StopVimInTerminal(buf)
2093 call delete('XtestPopupMenuMaxWidth')
2094endfunc
2095
Bram Moolenaara901a372019-07-13 16:38:50 +02002096func Test_popup_menu_with_scrollbar()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002097 CheckScreendump
Bram Moolenaara901a372019-07-13 16:38:50 +02002098
2099 let lines =<< trim END
2100 call setline(1, range(1, 20))
2101 hi ScrollThumb ctermbg=blue
2102 hi ScrollBar ctermbg=red
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002103 eval ['one', 'two', 'three', 'four', 'five',
2104 \ 'six', 'seven', 'eight', 'nine']
2105 \ ->popup_menu(#{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002106 \ minwidth: 8,
2107 \ maxheight: 3,
Bram Moolenaara901a372019-07-13 16:38:50 +02002108 \ })
2109 END
2110 call writefile(lines, 'XtestPopupMenuScroll')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002111 let buf = RunVimInTerminal('-S XtestPopupMenuScroll', #{rows: 10})
Bram Moolenaara901a372019-07-13 16:38:50 +02002112
2113 call term_sendkeys(buf, "j")
2114 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_1', {})
2115
2116 call term_sendkeys(buf, "jjj")
2117 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_2', {})
2118
2119 " if the cursor is the bottom line, it stays at the bottom line.
2120 call term_sendkeys(buf, repeat("j", 20))
2121 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_3', {})
2122
2123 call term_sendkeys(buf, "kk")
2124 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_4', {})
2125
2126 call term_sendkeys(buf, "k")
2127 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_5', {})
2128
2129 " if the cursor is in the top line, it stays in the top line.
2130 call term_sendkeys(buf, repeat("k", 20))
2131 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_6', {})
2132
2133 " close the menu popupwin.
2134 call term_sendkeys(buf, " ")
2135
2136 " clean up
2137 call StopVimInTerminal(buf)
2138 call delete('XtestPopupMenuScroll')
2139endfunc
2140
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002141func Test_popup_menu_filter()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002142 CheckScreendump
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002143
2144 let lines =<< trim END
2145 function! MyFilter(winid, key) abort
2146 if a:key == "0"
2147 call win_execute(a:winid, "call setpos('.', [0, 1, 1, 0])")
2148 return 1
2149 endif
2150 if a:key == "G"
2151 call win_execute(a:winid, "call setpos('.', [0, line('$'), 1, 0])")
2152 return 1
2153 endif
2154 if a:key == "j"
2155 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0])")
2156 return 1
2157 endif
2158 if a:key == "k"
2159 call win_execute(a:winid, "call setpos('.', [0, line('.') - 1, 1, 0])")
2160 return 1
2161 endif
Bram Moolenaarbcb4c8f2019-09-07 14:06:52 +02002162 if a:key == ':'
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002163 call popup_close(a:winid)
Bram Moolenaarbcb4c8f2019-09-07 14:06:52 +02002164 return 0
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002165 endif
2166 return 0
2167 endfunction
2168 call popup_menu(['111', '222', '333', '444', '555', '666', '777', '888', '999'], #{
2169 \ maxheight : 3,
2170 \ filter : 'MyFilter'
2171 \ })
2172 END
2173 call writefile(lines, 'XtestPopupMenuFilter')
2174 let buf = RunVimInTerminal('-S XtestPopupMenuFilter', #{rows: 10})
2175
2176 call term_sendkeys(buf, "j")
2177 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_1', {})
2178
2179 call term_sendkeys(buf, "k")
2180 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_2', {})
2181
2182 call term_sendkeys(buf, "G")
2183 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_3', {})
2184
2185 call term_sendkeys(buf, "0")
2186 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_4', {})
2187
Bram Moolenaarbcb4c8f2019-09-07 14:06:52 +02002188 " check that when the popup is closed in the filter the screen is redrawn
2189 call term_sendkeys(buf, ":")
2190 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_5', {})
2191 call term_sendkeys(buf, "\<CR>")
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002192
2193 " clean up
2194 call StopVimInTerminal(buf)
2195 call delete('XtestPopupMenuFilter')
2196endfunc
2197
2198func Test_popup_cursorline()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002199 CheckScreendump
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002200
2201 let winid = popup_create('some text', {})
2202 call assert_equal(0, popup_getoptions(winid).cursorline)
2203 call popup_close(winid)
2204
2205 let winid = popup_create('some text', #{ cursorline: 1, })
2206 call assert_equal(1, popup_getoptions(winid).cursorline)
2207 call popup_close(winid)
2208
2209 let winid = popup_create('some text', #{ cursorline: 0, })
2210 call assert_equal(0, popup_getoptions(winid).cursorline)
2211 call popup_close(winid)
2212
2213 let winid = popup_menu('some text', {})
2214 call assert_equal(1, popup_getoptions(winid).cursorline)
2215 call popup_close(winid)
2216
2217 let winid = popup_menu('some text', #{ cursorline: 1, })
2218 call assert_equal(1, popup_getoptions(winid).cursorline)
2219 call popup_close(winid)
2220
2221 let winid = popup_menu('some text', #{ cursorline: 0, })
2222 call assert_equal(0, popup_getoptions(winid).cursorline)
2223 call popup_close(winid)
2224
2225 " ---------
2226 " Pattern 1
2227 " ---------
2228 let lines =<< trim END
2229 call popup_create(['111', '222', '333'], #{ cursorline : 0 })
2230 END
2231 call writefile(lines, 'XtestPopupCursorLine')
2232 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2233 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_1', {})
2234 call term_sendkeys(buf, ":call popup_clear()\<cr>")
2235 call StopVimInTerminal(buf)
2236
2237 " ---------
2238 " Pattern 2
2239 " ---------
2240 let lines =<< trim END
2241 call popup_create(['111', '222', '333'], #{ cursorline : 1 })
2242 END
2243 call writefile(lines, 'XtestPopupCursorLine')
2244 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2245 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_2', {})
2246 call term_sendkeys(buf, ":call popup_clear()\<cr>")
2247 call StopVimInTerminal(buf)
2248
2249 " ---------
2250 " Pattern 3
2251 " ---------
2252 let lines =<< trim END
2253 function! MyFilter(winid, key) abort
2254 if a:key == "j"
2255 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0]) | redraw")
2256 return 1
2257 endif
2258 if a:key == 'x'
2259 call popup_close(a:winid)
2260 return 1
2261 endif
2262 return 0
2263 endfunction
2264 call popup_menu(['111', '222', '333'], #{
2265 \ cursorline : 0,
2266 \ maxheight : 2,
2267 \ filter : 'MyFilter',
2268 \ })
2269 END
2270 call writefile(lines, 'XtestPopupCursorLine')
2271 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2272 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_3', {})
2273 call term_sendkeys(buf, "j")
2274 call term_sendkeys(buf, "j")
2275 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_4', {})
2276 call term_sendkeys(buf, "x")
2277 call StopVimInTerminal(buf)
2278
2279 " ---------
2280 " Pattern 4
2281 " ---------
2282 let lines =<< trim END
2283 function! MyFilter(winid, key) abort
2284 if a:key == "j"
2285 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0]) | redraw")
2286 return 1
2287 endif
2288 if a:key == 'x'
2289 call popup_close(a:winid)
2290 return 1
2291 endif
2292 return 0
2293 endfunction
2294 call popup_menu(['111', '222', '333'], #{
2295 \ cursorline : 1,
2296 \ maxheight : 2,
2297 \ filter : 'MyFilter',
2298 \ })
2299 END
2300 call writefile(lines, 'XtestPopupCursorLine')
2301 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2302 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_5', {})
2303 call term_sendkeys(buf, "j")
2304 call term_sendkeys(buf, "j")
2305 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_6', {})
2306 call term_sendkeys(buf, "x")
2307 call StopVimInTerminal(buf)
2308
2309 call delete('XtestPopupCursorLine')
2310endfunc
2311
Bram Moolenaarf914a332019-07-20 15:09:56 +02002312func Test_previewpopup()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002313 CheckScreendump
2314
Bram Moolenaarf914a332019-07-20 15:09:56 +02002315 call writefile([
2316 \ "!_TAG_FILE_ENCODING\tutf-8\t//",
2317 \ "another\tXtagfile\t/^this is another",
2318 \ "theword\tXtagfile\t/^theword"],
2319 \ 'Xtags')
2320 call writefile(range(1,20)
2321 \ + ['theword is here']
2322 \ + range(22, 27)
2323 \ + ['this is another place']
2324 \ + range(29, 40),
2325 \ "Xtagfile")
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002326 call writefile(range(1,10)
2327 \ + ['searched word is here']
2328 \ + range(12, 20),
2329 \ "Xheader.h")
Bram Moolenaarf914a332019-07-20 15:09:56 +02002330 let lines =<< trim END
2331 set tags=Xtags
2332 call setline(1, [
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02002333 \ 'one',
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002334 \ '#include "Xheader.h"',
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02002335 \ 'three',
2336 \ 'four',
2337 \ 'five',
2338 \ 'six',
2339 \ 'seven',
2340 \ 'find theword somewhere',
2341 \ 'nine',
2342 \ 'this is another word',
2343 \ 'very long line where the word is also another'])
Bram Moolenaarf914a332019-07-20 15:09:56 +02002344 set previewpopup=height:4,width:40
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002345 set path=.
Bram Moolenaarf914a332019-07-20 15:09:56 +02002346 END
2347 call writefile(lines, 'XtestPreviewPopup')
2348 let buf = RunVimInTerminal('-S XtestPreviewPopup', #{rows: 14})
2349
2350 call term_sendkeys(buf, "/theword\<CR>\<C-W>}")
2351 call term_sendkeys(buf, ":\<CR>")
2352 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_1', {})
2353
2354 call term_sendkeys(buf, "/another\<CR>\<C-W>}")
2355 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_2', {})
2356
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002357 call term_sendkeys(buf, ":call popup_move(popup_findpreview(), #{col: 15})\<CR>")
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02002358 call term_sendkeys(buf, ":\<CR>")
2359 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_3', {})
2360
2361 call term_sendkeys(buf, "/another\<CR>\<C-W>}")
2362 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_4', {})
2363
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02002364 call term_sendkeys(buf, ":cd ..\<CR>:\<CR>")
2365 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_5', {})
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002366 call term_sendkeys(buf, ":cd testdir\<CR>")
2367
2368 call term_sendkeys(buf, ":pclose\<CR>")
Bram Moolenaar78d629a2019-08-16 17:31:15 +02002369 call term_sendkeys(buf, ":\<BS>")
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002370 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_6', {})
2371
2372 call term_sendkeys(buf, ":pedit +/theword Xtagfile\<CR>")
2373 call term_sendkeys(buf, ":\<CR>")
2374 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_7', {})
2375
2376 call term_sendkeys(buf, ":pclose\<CR>")
2377 call term_sendkeys(buf, ":psearch searched\<CR>")
2378 call term_sendkeys(buf, ":\<CR>")
2379 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_8', {})
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02002380
Bram Moolenaarf914a332019-07-20 15:09:56 +02002381 call StopVimInTerminal(buf)
2382 call delete('Xtags')
2383 call delete('Xtagfile')
2384 call delete('XtestPreviewPopup')
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002385 call delete('Xheader.h')
Bram Moolenaarf914a332019-07-20 15:09:56 +02002386endfunc
2387
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002388func Get_popupmenu_lines()
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002389 let lines =<< trim END
2390 set completeopt+=preview,popup
2391 set completefunc=CompleteFuncDict
Bram Moolenaar62a0cb42019-08-18 16:35:23 +02002392 hi InfoPopup ctermbg=yellow
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002393
2394 func CompleteFuncDict(findstart, base)
2395 if a:findstart
2396 if col('.') > 10
2397 return col('.') - 10
2398 endif
2399 return 0
2400 endif
2401
2402 return {
2403 \ 'words': [
2404 \ {
2405 \ 'word': 'aword',
2406 \ 'abbr': 'wrd',
2407 \ 'menu': 'extra text',
2408 \ 'info': 'words are cool',
2409 \ 'kind': 'W',
2410 \ 'user_data': 'test'
2411 \ },
2412 \ {
2413 \ 'word': 'anotherword',
2414 \ 'abbr': 'anotwrd',
2415 \ 'menu': 'extra text',
2416 \ 'info': "other words are\ncooler than this and some more text\nto make wrap",
2417 \ 'kind': 'W',
2418 \ 'user_data': 'notest'
2419 \ },
2420 \ {
2421 \ 'word': 'noinfo',
2422 \ 'abbr': 'noawrd',
2423 \ 'menu': 'extra text',
Bram Moolenaar62a0cb42019-08-18 16:35:23 +02002424 \ 'info': "lets\nshow\na\nscrollbar\nhere",
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002425 \ 'kind': 'W',
2426 \ 'user_data': 'notest'
2427 \ },
2428 \ {
2429 \ 'word': 'thatword',
2430 \ 'abbr': 'thatwrd',
2431 \ 'menu': 'extra text',
2432 \ 'info': 'that word is cool',
2433 \ 'kind': 'W',
2434 \ 'user_data': 'notest'
2435 \ },
2436 \ ]
2437 \ }
2438 endfunc
2439 call setline(1, 'text text text text text text text ')
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002440 func ChangeColor()
2441 let id = popup_findinfo()
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002442 eval id->popup_setoptions(#{highlight: 'InfoPopup'})
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002443 endfunc
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002444 END
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002445 return lines
2446endfunc
2447
2448func Test_popupmenu_info_border()
2449 CheckScreendump
2450
2451 let lines = Get_popupmenu_lines()
2452 call add(lines, 'set completepopup=height:4,highlight:InfoPopup')
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002453 call writefile(lines, 'XtestInfoPopup')
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002454
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002455 let buf = RunVimInTerminal('-S XtestInfoPopup', #{rows: 14})
2456 call term_wait(buf, 50)
2457
2458 call term_sendkeys(buf, "A\<C-X>\<C-U>")
2459 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_1', {})
2460
2461 call term_sendkeys(buf, "\<C-N>")
2462 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_2', {})
2463
2464 call term_sendkeys(buf, "\<C-N>")
2465 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_3', {})
2466
2467 call term_sendkeys(buf, "\<C-N>\<C-N>")
2468 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_4', {})
2469
Bram Moolenaarfe6e7612019-08-21 20:57:20 +02002470 " info on the left with scrollbar
2471 call term_sendkeys(buf, "test text test text\<C-X>\<C-U>")
2472 call term_sendkeys(buf, "\<C-N>\<C-N>")
2473 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_5', {})
2474
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002475 call StopVimInTerminal(buf)
2476 call delete('XtestInfoPopup')
2477endfunc
2478
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002479func Test_popupmenu_info_noborder()
2480 CheckScreendump
2481
2482 let lines = Get_popupmenu_lines()
2483 call add(lines, 'set completepopup=height:4,border:off')
2484 call writefile(lines, 'XtestInfoPopupNb')
2485
2486 let buf = RunVimInTerminal('-S XtestInfoPopupNb', #{rows: 14})
2487 call term_wait(buf, 50)
2488
2489 call term_sendkeys(buf, "A\<C-X>\<C-U>")
2490 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_nb_1', {})
2491
2492 call StopVimInTerminal(buf)
2493 call delete('XtestInfoPopupNb')
2494endfunc
2495
Bram Moolenaar258cef52019-08-21 17:29:29 +02002496func Test_popupmenu_info_align_menu()
2497 CheckScreendump
2498
2499 let lines = Get_popupmenu_lines()
2500 call add(lines, 'set completepopup=height:4,border:off,align:menu')
2501 call writefile(lines, 'XtestInfoPopupNb')
2502
2503 let buf = RunVimInTerminal('-S XtestInfoPopupNb', #{rows: 14})
2504 call term_wait(buf, 50)
2505
2506 call term_sendkeys(buf, "A\<C-X>\<C-U>")
2507 call term_sendkeys(buf, "\<C-N>")
2508 call term_sendkeys(buf, "\<C-N>")
2509 call term_sendkeys(buf, "\<C-N>")
2510 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_1', {})
2511
2512 call term_sendkeys(buf, "test text test text test\<C-X>\<C-U>")
2513 call term_sendkeys(buf, "\<C-N>")
2514 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_2', {})
2515
2516 call term_sendkeys(buf, "\<Esc>")
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002517 call term_sendkeys(buf, ":call ChangeColor()\<CR>")
Bram Moolenaar258cef52019-08-21 17:29:29 +02002518 call term_sendkeys(buf, ":call setline(2, ['x']->repeat(10))\<CR>")
2519 call term_sendkeys(buf, "Gotest text test text\<C-X>\<C-U>")
2520 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_3', {})
2521
2522 call StopVimInTerminal(buf)
2523 call delete('XtestInfoPopupNb')
2524endfunc
2525
Bram Moolenaar00b0d6d2019-08-21 22:25:30 +02002526func Test_popupwin_recycle_bnr()
Bram Moolenaare49fbff2019-08-21 22:50:07 +02002527 let bufnr = popup_notification('nothing wrong', {})->winbufnr()
Bram Moolenaar00b0d6d2019-08-21 22:25:30 +02002528 call popup_clear()
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002529 let winid = 'nothing wrong'->popup_notification({})
Bram Moolenaar00b0d6d2019-08-21 22:25:30 +02002530 call assert_equal(bufnr, winbufnr(winid))
2531 call popup_clear()
2532endfunc
2533
Bram Moolenaar331bafd2019-07-20 17:46:05 +02002534" vim: shiftwidth=2 sts=2