blob: 523bd592a9b5985ed786ce595698680c3c1e74f8 [file] [log] [blame]
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001" Tests for popup windows
2
3if !has('textprop')
4 finish
5endif
6
7source screendump.vim
8
9func Test_simple_popup()
10 if !CanRunVimInTerminal()
11 return
12 endif
13 call writefile([
14 \ "call setline(1, range(1, 100))",
Bram Moolenaar20c023a2019-05-26 21:03:24 +020015 \ "hi PopupColor1 ctermbg=lightblue",
16 \ "hi PopupColor2 ctermbg=lightcyan",
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020017 \ "hi Comment ctermfg=red",
18 \ "call prop_type_add('comment', {'highlight': 'Comment'})",
Bram Moolenaar60cdb302019-05-27 21:54:10 +020019 \ "let winid = popup_create('hello there', {'line': 3, 'col': 11, 'minwidth': 20, 'highlight': 'PopupColor1'})",
20 \ "let winid2 = popup_create(['another one', 'another two', 'another three'], {'line': 3, 'col': 25, 'minwidth': 20})",
Bram Moolenaar20c023a2019-05-26 21:03:24 +020021 \ "call setwinvar(winid2, '&wincolor', 'PopupColor2')",
Bram Moolenaar4d784b22019-05-25 19:51:39 +020022 \], 'XtestPopup')
23 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
24 call VerifyScreenDump(buf, 'Test_popupwin_01', {})
25
Bram Moolenaarec583842019-05-26 14:11:23 +020026 " Add a tabpage
27 call term_sendkeys(buf, ":tabnew\<CR>")
Bram Moolenaar60cdb302019-05-27 21:54:10 +020028 call term_sendkeys(buf, ":let popupwin = popup_create(["
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020029 \ .. "{'text': 'other tab'},"
30 \ .. "{'text': 'a comment line', 'props': [{"
Bram Moolenaar60cdb302019-05-27 21:54:10 +020031 \ .. "'col': 3, 'length': 7, 'minwidth': 20, 'type': 'comment'"
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020032 \ .. "}]},"
Bram Moolenaar60cdb302019-05-27 21:54:10 +020033 \ .. "], {'line': 4, 'col': 9, 'minwidth': 20})\<CR>")
Bram Moolenaarec583842019-05-26 14:11:23 +020034 call VerifyScreenDump(buf, 'Test_popupwin_02', {})
35
36 " switch back to first tabpage
37 call term_sendkeys(buf, "gt")
38 call VerifyScreenDump(buf, 'Test_popupwin_03', {})
39
40 " close that tabpage
41 call term_sendkeys(buf, ":quit!\<CR>")
42 call VerifyScreenDump(buf, 'Test_popupwin_04', {})
43
Bram Moolenaar17146962019-05-30 00:12:11 +020044 " resize popup, show empty line at bottom
Bram Moolenaar60cdb302019-05-27 21:54:10 +020045 call term_sendkeys(buf, ":call popup_move(popupwin, {'minwidth': 15, 'maxwidth': 25, 'minheight': 3, 'maxheight': 5})\<CR>")
46 call term_sendkeys(buf, ":redraw\<CR>")
47 call VerifyScreenDump(buf, 'Test_popupwin_05', {})
48
Bram Moolenaar17146962019-05-30 00:12:11 +020049 " show not fitting line at bottom
50 call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>")
51 call term_sendkeys(buf, ":redraw\<CR>")
52 call VerifyScreenDump(buf, 'Test_popupwin_06', {})
53
Bram Moolenaar4d784b22019-05-25 19:51:39 +020054 " clean up
55 call StopVimInTerminal(buf)
56 call delete('XtestPopup')
57endfunc
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020058
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020059func Test_popup_with_border_and_padding()
60 if !CanRunVimInTerminal()
61 return
62 endif
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020063
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +020064 for iter in range(0, 1)
65 call writefile([iter == 1 ? '' : 'set enc=latin1',
66 \ "call setline(1, range(1, 100))",
67 \ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': []})",
68 \ "call popup_create('hello padding', {'line': 2, 'col': 23, 'padding': []})",
69 \ "call popup_create('hello both', {'line': 2, 'col': 43, 'border': [], 'padding': []})",
70 \ "call popup_create('border TL', {'line': 6, 'col': 3, 'border': [1, 0, 0, 4]})",
71 \ "call popup_create('paddings', {'line': 6, 'col': 23, 'padding': [1, 3, 2, 4]})",
72 \], 'XtestPopupBorder')
73 let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 15})
74 call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {})
75
76 call StopVimInTerminal(buf)
77 call delete('XtestPopupBorder')
78 endfor
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020079
80 let with_border_or_padding = {
81 \ 'line': 2,
82 \ 'core_line': 3,
83 \ 'col': 3,
84 \ 'core_col': 4,
85 \ 'width': 14,
86 \ 'core_width': 12,
87 \ 'height': 3,
88 \ 'core_height': 1,
89 \ 'visible': 1}
90 let winid = popup_create('hello border', {'line': 2, 'col': 3, 'border': []})",
91 call assert_equal(with_border_or_padding, popup_getpos(winid))
92
93 let winid = popup_create('hello paddng', {'line': 2, 'col': 3, 'padding': []})
94 call assert_equal(with_border_or_padding, popup_getpos(winid))
95
96 let winid = popup_create('hello both', {'line': 3, 'col': 8, 'border': [], 'padding': []})
97 call assert_equal({
98 \ 'line': 3,
99 \ 'core_line': 5,
100 \ 'col': 8,
101 \ 'core_col': 10,
102 \ 'width': 14,
103 \ 'core_width': 10,
104 \ 'height': 5,
105 \ 'core_height': 1,
106 \ 'visible': 1}, popup_getpos(winid))
107endfunc
108
Bram Moolenaarb4230122019-05-30 18:40:53 +0200109func Test_popup_with_syntax_win_execute()
110 if !CanRunVimInTerminal()
111 return
112 endif
113 call writefile([
114 \ "call setline(1, range(1, 100))",
115 \ "hi PopupColor ctermbg=lightblue",
116 \ "let winid = popup_create([",
117 \ "\\ '#include <stdio.h>',",
118 \ "\\ 'int main(void)',",
119 \ "\\ '{',",
120 \ "\\ ' printf(123);',",
121 \ "\\ '}',",
122 \ "\\], {'line': 3, 'col': 25, 'highlight': 'PopupColor'})",
123 \ "call win_execute(winid, 'set syntax=cpp')",
124 \], 'XtestPopup')
125 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
126 call VerifyScreenDump(buf, 'Test_popupwin_10', {})
127
128 " clean up
129 call StopVimInTerminal(buf)
130 call delete('XtestPopup')
131endfunc
132
133func Test_popup_with_syntax_setbufvar()
134 if !CanRunVimInTerminal()
135 return
136 endif
Bram Moolenaar402502d2019-05-30 22:07:36 +0200137 let lines =<< trim END
138 call setline(1, range(1, 100))
139 hi PopupColor ctermbg=lightgrey
140 let winid = popup_create([
141 \ '#include <stdio.h>',
142 \ 'int main(void)',
143 \ '{',
144 \ ' printf(567);',
145 \ '}',
146 \], {'line': 3, 'col': 21, 'highlight': 'PopupColor'})
147 call setbufvar(winbufnr(winid), '&syntax', 'cpp')
148 END
149 call writefile(lines, 'XtestPopup')
Bram Moolenaarb4230122019-05-30 18:40:53 +0200150 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
151 call VerifyScreenDump(buf, 'Test_popupwin_11', {})
152
153 " clean up
154 call StopVimInTerminal(buf)
155 call delete('XtestPopup')
156endfunc
157
Bram Moolenaareea16992019-05-31 17:34:48 +0200158func Test_win_execute_closing_curwin()
159 split
160 let winid = popup_create('some text', {})
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200161 call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994')
162 popupclear
163endfunc
164
165func Test_win_execute_not_allowed()
166 let winid = popup_create('some text', {})
167 call assert_fails('call win_execute(winid, "split")', 'E994:')
168 call assert_fails('call win_execute(winid, "vsplit")', 'E994:')
169 call assert_fails('call win_execute(winid, "close")', 'E994:')
170 call assert_fails('call win_execute(winid, "bdelete")', 'E994:')
Bram Moolenaar2d247842019-06-01 17:06:25 +0200171 call assert_fails('call win_execute(winid, "bwipe!")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200172 call assert_fails('call win_execute(winid, "tabnew")', 'E994:')
173 call assert_fails('call win_execute(winid, "tabnext")', 'E994:')
174 call assert_fails('call win_execute(winid, "next")', 'E994:')
175 call assert_fails('call win_execute(winid, "rewind")', 'E994:')
176 call assert_fails('call win_execute(winid, "buf")', 'E994:')
177 call assert_fails('call win_execute(winid, "edit")', 'E994:')
178 call assert_fails('call win_execute(winid, "enew")', 'E994:')
179 call assert_fails('call win_execute(winid, "wincmd x")', 'E994:')
180 call assert_fails('call win_execute(winid, "wincmd w")', 'E994:')
181 call assert_fails('call win_execute(winid, "wincmd t")', 'E994:')
182 call assert_fails('call win_execute(winid, "wincmd b")', 'E994:')
Bram Moolenaareea16992019-05-31 17:34:48 +0200183 popupclear
184endfunc
185
Bram Moolenaar402502d2019-05-30 22:07:36 +0200186func Test_popup_with_wrap()
187 if !CanRunVimInTerminal()
188 return
189 endif
190 let lines =<< trim END
191 call setline(1, range(1, 100))
192 let winid = popup_create(
193 \ 'a long line that wont fit',
194 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1})
195 END
196 call writefile(lines, 'XtestPopup')
197 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
198 call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
199
200 " clean up
201 call StopVimInTerminal(buf)
202 call delete('XtestPopup')
203endfunc
204
205func Test_popup_without_wrap()
206 if !CanRunVimInTerminal()
207 return
208 endif
209 let lines =<< trim END
210 call setline(1, range(1, 100))
211 let winid = popup_create(
212 \ 'a long line that wont fit',
213 \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0})
214 END
215 call writefile(lines, 'XtestPopup')
216 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
217 call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
218
219 " clean up
220 call StopVimInTerminal(buf)
221 call delete('XtestPopup')
222endfunc
223
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200224func Test_popup_time()
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200225 if !has('timers')
226 return
227 endif
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200228 topleft vnew
229 call setline(1, 'hello')
230
231 call popup_create('world', {
232 \ 'line': 1,
233 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200234 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200235 \ 'time': 500,
236 \})
237 redraw
238 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
239 call assert_equal('world', line)
240
241 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200242 redraw
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200243 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
244 call assert_equal('hello', line)
245
246 call popup_create('on the command line', {
247 \ 'line': &lines,
248 \ 'col': 10,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200249 \ 'minwidth': 20,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200250 \ 'time': 500,
251 \})
252 redraw
253 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
254 call assert_match('.*on the command line.*', line)
255
256 sleep 700m
257 redraw
258 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
259 call assert_notmatch('.*on the command line.*', line)
260
261 bwipe!
262endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200263
264func Test_popup_hide()
265 topleft vnew
266 call setline(1, 'hello')
267
268 let winid = popup_create('world', {
269 \ 'line': 1,
270 \ 'col': 1,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200271 \ 'minwidth': 20,
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200272 \})
273 redraw
274 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
275 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200276 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200277 " buffer is still listed and active
278 call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200279
280 call popup_hide(winid)
281 redraw
282 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
283 call assert_equal('hello', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200284 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200285 " buffer is still listed but hidden
286 call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200287
288 call popup_show(winid)
289 redraw
290 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
291 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200292 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200293
294
295 call popup_close(winid)
296 redraw
297 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
298 call assert_equal('hello', line)
299
300 " error is given for existing non-popup window
301 call assert_fails('call popup_hide(win_getid())', 'E993:')
302
303 " no error non-existing window
304 call popup_hide(1234234)
305 call popup_show(41234234)
306
307 bwipe!
308endfunc
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200309
310func Test_popup_move()
311 topleft vnew
312 call setline(1, 'hello')
313
314 let winid = popup_create('world', {
315 \ 'line': 1,
316 \ 'col': 1,
317 \ 'minwidth': 20,
318 \})
319 redraw
320 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
321 call assert_equal('world ', line)
322
323 call popup_move(winid, {'line': 2, 'col': 2})
324 redraw
325 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
326 call assert_equal('hello ', line)
327 let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
328 call assert_equal('~world', line)
329
330 call popup_move(winid, {'line': 1})
331 redraw
332 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
333 call assert_equal('hworld', line)
334
335 call popup_close(winid)
336
337 bwipe!
338endfunc
Bram Moolenaarbc133542019-05-29 20:26:46 +0200339
Bram Moolenaar402502d2019-05-30 22:07:36 +0200340func Test_popup_getpos()
Bram Moolenaarbc133542019-05-29 20:26:46 +0200341 let winid = popup_create('hello', {
342 \ 'line': 2,
343 \ 'col': 3,
344 \ 'minwidth': 10,
345 \ 'minheight': 11,
346 \})
347 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200348 let res = popup_getpos(winid)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200349 call assert_equal(2, res.line)
350 call assert_equal(3, res.col)
351 call assert_equal(10, res.width)
352 call assert_equal(11, res.height)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200353 call assert_equal(1, res.visible)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200354
355 call popup_close(winid)
356endfunc
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200357
358func Test_popup_width_longest()
359 let tests = [
360 \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
361 \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
362 \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
363 \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
364 \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
365 \ ]
366
367 for test in tests
368 let winid = popup_create(test[0], {'line': 2, 'col': 3})
369 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200370 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200371 call assert_equal(test[1], position.width)
372 call popup_close(winid)
373 endfor
374endfunc
375
376func Test_popup_wraps()
377 let tests = [
378 \ ['nowrap', 6, 1],
379 \ ['a line that wraps once', 12, 2],
380 \ ['a line that wraps two times', 12, 3],
381 \ ]
382 for test in tests
383 let winid = popup_create(test[0],
384 \ {'line': 2, 'col': 3, 'maxwidth': 12})
385 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200386 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200387 call assert_equal(test[1], position.width)
388 call assert_equal(test[2], position.height)
389
390 call popup_close(winid)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200391 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200392 endfor
393endfunc
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200394
395func Test_popup_getoptions()
396 let winid = popup_create('hello', {
397 \ 'line': 2,
398 \ 'col': 3,
399 \ 'minwidth': 10,
400 \ 'minheight': 11,
401 \ 'maxwidth': 20,
402 \ 'maxheight': 21,
403 \ 'zindex': 100,
404 \ 'time': 5000,
405 \})
406 redraw
407 let res = popup_getoptions(winid)
408 call assert_equal(2, res.line)
409 call assert_equal(3, res.col)
410 call assert_equal(10, res.minwidth)
411 call assert_equal(11, res.minheight)
412 call assert_equal(20, res.maxwidth)
413 call assert_equal(21, res.maxheight)
414 call assert_equal(100, res.zindex)
415 if has('timers')
416 call assert_equal(5000, res.time)
417 endif
418 call popup_close(winid)
419
420 let winid = popup_create('hello', {})
421 redraw
422 let res = popup_getoptions(winid)
423 call assert_equal(0, res.line)
424 call assert_equal(0, res.col)
425 call assert_equal(0, res.minwidth)
426 call assert_equal(0, res.minheight)
427 call assert_equal(0, res.maxwidth)
428 call assert_equal(0, res.maxheight)
429 call assert_equal(50, res.zindex)
430 if has('timers')
431 call assert_equal(0, res.time)
432 endif
433 call popup_close(winid)
434 call assert_equal({}, popup_getoptions(winid))
435endfunc
Bram Moolenaarcacc6a52019-05-30 15:22:43 +0200436
437func Test_popup_option_values()
438 new
439 " window-local
440 setlocal number
441 setlocal nowrap
442 " buffer-local
443 setlocal omnifunc=Something
444 " global/buffer-local
445 setlocal path=/there
446 " global/window-local
447 setlocal scrolloff=9
448
449 let winid = popup_create('hello', {})
450 call assert_equal(0, getwinvar(winid, '&number'))
451 call assert_equal(1, getwinvar(winid, '&wrap'))
452 call assert_equal('', getwinvar(winid, '&omnifunc'))
453 call assert_equal(&g:path, getwinvar(winid, '&path'))
454 call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff'))
455
456 call popup_close(winid)
457 bwipe
458endfunc
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200459
460func Test_popup_atcursor()
461 topleft vnew
462 call setline(1, [
463 \ 'xxxxxxxxxxxxxxxxx',
464 \ 'xxxxxxxxxxxxxxxxx',
465 \ 'xxxxxxxxxxxxxxxxx',
466 \])
467
468 call cursor(2, 2)
469 redraw
470 let winid = popup_atcursor('vim', {})
471 redraw
472 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
473 call assert_equal('xvimxxxxxxxxxxxxx', line)
474 call popup_close(winid)
475
476 call cursor(3, 4)
477 redraw
478 let winid = popup_atcursor('vim', {})
479 redraw
480 let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
481 call assert_equal('xxxvimxxxxxxxxxxx', line)
482 call popup_close(winid)
483
484 call cursor(1, 1)
485 redraw
486 let winid = popup_create('vim', {
487 \ 'line': 'cursor+2',
488 \ 'col': 'cursor+1',
489 \})
490 redraw
491 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '')
492 call assert_equal('xvimxxxxxxxxxxxxx', line)
493 call popup_close(winid)
494
495 call cursor(3, 3)
496 redraw
497 let winid = popup_create('vim', {
498 \ 'line': 'cursor-2',
499 \ 'col': 'cursor-1',
500 \})
501 redraw
502 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
503 call assert_equal('xvimxxxxxxxxxxxxx', line)
504 call popup_close(winid)
505
Bram Moolenaar402502d2019-05-30 22:07:36 +0200506 " just enough room above
507 call cursor(3, 3)
508 redraw
509 let winid = popup_atcursor(['vim', 'is great'], {})
510 redraw
511 let pos = popup_getpos(winid)
512 call assert_equal(1, pos.line)
513 call popup_close(winid)
514
515 " not enough room above, popup goes below the cursor
516 call cursor(3, 3)
517 redraw
518 let winid = popup_atcursor(['vim', 'is', 'great'], {})
519 redraw
520 let pos = popup_getpos(winid)
521 call assert_equal(4, pos.line)
522 call popup_close(winid)
523
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200524 bwipe!
525endfunc
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200526
527func Test_popup_filter()
528 new
529 call setline(1, 'some text')
530
531 func MyPopupFilter(winid, c)
532 if a:c == 'e'
533 let g:eaten = 'e'
534 return 1
535 endif
536 if a:c == '0'
537 let g:ignored = '0'
538 return 0
539 endif
540 if a:c == 'x'
541 call popup_close(a:winid)
542 return 1
543 endif
544 return 0
545 endfunc
546
547 let winid = popup_create('something', {'filter': 'MyPopupFilter'})
548 redraw
549
550 " e is consumed by the filter
551 call feedkeys('e', 'xt')
552 call assert_equal('e', g:eaten)
553
554 " 0 is ignored by the filter
555 normal $
556 call assert_equal(9, getcurpos()[2])
557 call feedkeys('0', 'xt')
558 call assert_equal('0', g:ignored)
559 call assert_equal(1, getcurpos()[2])
560
561 " x closes the popup
562 call feedkeys('x', 'xt')
563 call assert_equal('e', g:eaten)
564 call assert_equal(-1, winbufnr(winid))
565
566 delfunc MyPopupFilter
567 popupclear
568endfunc