blob: 99b4458250d1fea69a01ca9ca6c223ef9e029c20 [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
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004CheckFeature popupwin
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
Bram Moolenaar1666ac92019-11-10 17:22:31 +010015 hi EndOfBuffer ctermbg=lightgrey
Bram Moolenaare7eb9272019-06-24 00:58:07 +020016 hi Comment ctermfg=red
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020017 call prop_type_add('comment', #{highlight: 'Comment'})
18 let winid = popup_create('hello there', #{line: 3, col: 11, minwidth: 20, highlight: 'PopupColor1'})
19 let winid2 = popup_create(['another one', 'another two', 'another three'], #{line: 3, col: 25, minwidth: 20})
Bram Moolenaare7eb9272019-06-24 00:58:07 +020020 call setwinvar(winid2, '&wincolor', 'PopupColor2')
21 END
22 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020023 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaar4d784b22019-05-25 19:51:39 +020024 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 Moolenaar4c6d9042019-07-16 22:04:02 +020029 \ .. "#{text: 'other tab'},"
30 \ .. "#{text: 'a comment line', props: [#{"
Bram Moolenaard5abb4c2019-07-13 22:46:10 +020031 \ .. "col: 3, length: 7, minwidth: 20, type: 'comment'"
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020032 \ .. "}]},"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +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 Moolenaar202d9822019-06-11 21:56:30 +020044 " set 'columns' to a small value, size must be recomputed
45 call term_sendkeys(buf, ":let cols = &columns\<CR>")
46 call term_sendkeys(buf, ":set columns=12\<CR>")
47 call VerifyScreenDump(buf, 'Test_popupwin_04a', {})
48 call term_sendkeys(buf, ":let &columns = cols\<CR>")
49
Bram Moolenaar17146962019-05-30 00:12:11 +020050 " resize popup, show empty line at bottom
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020051 call term_sendkeys(buf, ":call popup_move(popupwin, #{minwidth: 15, maxwidth: 25, minheight: 3, maxheight: 5})\<CR>")
Bram Moolenaar60cdb302019-05-27 21:54:10 +020052 call term_sendkeys(buf, ":redraw\<CR>")
53 call VerifyScreenDump(buf, 'Test_popupwin_05', {})
54
Bram Moolenaar17146962019-05-30 00:12:11 +020055 " show not fitting line at bottom
56 call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>")
57 call term_sendkeys(buf, ":redraw\<CR>")
58 call VerifyScreenDump(buf, 'Test_popupwin_06', {})
59
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020060 " move popup over ruler
61 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020062 call term_sendkeys(buf, ":call popup_move(popupwin, #{line: 7, col: 55})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +020063 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020064 call VerifyScreenDump(buf, 'Test_popupwin_07', {})
65
66 " clear all popups after moving the cursor a bit, so that ruler is updated
67 call term_sendkeys(buf, "axxx\<Esc>")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +020068 call TermWait(buf)
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020069 call term_sendkeys(buf, "0")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +020070 call TermWait(buf)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +020071 call term_sendkeys(buf, ":call popup_clear()\<CR>")
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020072 call VerifyScreenDump(buf, 'Test_popupwin_08', {})
73
Bram Moolenaar4d784b22019-05-25 19:51:39 +020074 " clean up
75 call StopVimInTerminal(buf)
76 call delete('XtestPopup')
77endfunc
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020078
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020079func Test_popup_with_border_and_padding()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +020080 CheckScreendump
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020081
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +020082 for iter in range(0, 1)
Bram Moolenaare7eb9272019-06-24 00:58:07 +020083 let lines =<< trim END
84 call setline(1, range(1, 100))
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020085 call popup_create('hello border', #{line: 2, col: 3, border: []})
86 call popup_create('hello padding', #{line: 2, col: 23, padding: []})
Bram Moolenaarc363fe12019-08-04 18:13:46 +020087 call popup_create('hello both', #{line: 2, col: 43, border: [], padding: [], highlight: 'Normal'})
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020088 call popup_create('border TL', #{line: 6, col: 3, border: [1, 0, 0, 4]})
Bram Moolenaarb0992022020-01-30 14:55:42 +010089 call popup_create('paddings', #{line: 6, col: 23, padding: range(1, 4)})
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020090 call popup_create('wrapped longer text', #{line: 8, col: 55, padding: [0, 3, 0, 3], border: [0, 1, 0, 1]})
91 call popup_create('right aligned text', #{line: 11, col: 56, wrap: 0, padding: [0, 3, 0, 3], border: [0, 1, 0, 1]})
Bram Moolenaarfbcdf672020-01-06 23:07:48 +010092 call popup_create('X', #{line: 2, col: 73})
93 call popup_create('X', #{line: 3, col: 74})
94 call popup_create('X', #{line: 4, col: 75})
95 call popup_create('X', #{line: 5, col: 76})
Bram Moolenaare7eb9272019-06-24 00:58:07 +020096 END
97 call insert(lines, iter == 1 ? '' : 'set enc=latin1')
98 call writefile(lines, 'XtestPopupBorder')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020099 let buf = RunVimInTerminal('-S XtestPopupBorder', #{rows: 15})
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +0200100 call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {})
101
102 call StopVimInTerminal(buf)
103 call delete('XtestPopupBorder')
104 endfor
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200105
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200106 let lines =<< trim END
107 call setline(1, range(1, 100))
108 hi BlueColor ctermbg=lightblue
109 hi TopColor ctermbg=253
110 hi RightColor ctermbg=245
111 hi BottomColor ctermbg=240
112 hi LeftColor ctermbg=248
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200113 call popup_create('hello border', #{line: 2, col: 3, border: [], borderhighlight: ['BlueColor']})
114 call popup_create(['hello border', 'and more'], #{line: 2, col: 23, border: [], borderhighlight: ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']})
115 call popup_create(['hello border', 'lines only'], #{line: 2, col: 43, border: [], borderhighlight: ['BlueColor'], borderchars: ['x']})
116 call popup_create(['hello border', 'with corners'], #{line: 2, col: 60, border: [], borderhighlight: ['BlueColor'], borderchars: ['x', '#']})
117 let winid = popup_create(['hello border', 'with numbers'], #{line: 6, col: 3, border: [], borderhighlight: ['BlueColor'], borderchars: ['0', '1', '2', '3', '4', '5', '6', '7']})
118 call popup_create(['hello border', 'just blanks'], #{line: 7, col: 23, border: [], borderhighlight: ['BlueColor'], borderchars: [' ']})
Bram Moolenaar3dabd712019-07-08 23:30:22 +0200119 func MultiByte()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200120 call popup_create(['hello'], #{line: 8, col: 43, border: [], borderchars: ['─', '│', '─', '│', '┌', '┐', '┘', '└']})
Bram Moolenaar3dabd712019-07-08 23:30:22 +0200121 endfunc
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200122 END
123 call writefile(lines, 'XtestPopupBorder')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200124 let buf = RunVimInTerminal('-S XtestPopupBorder', #{rows: 12})
Bram Moolenaar790498b2019-06-01 22:15:29 +0200125 call VerifyScreenDump(buf, 'Test_popupwin_22', {})
126
Bram Moolenaarad24a712019-06-17 20:05:45 +0200127 " check that changing borderchars triggers a redraw
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200128 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 +0200129 call VerifyScreenDump(buf, 'Test_popupwin_23', {})
130
Bram Moolenaar3dabd712019-07-08 23:30:22 +0200131 " check multi-byte border only with 'ambiwidth' single
132 if &ambiwidth == 'single'
133 call term_sendkeys(buf, ":call MultiByte()\<CR>")
134 call VerifyScreenDump(buf, 'Test_popupwin_24', {})
135 endif
136
Bram Moolenaar790498b2019-06-01 22:15:29 +0200137 call StopVimInTerminal(buf)
138 call delete('XtestPopupBorder')
139
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200140 let with_border_or_padding = #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200141 \ line: 2,
142 \ core_line: 3,
143 \ col: 3,
144 \ core_col: 4,
145 \ width: 14,
146 \ core_width: 12,
147 \ height: 3,
148 \ core_height: 1,
149 \ firstline: 1,
Bram Moolenaar30efcf32019-11-03 22:29:38 +0100150 \ lastline: 1,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200151 \ scrollbar: 0,
152 \ visible: 1}
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200153 let winid = popup_create('hello border', #{line: 2, col: 3, border: []})",
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200154 call assert_equal(with_border_or_padding, winid->popup_getpos())
Bram Moolenaarae943152019-06-16 22:54:14 +0200155 let options = popup_getoptions(winid)
156 call assert_equal([], options.border)
157 call assert_false(has_key(options, "padding"))
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200158
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200159 let winid = popup_create('hello padding', #{line: 2, col: 3, padding: []})
Bram Moolenaarae943152019-06-16 22:54:14 +0200160 let with_border_or_padding.width = 15
161 let with_border_or_padding.core_width = 13
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200162 call assert_equal(with_border_or_padding, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200163 let options = popup_getoptions(winid)
164 call assert_false(has_key(options, "border"))
165 call assert_equal([], options.padding)
166
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200167 call popup_setoptions(winid, #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200168 \ padding: [1, 2, 3, 4],
169 \ border: [4, 0, 7, 8],
170 \ borderhighlight: ['Top', 'Right', 'Bottom', 'Left'],
171 \ borderchars: ['1', '^', '2', '>', '3', 'v', '4', '<'],
Bram Moolenaarae943152019-06-16 22:54:14 +0200172 \ })
173 let options = popup_getoptions(winid)
174 call assert_equal([1, 0, 1, 1], options.border)
175 call assert_equal([1, 2, 3, 4], options.padding)
176 call assert_equal(['Top', 'Right', 'Bottom', 'Left'], options.borderhighlight)
177 call assert_equal(['1', '^', '2', '>', '3', 'v', '4', '<'], options.borderchars)
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200178
Bram Moolenaara1396152019-10-20 18:46:05 +0200179 " Check that popup_setoptions() takes the output of popup_getoptions()
180 call popup_setoptions(winid, options)
181 call assert_equal(options, popup_getoptions(winid))
182
Bram Moolenaarb0992022020-01-30 14:55:42 +0100183 " Check that range() doesn't crash
184 call popup_setoptions(winid, #{
185 \ padding: range(1, 4),
186 \ border: range(5, 8),
187 \ borderhighlight: range(4),
188 \ borderchars: range(8),
189 \ })
190
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200191 let winid = popup_create('hello both', #{line: 3, col: 8, border: [], padding: []})
192 call assert_equal(#{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200193 \ line: 3,
194 \ core_line: 5,
195 \ col: 8,
196 \ core_col: 10,
197 \ width: 14,
198 \ core_width: 10,
199 \ height: 5,
200 \ scrollbar: 0,
201 \ core_height: 1,
202 \ firstline: 1,
Bram Moolenaar30efcf32019-11-03 22:29:38 +0100203 \ lastline: 1,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200204 \ visible: 1}, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200205
206 call popup_clear()
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200207endfunc
208
Bram Moolenaarb4230122019-05-30 18:40:53 +0200209func Test_popup_with_syntax_win_execute()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200210 CheckScreendump
211
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200212 let lines =<< trim END
213 call setline(1, range(1, 100))
214 hi PopupColor ctermbg=lightblue
215 let winid = popup_create([
216 \ '#include <stdio.h>',
217 \ 'int main(void)',
218 \ '{',
219 \ ' printf(123);',
220 \ '}',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200221 \], #{line: 3, col: 25, highlight: 'PopupColor'})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200222 call win_execute(winid, 'set syntax=cpp')
223 END
224 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200225 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaarb4230122019-05-30 18:40:53 +0200226 call VerifyScreenDump(buf, 'Test_popupwin_10', {})
227
228 " clean up
229 call StopVimInTerminal(buf)
230 call delete('XtestPopup')
231endfunc
232
233func Test_popup_with_syntax_setbufvar()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200234 CheckScreendump
235
Bram Moolenaar402502d2019-05-30 22:07:36 +0200236 let lines =<< trim END
237 call setline(1, range(1, 100))
238 hi PopupColor ctermbg=lightgrey
239 let winid = popup_create([
240 \ '#include <stdio.h>',
241 \ 'int main(void)',
242 \ '{',
Bram Moolenaare089c3f2019-07-09 20:25:25 +0200243 \ "\tprintf(567);",
Bram Moolenaar402502d2019-05-30 22:07:36 +0200244 \ '}',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200245 \], #{line: 3, col: 21, highlight: 'PopupColor'})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200246 call setbufvar(winbufnr(winid), '&syntax', 'cpp')
247 END
248 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200249 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaarb4230122019-05-30 18:40:53 +0200250 call VerifyScreenDump(buf, 'Test_popupwin_11', {})
251
252 " clean up
253 call StopVimInTerminal(buf)
254 call delete('XtestPopup')
255endfunc
256
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200257func Test_popup_with_matches()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200258 CheckScreendump
259
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200260 let lines =<< trim END
261 call setline(1, ['111 222 333', '444 555 666'])
262 let winid = popup_create([
263 \ '111 222 333',
264 \ '444 555 666',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200265 \], #{line: 3, col: 10, border: []})
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200266 set hlsearch
Bram Moolenaar024dbd22019-11-02 22:00:15 +0100267 hi VeryBlue ctermfg=blue guifg=blue
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200268 /666
269 call matchadd('ErrorMsg', '111')
Bram Moolenaar024dbd22019-11-02 22:00:15 +0100270 call matchadd('VeryBlue', '444')
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200271 call win_execute(winid, "call matchadd('ErrorMsg', '111')")
Bram Moolenaar024dbd22019-11-02 22:00:15 +0100272 call win_execute(winid, "call matchadd('VeryBlue', '555')")
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200273 END
274 call writefile(lines, 'XtestPopupMatches')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200275 let buf = RunVimInTerminal('-S XtestPopupMatches', #{rows: 10})
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200276 call VerifyScreenDump(buf, 'Test_popupwin_matches', {})
277
278 " clean up
279 call StopVimInTerminal(buf)
280 call delete('XtestPopupMatches')
281endfunc
282
Bram Moolenaar399d8982019-06-02 15:34:29 +0200283func Test_popup_all_corners()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200284 CheckScreendump
285
Bram Moolenaar399d8982019-06-02 15:34:29 +0200286 let lines =<< trim END
287 call setline(1, repeat([repeat('-', 60)], 15))
288 set so=0
289 normal 2G3|r#
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200290 let winid1 = popup_create(['first', 'second'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200291 \ line: 'cursor+1',
292 \ col: 'cursor',
293 \ pos: 'topleft',
294 \ border: [],
295 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200296 \ })
Bram Moolenaarb754b5b2019-10-24 19:25:00 +0200297 normal 24|r@
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200298 let winid1 = popup_create(['First', 'SeconD'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200299 \ line: 'cursor+1',
300 \ col: 'cursor',
301 \ pos: 'topright',
302 \ border: [],
303 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200304 \ })
Bram Moolenaarb754b5b2019-10-24 19:25:00 +0200305 normal 9G27|r%
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200306 let winid1 = popup_create(['fiRSt', 'seCOnd'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200307 \ line: 'cursor-1',
308 \ col: 'cursor',
309 \ pos: 'botleft',
310 \ border: [],
311 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200312 \ })
Bram Moolenaarb754b5b2019-10-24 19:25:00 +0200313 normal 48|r&
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200314 let winid1 = popup_create(['FIrsT', 'SEcoND'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200315 \ line: 'cursor-1',
316 \ col: 'cursor',
317 \ pos: 'botright',
318 \ border: [],
319 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200320 \ })
Bram Moolenaarb754b5b2019-10-24 19:25:00 +0200321 normal 1G51|r*
322 let winid1 = popup_create(['one', 'two'], #{
323 \ line: 'cursor-1',
324 \ col: 'cursor',
325 \ pos: 'botleft',
326 \ border: [],
327 \ padding: [],
328 \ })
Bram Moolenaar399d8982019-06-02 15:34:29 +0200329 END
330 call writefile(lines, 'XtestPopupCorners')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200331 let buf = RunVimInTerminal('-S XtestPopupCorners', #{rows: 12})
Bram Moolenaar399d8982019-06-02 15:34:29 +0200332 call VerifyScreenDump(buf, 'Test_popupwin_corners', {})
333
334 " clean up
335 call StopVimInTerminal(buf)
336 call delete('XtestPopupCorners')
337endfunc
338
Bram Moolenaar638a4a72019-11-06 19:25:22 +0100339func Test_popup_nospace()
340 CheckScreendump
341
342 let lines =<< trim END
343 call setline(1, repeat([repeat('-', 60)], 15))
344 set so=0
345
346 " cursor in a line in top half, using "botleft" with popup that
347 " does fit
348 normal 5G2|r@
349 let winid1 = popup_create(['one', 'two'], #{
350 \ line: 'cursor-1',
351 \ col: 'cursor',
352 \ pos: 'botleft',
353 \ border: [],
354 \ })
355 " cursor in a line in top half, using "botleft" with popup that
356 " doesn't fit: gets truncated
357 normal 5G9|r#
358 let winid1 = popup_create(['one', 'two', 'tee'], #{
359 \ line: 'cursor-1',
360 \ col: 'cursor',
361 \ pos: 'botleft',
362 \ posinvert: 0,
363 \ border: [],
364 \ })
365 " cursor in a line in top half, using "botleft" with popup that
366 " doesn't fit and 'posinvert' set: flips to below.
367 normal 5G16|r%
368 let winid1 = popup_create(['one', 'two', 'tee'], #{
369 \ line: 'cursor-1',
370 \ col: 'cursor',
371 \ pos: 'botleft',
372 \ border: [],
373 \ })
374 " cursor in a line in bottom half, using "botleft" with popup that
375 " doesn't fit: does not flip.
376 normal 8G23|r*
377 let winid1 = popup_create(['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'], #{
378 \ line: 'cursor-1',
379 \ col: 'cursor',
380 \ pos: 'botleft',
381 \ border: [],
382 \ })
383
384 " cursor in a line in bottom half, using "topleft" with popup that
385 " does fit
386 normal 8G30|r@
387 let winid1 = popup_create(['one', 'two'], #{
388 \ line: 'cursor+1',
389 \ col: 'cursor',
390 \ pos: 'topleft',
391 \ border: [],
392 \ })
393 " cursor in a line in top half, using "topleft" with popup that
394 " doesn't fit: truncated
395 normal 8G37|r#
396 let winid1 = popup_create(['one', 'two', 'tee'], #{
397 \ line: 'cursor+1',
398 \ col: 'cursor',
399 \ pos: 'topleft',
400 \ posinvert: 0,
401 \ border: [],
402 \ })
403 " cursor in a line in top half, using "topleft" with popup that
Bram Moolenaar5c6b6182019-11-10 17:51:38 +0100404 " doesn't fit and "posinvert" set: flips to above.
Bram Moolenaar638a4a72019-11-06 19:25:22 +0100405 normal 8G44|r%
Bram Moolenaar5c6b6182019-11-10 17:51:38 +0100406 let winid1 = popup_create(['one', 'two', 'tee', 'fou', 'fiv'], #{
Bram Moolenaar638a4a72019-11-06 19:25:22 +0100407 \ line: 'cursor+1',
408 \ col: 'cursor',
409 \ pos: 'topleft',
410 \ border: [],
411 \ })
412 " cursor in a line in top half, using "topleft" with popup that
413 " doesn't fit: does not flip.
414 normal 5G51|r*
415 let winid1 = popup_create(['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'], #{
416 \ line: 'cursor+1',
417 \ col: 'cursor',
418 \ pos: 'topleft',
419 \ border: [],
420 \ })
421 END
422 call writefile(lines, 'XtestPopupNospace')
423 let buf = RunVimInTerminal('-S XtestPopupNospace', #{rows: 12})
424 call VerifyScreenDump(buf, 'Test_popupwin_nospace', {})
425
426 " clean up
427 call StopVimInTerminal(buf)
428 call delete('XtestPopupNospace')
429endfunc
430
Bram Moolenaar8d241042019-06-12 23:40:01 +0200431func Test_popup_firstline()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200432 CheckScreendump
433
Bram Moolenaar8d241042019-06-12 23:40:01 +0200434 let lines =<< trim END
435 call setline(1, range(1, 20))
Bram Moolenaar8c6173c2019-08-30 22:08:34 +0200436 let winid = popup_create(['1111', '222222', '33333', '44', '5', '666666', '77777', '888', '9999999999999999'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200437 \ maxheight: 4,
438 \ firstline: 3,
Bram Moolenaar8d241042019-06-12 23:40:01 +0200439 \ })
440 END
441 call writefile(lines, 'XtestPopupFirstline')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200442 let buf = RunVimInTerminal('-S XtestPopupFirstline', #{rows: 10})
Bram Moolenaar8c6173c2019-08-30 22:08:34 +0200443 call VerifyScreenDump(buf, 'Test_popupwin_firstline_1', {})
444
445 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: -1})\<CR>")
446 call term_sendkeys(buf, ":\<CR>")
447 call VerifyScreenDump(buf, 'Test_popupwin_firstline_2', {})
Bram Moolenaar8d241042019-06-12 23:40:01 +0200448
449 " clean up
450 call StopVimInTerminal(buf)
451 call delete('XtestPopupFirstline')
Bram Moolenaarae943152019-06-16 22:54:14 +0200452
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200453 let winid = popup_create(['1111', '222222', '33333', '44444'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200454 \ maxheight: 2,
455 \ firstline: 3,
Bram Moolenaarae943152019-06-16 22:54:14 +0200456 \ })
457 call assert_equal(3, popup_getoptions(winid).firstline)
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200458 call popup_setoptions(winid, #{firstline: 1})
Bram Moolenaarae943152019-06-16 22:54:14 +0200459 call assert_equal(1, popup_getoptions(winid).firstline)
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200460 eval winid->popup_close()
Bram Moolenaar9e67b6a2019-08-30 17:34:08 +0200461
462 let winid = popup_create(['xxx']->repeat(50), #{
463 \ maxheight: 3,
464 \ firstline: 11,
465 \ })
466 redraw
467 call assert_equal(11, popup_getoptions(winid).firstline)
468 call assert_equal(11, popup_getpos(winid).firstline)
Bram Moolenaar8e0a8e72019-09-02 22:56:24 +0200469 " check line() works with popup window
470 call assert_equal(11, line('.', winid))
471 call assert_equal(50, line('$', winid))
472 call assert_equal(0, line('$', 123456))
Bram Moolenaar9e67b6a2019-08-30 17:34:08 +0200473
474 " Normal command changes what is displayed but not "firstline"
475 call win_execute(winid, "normal! \<c-y>")
476 call assert_equal(11, popup_getoptions(winid).firstline)
477 call assert_equal(10, popup_getpos(winid).firstline)
478
479 " Making some property change applies "firstline" again
480 call popup_setoptions(winid, #{line: 4})
481 call assert_equal(11, popup_getoptions(winid).firstline)
482 call assert_equal(11, popup_getpos(winid).firstline)
483
484 " Remove "firstline" property and scroll
485 call popup_setoptions(winid, #{firstline: 0})
486 call win_execute(winid, "normal! \<c-y>")
487 call assert_equal(0, popup_getoptions(winid).firstline)
488 call assert_equal(10, popup_getpos(winid).firstline)
489
490 " Making some property change has no side effect
491 call popup_setoptions(winid, #{line: 3})
492 call assert_equal(0, popup_getoptions(winid).firstline)
493 call assert_equal(10, popup_getpos(winid).firstline)
Bram Moolenaarae943152019-06-16 22:54:14 +0200494
Bram Moolenaar30efcf32019-11-03 22:29:38 +0100495 " CTRL-D scrolls down half a page
496 let winid = popup_create(['xxx']->repeat(50), #{
497 \ maxheight: 8,
498 \ })
499 redraw
500 call assert_equal(1, popup_getpos(winid).firstline)
501 call win_execute(winid, "normal! \<C-D>")
502 call assert_equal(5, popup_getpos(winid).firstline)
503 call win_execute(winid, "normal! \<C-D>")
504 call assert_equal(9, popup_getpos(winid).firstline)
505 call win_execute(winid, "normal! \<C-U>")
506 call assert_equal(5, popup_getpos(winid).firstline)
507
508 call win_execute(winid, "normal! \<C-F>")
509 call assert_equal(11, popup_getpos(winid).firstline)
510 call win_execute(winid, "normal! \<C-B>")
511 call assert_equal(5, popup_getpos(winid).firstline)
512
Bram Moolenaarae943152019-06-16 22:54:14 +0200513 call popup_close(winid)
Bram Moolenaar8d241042019-06-12 23:40:01 +0200514endfunc
515
Bram Moolenaara112f2d2019-09-01 17:38:09 +0200516func Test_popup_noscrolloff()
517 set scrolloff=5
518 let winid = popup_create(['xxx']->repeat(50), #{
519 \ maxheight: 5,
520 \ firstline: 11,
521 \ })
522 redraw
523 call assert_equal(11, popup_getoptions(winid).firstline)
524 call assert_equal(11, popup_getpos(winid).firstline)
525
526 call popup_setoptions(winid, #{firstline: 0})
527 call win_execute(winid, "normal! \<c-y>")
528 call assert_equal(0, popup_getoptions(winid).firstline)
529 call assert_equal(10, popup_getpos(winid).firstline)
530
531 call popup_close(winid)
532endfunc
533
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200534func Test_popup_drag()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200535 CheckScreendump
536
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200537 " create a popup that covers the command line
538 let lines =<< trim END
539 call setline(1, range(1, 20))
Bram Moolenaar356375f2019-08-24 14:46:29 +0200540 split
541 vsplit
542 $wincmd w
543 vsplit
544 1wincmd w
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200545 let winid = popup_create(['1111', '222222', '33333'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200546 \ drag: 1,
Bram Moolenaar9bcb70c2019-08-01 21:11:05 +0200547 \ resize: 1,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200548 \ border: [],
549 \ line: &lines - 4,
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200550 \ })
551 func Dragit()
552 call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
553 endfunc
554 map <silent> <F3> :call test_setmouse(&lines - 4, &columns / 2)<CR>
Bram Moolenaar356375f2019-08-24 14:46:29 +0200555 map <silent> <F4> :call test_setmouse(&lines - 8, &columns / 2 - 20)<CR>
Bram Moolenaar9bcb70c2019-08-01 21:11:05 +0200556 func Resize()
557 call feedkeys("\<F5>\<LeftMouse>\<F6>\<LeftDrag>\<LeftRelease>", "xt")
558 endfunc
Bram Moolenaar356375f2019-08-24 14:46:29 +0200559 map <silent> <F5> :call test_setmouse(6, 21)<CR>
560 map <silent> <F6> :call test_setmouse(7, 25)<CR>
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200561 END
562 call writefile(lines, 'XtestPopupDrag')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200563 let buf = RunVimInTerminal('-S XtestPopupDrag', #{rows: 10})
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200564 call VerifyScreenDump(buf, 'Test_popupwin_drag_01', {})
565
566 call term_sendkeys(buf, ":call Dragit()\<CR>")
567 call VerifyScreenDump(buf, 'Test_popupwin_drag_02', {})
568
Bram Moolenaar9bcb70c2019-08-01 21:11:05 +0200569 call term_sendkeys(buf, ":call Resize()\<CR>")
570 call VerifyScreenDump(buf, 'Test_popupwin_drag_03', {})
571
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200572 " clean up
573 call StopVimInTerminal(buf)
574 call delete('XtestPopupDrag')
575endfunc
576
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200577func Test_popup_close_with_mouse()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200578 CheckScreendump
579
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200580 let lines =<< trim END
581 call setline(1, range(1, 20))
582 " With border, can click on X
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200583 let winid = popup_create('foobar', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200584 \ close: 'button',
585 \ border: [],
586 \ line: 1,
587 \ col: 1,
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200588 \ })
589 func CloseMsg(id, result)
590 echomsg 'Popup closed with ' .. a:result
591 endfunc
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200592 let winid = popup_create('notification', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200593 \ close: 'click',
594 \ line: 3,
595 \ col: 15,
596 \ callback: 'CloseMsg',
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200597 \ })
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200598 let winid = popup_create('no border here', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200599 \ close: 'button',
600 \ line: 5,
601 \ col: 3,
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200602 \ })
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200603 let winid = popup_create('only padding', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200604 \ close: 'button',
605 \ padding: [],
606 \ line: 5,
607 \ col: 23,
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200608 \ })
609 func CloseWithX()
610 call feedkeys("\<F3>\<LeftMouse>\<LeftRelease>", "xt")
611 endfunc
612 map <silent> <F3> :call test_setmouse(1, len('foobar') + 2)<CR>
613 func CloseWithClick()
614 call feedkeys("\<F4>\<LeftMouse>\<LeftRelease>", "xt")
615 endfunc
616 map <silent> <F4> :call test_setmouse(3, 17)<CR>
Bram Moolenaarf6396232019-08-24 19:36:00 +0200617 func CreateWithMenuFilter()
618 let winid = popup_create('barfoo', #{
619 \ close: 'button',
620 \ filter: 'popup_filter_menu',
621 \ border: [],
622 \ line: 1,
623 \ col: 40,
624 \ })
625 endfunc
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200626 END
627 call writefile(lines, 'XtestPopupClose')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200628 let buf = RunVimInTerminal('-S XtestPopupClose', #{rows: 10})
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200629 call VerifyScreenDump(buf, 'Test_popupwin_close_01', {})
630
631 call term_sendkeys(buf, ":call CloseWithX()\<CR>")
632 call VerifyScreenDump(buf, 'Test_popupwin_close_02', {})
633
634 call term_sendkeys(buf, ":call CloseWithClick()\<CR>")
635 call VerifyScreenDump(buf, 'Test_popupwin_close_03', {})
636
Bram Moolenaarf6396232019-08-24 19:36:00 +0200637 call term_sendkeys(buf, ":call CreateWithMenuFilter()\<CR>")
638 call VerifyScreenDump(buf, 'Test_popupwin_close_04', {})
639
640 " We have to send the actual mouse code, feedkeys() would be caught the
641 " filter.
642 call term_sendkeys(buf, "\<Esc>[<0;47;1M")
643 call VerifyScreenDump(buf, 'Test_popupwin_close_05', {})
644
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200645 " clean up
646 call StopVimInTerminal(buf)
647 call delete('XtestPopupClose')
648endfunction
649
Bram Moolenaar7b3d9392019-10-16 22:17:07 +0200650func Test_popup_menu_wrap()
651 CheckScreendump
652
653 let lines =<< trim END
654 call setline(1, range(1, 20))
655 call popup_create([
656 \ 'one',
657 \ 'asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfas',
658 \ 'three',
659 \ 'four',
660 \ ], #{
661 \ pos: "botleft",
662 \ border: [],
663 \ padding: [0,1,0,1],
664 \ maxheight: 3,
665 \ cursorline: 1,
666 \ filter: 'popup_filter_menu',
667 \ })
668 END
669 call writefile(lines, 'XtestPopupWrap')
670 let buf = RunVimInTerminal('-S XtestPopupWrap', #{rows: 10})
671 call VerifyScreenDump(buf, 'Test_popupwin_wrap_1', {})
672
673 call term_sendkeys(buf, "jj")
674 call VerifyScreenDump(buf, 'Test_popupwin_wrap_2', {})
675
676 " clean up
677 call term_sendkeys(buf, "\<Esc>")
678 call StopVimInTerminal(buf)
679 call delete('XtestPopupWrap')
680endfunction
681
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200682func Test_popup_with_mask()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200683 CheckScreendump
684
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200685 let lines =<< trim END
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200686 call setline(1, repeat([join(range(1, 42), '')], 13))
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200687 hi PopupColor ctermbg=lightgrey
688 let winid = popup_create([
689 \ 'some text',
690 \ 'another line',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200691 \], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200692 \ line: 1,
693 \ col: 10,
Bram Moolenaar638a4a72019-11-06 19:25:22 +0100694 \ posinvert: 0,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200695 \ wrap: 0,
696 \ fixed: 1,
697 \ zindex: 90,
698 \ padding: [],
699 \ highlight: 'PopupColor',
700 \ mask: [[1,1,1,1], [-5,-1,4,4], [7,9,2,3], [2,4,3,3]]})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200701 call popup_create([
702 \ 'xxxxxxxxx',
703 \ 'yyyyyyyyy',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200704 \], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200705 \ line: 3,
706 \ col: 18,
707 \ zindex: 20})
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200708 let winidb = popup_create([
709 \ 'just one line',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200710 \], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200711 \ line: 7,
712 \ col: 10,
Bram Moolenaar638a4a72019-11-06 19:25:22 +0100713 \ posinvert: 0,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200714 \ wrap: 0,
715 \ fixed: 1,
716 \ close: 'button',
717 \ zindex: 90,
718 \ padding: [],
719 \ border: [],
720 \ 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 +0200721 END
722 call writefile(lines, 'XtestPopupMask')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200723 let buf = RunVimInTerminal('-S XtestPopupMask', #{rows: 13})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200724 call VerifyScreenDump(buf, 'Test_popupwin_mask_1', {})
725
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200726 call term_sendkeys(buf, ":call popup_move(winid, #{col: 11, line: 2})\<CR>")
727 call term_sendkeys(buf, ":call popup_move(winidb, #{col: 12})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200728 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200729 call VerifyScreenDump(buf, 'Test_popupwin_mask_2', {})
730
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200731 call term_sendkeys(buf, ":call popup_move(winid, #{col: 65, line: 2})\<CR>")
732 call term_sendkeys(buf, ":call popup_move(winidb, #{col: 63})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200733 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaard529ba52019-07-02 23:13:53 +0200734 call VerifyScreenDump(buf, 'Test_popupwin_mask_3', {})
735
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200736 call term_sendkeys(buf, ":call popup_move(winid, #{pos: 'topright', col: 12, line: 2})\<CR>")
737 call term_sendkeys(buf, ":call popup_move(winidb, #{pos: 'topright', col: 12})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200738 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaard529ba52019-07-02 23:13:53 +0200739 call VerifyScreenDump(buf, 'Test_popupwin_mask_4', {})
740
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200741 call term_sendkeys(buf, ":call popup_move(winid, #{pos: 'topright', col: 12, line: 11})\<CR>")
742 call term_sendkeys(buf, ":call popup_move(winidb, #{pos: 'topleft', col: 42, line: 11})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200743 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaarb4207472019-07-12 16:05:45 +0200744 call VerifyScreenDump(buf, 'Test_popupwin_mask_5', {})
745
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200746 " clean up
747 call StopVimInTerminal(buf)
748 call delete('XtestPopupMask')
749endfunc
750
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200751func Test_popup_select()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200752 CheckScreendump
753 CheckFeature clipboard_working
754
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200755 " create a popup with some text to be selected
756 let lines =<< trim END
Bram Moolenaar1755ec42019-06-15 13:13:54 +0200757 set clipboard=autoselect
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200758 call setline(1, range(1, 20))
Bram Moolenaar4dd751b2019-08-17 19:10:53 +0200759 let winid = popup_create(['the word', 'some more', 'several words here', 'invisible', '5', '6', '7'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200760 \ drag: 1,
761 \ border: [],
762 \ line: 3,
763 \ col: 10,
Bram Moolenaar4dd751b2019-08-17 19:10:53 +0200764 \ maxheight: 3,
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200765 \ })
766 func Select1()
767 call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
768 endfunc
769 map <silent> <F3> :call test_setmouse(4, 15)<CR>
770 map <silent> <F4> :call test_setmouse(6, 23)<CR>
771 END
772 call writefile(lines, 'XtestPopupSelect')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200773 let buf = RunVimInTerminal('-S XtestPopupSelect', #{rows: 10})
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200774 call term_sendkeys(buf, ":call Select1()\<CR>")
775 call VerifyScreenDump(buf, 'Test_popupwin_select_01', {})
776
777 call term_sendkeys(buf, ":call popup_close(winid)\<CR>")
778 call term_sendkeys(buf, "\"*p")
Bram Moolenaar8ccabf62019-07-12 18:12:51 +0200779 " clean the command line, sometimes it still shows a command
780 call term_sendkeys(buf, ":\<esc>")
781
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200782 call VerifyScreenDump(buf, 'Test_popupwin_select_02', {})
783
784 " clean up
785 call StopVimInTerminal(buf)
786 call delete('XtestPopupSelect')
787endfunc
788
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200789func Test_popup_in_tab()
790 " default popup is local to tab, not visible when in other tab
791 let winid = popup_create("text", {})
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200792 let bufnr = winbufnr(winid)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200793 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200794 call assert_equal(0, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200795 tabnew
796 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200797 call assert_equal(1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200798 quit
799 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200800
801 call assert_equal(1, bufexists(bufnr))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200802 call popup_clear()
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200803 " buffer is gone now
804 call assert_equal(0, bufexists(bufnr))
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200805
806 " global popup is visible in any tab
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200807 let winid = popup_create("text", #{tabpage: -1})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200808 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200809 call assert_equal(-1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200810 tabnew
811 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200812 call assert_equal(-1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200813 quit
814 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200815 call popup_clear()
Bram Moolenaara3fce622019-06-20 02:31:49 +0200816
817 " create popup in other tab
818 tabnew
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200819 let winid = popup_create("text", #{tabpage: 1})
Bram Moolenaara3fce622019-06-20 02:31:49 +0200820 call assert_equal(0, popup_getpos(winid).visible)
821 call assert_equal(1, popup_getoptions(winid).tabpage)
822 quit
823 call assert_equal(1, popup_getpos(winid).visible)
824 call assert_equal(0, popup_getoptions(winid).tabpage)
825 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200826endfunc
827
828func Test_popup_valid_arguments()
829 " Zero value is like the property wasn't there
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200830 let winid = popup_create("text", #{col: 0})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200831 let pos = popup_getpos(winid)
832 call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200833 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200834
835 " using cursor column has minimum value of 1
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200836 let winid = popup_create("text", #{col: 'cursor-100'})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200837 let pos = popup_getpos(winid)
838 call assert_equal(1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200839 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200840
841 " center
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200842 let winid = popup_create("text", #{pos: 'center'})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200843 let pos = popup_getpos(winid)
844 let around = (&columns - pos.width) / 2
845 call assert_inrange(around - 1, around + 1, pos.col)
846 let around = (&lines - pos.height) / 2
847 call assert_inrange(around - 1, around + 1, pos.line)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200848 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200849endfunc
850
851func Test_popup_invalid_arguments()
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +0200852 call assert_fails('call popup_create(666, {})', 'E86:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200853 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200854 call assert_fails('call popup_create("text", "none")', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200855 call popup_clear()
Bram Moolenaarad48e6c2020-04-21 22:19:45 +0200856 call assert_fails('call popup_create(test_null_string(), {})', 'E450:')
857 call assert_fails('call popup_create(test_null_list(), {})', 'E450:')
858 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200859
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200860 call assert_fails('call popup_create("text", #{col: "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200861 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200862 call assert_fails('call popup_create("text", #{col: "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200863 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200864 call assert_fails('call popup_create("text", #{col: "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200865 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200866 call assert_fails('call popup_create("text", #{col: "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200867 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200868
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200869 call assert_fails('call popup_create("text", #{line: "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200870 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200871 call assert_fails('call popup_create("text", #{line: "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200872 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200873 call assert_fails('call popup_create("text", #{line: "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200874 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200875 call assert_fails('call popup_create("text", #{line: "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200876 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200877
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200878 call assert_fails('call popup_create("text", #{pos: "there"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200879 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200880 call assert_fails('call popup_create("text", #{padding: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200881 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200882 call assert_fails('call popup_create("text", #{border: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200883 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200884 call assert_fails('call popup_create("text", #{borderhighlight: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200885 call popup_clear()
Bram Moolenaar403d0902019-07-17 21:37:32 +0200886 call assert_fails('call popup_create("text", #{borderhighlight: test_null_list()})', 'E714:')
887 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200888 call assert_fails('call popup_create("text", #{borderchars: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200889 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200890
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200891 call assert_fails('call popup_create([#{text: "text"}, 666], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200892 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200893 call assert_fails('call popup_create([#{text: "text", props: "none"}], {})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200894 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200895 call assert_fails('call popup_create([#{text: "text", props: ["none"]}], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200896 call popup_clear()
Bram Moolenaarb0992022020-01-30 14:55:42 +0100897 call assert_fails('call popup_create([#{text: "text", props: range(3)}], {})', 'E715:')
898 call popup_clear()
Bram Moolenaarcfdbc5a2019-07-17 21:27:52 +0200899 call assert_fails('call popup_create("text", #{mask: ["asdf"]})', 'E475:')
900 call popup_clear()
Bram Moolenaarb0992022020-01-30 14:55:42 +0100901 call assert_fails('call popup_create("text", #{mask: range(5)})', 'E475:')
902 call popup_clear()
903 call popup_create("text", #{mask: [range(4)]})
904 call popup_clear()
Bram Moolenaarcfdbc5a2019-07-17 21:27:52 +0200905 call assert_fails('call popup_create("text", #{mask: test_null_list()})', 'E475:')
Bram Moolenaar749fa0a2019-08-03 16:18:07 +0200906 call assert_fails('call popup_create("text", #{mapping: []})', 'E745:')
Bram Moolenaarcfdbc5a2019-07-17 21:27:52 +0200907 call popup_clear()
Bram Moolenaarad48e6c2020-04-21 22:19:45 +0200908 call assert_fails('call popup_create("text", #{tabpage : 4})', 'E997:')
909 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200910endfunc
911
Bram Moolenaareea16992019-05-31 17:34:48 +0200912func Test_win_execute_closing_curwin()
913 split
914 let winid = popup_create('some text', {})
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200915 call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200916 call popup_clear()
Bram Moolenaar49540192019-12-11 19:34:54 +0100917
918 let winid = popup_create('some text', {})
919 call assert_fails('call win_execute(winid, printf("normal! :\<C-u>call popup_close(%d)\<CR>", winid))', 'E994')
920 call popup_clear()
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200921endfunc
922
923func Test_win_execute_not_allowed()
924 let winid = popup_create('some text', {})
925 call assert_fails('call win_execute(winid, "split")', 'E994:')
926 call assert_fails('call win_execute(winid, "vsplit")', 'E994:')
927 call assert_fails('call win_execute(winid, "close")', 'E994:')
928 call assert_fails('call win_execute(winid, "bdelete")', 'E994:')
Bram Moolenaar2d247842019-06-01 17:06:25 +0200929 call assert_fails('call win_execute(winid, "bwipe!")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200930 call assert_fails('call win_execute(winid, "tabnew")', 'E994:')
931 call assert_fails('call win_execute(winid, "tabnext")', 'E994:')
932 call assert_fails('call win_execute(winid, "next")', 'E994:')
933 call assert_fails('call win_execute(winid, "rewind")', 'E994:')
Bram Moolenaar3a2505c2020-03-09 16:40:41 +0100934 call assert_fails('call win_execute(winid, "pedit filename")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200935 call assert_fails('call win_execute(winid, "buf")', 'E994:')
Bram Moolenaar3029bcc2020-01-18 15:06:19 +0100936 call assert_fails('call win_execute(winid, "bnext")', 'E994:')
937 call assert_fails('call win_execute(winid, "bprev")', 'E994:')
938 call assert_fails('call win_execute(winid, "bfirst")', 'E994:')
939 call assert_fails('call win_execute(winid, "blast")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200940 call assert_fails('call win_execute(winid, "edit")', 'E994:')
941 call assert_fails('call win_execute(winid, "enew")', 'E994:')
942 call assert_fails('call win_execute(winid, "wincmd x")', 'E994:')
943 call assert_fails('call win_execute(winid, "wincmd w")', 'E994:')
944 call assert_fails('call win_execute(winid, "wincmd t")', 'E994:')
945 call assert_fails('call win_execute(winid, "wincmd b")', 'E994:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200946 call popup_clear()
Bram Moolenaareea16992019-05-31 17:34:48 +0200947endfunc
948
Bram Moolenaar402502d2019-05-30 22:07:36 +0200949func Test_popup_with_wrap()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200950 CheckScreendump
951
Bram Moolenaar402502d2019-05-30 22:07:36 +0200952 let lines =<< trim END
953 call setline(1, range(1, 100))
954 let winid = popup_create(
955 \ 'a long line that wont fit',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200956 \ #{line: 3, col: 20, maxwidth: 10, wrap: 1})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200957 END
958 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200959 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200960 call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
961
962 " clean up
963 call StopVimInTerminal(buf)
964 call delete('XtestPopup')
965endfunc
966
967func Test_popup_without_wrap()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200968 CheckScreendump
969
Bram Moolenaar402502d2019-05-30 22:07:36 +0200970 let lines =<< trim END
971 call setline(1, range(1, 100))
972 let winid = popup_create(
973 \ 'a long line that wont fit',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200974 \ #{line: 3, col: 20, maxwidth: 10, wrap: 0})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200975 END
976 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200977 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200978 call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
979
980 " clean up
981 call StopVimInTerminal(buf)
982 call delete('XtestPopup')
983endfunc
984
Bram Moolenaar331bafd2019-07-20 17:46:05 +0200985func Test_popup_with_showbreak()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200986 CheckScreendump
987
Bram Moolenaar331bafd2019-07-20 17:46:05 +0200988 let lines =<< trim END
989 set showbreak=>>\
990 call setline(1, range(1, 20))
991 let winid = popup_dialog(
Bram Moolenaar8ae54372019-09-15 18:11:16 +0200992 \ 'a long line here that wraps',
993 \ #{filter: 'popup_filter_yesno',
994 \ maxwidth: 12})
Bram Moolenaar331bafd2019-07-20 17:46:05 +0200995 END
996 call writefile(lines, 'XtestPopupShowbreak')
997 let buf = RunVimInTerminal('-S XtestPopupShowbreak', #{rows: 10})
998 call VerifyScreenDump(buf, 'Test_popupwin_showbreak', {})
999
1000 " clean up
1001 call term_sendkeys(buf, "y")
1002 call StopVimInTerminal(buf)
1003 call delete('XtestPopupShowbreak')
1004endfunc
1005
Bram Moolenaar51fe3b12019-05-26 20:10:06 +02001006func Test_popup_time()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001007 CheckFeature timers
1008
Bram Moolenaar51fe3b12019-05-26 20:10:06 +02001009 topleft vnew
1010 call setline(1, 'hello')
1011
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001012 let winid = popup_create('world', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001013 \ line: 1,
1014 \ col: 1,
1015 \ minwidth: 20,
1016 \ time: 500,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +02001017 \})
1018 redraw
1019 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
1020 call assert_equal('world', line)
1021
Bram Moolenaarb4f06282019-07-12 21:07:54 +02001022 call assert_equal(winid, popup_locate(1, 1))
1023 call assert_equal(winid, popup_locate(1, 20))
1024 call assert_equal(0, popup_locate(1, 21))
1025 call assert_equal(0, popup_locate(2, 1))
1026
Bram Moolenaar51fe3b12019-05-26 20:10:06 +02001027 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +02001028 redraw
Bram Moolenaar196b4662019-09-06 21:34:30 +02001029 let line = join(map(range(1, 5), '1->screenstring(v:val)'), '')
Bram Moolenaar51fe3b12019-05-26 20:10:06 +02001030 call assert_equal('hello', line)
1031
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001032 call popup_create('on the command line', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001033 \ line: &lines,
1034 \ col: 10,
1035 \ minwidth: 20,
1036 \ time: 500,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +02001037 \})
1038 redraw
1039 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
1040 call assert_match('.*on the command line.*', line)
1041
1042 sleep 700m
1043 redraw
1044 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
1045 call assert_notmatch('.*on the command line.*', line)
1046
1047 bwipe!
1048endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001049
1050func Test_popup_hide()
1051 topleft vnew
1052 call setline(1, 'hello')
1053
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001054 let winid = popup_create('world', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001055 \ line: 1,
1056 \ col: 1,
1057 \ minwidth: 20,
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001058 \})
1059 redraw
1060 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
1061 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +02001062 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +02001063 " buffer is still listed and active
1064 call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001065
1066 call popup_hide(winid)
1067 redraw
1068 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
1069 call assert_equal('hello', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +02001070 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +02001071 " buffer is still listed but hidden
Bram Moolenaarca7c0782020-01-14 20:42:48 +01001072 call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001073
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001074 eval winid->popup_show()
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001075 redraw
1076 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
1077 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +02001078 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001079
1080
1081 call popup_close(winid)
1082 redraw
1083 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
1084 call assert_equal('hello', line)
1085
1086 " error is given for existing non-popup window
1087 call assert_fails('call popup_hide(win_getid())', 'E993:')
1088
1089 " no error non-existing window
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001090 eval 1234234->popup_hide()
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001091 call popup_show(41234234)
1092
1093 bwipe!
1094endfunc
Bram Moolenaar60cdb302019-05-27 21:54:10 +02001095
1096func Test_popup_move()
1097 topleft vnew
1098 call setline(1, 'hello')
1099
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001100 let winid = popup_create('world', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001101 \ line: 1,
1102 \ col: 1,
1103 \ minwidth: 20,
Bram Moolenaar60cdb302019-05-27 21:54:10 +02001104 \})
1105 redraw
1106 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
1107 call assert_equal('world ', line)
1108
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001109 call popup_move(winid, #{line: 2, col: 2})
Bram Moolenaar60cdb302019-05-27 21:54:10 +02001110 redraw
1111 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
1112 call assert_equal('hello ', line)
1113 let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
1114 call assert_equal('~world', line)
1115
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001116 eval winid->popup_move(#{line: 1})
Bram Moolenaar60cdb302019-05-27 21:54:10 +02001117 redraw
1118 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
1119 call assert_equal('hworld', line)
1120
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001121 call assert_fails('call popup_move(winid, [])', 'E715:')
1122 call assert_fails('call popup_move(winid, test_null_dict())', 'E715:')
1123
Bram Moolenaar60cdb302019-05-27 21:54:10 +02001124 call popup_close(winid)
1125
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02001126 call assert_equal(0, popup_move(-1, {}))
1127
Bram Moolenaar60cdb302019-05-27 21:54:10 +02001128 bwipe!
1129endfunc
Bram Moolenaarbc133542019-05-29 20:26:46 +02001130
Bram Moolenaar402502d2019-05-30 22:07:36 +02001131func Test_popup_getpos()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001132 let winid = popup_create('hello', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001133 \ line: 2,
1134 \ col: 3,
1135 \ minwidth: 10,
1136 \ minheight: 11,
Bram Moolenaarbc133542019-05-29 20:26:46 +02001137 \})
1138 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +02001139 let res = popup_getpos(winid)
Bram Moolenaarbc133542019-05-29 20:26:46 +02001140 call assert_equal(2, res.line)
1141 call assert_equal(3, res.col)
1142 call assert_equal(10, res.width)
1143 call assert_equal(11, res.height)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001144 call assert_equal(1, res.visible)
Bram Moolenaarbc133542019-05-29 20:26:46 +02001145
1146 call popup_close(winid)
1147endfunc
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +02001148
1149func Test_popup_width_longest()
1150 let tests = [
1151 \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
1152 \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
1153 \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
1154 \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
1155 \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
1156 \ ]
1157
1158 for test in tests
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001159 let winid = popup_create(test[0], #{line: 2, col: 3})
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +02001160 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +02001161 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +02001162 call assert_equal(test[1], position.width)
1163 call popup_close(winid)
1164 endfor
1165endfunc
1166
1167func Test_popup_wraps()
1168 let tests = [
1169 \ ['nowrap', 6, 1],
1170 \ ['a line that wraps once', 12, 2],
1171 \ ['a line that wraps two times', 12, 3],
1172 \ ]
1173 for test in tests
1174 let winid = popup_create(test[0],
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001175 \ #{line: 2, col: 3, maxwidth: 12})
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +02001176 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +02001177 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +02001178 call assert_equal(test[1], position.width)
1179 call assert_equal(test[2], position.height)
1180
1181 call popup_close(winid)
Bram Moolenaar402502d2019-05-30 22:07:36 +02001182 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +02001183 endfor
1184endfunc
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001185
1186func Test_popup_getoptions()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001187 let winid = popup_create('hello', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001188 \ line: 2,
1189 \ col: 3,
1190 \ minwidth: 10,
1191 \ minheight: 11,
1192 \ maxwidth: 20,
1193 \ maxheight: 21,
1194 \ zindex: 100,
1195 \ time: 5000,
1196 \ fixed: 1
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001197 \})
1198 redraw
1199 let res = popup_getoptions(winid)
1200 call assert_equal(2, res.line)
1201 call assert_equal(3, res.col)
1202 call assert_equal(10, res.minwidth)
1203 call assert_equal(11, res.minheight)
1204 call assert_equal(20, res.maxwidth)
1205 call assert_equal(21, res.maxheight)
1206 call assert_equal(100, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001207 call assert_equal(1, res.fixed)
Bram Moolenaarb8350ab2019-08-04 17:59:49 +02001208 call assert_equal(1, res.mapping)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001209 if has('timers')
1210 call assert_equal(5000, res.time)
1211 endif
1212 call popup_close(winid)
1213
1214 let winid = popup_create('hello', {})
1215 redraw
1216 let res = popup_getoptions(winid)
1217 call assert_equal(0, res.line)
1218 call assert_equal(0, res.col)
1219 call assert_equal(0, res.minwidth)
1220 call assert_equal(0, res.minheight)
1221 call assert_equal(0, res.maxwidth)
1222 call assert_equal(0, res.maxheight)
1223 call assert_equal(50, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001224 call assert_equal(0, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001225 if has('timers')
1226 call assert_equal(0, res.time)
1227 endif
1228 call popup_close(winid)
1229 call assert_equal({}, popup_getoptions(winid))
1230endfunc
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02001231
1232func Test_popup_option_values()
1233 new
1234 " window-local
1235 setlocal number
1236 setlocal nowrap
1237 " buffer-local
1238 setlocal omnifunc=Something
1239 " global/buffer-local
1240 setlocal path=/there
1241 " global/window-local
Bram Moolenaara112f2d2019-09-01 17:38:09 +02001242 setlocal statusline=2
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02001243
1244 let winid = popup_create('hello', {})
1245 call assert_equal(0, getwinvar(winid, '&number'))
1246 call assert_equal(1, getwinvar(winid, '&wrap'))
1247 call assert_equal('', getwinvar(winid, '&omnifunc'))
1248 call assert_equal(&g:path, getwinvar(winid, '&path'))
Bram Moolenaara112f2d2019-09-01 17:38:09 +02001249 call assert_equal(&g:statusline, getwinvar(winid, '&statusline'))
1250
1251 " 'scrolloff' is reset to zero
1252 call assert_equal(5, &scrolloff)
1253 call assert_equal(0, getwinvar(winid, '&scrolloff'))
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02001254
1255 call popup_close(winid)
1256 bwipe
1257endfunc
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001258
1259func Test_popup_atcursor()
1260 topleft vnew
1261 call setline(1, [
1262 \ 'xxxxxxxxxxxxxxxxx',
1263 \ 'xxxxxxxxxxxxxxxxx',
1264 \ 'xxxxxxxxxxxxxxxxx',
1265 \])
1266
1267 call cursor(2, 2)
1268 redraw
1269 let winid = popup_atcursor('vim', {})
1270 redraw
1271 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
1272 call assert_equal('xvimxxxxxxxxxxxxx', line)
1273 call popup_close(winid)
1274
1275 call cursor(3, 4)
1276 redraw
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001277 let winid = 'vim'->popup_atcursor({})
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001278 redraw
1279 let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
1280 call assert_equal('xxxvimxxxxxxxxxxx', line)
1281 call popup_close(winid)
1282
1283 call cursor(1, 1)
1284 redraw
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001285 let winid = popup_create('vim', #{
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001286 \ line: 'cursor+2',
1287 \ col: 'cursor+1',
1288 \})
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001289 redraw
1290 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '')
1291 call assert_equal('xvimxxxxxxxxxxxxx', line)
1292 call popup_close(winid)
1293
1294 call cursor(3, 3)
1295 redraw
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001296 let winid = popup_create('vim', #{
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001297 \ line: 'cursor-2',
1298 \ col: 'cursor-1',
1299 \})
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001300 redraw
1301 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
1302 call assert_equal('xvimxxxxxxxxxxxxx', line)
1303 call popup_close(winid)
1304
Bram Moolenaar402502d2019-05-30 22:07:36 +02001305 " just enough room above
1306 call cursor(3, 3)
1307 redraw
1308 let winid = popup_atcursor(['vim', 'is great'], {})
1309 redraw
1310 let pos = popup_getpos(winid)
1311 call assert_equal(1, pos.line)
1312 call popup_close(winid)
1313
1314 " not enough room above, popup goes below the cursor
1315 call cursor(3, 3)
1316 redraw
1317 let winid = popup_atcursor(['vim', 'is', 'great'], {})
1318 redraw
1319 let pos = popup_getpos(winid)
1320 call assert_equal(4, pos.line)
1321 call popup_close(winid)
1322
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +02001323 " cursor in first line, popup in line 2
1324 call cursor(1, 1)
1325 redraw
1326 let winid = popup_atcursor(['vim', 'is', 'great'], {})
1327 redraw
1328 let pos = popup_getpos(winid)
1329 call assert_equal(2, pos.line)
1330 call popup_close(winid)
1331
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001332 bwipe!
1333endfunc
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001334
Bram Moolenaar4dd8fe02019-11-09 15:33:31 +01001335func Test_popup_atcursor_pos()
1336 CheckScreendump
1337
1338 let lines =<< trim END
1339 call setline(1, repeat([repeat('-', 60)], 15))
1340 set so=0
1341
1342 normal 9G3|r#
1343 let winid1 = popup_atcursor(['first', 'second'], #{
1344 \ moved: [0, 0, 0],
1345 \ })
1346 normal 9G21|r&
1347 let winid1 = popup_atcursor(['FIrsT', 'SEcoND'], #{
1348 \ pos: 'botright',
1349 \ moved: [0, 0, 0],
1350 \ })
1351 normal 3G27|r%
1352 let winid1 = popup_atcursor(['fiRSt', 'seCOnd'], #{
1353 \ pos: 'topleft',
1354 \ moved: [0, 0, 0],
1355 \ })
1356 normal 3G45|r@
1357 let winid1 = popup_atcursor(['First', 'SeconD'], #{
1358 \ pos: 'topright',
Bram Moolenaarb0992022020-01-30 14:55:42 +01001359 \ moved: range(3),
1360 \ mousemoved: range(3),
Bram Moolenaar4dd8fe02019-11-09 15:33:31 +01001361 \ })
1362 END
1363 call writefile(lines, 'XtestPopupAtcursorPos')
1364 let buf = RunVimInTerminal('-S XtestPopupAtcursorPos', #{rows: 12})
1365 call VerifyScreenDump(buf, 'Test_popupwin_atcursor_pos', {})
1366
1367 " clean up
1368 call StopVimInTerminal(buf)
1369 call delete('XtestPopupAtcursorPos')
1370endfunc
1371
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001372func Test_popup_beval()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001373 CheckScreendump
Bram Moolenaar1e82a782019-09-21 22:57:06 +02001374 CheckFeature balloon_eval_term
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001375
1376 let lines =<< trim END
1377 call setline(1, range(1, 20))
1378 call setline(5, 'here is some text to hover over')
1379 set balloonevalterm
1380 set balloonexpr=BalloonExpr()
1381 set balloondelay=100
1382 func BalloonExpr()
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001383 let s:winid = [v:beval_text]->popup_beval({})
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001384 return ''
1385 endfunc
1386 func Hover()
1387 call test_setmouse(5, 15)
1388 call feedkeys("\<MouseMove>\<Ignore>", "xt")
1389 sleep 100m
1390 endfunc
1391 func MoveOntoPopup()
1392 call test_setmouse(4, 17)
1393 call feedkeys("\<F4>\<MouseMove>\<Ignore>", "xt")
1394 endfunc
1395 func MoveAway()
1396 call test_setmouse(5, 13)
1397 call feedkeys("\<F5>\<MouseMove>\<Ignore>", "xt")
1398 endfunc
1399 END
1400 call writefile(lines, 'XtestPopupBeval')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001401 let buf = RunVimInTerminal('-S XtestPopupBeval', #{rows: 10})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02001402 call TermWait(buf, 50)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001403 call term_sendkeys(buf, 'j')
1404 call term_sendkeys(buf, ":call Hover()\<CR>")
1405 call VerifyScreenDump(buf, 'Test_popupwin_beval_1', {})
1406
1407 call term_sendkeys(buf, ":call MoveOntoPopup()\<CR>")
1408 call VerifyScreenDump(buf, 'Test_popupwin_beval_2', {})
1409
1410 call term_sendkeys(buf, ":call MoveAway()\<CR>")
1411 call VerifyScreenDump(buf, 'Test_popupwin_beval_3', {})
1412
1413 " clean up
1414 call StopVimInTerminal(buf)
1415 call delete('XtestPopupBeval')
1416endfunc
1417
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001418func Test_popup_filter()
1419 new
1420 call setline(1, 'some text')
1421
1422 func MyPopupFilter(winid, c)
Bram Moolenaarec084d32020-02-28 22:44:47 +01001423 if a:c == 'e' || a:c == "\<F9>"
1424 let g:eaten = a:c
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001425 return 1
1426 endif
1427 if a:c == '0'
1428 let g:ignored = '0'
1429 return 0
1430 endif
1431 if a:c == 'x'
1432 call popup_close(a:winid)
1433 return 1
1434 endif
1435 return 0
1436 endfunc
1437
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001438 let winid = 'something'->popup_create(#{filter: 'MyPopupFilter'})
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001439 redraw
1440
1441 " e is consumed by the filter
1442 call feedkeys('e', 'xt')
1443 call assert_equal('e', g:eaten)
Bram Moolenaarec084d32020-02-28 22:44:47 +01001444 call feedkeys("\<F9>", 'xt')
1445 call assert_equal("\<F9>", g:eaten)
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001446
1447 " 0 is ignored by the filter
1448 normal $
1449 call assert_equal(9, getcurpos()[2])
1450 call feedkeys('0', 'xt')
1451 call assert_equal('0', g:ignored)
1452 call assert_equal(1, getcurpos()[2])
1453
1454 " x closes the popup
1455 call feedkeys('x', 'xt')
Bram Moolenaarec084d32020-02-28 22:44:47 +01001456 call assert_equal("\<F9>", g:eaten)
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001457 call assert_equal(-1, winbufnr(winid))
1458
1459 delfunc MyPopupFilter
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001460 call popup_clear()
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001461endfunc
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001462
Bram Moolenaara42d9452019-06-15 21:46:30 +02001463func ShowDialog(key, result)
1464 let s:cb_res = 999
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001465 let winid = popup_dialog('do you want to quit (Yes/no)?', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001466 \ filter: 'popup_filter_yesno',
1467 \ callback: 'QuitCallback',
Bram Moolenaara42d9452019-06-15 21:46:30 +02001468 \ })
1469 redraw
1470 call feedkeys(a:key, "xt")
1471 call assert_equal(winid, s:cb_winid)
1472 call assert_equal(a:result, s:cb_res)
1473endfunc
1474
1475func Test_popup_dialog()
1476 func QuitCallback(id, res)
1477 let s:cb_winid = a:id
1478 let s:cb_res = a:res
1479 endfunc
1480
1481 let winid = ShowDialog("y", 1)
1482 let winid = ShowDialog("Y", 1)
1483 let winid = ShowDialog("n", 0)
1484 let winid = ShowDialog("N", 0)
1485 let winid = ShowDialog("x", 0)
1486 let winid = ShowDialog("X", 0)
1487 let winid = ShowDialog("\<Esc>", 0)
1488 let winid = ShowDialog("\<C-C>", -1)
1489
1490 delfunc QuitCallback
1491endfunc
1492
Bram Moolenaara730e552019-06-16 19:05:31 +02001493func ShowMenu(key, result)
1494 let s:cb_res = 999
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001495 let winid = popup_menu(['one', 'two', 'something else'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001496 \ callback: 'QuitCallback',
Bram Moolenaara730e552019-06-16 19:05:31 +02001497 \ })
1498 redraw
1499 call feedkeys(a:key, "xt")
1500 call assert_equal(winid, s:cb_winid)
1501 call assert_equal(a:result, s:cb_res)
1502endfunc
1503
1504func Test_popup_menu()
1505 func QuitCallback(id, res)
1506 let s:cb_winid = a:id
1507 let s:cb_res = a:res
1508 endfunc
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02001509 " mapping won't be used in popup
1510 map j k
Bram Moolenaara730e552019-06-16 19:05:31 +02001511
1512 let winid = ShowMenu(" ", 1)
1513 let winid = ShowMenu("j \<CR>", 2)
1514 let winid = ShowMenu("JjK \<CR>", 2)
1515 let winid = ShowMenu("jjjjjj ", 3)
1516 let winid = ShowMenu("kkk ", 1)
1517 let winid = ShowMenu("x", -1)
1518 let winid = ShowMenu("X", -1)
1519 let winid = ShowMenu("\<Esc>", -1)
1520 let winid = ShowMenu("\<C-C>", -1)
1521
1522 delfunc QuitCallback
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02001523 unmap j
Bram Moolenaara730e552019-06-16 19:05:31 +02001524endfunc
1525
1526func Test_popup_menu_screenshot()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001527 CheckScreendump
Bram Moolenaara730e552019-06-16 19:05:31 +02001528
1529 let lines =<< trim END
1530 call setline(1, range(1, 20))
1531 hi PopupSelected ctermbg=lightblue
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001532 call popup_menu(['one', 'two', 'another'], #{callback: 'MenuDone', title: ' make a choice from the list '})
Bram Moolenaara730e552019-06-16 19:05:31 +02001533 func MenuDone(id, res)
1534 echomsg "selected " .. a:res
1535 endfunc
1536 END
1537 call writefile(lines, 'XtestPopupMenu')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001538 let buf = RunVimInTerminal('-S XtestPopupMenu', #{rows: 10})
Bram Moolenaara730e552019-06-16 19:05:31 +02001539 call VerifyScreenDump(buf, 'Test_popupwin_menu_01', {})
1540
1541 call term_sendkeys(buf, "jj")
1542 call VerifyScreenDump(buf, 'Test_popupwin_menu_02', {})
1543
1544 call term_sendkeys(buf, " ")
1545 call VerifyScreenDump(buf, 'Test_popupwin_menu_03', {})
1546
1547 " clean up
1548 call StopVimInTerminal(buf)
1549 call delete('XtestPopupMenu')
1550endfunc
1551
Bram Moolenaarf914a332019-07-20 15:09:56 +02001552func Test_popup_menu_narrow()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001553 CheckScreendump
Bram Moolenaarf914a332019-07-20 15:09:56 +02001554
1555 let lines =<< trim END
1556 call setline(1, range(1, 20))
1557 hi PopupSelected ctermbg=green
1558 call popup_menu(['one', 'two', 'three'], #{callback: 'MenuDone'})
1559 func MenuDone(id, res)
1560 echomsg "selected " .. a:res
1561 endfunc
1562 END
1563 call writefile(lines, 'XtestPopupNarrowMenu')
1564 let buf = RunVimInTerminal('-S XtestPopupNarrowMenu', #{rows: 10})
1565 call VerifyScreenDump(buf, 'Test_popupwin_menu_04', {})
1566
1567 " clean up
1568 call term_sendkeys(buf, "x")
1569 call StopVimInTerminal(buf)
1570 call delete('XtestPopupNarrowMenu')
1571endfunc
1572
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001573func Test_popup_title()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001574 CheckScreendump
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001575
1576 " Create a popup without title or border, a line of padding will be added to
1577 " put the title on.
1578 let lines =<< trim END
1579 call setline(1, range(1, 20))
Bram Moolenaar5d458a72019-08-04 21:12:15 +02001580 let winid = popup_create(['one', 'two', 'another'], #{title: 'Title String'})
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001581 END
1582 call writefile(lines, 'XtestPopupTitle')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001583 let buf = RunVimInTerminal('-S XtestPopupTitle', #{rows: 10})
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001584 call VerifyScreenDump(buf, 'Test_popupwin_title', {})
1585
Bram Moolenaar5d458a72019-08-04 21:12:15 +02001586 call term_sendkeys(buf, ":call popup_setoptions(winid, #{maxwidth: 20, title: 'a very long title that is not going to fit'})\<CR>")
1587 call term_sendkeys(buf, ":\<CR>")
1588 call VerifyScreenDump(buf, 'Test_popupwin_longtitle_1', {})
1589
1590 call term_sendkeys(buf, ":call popup_setoptions(winid, #{border: []})\<CR>")
1591 call term_sendkeys(buf, ":\<CR>")
1592 call VerifyScreenDump(buf, 'Test_popupwin_longtitle_2', {})
1593
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001594 " clean up
1595 call StopVimInTerminal(buf)
1596 call delete('XtestPopupTitle')
Bram Moolenaarae943152019-06-16 22:54:14 +02001597
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001598 let winid = popup_create('something', #{title: 'Some Title'})
Bram Moolenaarae943152019-06-16 22:54:14 +02001599 call assert_equal('Some Title', popup_getoptions(winid).title)
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001600 call popup_setoptions(winid, #{title: 'Another Title'})
Bram Moolenaarae943152019-06-16 22:54:14 +02001601 call assert_equal('Another Title', popup_getoptions(winid).title)
1602
1603 call popup_clear()
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001604endfunc
1605
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001606func Test_popup_close_callback()
1607 func PopupDone(id, result)
1608 let g:result = a:result
1609 endfunc
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001610 let winid = popup_create('something', #{callback: 'PopupDone'})
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001611 redraw
1612 call popup_close(winid, 'done')
1613 call assert_equal('done', g:result)
1614endfunc
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001615
1616func Test_popup_empty()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001617 let winid = popup_create('', #{padding: [2,2,2,2]})
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001618 redraw
1619 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001620 call assert_equal(5, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001621 call assert_equal(5, pos.height)
1622
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001623 let winid = popup_create([], #{border: []})
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001624 redraw
1625 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001626 call assert_equal(3, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001627 call assert_equal(3, pos.height)
1628endfunc
Bram Moolenaar988c4332019-06-02 14:12:11 +02001629
1630func Test_popup_never_behind()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001631 CheckScreendump
1632
Bram Moolenaar988c4332019-06-02 14:12:11 +02001633 " +-----------------------------+
1634 " | | |
1635 " | | |
1636 " | | |
1637 " | line1 |
1638 " |------------line2------------|
1639 " | line3 |
1640 " | line4 |
1641 " | |
1642 " | |
1643 " +-----------------------------+
1644 let lines =<< trim END
Bram Moolenaar988c4332019-06-02 14:12:11 +02001645 split
1646 vsplit
1647 let info_window1 = getwininfo()[0]
1648 let line = info_window1['height']
1649 let col = info_window1['width']
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001650 call popup_create(['line1', 'line2', 'line3', 'line4'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001651 \ line : line,
1652 \ col : col,
Bram Moolenaar988c4332019-06-02 14:12:11 +02001653 \ })
1654 END
1655 call writefile(lines, 'XtestPopupBehind')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001656 let buf = RunVimInTerminal('-S XtestPopupBehind', #{rows: 10})
Bram Moolenaar988c4332019-06-02 14:12:11 +02001657 call term_sendkeys(buf, "\<C-W>w")
1658 call VerifyScreenDump(buf, 'Test_popupwin_behind', {})
1659
1660 " clean up
1661 call StopVimInTerminal(buf)
1662 call delete('XtestPopupBehind')
1663endfunc
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001664
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001665func s:VerifyPosition(p, msg, line, col, width, height)
1666 call assert_equal(a:line, popup_getpos(a:p).line, a:msg . ' (l)')
1667 call assert_equal(a:col, popup_getpos(a:p).col, a:msg . ' (c)')
1668 call assert_equal(a:width, popup_getpos(a:p).width, a:msg . ' (w)')
1669 call assert_equal(a:height, popup_getpos(a:p).height, a:msg . ' (h)')
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001670endfunc
1671
1672func Test_popup_position_adjust()
Bram Moolenaarfbcdf672020-01-06 23:07:48 +01001673 " Anything placed past the last cell on the right of the screen is moved to
1674 " the left.
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001675 "
1676 " When wrapping is disabled, we also shift to the left to display on the
1677 " screen, unless fixed is set.
1678
1679 " Entries for cases which don't vary based on wrapping.
1680 " Format is per tests described below
1681 let both_wrap_tests = [
Bram Moolenaarfbcdf672020-01-06 23:07:48 +01001682 \ ['a', 5, &columns, 5, &columns, 1, 1],
1683 \ ['b', 5, &columns + 1, 5, &columns, 1, 1],
1684 \ ['c', 5, &columns - 1, 5, &columns - 1, 1, 1],
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001685 \ ['d', 5, &columns - 2, 5, &columns - 2, 1, 1],
Bram Moolenaarfbcdf672020-01-06 23:07:48 +01001686 \ ['e', 5, &columns - 3, 5, &columns - 3, 1, 1]]
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001687
1688 " these test groups are dicts with:
1689 " - comment: something to identify the group of tests by
1690 " - options: dict of options to merge with the row/col in tests
1691 " - tests: list of cases. Each one is a list with elements:
1692 " - text
1693 " - row
1694 " - col
1695 " - expected row
1696 " - expected col
1697 " - expected width
1698 " - expected height
1699 let tests = [
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001700 \ #{
1701 \ comment: 'left-aligned with wrapping',
1702 \ options: #{
1703 \ wrap: 1,
1704 \ pos: 'botleft',
1705 \ },
1706 \ tests: both_wrap_tests + [
Bram Moolenaarfbcdf672020-01-06 23:07:48 +01001707 \ ['aa', 5, &columns, 4, &columns, 1, 2],
1708 \ ['bb', 5, &columns + 1, 4, &columns, 1, 2],
1709 \ ['cc', 5, &columns - 1, 5, &columns - 1, 2, 1],
1710 \ ['dd', 5, &columns - 2, 5, &columns - 2, 2, 1],
1711 \ ['ee', 5, &columns - 3, 5, &columns - 3, 2, 1],
1712 \
1713 \ ['aaa', 5, &columns, 3, &columns, 1, 3],
1714 \ ['bbb', 5, &columns + 1, 3, &columns, 1, 3],
1715 \ ['ccc', 5, &columns - 1, 4, &columns - 1, 2, 2],
1716 \ ['ddd', 5, &columns - 2, 5, &columns - 2, 3, 1],
1717 \ ['eee', 5, &columns - 3, 5, &columns - 3, 3, 1],
1718 \
1719 \ ['aaaa', 5, &columns, 2, &columns, 1, 4],
1720 \ ['bbbb', 5, &columns + 1, 2, &columns, 1, 4],
1721 \ ['cccc', 5, &columns - 1, 4, &columns - 1, 2, 2],
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001722 \ ['dddd', 5, &columns - 2, 4, &columns - 2, 3, 2],
1723 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1],
Bram Moolenaarfbcdf672020-01-06 23:07:48 +01001724 \ ['eeee', 5, &columns - 4, 5, &columns - 4, 4, 1],
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001725 \ ],
1726 \ },
1727 \ #{
1728 \ comment: 'left aligned without wrapping',
1729 \ options: #{
1730 \ wrap: 0,
1731 \ pos: 'botleft',
1732 \ },
1733 \ tests: both_wrap_tests + [
Bram Moolenaarfbcdf672020-01-06 23:07:48 +01001734 \ ['aa', 5, &columns, 5, &columns - 1, 2, 1],
1735 \ ['bb', 5, &columns + 1, 5, &columns - 1, 2, 1],
1736 \ ['cc', 5, &columns - 1, 5, &columns - 1, 2, 1],
1737 \ ['dd', 5, &columns - 2, 5, &columns - 2, 2, 1],
1738 \ ['ee', 5, &columns - 3, 5, &columns - 3, 2, 1],
1739 \
1740 \ ['aaa', 5, &columns, 5, &columns - 2, 3, 1],
1741 \ ['bbb', 5, &columns + 1, 5, &columns - 2, 3, 1],
1742 \ ['ccc', 5, &columns - 1, 5, &columns - 2, 3, 1],
1743 \ ['ddd', 5, &columns - 2, 5, &columns - 2, 3, 1],
1744 \ ['eee', 5, &columns - 3, 5, &columns - 3, 3, 1],
1745 \
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001746 \ ['aaaa', 5, &columns, 5, &columns - 3, 4, 1],
1747 \ ['bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1],
1748 \ ['cccc', 5, &columns - 1, 5, &columns - 3, 4, 1],
1749 \ ['dddd', 5, &columns - 2, 5, &columns - 3, 4, 1],
1750 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1],
1751 \ ],
1752 \ },
1753 \ #{
1754 \ comment: 'left aligned with fixed position',
1755 \ options: #{
1756 \ wrap: 0,
1757 \ fixed: 1,
1758 \ pos: 'botleft',
1759 \ },
1760 \ tests: both_wrap_tests + [
Bram Moolenaarfbcdf672020-01-06 23:07:48 +01001761 \ ['aa', 5, &columns, 5, &columns, 1, 1],
1762 \ ['bb', 5, &columns + 1, 5, &columns, 1, 1],
1763 \ ['cc', 5, &columns - 1, 5, &columns - 1, 2, 1],
1764 \ ['dd', 5, &columns - 2, 5, &columns - 2, 2, 1],
1765 \ ['ee', 5, &columns - 3, 5, &columns - 3, 2, 1],
1766 \
1767 \ ['aaa', 5, &columns, 5, &columns, 1, 1],
1768 \ ['bbb', 5, &columns + 1, 5, &columns, 1, 1],
1769 \ ['ccc', 5, &columns - 1, 5, &columns - 1, 2, 1],
1770 \ ['ddd', 5, &columns - 2, 5, &columns - 2, 3, 1],
1771 \ ['eee', 5, &columns - 3, 5, &columns - 3, 3, 1],
1772 \
1773 \ ['aaaa', 5, &columns, 5, &columns, 1, 1],
1774 \ ['bbbb', 5, &columns + 1, 5, &columns, 1, 1],
1775 \ ['cccc', 5, &columns - 1, 5, &columns - 1, 2, 1],
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001776 \ ['dddd', 5, &columns - 2, 5, &columns - 2, 3, 1],
1777 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1],
1778 \ ],
1779 \ },
1780 \ ]
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001781
1782 for test_group in tests
1783 for test in test_group.tests
1784 let [ text, line, col, e_line, e_col, e_width, e_height ] = test
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001785 let options = #{
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001786 \ line: line,
1787 \ col: col,
1788 \ }
1789 call extend(options, test_group.options)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001790
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001791 let p = popup_create(text, options)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001792
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001793 let msg = string(extend(options, #{text: text}))
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001794 call s:VerifyPosition(p, msg, e_line, e_col, e_width, e_height)
1795 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001796 endfor
1797 endfor
1798
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001799 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001800 %bwipe!
1801endfunc
1802
Bram Moolenaar3397f742019-06-02 18:40:06 +02001803func Test_adjust_left_past_screen_width()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001804 " width of screen
1805 let X = join(map(range(&columns), {->'X'}), '')
1806
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001807 let p = popup_create(X, #{line: 1, col: 1, wrap: 0})
1808 call s:VerifyPosition(p, 'full width topleft', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001809
1810 redraw
1811 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1812 call assert_equal(X, line)
1813
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001814 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001815 redraw
1816
1817 " Same if placed on the right hand side
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001818 let p = popup_create(X, #{line: 1, col: &columns, wrap: 0})
1819 call s:VerifyPosition(p, 'full width topright', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001820
1821 redraw
1822 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1823 call assert_equal(X, line)
1824
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001825 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001826 redraw
1827
1828 " Extend so > window width
1829 let X .= 'x'
1830
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001831 let p = popup_create(X, #{line: 1, col: 1, wrap: 0})
1832 call s:VerifyPosition(p, 'full width + 1 topleft', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001833
1834 redraw
1835 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1836 call assert_equal(X[ : -2 ], line)
1837
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001838 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001839 redraw
1840
1841 " Shifted then truncated (the x is not visible)
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001842 let p = popup_create(X, #{line: 1, col: &columns - 3, wrap: 0})
1843 call s:VerifyPosition(p, 'full width + 1 topright', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001844
1845 redraw
1846 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1847 call assert_equal(X[ : -2 ], line)
1848
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001849 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001850 redraw
1851
1852 " Not shifted, just truncated
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001853 let p = popup_create(X,
1854 \ #{line: 1, col: 2, wrap: 0, fixed: 1})
1855 call s:VerifyPosition(p, 'full width + 1 fixed', 1, 2, &columns - 1, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001856
1857 redraw
1858 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1859 let e_line = ' ' . X[ 1 : -2 ]
1860 call assert_equal(e_line, line)
1861
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001862 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001863 redraw
1864
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001865 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001866 %bwipe!
Bram Moolenaar3397f742019-06-02 18:40:06 +02001867endfunc
1868
1869func Test_popup_moved()
1870 new
1871 call test_override('char_avail', 1)
1872 call setline(1, ['one word to move around', 'a WORD.and->some thing'])
1873
1874 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001875 let winid = popup_atcursor('text', #{moved: 'any'})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001876 redraw
1877 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001878 call assert_equal([1, 4, 4], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001879 " trigger the check for last_cursormoved by going into insert mode
1880 call feedkeys("li\<Esc>", 'xt')
1881 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001882 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001883
1884 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001885 let winid = popup_atcursor('text', #{moved: 'word'})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001886 redraw
1887 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001888 call assert_equal([1, 4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001889 call feedkeys("hi\<Esc>", 'xt')
1890 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001891 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001892
1893 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001894 let winid = popup_atcursor('text', #{moved: 'word'})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001895 redraw
1896 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001897 call assert_equal([1, 4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001898 call feedkeys("li\<Esc>", 'xt')
1899 call assert_equal(1, popup_getpos(winid).visible)
1900 call feedkeys("ei\<Esc>", 'xt')
1901 call assert_equal(1, popup_getpos(winid).visible)
1902 call feedkeys("eli\<Esc>", 'xt')
1903 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001904 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001905
Bram Moolenaar17627312019-06-02 19:53:44 +02001906 " WORD is the default
Bram Moolenaar3397f742019-06-02 18:40:06 +02001907 exe "normal gg0/WORD\<CR>"
Bram Moolenaar17627312019-06-02 19:53:44 +02001908 let winid = popup_atcursor('text', {})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001909 redraw
1910 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001911 call assert_equal([2, 2, 15], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001912 call feedkeys("eli\<Esc>", 'xt')
1913 call assert_equal(1, popup_getpos(winid).visible)
1914 call feedkeys("wi\<Esc>", 'xt')
1915 call assert_equal(1, popup_getpos(winid).visible)
1916 call feedkeys("Eli\<Esc>", 'xt')
1917 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001918 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001919
1920 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001921 let winid = popup_atcursor('text', #{moved: [5, 10]})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001922 redraw
1923 call assert_equal(1, popup_getpos(winid).visible)
1924 call feedkeys("eli\<Esc>", 'xt')
1925 call feedkeys("ei\<Esc>", 'xt')
1926 call assert_equal(1, popup_getpos(winid).visible)
1927 call feedkeys("eli\<Esc>", 'xt')
1928 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001929 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001930
1931 bwipe!
1932 call test_override('ALL', 0)
1933endfunc
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001934
1935func Test_notifications()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001936 CheckFeature timers
1937 CheckScreendump
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001938
Bram Moolenaar0fdddee2019-09-01 15:26:23 +02001939 let lines =<< trim END
1940 call setline(1, range(1, 20))
1941 hi Notification ctermbg=lightblue
1942 call popup_notification('first notification', {})
1943 END
1944 call writefile(lines, 'XtestNotifications')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001945 let buf = RunVimInTerminal('-S XtestNotifications', #{rows: 10})
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001946 call VerifyScreenDump(buf, 'Test_popupwin_notify_01', {})
1947
1948 " second one goes below the first one
Bram Moolenaardfa97f22019-06-15 14:31:55 +02001949 call term_sendkeys(buf, ":hi link PopupNotification Notification\<CR>")
1950 call term_sendkeys(buf, ":call popup_notification('another important notification', {})\<CR>")
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001951 call VerifyScreenDump(buf, 'Test_popupwin_notify_02', {})
1952
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001953 " clean up
1954 call StopVimInTerminal(buf)
1955 call delete('XtestNotifications')
1956endfunc
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001957
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001958func Test_popup_scrollbar()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001959 CheckScreendump
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001960
1961 let lines =<< trim END
1962 call setline(1, range(1, 20))
Bram Moolenaar8da41812019-06-26 18:04:54 +02001963 hi ScrollThumb ctermbg=blue
1964 hi ScrollBar ctermbg=red
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001965 let winid = popup_create(['one', 'two', 'three', 'four', 'five',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001966 \ 'six', 'seven', 'eight', 'nine'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001967 \ minwidth: 8,
1968 \ maxheight: 4,
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001969 \ })
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001970 func ScrollUp()
1971 call feedkeys("\<F3>\<ScrollWheelUp>", "xt")
1972 endfunc
1973 func ScrollDown()
1974 call feedkeys("\<F3>\<ScrollWheelDown>", "xt")
1975 endfunc
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001976 func ClickTop()
1977 call feedkeys("\<F4>\<LeftMouse>", "xt")
1978 endfunc
1979 func ClickBot()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001980 call popup_setoptions(g:winid, #{border: [], close: 'button'})
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001981 call feedkeys("\<F5>\<LeftMouse>", "xt")
1982 endfunc
Bram Moolenaarf2885d32019-11-02 20:21:25 +01001983 func Popup_filter(winid, key)
1984 if a:key == 'j'
1985 let line = popup_getoptions(a:winid).firstline
1986 let nlines = line('$', a:winid)
1987 let newline = line < nlines ? (line + 1) : nlines
1988 call popup_setoptions(a:winid, #{firstline: newline})
1989 return v:true
1990 elseif a:key == 'x'
1991 call popup_close(a:winid)
1992 return v:true
1993 endif
1994 endfunc
1995
1996 func PopupScroll()
1997 call popup_clear()
1998 let text =<< trim END
1999 1
2000 2
2001 3
2002 4
2003 long line long line long line long line long line long line
2004 long line long line long line long line long line long line
2005 long line long line long line long line long line long line
2006 END
2007 call popup_create(text, #{
2008 \ minwidth: 30,
2009 \ maxwidth: 30,
2010 \ minheight: 4,
2011 \ maxheight: 4,
2012 \ firstline: 1,
Bram Moolenaar30efcf32019-11-03 22:29:38 +01002013 \ lastline: 4,
Bram Moolenaarf2885d32019-11-02 20:21:25 +01002014 \ wrap: v:true,
2015 \ scrollbar: v:true,
2016 \ mapping: v:false,
2017 \ filter: funcref('Popup_filter')
2018 \ })
2019 endfunc
Bram Moolenaar53a95d62019-06-26 03:54:08 +02002020 map <silent> <F3> :call test_setmouse(5, 36)<CR>
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02002021 map <silent> <F4> :call test_setmouse(4, 42)<CR>
2022 map <silent> <F5> :call test_setmouse(7, 42)<CR>
Bram Moolenaar75fb0852019-06-25 05:15:58 +02002023 END
2024 call writefile(lines, 'XtestPopupScroll')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002025 let buf = RunVimInTerminal('-S XtestPopupScroll', #{rows: 10})
Bram Moolenaar75fb0852019-06-25 05:15:58 +02002026 call VerifyScreenDump(buf, 'Test_popupwin_scroll_1', {})
2027
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002028 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 2})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +02002029 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar75fb0852019-06-25 05:15:58 +02002030 call VerifyScreenDump(buf, 'Test_popupwin_scroll_2', {})
2031
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002032 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 6})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +02002033 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar75fb0852019-06-25 05:15:58 +02002034 call VerifyScreenDump(buf, 'Test_popupwin_scroll_3', {})
2035
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002036 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 9})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +02002037 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar75fb0852019-06-25 05:15:58 +02002038 call VerifyScreenDump(buf, 'Test_popupwin_scroll_4', {})
2039
Bram Moolenaar9e67b6a2019-08-30 17:34:08 +02002040 call term_sendkeys(buf, ":call popup_setoptions(winid, #{scrollbarhighlight: 'ScrollBar', thumbhighlight: 'ScrollThumb', firstline: 5})\<CR>")
Bram Moolenaara112f2d2019-09-01 17:38:09 +02002041 " this scrolls two lines (half the window height)
Bram Moolenaar53a95d62019-06-26 03:54:08 +02002042 call term_sendkeys(buf, ":call ScrollUp()\<CR>")
2043 call VerifyScreenDump(buf, 'Test_popupwin_scroll_5', {})
2044
2045 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
2046 call VerifyScreenDump(buf, 'Test_popupwin_scroll_6', {})
2047
2048 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
Bram Moolenaar13b47c32019-06-28 21:55:48 +02002049 " wait a bit, otherwise it fails sometimes (double click recognized?)
2050 sleep 100m
Bram Moolenaar53a95d62019-06-26 03:54:08 +02002051 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
2052 call VerifyScreenDump(buf, 'Test_popupwin_scroll_7', {})
2053
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02002054 call term_sendkeys(buf, ":call ClickTop()\<CR>")
2055 sleep 100m
2056 call term_sendkeys(buf, ":call ClickTop()\<CR>")
2057 call VerifyScreenDump(buf, 'Test_popupwin_scroll_8', {})
2058
2059 call term_sendkeys(buf, ":call ClickBot()\<CR>")
2060 call VerifyScreenDump(buf, 'Test_popupwin_scroll_9', {})
2061
Bram Moolenaar8c6173c2019-08-30 22:08:34 +02002062 " remove the minwidth and maxheight
2063 call term_sendkeys(buf, ":call popup_setoptions(winid, #{maxheight: 0, minwidth: 0})\<CR>")
Bram Moolenaar7e0f4622019-09-17 21:23:39 +02002064 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar8c6173c2019-08-30 22:08:34 +02002065 call VerifyScreenDump(buf, 'Test_popupwin_scroll_10', {})
2066
Bram Moolenaarf2885d32019-11-02 20:21:25 +01002067 " check size with non-wrapping lines
2068 call term_sendkeys(buf, ":call PopupScroll()\<CR>")
2069 call VerifyScreenDump(buf, 'Test_popupwin_scroll_11', {})
2070
2071 " check size with wrapping lines
2072 call term_sendkeys(buf, "j")
2073 call VerifyScreenDump(buf, 'Test_popupwin_scroll_12', {})
2074 call term_sendkeys(buf, "x")
2075
Bram Moolenaar75fb0852019-06-25 05:15:58 +02002076 " clean up
2077 call StopVimInTerminal(buf)
2078 call delete('XtestPopupScroll')
2079endfunc
2080
Bram Moolenaar437a7462019-07-05 20:17:22 +02002081func Test_popup_fitting_scrollbar()
2082 " this was causing a crash, divide by zero
2083 let winid = popup_create([
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002084 \ 'one', 'two', 'longer line that wraps', 'four', 'five'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002085 \ scrollbar: 1,
2086 \ maxwidth: 10,
2087 \ maxheight: 5,
2088 \ firstline: 2})
Bram Moolenaar437a7462019-07-05 20:17:22 +02002089 redraw
2090 call popup_clear()
2091endfunc
2092
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02002093func Test_popup_settext()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002094 CheckScreendump
Bram Moolenaardc2ce582019-06-16 15:32:14 +02002095
2096 let lines =<< trim END
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002097 let opts = #{wrap: 0}
Bram Moolenaardc2ce582019-06-16 15:32:14 +02002098 let p = popup_create('test', opts)
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002099 eval p->popup_settext('this is a text')
Bram Moolenaardc2ce582019-06-16 15:32:14 +02002100 END
2101
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02002102 call writefile(lines, 'XtestPopupSetText')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002103 let buf = RunVimInTerminal('-S XtestPopupSetText', #{rows: 10})
Bram Moolenaardc2ce582019-06-16 15:32:14 +02002104 call VerifyScreenDump(buf, 'Test_popup_settext_01', {})
2105
2106 " Setting to empty string clears it
2107 call term_sendkeys(buf, ":call popup_settext(p, '')\<CR>")
2108 call VerifyScreenDump(buf, 'Test_popup_settext_02', {})
2109
2110 " Setting a list
2111 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
2112 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
2113
2114 " Shrinking with a list
2115 call term_sendkeys(buf, ":call popup_settext(p, ['a'])\<CR>")
2116 call VerifyScreenDump(buf, 'Test_popup_settext_04', {})
2117
2118 " Growing with a list
2119 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
2120 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
2121
2122 " Empty list clears
2123 call term_sendkeys(buf, ":call popup_settext(p, [])\<CR>")
2124 call VerifyScreenDump(buf, 'Test_popup_settext_05', {})
2125
2126 " Dicts
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002127 call term_sendkeys(buf, ":call popup_settext(p, [#{text: 'aaaa'}, #{text: 'bbbb'}, #{text: 'cccc'}])\<CR>")
Bram Moolenaardc2ce582019-06-16 15:32:14 +02002128 call VerifyScreenDump(buf, 'Test_popup_settext_06', {})
2129
Bram Moolenaarb0992022020-01-30 14:55:42 +01002130 " range() (doesn't work)
2131 call term_sendkeys(buf, ":call popup_settext(p, range(4, 8))\<CR>")
2132 call VerifyScreenDump(buf, 'Test_popup_settext_07', {})
2133
Bram Moolenaardc2ce582019-06-16 15:32:14 +02002134 " clean up
2135 call StopVimInTerminal(buf)
2136 call delete('XtestPopupSetText')
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02002137endfunc
2138
2139func Test_popup_hidden()
2140 new
2141
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002142 let winid = popup_atcursor('text', #{hidden: 1})
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02002143 redraw
2144 call assert_equal(0, popup_getpos(winid).visible)
2145 call popup_close(winid)
2146
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002147 let winid = popup_create('text', #{hidden: 1})
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02002148 redraw
2149 call assert_equal(0, popup_getpos(winid).visible)
2150 call popup_close(winid)
2151
2152 func QuitCallback(id, res)
2153 let s:cb_winid = a:id
2154 let s:cb_res = a:res
2155 endfunc
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002156 let winid = 'make a choice'->popup_dialog(#{hidden: 1,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002157 \ filter: 'popup_filter_yesno',
2158 \ callback: 'QuitCallback',
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02002159 \ })
2160 redraw
2161 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02002162 call assert_equal(function('popup_filter_yesno'), popup_getoptions(winid).filter)
2163 call assert_equal(function('QuitCallback'), popup_getoptions(winid).callback)
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02002164 exe "normal anot used by filter\<Esc>"
2165 call assert_equal('not used by filter', getline(1))
2166
2167 call popup_show(winid)
2168 call feedkeys('y', "xt")
2169 call assert_equal(1, s:cb_res)
2170
2171 bwipe!
2172 delfunc QuitCallback
2173endfunc
Bram Moolenaarae943152019-06-16 22:54:14 +02002174
2175" Test options not checked elsewhere
2176func Test_set_get_options()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002177 let winid = popup_create('some text', #{highlight: 'Beautiful'})
Bram Moolenaarae943152019-06-16 22:54:14 +02002178 let options = popup_getoptions(winid)
2179 call assert_equal(1, options.wrap)
2180 call assert_equal(0, options.drag)
2181 call assert_equal('Beautiful', options.highlight)
2182
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002183 call popup_setoptions(winid, #{wrap: 0, drag: 1, highlight: 'Another'})
Bram Moolenaarae943152019-06-16 22:54:14 +02002184 let options = popup_getoptions(winid)
2185 call assert_equal(0, options.wrap)
2186 call assert_equal(1, options.drag)
2187 call assert_equal('Another', options.highlight)
2188
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02002189 call assert_fails('call popup_setoptions(winid, [])', 'E715:')
2190 call assert_fails('call popup_setoptions(winid, test_null_dict())', 'E715:')
2191
Bram Moolenaarae943152019-06-16 22:54:14 +02002192 call popup_close(winid)
Bram Moolenaarad48e6c2020-04-21 22:19:45 +02002193 call assert_equal(0, popup_setoptions(winid, options.wrap))
Bram Moolenaarae943152019-06-16 22:54:14 +02002194endfunc
Bram Moolenaar75a1a942019-06-20 03:45:36 +02002195
2196func Test_popupwin_garbage_collect()
2197 func MyPopupFilter(x, winid, c)
2198 " NOP
2199 endfunc
2200
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002201 let winid = popup_create('something', #{filter: function('MyPopupFilter', [{}])})
Bram Moolenaar75a1a942019-06-20 03:45:36 +02002202 call test_garbagecollect_now()
2203 redraw
Bram Moolenaar1bc353b2019-09-01 14:45:28 +02002204 " Must not crash caused by invalid memory access
Bram Moolenaar75a1a942019-06-20 03:45:36 +02002205 call feedkeys('j', 'xt')
2206 call assert_true(v:true)
2207
2208 call popup_close(winid)
2209 delfunc MyPopupFilter
2210endfunc
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02002211
Bram Moolenaar581ba392019-09-03 22:08:33 +02002212func Test_popupwin_filter_mode()
2213 func MyPopupFilter(winid, c)
2214 let s:typed = a:c
2215 if a:c == ':' || a:c == "\r" || a:c == 'v'
2216 " can start cmdline mode, get out, and start/stop Visual mode
2217 return 0
2218 endif
2219 return 1
2220 endfunc
2221
2222 " Normal, Visual and Insert mode
2223 let winid = popup_create('something', #{filter: 'MyPopupFilter', filtermode: 'nvi'})
2224 redraw
2225 call feedkeys('x', 'xt')
2226 call assert_equal('x', s:typed)
2227
2228 call feedkeys(":let g:foo = 'foo'\<CR>", 'xt')
2229 call assert_equal(':', s:typed)
2230 call assert_equal('foo', g:foo)
2231
2232 let @x = 'something'
2233 call feedkeys('v$"xy', 'xt')
2234 call assert_equal('y', s:typed)
2235 call assert_equal('something', @x) " yank command is filtered out
2236 call feedkeys('v', 'xt') " end Visual mode
2237
2238 call popup_close(winid)
2239
2240 " only Normal mode
2241 let winid = popup_create('something', #{filter: 'MyPopupFilter', filtermode: 'n'})
2242 redraw
2243 call feedkeys('x', 'xt')
2244 call assert_equal('x', s:typed)
2245
2246 call feedkeys(":let g:foo = 'foo'\<CR>", 'xt')
2247 call assert_equal(':', s:typed)
2248 call assert_equal('foo', g:foo)
2249
2250 let @x = 'something'
2251 call feedkeys('v$"xy', 'xt')
2252 call assert_equal('v', s:typed)
2253 call assert_notequal('something', @x)
2254
2255 call popup_close(winid)
2256
2257 " default: all modes
2258 let winid = popup_create('something', #{filter: 'MyPopupFilter'})
2259 redraw
2260 call feedkeys('x', 'xt')
2261 call assert_equal('x', s:typed)
2262
2263 let g:foo = 'bar'
2264 call feedkeys(":let g:foo = 'foo'\<CR>", 'xt')
2265 call assert_equal("\r", s:typed)
2266 call assert_equal('bar', g:foo)
2267
2268 let @x = 'something'
2269 call feedkeys('v$"xy', 'xt')
2270 call assert_equal('y', s:typed)
2271 call assert_equal('something', @x) " yank command is filtered out
2272 call feedkeys('v', 'xt') " end Visual mode
2273
2274 call popup_close(winid)
2275 delfunc MyPopupFilter
2276endfunc
2277
Bram Moolenaarf8b036b2019-11-06 21:09:17 +01002278func Test_popupwin_filter_mouse()
2279 func MyPopupFilter(winid, c)
Bram Moolenaardb3a2052019-11-16 18:22:41 +01002280 let g:got_mousepos = getmousepos()
Bram Moolenaarf8b036b2019-11-06 21:09:17 +01002281 return 0
2282 endfunc
2283
Bram Moolenaardb3a2052019-11-16 18:22:41 +01002284 call setline(1, ['.'->repeat(25)]->repeat(10))
2285 let winid = popup_create(['short', 'long line that will wrap', 'other'], #{
2286 \ line: 2,
2287 \ col: 4,
Bram Moolenaarf8b036b2019-11-06 21:09:17 +01002288 \ maxwidth: 12,
Bram Moolenaardb3a2052019-11-16 18:22:41 +01002289 \ padding: [],
2290 \ border: [],
Bram Moolenaarf8b036b2019-11-06 21:09:17 +01002291 \ filter: 'MyPopupFilter',
2292 \ })
2293 redraw
Bram Moolenaardb3a2052019-11-16 18:22:41 +01002294 " 123456789012345678901
2295 " 1 .....................
2296 " 2 ...+--------------+..
2297 " 3 ...| |..
2298 " 4 ...| short |..
2299 " 5 ...| long line th |..
2300 " 6 ...| at will wrap |..
2301 " 7 ...| other |..
2302 " 8 ...| |..
2303 " 9 ...+--------------+..
2304 " 10 .....................
2305 let tests = []
Bram Moolenaarf8b036b2019-11-06 21:09:17 +01002306
Bram Moolenaardb3a2052019-11-16 18:22:41 +01002307 func AddItemOutsidePopup(tests, row, col)
2308 eval a:tests->add(#{clickrow: a:row, clickcol: a:col, result: #{
2309 \ screenrow: a:row, screencol: a:col,
2310 \ winid: win_getid(), winrow: a:row, wincol: a:col,
2311 \ line: a:row, column: a:col,
2312 \ }})
2313 endfunc
2314 func AddItemInPopupBorder(tests, winid, row, col)
2315 eval a:tests->add(#{clickrow: a:row, clickcol: a:col, result: #{
2316 \ screenrow: a:row, screencol: a:col,
2317 \ winid: a:winid, winrow: a:row - 1, wincol: a:col - 3,
2318 \ line: 0, column: 0,
2319 \ }})
2320 endfunc
2321 func AddItemInPopupText(tests, winid, row, col, textline, textcol)
2322 eval a:tests->add(#{clickrow: a:row, clickcol: a:col, result: #{
2323 \ screenrow: a:row, screencol: a:col,
2324 \ winid: a:winid, winrow: a:row - 1, wincol: a:col - 3,
2325 \ line: a:textline, column: a:textcol,
2326 \ }})
2327 endfunc
Bram Moolenaarf8b036b2019-11-06 21:09:17 +01002328
Bram Moolenaardb3a2052019-11-16 18:22:41 +01002329 " above and below popup
2330 for c in range(1, 21)
2331 call AddItemOutsidePopup(tests, 1, c)
2332 call AddItemOutsidePopup(tests, 10, c)
2333 endfor
2334 " left and right of popup
2335 for r in range(1, 10)
2336 call AddItemOutsidePopup(tests, r, 3)
2337 call AddItemOutsidePopup(tests, r, 20)
2338 endfor
2339 " top and bottom in popup
2340 for c in range(4, 19)
2341 call AddItemInPopupBorder(tests, winid, 2, c)
2342 call AddItemInPopupBorder(tests, winid, 3, c)
2343 call AddItemInPopupBorder(tests, winid, 8, c)
2344 call AddItemInPopupBorder(tests, winid, 9, c)
2345 endfor
2346 " left and right margin in popup
2347 for r in range(2, 9)
2348 call AddItemInPopupBorder(tests, winid, r, 4)
2349 call AddItemInPopupBorder(tests, winid, r, 5)
2350 call AddItemInPopupBorder(tests, winid, r, 18)
2351 call AddItemInPopupBorder(tests, winid, r, 19)
2352 endfor
2353 " text "short"
2354 call AddItemInPopupText(tests, winid, 4, 6, 1, 1)
2355 call AddItemInPopupText(tests, winid, 4, 10, 1, 5)
2356 call AddItemInPopupText(tests, winid, 4, 11, 1, 6)
2357 call AddItemInPopupText(tests, winid, 4, 17, 1, 6)
2358 " text "long line th"
2359 call AddItemInPopupText(tests, winid, 5, 6, 2, 1)
2360 call AddItemInPopupText(tests, winid, 5, 10, 2, 5)
2361 call AddItemInPopupText(tests, winid, 5, 17, 2, 12)
2362 " text "at will wrap"
2363 call AddItemInPopupText(tests, winid, 6, 6, 2, 13)
2364 call AddItemInPopupText(tests, winid, 6, 10, 2, 17)
2365 call AddItemInPopupText(tests, winid, 6, 17, 2, 24)
2366 " text "other"
2367 call AddItemInPopupText(tests, winid, 7, 6, 3, 1)
2368 call AddItemInPopupText(tests, winid, 7, 10, 3, 5)
2369 call AddItemInPopupText(tests, winid, 7, 11, 3, 6)
2370 call AddItemInPopupText(tests, winid, 7, 17, 3, 6)
Bram Moolenaarf8b036b2019-11-06 21:09:17 +01002371
Bram Moolenaardb3a2052019-11-16 18:22:41 +01002372 for item in tests
2373 call test_setmouse(item.clickrow, item.clickcol)
2374 call feedkeys("\<LeftMouse>", 'xt')
2375 call assert_equal(item.result, g:got_mousepos)
2376 endfor
Bram Moolenaarf8b036b2019-11-06 21:09:17 +01002377
2378 call popup_close(winid)
Bram Moolenaardb3a2052019-11-16 18:22:41 +01002379 enew!
Bram Moolenaarf8b036b2019-11-06 21:09:17 +01002380 delfunc MyPopupFilter
2381endfunc
2382
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02002383func Test_popupwin_with_buffer()
2384 call writefile(['some text', 'in a buffer'], 'XsomeFile')
2385 let buf = bufadd('XsomeFile')
2386 call assert_equal(0, bufloaded(buf))
Bram Moolenaar46451042019-08-24 15:50:46 +02002387
2388 setlocal number
2389 call setbufvar(buf, "&wrapmargin", 13)
2390
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02002391 let winid = popup_create(buf, {})
2392 call assert_notequal(0, winid)
2393 let pos = popup_getpos(winid)
2394 call assert_equal(2, pos.height)
2395 call assert_equal(1, bufloaded(buf))
Bram Moolenaar46451042019-08-24 15:50:46 +02002396
2397 " window-local option is set to default, buffer-local is not
2398 call assert_equal(0, getwinvar(winid, '&number'))
2399 call assert_equal(13, getbufvar(buf, '&wrapmargin'))
2400
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02002401 call popup_close(winid)
2402 call assert_equal({}, popup_getpos(winid))
2403 call assert_equal(1, bufloaded(buf))
2404 exe 'bwipe! ' .. buf
Bram Moolenaar46451042019-08-24 15:50:46 +02002405 setlocal nonumber
Bram Moolenaar7866b872019-07-01 22:21:01 +02002406
2407 edit test_popupwin.vim
2408 let winid = popup_create(bufnr(''), {})
2409 redraw
2410 call popup_close(winid)
Bram Moolenaar3940ec62019-07-05 21:53:24 +02002411 call delete('XsomeFile')
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02002412endfunc
Bram Moolenaare296e312019-07-03 23:20:18 +02002413
Bram Moolenaare0d749a2019-09-25 22:14:48 +02002414func Test_popupwin_terminal_buffer()
Bram Moolenaard2c1fb42019-09-25 23:06:40 +02002415 CheckFeature terminal
Bram Moolenaard98c0b62020-02-02 15:25:16 +01002416 CheckUnix
Bram Moolenaard2c1fb42019-09-25 23:06:40 +02002417
Bram Moolenaard98c0b62020-02-02 15:25:16 +01002418 let origwin = win_getid()
Bram Moolenaare0d749a2019-09-25 22:14:48 +02002419 let ptybuf = term_start(&shell, #{hidden: 1})
Bram Moolenaar631ebc42020-02-03 22:15:26 +01002420 let winid = popup_create(ptybuf, #{minwidth: 40, minheight: 10})
Bram Moolenaard98c0b62020-02-02 15:25:16 +01002421 " Wait for shell to start
2422 sleep 200m
Bram Moolenaar631ebc42020-02-03 22:15:26 +01002423 " Check this doesn't crash
2424 call assert_equal(winnr(), winnr('j'))
2425 call assert_equal(winnr(), winnr('k'))
2426 call assert_equal(winnr(), winnr('h'))
2427 call assert_equal(winnr(), winnr('l'))
Bram Moolenaard98c0b62020-02-02 15:25:16 +01002428 " Cannot quit while job is running
2429 call assert_fails('call feedkeys("\<C-W>:quit\<CR>", "xt")', 'E948:')
2430 call feedkeys("exit\<CR>", 'xt')
2431 " Wait for shell to exit
2432 sleep 100m
2433 call feedkeys(":quit\<CR>", 'xt')
2434 call assert_equal(origwin, win_getid())
Bram Moolenaare0d749a2019-09-25 22:14:48 +02002435endfunc
2436
Bram Moolenaar934470e2019-09-01 23:27:05 +02002437func Test_popupwin_with_buffer_and_filter()
2438 new Xwithfilter
2439 call setline(1, range(100))
2440 let bufnr = bufnr()
2441 hide
2442
2443 func BufferFilter(win, key)
2444 if a:key == 'G'
2445 " recursive use of "G" does not cause problems.
2446 call win_execute(a:win, 'normal! G')
2447 return 1
2448 endif
2449 return 0
2450 endfunc
2451
2452 let winid = popup_create(bufnr, #{maxheight: 5, filter: 'BufferFilter'})
2453 call assert_equal(1, popup_getpos(winid).firstline)
2454 redraw
2455 call feedkeys("G", 'xt')
2456 call assert_equal(99, popup_getpos(winid).firstline)
2457
2458 call popup_close(winid)
2459 exe 'bwipe! ' .. bufnr
2460endfunc
2461
Bram Moolenaare296e312019-07-03 23:20:18 +02002462func Test_popupwin_width()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002463 let winid = popup_create(repeat(['short', 'long long long line', 'medium width'], 50), #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002464 \ maxwidth: 40,
2465 \ maxheight: 10,
Bram Moolenaare296e312019-07-03 23:20:18 +02002466 \ })
2467 for top in range(1, 20)
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002468 eval winid->popup_setoptions(#{firstline: top})
Bram Moolenaare296e312019-07-03 23:20:18 +02002469 redraw
2470 call assert_equal(19, popup_getpos(winid).width)
2471 endfor
2472 call popup_clear()
2473endfunc
Bram Moolenaar5ca1ac32019-07-04 15:39:28 +02002474
2475func Test_popupwin_buf_close()
2476 let buf = bufadd('Xtestbuf')
2477 call bufload(buf)
2478 call setbufline(buf, 1, ['just', 'some', 'lines'])
2479 let winid = popup_create(buf, {})
2480 redraw
2481 call assert_equal(3, popup_getpos(winid).height)
2482 let bufinfo = getbufinfo(buf)[0]
2483 call assert_equal(1, bufinfo.changed)
2484 call assert_equal(0, bufinfo.hidden)
2485 call assert_equal(0, bufinfo.listed)
2486 call assert_equal(1, bufinfo.loaded)
2487 call assert_equal([], bufinfo.windows)
2488 call assert_equal([winid], bufinfo.popups)
2489
2490 call popup_close(winid)
2491 call assert_equal({}, popup_getpos(winid))
2492 let bufinfo = getbufinfo(buf)[0]
2493 call assert_equal(1, bufinfo.changed)
2494 call assert_equal(1, bufinfo.hidden)
2495 call assert_equal(0, bufinfo.listed)
2496 call assert_equal(1, bufinfo.loaded)
2497 call assert_equal([], bufinfo.windows)
2498 call assert_equal([], bufinfo.popups)
2499 exe 'bwipe! ' .. buf
2500endfunc
Bram Moolenaar017c2692019-07-13 14:17:51 +02002501
2502func Test_popup_menu_with_maxwidth()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002503 CheckScreendump
Bram Moolenaar017c2692019-07-13 14:17:51 +02002504
2505 let lines =<< trim END
2506 call setline(1, range(1, 10))
2507 hi ScrollThumb ctermbg=blue
2508 hi ScrollBar ctermbg=red
2509 func PopupMenu(lines, line, col, scrollbar = 0)
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002510 return popup_menu(a:lines, #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002511 \ maxwidth: 10,
2512 \ maxheight: 3,
2513 \ pos : 'topleft',
2514 \ col : a:col,
2515 \ line : a:line,
2516 \ scrollbar : a:scrollbar,
Bram Moolenaar017c2692019-07-13 14:17:51 +02002517 \ })
2518 endfunc
2519 call PopupMenu(['x'], 1, 1)
2520 call PopupMenu(['123456789|'], 1, 16)
2521 call PopupMenu(['123456789|' .. ' '], 7, 1)
2522 call PopupMenu([repeat('123456789|', 100)], 7, 16)
2523 call PopupMenu(repeat(['123456789|' .. ' '], 5), 1, 33, 1)
2524 END
2525 call writefile(lines, 'XtestPopupMenuMaxWidth')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002526 let buf = RunVimInTerminal('-S XtestPopupMenuMaxWidth', #{rows: 13})
Bram Moolenaar017c2692019-07-13 14:17:51 +02002527 call VerifyScreenDump(buf, 'Test_popupwin_menu_maxwidth_1', {})
2528
2529 " close the menu popupwin.
2530 call term_sendkeys(buf, " ")
2531 call term_sendkeys(buf, " ")
2532 call term_sendkeys(buf, " ")
2533 call term_sendkeys(buf, " ")
2534 call term_sendkeys(buf, " ")
2535
2536 " clean up
2537 call StopVimInTerminal(buf)
2538 call delete('XtestPopupMenuMaxWidth')
2539endfunc
2540
Bram Moolenaara901a372019-07-13 16:38:50 +02002541func Test_popup_menu_with_scrollbar()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002542 CheckScreendump
Bram Moolenaara901a372019-07-13 16:38:50 +02002543
2544 let lines =<< trim END
2545 call setline(1, range(1, 20))
2546 hi ScrollThumb ctermbg=blue
2547 hi ScrollBar ctermbg=red
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002548 eval ['one', 'two', 'three', 'four', 'five',
2549 \ 'six', 'seven', 'eight', 'nine']
2550 \ ->popup_menu(#{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002551 \ minwidth: 8,
2552 \ maxheight: 3,
Bram Moolenaara901a372019-07-13 16:38:50 +02002553 \ })
2554 END
2555 call writefile(lines, 'XtestPopupMenuScroll')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002556 let buf = RunVimInTerminal('-S XtestPopupMenuScroll', #{rows: 10})
Bram Moolenaara901a372019-07-13 16:38:50 +02002557
2558 call term_sendkeys(buf, "j")
2559 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_1', {})
2560
2561 call term_sendkeys(buf, "jjj")
2562 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_2', {})
2563
2564 " if the cursor is the bottom line, it stays at the bottom line.
2565 call term_sendkeys(buf, repeat("j", 20))
2566 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_3', {})
2567
2568 call term_sendkeys(buf, "kk")
2569 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_4', {})
2570
2571 call term_sendkeys(buf, "k")
2572 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_5', {})
2573
2574 " if the cursor is in the top line, it stays in the top line.
2575 call term_sendkeys(buf, repeat("k", 20))
2576 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_6', {})
2577
2578 " close the menu popupwin.
2579 call term_sendkeys(buf, " ")
2580
2581 " clean up
2582 call StopVimInTerminal(buf)
2583 call delete('XtestPopupMenuScroll')
2584endfunc
2585
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002586func Test_popup_menu_filter()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002587 CheckScreendump
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002588
2589 let lines =<< trim END
2590 function! MyFilter(winid, key) abort
2591 if a:key == "0"
2592 call win_execute(a:winid, "call setpos('.', [0, 1, 1, 0])")
2593 return 1
2594 endif
2595 if a:key == "G"
2596 call win_execute(a:winid, "call setpos('.', [0, line('$'), 1, 0])")
2597 return 1
2598 endif
2599 if a:key == "j"
2600 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0])")
2601 return 1
2602 endif
2603 if a:key == "k"
2604 call win_execute(a:winid, "call setpos('.', [0, line('.') - 1, 1, 0])")
2605 return 1
2606 endif
Bram Moolenaarbcb4c8f2019-09-07 14:06:52 +02002607 if a:key == ':'
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002608 call popup_close(a:winid)
Bram Moolenaarbcb4c8f2019-09-07 14:06:52 +02002609 return 0
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002610 endif
2611 return 0
2612 endfunction
2613 call popup_menu(['111', '222', '333', '444', '555', '666', '777', '888', '999'], #{
2614 \ maxheight : 3,
2615 \ filter : 'MyFilter'
2616 \ })
2617 END
2618 call writefile(lines, 'XtestPopupMenuFilter')
2619 let buf = RunVimInTerminal('-S XtestPopupMenuFilter', #{rows: 10})
2620
2621 call term_sendkeys(buf, "j")
2622 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_1', {})
2623
2624 call term_sendkeys(buf, "k")
2625 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_2', {})
2626
2627 call term_sendkeys(buf, "G")
2628 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_3', {})
2629
2630 call term_sendkeys(buf, "0")
2631 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_4', {})
2632
Bram Moolenaarbcb4c8f2019-09-07 14:06:52 +02002633 " check that when the popup is closed in the filter the screen is redrawn
2634 call term_sendkeys(buf, ":")
2635 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_5', {})
2636 call term_sendkeys(buf, "\<CR>")
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002637
2638 " clean up
2639 call StopVimInTerminal(buf)
2640 call delete('XtestPopupMenuFilter')
2641endfunc
2642
2643func Test_popup_cursorline()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002644 CheckScreendump
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002645
2646 let winid = popup_create('some text', {})
2647 call assert_equal(0, popup_getoptions(winid).cursorline)
2648 call popup_close(winid)
2649
2650 let winid = popup_create('some text', #{ cursorline: 1, })
2651 call assert_equal(1, popup_getoptions(winid).cursorline)
2652 call popup_close(winid)
2653
2654 let winid = popup_create('some text', #{ cursorline: 0, })
2655 call assert_equal(0, popup_getoptions(winid).cursorline)
2656 call popup_close(winid)
2657
2658 let winid = popup_menu('some text', {})
2659 call assert_equal(1, popup_getoptions(winid).cursorline)
2660 call popup_close(winid)
2661
2662 let winid = popup_menu('some text', #{ cursorline: 1, })
2663 call assert_equal(1, popup_getoptions(winid).cursorline)
2664 call popup_close(winid)
2665
2666 let winid = popup_menu('some text', #{ cursorline: 0, })
2667 call assert_equal(0, popup_getoptions(winid).cursorline)
2668 call popup_close(winid)
2669
2670 " ---------
2671 " Pattern 1
2672 " ---------
2673 let lines =<< trim END
2674 call popup_create(['111', '222', '333'], #{ cursorline : 0 })
2675 END
2676 call writefile(lines, 'XtestPopupCursorLine')
2677 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2678 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_1', {})
2679 call term_sendkeys(buf, ":call popup_clear()\<cr>")
2680 call StopVimInTerminal(buf)
2681
2682 " ---------
2683 " Pattern 2
2684 " ---------
2685 let lines =<< trim END
2686 call popup_create(['111', '222', '333'], #{ cursorline : 1 })
2687 END
2688 call writefile(lines, 'XtestPopupCursorLine')
2689 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2690 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_2', {})
2691 call term_sendkeys(buf, ":call popup_clear()\<cr>")
2692 call StopVimInTerminal(buf)
2693
2694 " ---------
2695 " Pattern 3
2696 " ---------
2697 let lines =<< trim END
2698 function! MyFilter(winid, key) abort
2699 if a:key == "j"
2700 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0]) | redraw")
2701 return 1
2702 endif
2703 if a:key == 'x'
2704 call popup_close(a:winid)
2705 return 1
2706 endif
2707 return 0
2708 endfunction
2709 call popup_menu(['111', '222', '333'], #{
2710 \ cursorline : 0,
2711 \ maxheight : 2,
2712 \ filter : 'MyFilter',
2713 \ })
2714 END
2715 call writefile(lines, 'XtestPopupCursorLine')
2716 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2717 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_3', {})
2718 call term_sendkeys(buf, "j")
2719 call term_sendkeys(buf, "j")
2720 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_4', {})
2721 call term_sendkeys(buf, "x")
2722 call StopVimInTerminal(buf)
2723
2724 " ---------
2725 " Pattern 4
2726 " ---------
2727 let lines =<< trim END
2728 function! MyFilter(winid, key) abort
2729 if a:key == "j"
2730 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0]) | redraw")
2731 return 1
2732 endif
2733 if a:key == 'x'
2734 call popup_close(a:winid)
2735 return 1
2736 endif
2737 return 0
2738 endfunction
2739 call popup_menu(['111', '222', '333'], #{
2740 \ cursorline : 1,
2741 \ maxheight : 2,
2742 \ filter : 'MyFilter',
2743 \ })
2744 END
2745 call writefile(lines, 'XtestPopupCursorLine')
2746 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2747 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_5', {})
2748 call term_sendkeys(buf, "j")
2749 call term_sendkeys(buf, "j")
2750 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_6', {})
2751 call term_sendkeys(buf, "x")
2752 call StopVimInTerminal(buf)
2753
Bram Moolenaar3d2a3cb2019-09-08 17:12:01 +02002754 " ---------
2755 " Cursor in second line when creating the popup
2756 " ---------
2757 let lines =<< trim END
2758 let winid = popup_create(['111', '222', '333'], #{
2759 \ cursorline : 1,
2760 \ })
2761 call win_execute(winid, "2")
2762 END
2763 call writefile(lines, 'XtestPopupCursorLine')
2764 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2765 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_7', {})
2766 call StopVimInTerminal(buf)
2767
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002768 call delete('XtestPopupCursorLine')
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +01002769
2770 " ---------
2771 " Use current buffer for popupmenu
2772 " ---------
2773 let lines =<< trim END
2774 call setline(1, ['one', 'two', 'three'])
2775 let winid = popup_create(bufnr('%'), #{
2776 \ cursorline : 1,
2777 \ })
2778 call win_execute(winid, "2")
2779 END
2780 call writefile(lines, 'XtestPopupCursorLine')
2781 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2782 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_8', {})
2783 call StopVimInTerminal(buf)
2784
2785 call delete('XtestPopupCursorLine')
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002786endfunc
2787
Bram Moolenaarf914a332019-07-20 15:09:56 +02002788func Test_previewpopup()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002789 CheckScreendump
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01002790 CheckFeature quickfix
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002791
Bram Moolenaarf914a332019-07-20 15:09:56 +02002792 call writefile([
2793 \ "!_TAG_FILE_ENCODING\tutf-8\t//",
2794 \ "another\tXtagfile\t/^this is another",
2795 \ "theword\tXtagfile\t/^theword"],
2796 \ 'Xtags')
2797 call writefile(range(1,20)
2798 \ + ['theword is here']
2799 \ + range(22, 27)
2800 \ + ['this is another place']
2801 \ + range(29, 40),
2802 \ "Xtagfile")
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002803 call writefile(range(1,10)
2804 \ + ['searched word is here']
2805 \ + range(12, 20),
2806 \ "Xheader.h")
Bram Moolenaarf914a332019-07-20 15:09:56 +02002807 let lines =<< trim END
2808 set tags=Xtags
2809 call setline(1, [
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02002810 \ 'one',
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002811 \ '#include "Xheader.h"',
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02002812 \ 'three',
2813 \ 'four',
2814 \ 'five',
2815 \ 'six',
2816 \ 'seven',
2817 \ 'find theword somewhere',
2818 \ 'nine',
2819 \ 'this is another word',
2820 \ 'very long line where the word is also another'])
Bram Moolenaarf914a332019-07-20 15:09:56 +02002821 set previewpopup=height:4,width:40
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002822 set path=.
Bram Moolenaarf914a332019-07-20 15:09:56 +02002823 END
2824 call writefile(lines, 'XtestPreviewPopup')
2825 let buf = RunVimInTerminal('-S XtestPreviewPopup', #{rows: 14})
2826
2827 call term_sendkeys(buf, "/theword\<CR>\<C-W>}")
2828 call term_sendkeys(buf, ":\<CR>")
2829 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_1', {})
2830
2831 call term_sendkeys(buf, "/another\<CR>\<C-W>}")
2832 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_2', {})
2833
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002834 call term_sendkeys(buf, ":call popup_move(popup_findpreview(), #{col: 15})\<CR>")
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02002835 call term_sendkeys(buf, ":\<CR>")
2836 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_3', {})
2837
2838 call term_sendkeys(buf, "/another\<CR>\<C-W>}")
2839 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_4', {})
2840
Bram Moolenaar799439a2020-02-11 21:44:17 +01002841 call term_sendkeys(buf, ":silent cd ..\<CR>:\<CR>")
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02002842 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_5', {})
Bram Moolenaar799439a2020-02-11 21:44:17 +01002843 call term_sendkeys(buf, ":silent cd testdir\<CR>")
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002844
2845 call term_sendkeys(buf, ":pclose\<CR>")
Bram Moolenaar78d629a2019-08-16 17:31:15 +02002846 call term_sendkeys(buf, ":\<BS>")
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002847 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_6', {})
2848
2849 call term_sendkeys(buf, ":pedit +/theword Xtagfile\<CR>")
2850 call term_sendkeys(buf, ":\<CR>")
2851 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_7', {})
2852
2853 call term_sendkeys(buf, ":pclose\<CR>")
2854 call term_sendkeys(buf, ":psearch searched\<CR>")
2855 call term_sendkeys(buf, ":\<CR>")
2856 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_8', {})
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02002857
Bram Moolenaar8bf716c2020-01-23 15:33:54 +01002858 call term_sendkeys(buf, "\<C-W>p")
2859 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_9', {})
2860
2861 call term_sendkeys(buf, ":call win_execute(popup_findpreview(), 'call popup_clear()')\<CR>")
2862 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_10', {})
2863
Bram Moolenaarf914a332019-07-20 15:09:56 +02002864 call StopVimInTerminal(buf)
2865 call delete('Xtags')
2866 call delete('Xtagfile')
2867 call delete('XtestPreviewPopup')
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002868 call delete('Xheader.h')
Bram Moolenaarf914a332019-07-20 15:09:56 +02002869endfunc
2870
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002871func Get_popupmenu_lines()
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002872 let lines =<< trim END
2873 set completeopt+=preview,popup
2874 set completefunc=CompleteFuncDict
Bram Moolenaar62a0cb42019-08-18 16:35:23 +02002875 hi InfoPopup ctermbg=yellow
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002876
2877 func CompleteFuncDict(findstart, base)
2878 if a:findstart
2879 if col('.') > 10
2880 return col('.') - 10
2881 endif
2882 return 0
2883 endif
2884
2885 return {
2886 \ 'words': [
2887 \ {
2888 \ 'word': 'aword',
2889 \ 'abbr': 'wrd',
2890 \ 'menu': 'extra text',
2891 \ 'info': 'words are cool',
2892 \ 'kind': 'W',
2893 \ 'user_data': 'test'
2894 \ },
2895 \ {
2896 \ 'word': 'anotherword',
2897 \ 'abbr': 'anotwrd',
2898 \ 'menu': 'extra text',
2899 \ 'info': "other words are\ncooler than this and some more text\nto make wrap",
2900 \ 'kind': 'W',
2901 \ 'user_data': 'notest'
2902 \ },
2903 \ {
2904 \ 'word': 'noinfo',
2905 \ 'abbr': 'noawrd',
2906 \ 'menu': 'extra text',
Bram Moolenaar62a0cb42019-08-18 16:35:23 +02002907 \ 'info': "lets\nshow\na\nscrollbar\nhere",
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002908 \ 'kind': 'W',
2909 \ 'user_data': 'notest'
2910 \ },
2911 \ {
2912 \ 'word': 'thatword',
2913 \ 'abbr': 'thatwrd',
2914 \ 'menu': 'extra text',
2915 \ 'info': 'that word is cool',
2916 \ 'kind': 'W',
2917 \ 'user_data': 'notest'
2918 \ },
2919 \ ]
2920 \ }
2921 endfunc
2922 call setline(1, 'text text text text text text text ')
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002923 func ChangeColor()
2924 let id = popup_findinfo()
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002925 eval id->popup_setoptions(#{highlight: 'InfoPopup'})
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002926 endfunc
Bram Moolenaardca7abe2019-10-20 18:17:57 +02002927
2928 func InfoHidden()
2929 set completepopup=height:4,border:off,align:menu
2930 set completeopt-=popup completeopt+=popuphidden
2931 au CompleteChanged * call HandleChange()
2932 endfunc
2933
2934 let s:counter = 0
2935 func HandleChange()
2936 let s:counter += 1
2937 let selected = complete_info(['selected']).selected
2938 if selected <= 0
2939 " First time: do nothing, info remains hidden
2940 return
2941 endif
2942 if selected == 1
2943 " Second time: show info right away
2944 let id = popup_findinfo()
2945 if id
2946 call popup_settext(id, 'immediate info ' .. s:counter)
2947 call popup_show(id)
2948 endif
2949 else
2950 " Third time: show info after a short delay
2951 call timer_start(100, 'ShowInfo')
2952 endif
2953 endfunc
2954
2955 func ShowInfo(...)
2956 let id = popup_findinfo()
2957 if id
2958 call popup_settext(id, 'async info ' .. s:counter)
2959 call popup_show(id)
2960 endif
2961 endfunc
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002962 END
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002963 return lines
2964endfunc
2965
2966func Test_popupmenu_info_border()
2967 CheckScreendump
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01002968 CheckFeature quickfix
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002969
2970 let lines = Get_popupmenu_lines()
2971 call add(lines, 'set completepopup=height:4,highlight:InfoPopup')
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002972 call writefile(lines, 'XtestInfoPopup')
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002973
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002974 let buf = RunVimInTerminal('-S XtestInfoPopup', #{rows: 14})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02002975 call TermWait(buf, 25)
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002976
2977 call term_sendkeys(buf, "A\<C-X>\<C-U>")
2978 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_1', {})
2979
2980 call term_sendkeys(buf, "\<C-N>")
2981 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_2', {})
2982
2983 call term_sendkeys(buf, "\<C-N>")
2984 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_3', {})
2985
2986 call term_sendkeys(buf, "\<C-N>\<C-N>")
2987 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_4', {})
2988
Bram Moolenaarfe6e7612019-08-21 20:57:20 +02002989 " info on the left with scrollbar
2990 call term_sendkeys(buf, "test text test text\<C-X>\<C-U>")
2991 call term_sendkeys(buf, "\<C-N>\<C-N>")
2992 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_5', {})
2993
Bram Moolenaar202c3f72019-11-21 12:12:35 +01002994 " Test that the popupmenu's scrollbar and infopopup do not overlap
2995 call term_sendkeys(buf, "\<Esc>")
2996 call term_sendkeys(buf, ":set pumheight=3\<CR>")
2997 call term_sendkeys(buf, "cc\<C-X>\<C-U>")
2998 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_6', {})
2999
Bram Moolenaarca7c0782020-01-14 20:42:48 +01003000 " Hide the info popup, cycle trough buffers, make sure it didn't get
3001 " deleted.
3002 call term_sendkeys(buf, "\<Esc>")
3003 call term_sendkeys(buf, ":set hidden\<CR>")
3004 call term_sendkeys(buf, ":bn\<CR>")
3005 call term_sendkeys(buf, ":bn\<CR>")
3006 call term_sendkeys(buf, "otest text test text\<C-X>\<C-U>")
3007 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_7', {})
3008
3009 call term_sendkeys(buf, "\<Esc>")
Bram Moolenaar576a4a62019-08-18 15:25:17 +02003010 call StopVimInTerminal(buf)
3011 call delete('XtestInfoPopup')
3012endfunc
3013
Bram Moolenaarbd483b32019-08-21 15:13:41 +02003014func Test_popupmenu_info_noborder()
3015 CheckScreendump
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01003016 CheckFeature quickfix
Bram Moolenaarbd483b32019-08-21 15:13:41 +02003017
3018 let lines = Get_popupmenu_lines()
3019 call add(lines, 'set completepopup=height:4,border:off')
3020 call writefile(lines, 'XtestInfoPopupNb')
3021
3022 let buf = RunVimInTerminal('-S XtestInfoPopupNb', #{rows: 14})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02003023 call TermWait(buf, 25)
Bram Moolenaarbd483b32019-08-21 15:13:41 +02003024
3025 call term_sendkeys(buf, "A\<C-X>\<C-U>")
3026 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_nb_1', {})
3027
3028 call StopVimInTerminal(buf)
3029 call delete('XtestInfoPopupNb')
3030endfunc
3031
Bram Moolenaar258cef52019-08-21 17:29:29 +02003032func Test_popupmenu_info_align_menu()
3033 CheckScreendump
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01003034 CheckFeature quickfix
Bram Moolenaar258cef52019-08-21 17:29:29 +02003035
3036 let lines = Get_popupmenu_lines()
3037 call add(lines, 'set completepopup=height:4,border:off,align:menu')
3038 call writefile(lines, 'XtestInfoPopupNb')
3039
3040 let buf = RunVimInTerminal('-S XtestInfoPopupNb', #{rows: 14})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02003041 call TermWait(buf, 25)
Bram Moolenaar258cef52019-08-21 17:29:29 +02003042
3043 call term_sendkeys(buf, "A\<C-X>\<C-U>")
3044 call term_sendkeys(buf, "\<C-N>")
3045 call term_sendkeys(buf, "\<C-N>")
3046 call term_sendkeys(buf, "\<C-N>")
3047 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_1', {})
3048
3049 call term_sendkeys(buf, "test text test text test\<C-X>\<C-U>")
3050 call term_sendkeys(buf, "\<C-N>")
3051 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_2', {})
3052
3053 call term_sendkeys(buf, "\<Esc>")
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02003054 call term_sendkeys(buf, ":call ChangeColor()\<CR>")
Bram Moolenaar258cef52019-08-21 17:29:29 +02003055 call term_sendkeys(buf, ":call setline(2, ['x']->repeat(10))\<CR>")
3056 call term_sendkeys(buf, "Gotest text test text\<C-X>\<C-U>")
3057 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_3', {})
3058
3059 call StopVimInTerminal(buf)
3060 call delete('XtestInfoPopupNb')
3061endfunc
3062
Bram Moolenaardca7abe2019-10-20 18:17:57 +02003063func Test_popupmenu_info_hidden()
3064 CheckScreendump
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01003065 CheckFeature quickfix
Bram Moolenaardca7abe2019-10-20 18:17:57 +02003066
3067 let lines = Get_popupmenu_lines()
3068 call add(lines, 'call InfoHidden()')
3069 call writefile(lines, 'XtestInfoPopupHidden')
3070
3071 let buf = RunVimInTerminal('-S XtestInfoPopupHidden', #{rows: 14})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02003072 call TermWait(buf, 25)
Bram Moolenaardca7abe2019-10-20 18:17:57 +02003073
3074 call term_sendkeys(buf, "A\<C-X>\<C-U>")
3075 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_hidden_1', {})
3076
3077 call term_sendkeys(buf, "\<C-N>")
3078 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_hidden_2', {})
3079
3080 call term_sendkeys(buf, "\<C-N>")
3081 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_hidden_3', {})
3082
3083 call term_sendkeys(buf, "\<Esc>")
3084 call StopVimInTerminal(buf)
3085 call delete('XtestInfoPopupHidden')
3086endfunc
3087
Bram Moolenaarbef93ac2019-12-06 20:17:35 +01003088func Test_popupmenu_info_too_wide()
3089 CheckScreendump
3090 CheckFeature quickfix
3091
3092 let lines =<< trim END
3093 call setline(1, range(10))
3094
3095 set completeopt+=preview,popup
3096 set completepopup=align:menu
3097 set omnifunc=OmniFunc
3098 hi InfoPopup ctermbg=lightgrey
3099
3100 func OmniFunc(findstart, base)
3101 if a:findstart
3102 return 0
3103 endif
3104
3105 let menuText = 'some long text to make sure the menu takes up all of the width of the window'
3106 return #{
3107 \ words: [
3108 \ #{
3109 \ word: 'scrap',
3110 \ menu: menuText,
3111 \ info: "other words are\ncooler than this and some more text\nto make wrap",
3112 \ },
3113 \ #{
3114 \ word: 'scappier',
3115 \ menu: menuText,
3116 \ info: 'words are cool',
3117 \ },
3118 \ #{
3119 \ word: 'scrappier2',
3120 \ menu: menuText,
3121 \ info: 'words are cool',
3122 \ },
3123 \ ]
3124 \ }
3125 endfunc
3126 END
3127
3128 call writefile(lines, 'XtestInfoPopupWide')
3129 let buf = RunVimInTerminal('-S XtestInfoPopupWide', #{rows: 8})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +02003130 call TermWait(buf, 25)
Bram Moolenaarbef93ac2019-12-06 20:17:35 +01003131
3132 call term_sendkeys(buf, "Ascr\<C-X>\<C-O>")
3133 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_wide_1', {})
3134
3135 call term_sendkeys(buf, "\<Esc>")
3136 call StopVimInTerminal(buf)
3137 call delete('XtestInfoPopupWide')
3138endfunc
3139
Bram Moolenaar00b0d6d2019-08-21 22:25:30 +02003140func Test_popupwin_recycle_bnr()
Bram Moolenaare49fbff2019-08-21 22:50:07 +02003141 let bufnr = popup_notification('nothing wrong', {})->winbufnr()
Bram Moolenaar00b0d6d2019-08-21 22:25:30 +02003142 call popup_clear()
Bram Moolenaar6a124e62019-09-04 18:15:19 +02003143 let winid = 'nothing wrong'->popup_notification({})
Bram Moolenaar00b0d6d2019-08-21 22:25:30 +02003144 call assert_equal(bufnr, winbufnr(winid))
3145 call popup_clear()
3146endfunc
3147
Bram Moolenaar1824f452019-10-02 23:06:46 +02003148func Test_popupwin_getoptions_tablocal()
3149 topleft split
3150 let win1 = popup_create('nothing', #{maxheight: 8})
3151 let win2 = popup_create('something', #{maxheight: 10})
3152 let win3 = popup_create('something', #{maxheight: 15})
3153 call assert_equal(8, popup_getoptions(win1).maxheight)
3154 call assert_equal(10, popup_getoptions(win2).maxheight)
3155 call assert_equal(15, popup_getoptions(win3).maxheight)
3156 call popup_clear()
3157 quit
3158endfunc
3159
Bram Moolenaare8a7dfe2019-10-03 22:35:52 +02003160func Test_popupwin_cancel()
3161 let win1 = popup_create('one', #{line: 5, filter: {... -> 0}})
3162 let win2 = popup_create('two', #{line: 10, filter: {... -> 0}})
3163 let win3 = popup_create('three', #{line: 15, filter: {... -> 0}})
3164 call assert_equal(5, popup_getpos(win1).line)
3165 call assert_equal(10, popup_getpos(win2).line)
3166 call assert_equal(15, popup_getpos(win3).line)
3167 " TODO: this also works without patch 8.1.2110
3168 call feedkeys("\<C-C>", 'xt')
3169 call assert_equal(5, popup_getpos(win1).line)
3170 call assert_equal(10, popup_getpos(win2).line)
3171 call assert_equal({}, popup_getpos(win3))
3172 call feedkeys("\<C-C>", 'xt')
3173 call assert_equal(5, popup_getpos(win1).line)
3174 call assert_equal({}, popup_getpos(win2))
3175 call assert_equal({}, popup_getpos(win3))
3176 call feedkeys("\<C-C>", 'xt')
3177 call assert_equal({}, popup_getpos(win1))
3178 call assert_equal({}, popup_getpos(win2))
3179 call assert_equal({}, popup_getpos(win3))
3180endfunc
3181
Bram Moolenaarafe45b62019-11-13 22:35:19 +01003182func Test_popupwin_filter_redraw()
3183 " Create two popups with a filter that closes the popup when typing "0".
3184 " Both popups should close, even though the redraw also calls
3185 " popup_reset_handled()
3186
3187 func CloseFilter(winid, key)
3188 if a:key == '0'
3189 call popup_close(a:winid)
3190 redraw
3191 endif
3192 return 0 " pass the key
3193 endfunc
3194
3195 let id1 = popup_create('first one', #{
3196 \ line: 1,
3197 \ col: 1,
3198 \ filter: 'CloseFilter',
3199 \ })
3200 let id2 = popup_create('second one', #{
3201 \ line: 9,
3202 \ col: 1,
3203 \ filter: 'CloseFilter',
3204 \ })
3205 call assert_equal(1, popup_getpos(id1).line)
3206 call assert_equal(9, popup_getpos(id2).line)
3207
3208 call feedkeys('0', 'xt')
3209 call assert_equal({}, popup_getpos(id1))
3210 call assert_equal({}, popup_getpos(id2))
3211
3212 call popup_clear()
3213 delfunc CloseFilter
3214endfunc
3215
Bram Moolenaar20ebbea2019-11-30 17:58:27 +01003216func Test_popupwin_double_width()
3217 CheckScreendump
3218
3219 let lines =<< trim END
3220 call setline(1, 'x你好世界你好世你好世界你好')
3221 call setline(2, '你好世界你好世你好世界你好')
3222 call setline(3, 'x你好世界你好世你好世界你好')
3223 call popup_create('你好,世界 - 你好,世界xxxxx', #{line: 1, col: 3, maxwidth: 14})
3224 END
3225 call writefile(lines, 'XtestPopupWide')
3226
3227 let buf = RunVimInTerminal('-S XtestPopupWide', #{rows: 10})
3228 call VerifyScreenDump(buf, 'Test_popupwin_doublewidth_1', {})
3229
3230 call StopVimInTerminal(buf)
3231 call delete('XtestPopupWide')
3232endfunc
3233
3234func Test_popupwin_sign()
3235 CheckScreendump
3236
3237 let lines =<< trim END
3238 call setline(1, range(10))
3239 call sign_define('Current', {
3240 \ 'text': '>>',
3241 \ 'texthl': 'WarningMsg',
3242 \ 'linehl': 'Error',
3243 \ })
3244 call sign_define('Other', {
3245 \ 'text': '#!',
3246 \ 'texthl': 'Error',
3247 \ 'linehl': 'Search',
3248 \ })
3249 let winid = popup_create(['hello', 'bright', 'world'], {
3250 \ 'minwidth': 20,
3251 \ })
3252 call setwinvar(winid, "&signcolumn", "yes")
3253 let winbufnr = winbufnr(winid)
3254
3255 " add sign to current buffer, shows
3256 call sign_place(1, 'Selected', 'Current', bufnr('%'), {'lnum': 1})
3257 " add sign to current buffer, does not show
3258 call sign_place(2, 'PopUpSelected', 'Other', bufnr('%'), {'lnum': 2})
3259
3260 " add sign to popup buffer, shows
3261 call sign_place(3, 'PopUpSelected', 'Other', winbufnr, {'lnum': 1})
3262 " add sign to popup buffer, does not show
3263 call sign_place(4, 'Selected', 'Current', winbufnr, {'lnum': 2})
3264 END
3265 call writefile(lines, 'XtestPopupSign')
3266
3267 let buf = RunVimInTerminal('-S XtestPopupSign', #{rows: 10})
3268 call VerifyScreenDump(buf, 'Test_popupwin_sign_1', {})
3269
3270 call StopVimInTerminal(buf)
3271 call delete('XtestPopupSign')
3272endfunc
3273
Bram Moolenaar99ebf222019-12-10 23:44:48 +01003274func Test_popupwin_bufnr()
3275 let popwin = popup_create(['blah'], #{})
3276 let popbuf = winbufnr(popwin)
3277 split asdfasdf
3278 let newbuf = bufnr()
3279 call assert_true(newbuf > popbuf, 'New buffer number is higher')
3280 call assert_equal(newbuf, bufnr('$'))
3281 call popup_clear()
3282 let popwin = popup_create(['blah'], #{})
3283 " reuses previous buffer number
3284 call assert_equal(popbuf, winbufnr(popwin))
3285 call assert_equal(newbuf, bufnr('$'))
3286
3287 call popup_clear()
3288 bwipe!
3289endfunc
3290
Bram Moolenaarec084d32020-02-28 22:44:47 +01003291func Test_popupwin_filter_input_multibyte()
3292 func MyPopupFilter(winid, c)
3293 let g:bytes = range(a:c->strlen())->map({i -> char2nr(a:c[i])})
3294 return 0
3295 endfunc
3296 let winid = popup_create('', #{mapping: 0, filter: 'MyPopupFilter'})
3297
3298 " UTF-8: E3 80 80, including K_SPECIAL(0x80)
3299 call feedkeys("\u3000", 'xt')
3300 call assert_equal([0xe3, 0x80, 0x80], g:bytes)
3301
Bram Moolenaar8f027fe2020-03-04 23:21:35 +01003302 " UTF-8: E3 80 9B, including CSI(0x9B)
3303 call feedkeys("\u301b", 'xt')
3304 call assert_equal([0xe3, 0x80, 0x9b], g:bytes)
Bram Moolenaarec084d32020-02-28 22:44:47 +01003305
3306 call popup_clear()
3307 delfunc MyPopupFilter
3308 unlet g:bytes
3309endfunc
3310
Bram Moolenaarba2920f2020-03-06 21:43:17 +01003311func Test_popupwin_atcursor_far_right()
3312 new
3313
3314 " this was getting stuck
3315 set signcolumn=yes
3316 call setline(1, repeat('=', &columns))
3317 normal! ggg$
3318 call popup_atcursor(repeat('x', 500), #{moved: 'any', border: []})
3319
3320 bwipe!
3321 set signcolumn&
3322endfunc
3323
Bram Moolenaar0f1563f2020-03-20 21:15:51 +01003324func Test_popupwin_splitmove()
3325 vsplit
3326 let win2 = win_getid()
3327 let popup_winid = popup_dialog('hello', {})
3328 call assert_fails('call win_splitmove(popup_winid, win2)', 'E957:')
3329 call assert_fails('call win_splitmove(win2, popup_winid)', 'E957:')
3330
3331 call popup_clear()
3332 bwipe
3333endfunc
3334
3335
Bram Moolenaar331bafd2019-07-20 17:46:05 +02003336" vim: shiftwidth=2 sts=2