blob: dfdfc13ebb163b939302cf67ad4294299f5f1b8e [file] [log] [blame]
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001" Tests for popup windows
2
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02003source check.vim
4CheckFeature textprop
Bram Moolenaar4d784b22019-05-25 19:51:39 +02005
6source screendump.vim
7
8func Test_simple_popup()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02009 CheckScreendump
10
Bram Moolenaare7eb9272019-06-24 00:58:07 +020011 let lines =<< trim END
12 call setline(1, range(1, 100))
13 hi PopupColor1 ctermbg=lightblue
14 hi PopupColor2 ctermbg=lightcyan
15 hi Comment ctermfg=red
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020016 call prop_type_add('comment', #{highlight: 'Comment'})
17 let winid = popup_create('hello there', #{line: 3, col: 11, minwidth: 20, highlight: 'PopupColor1'})
18 let winid2 = popup_create(['another one', 'another two', 'another three'], #{line: 3, col: 25, minwidth: 20})
Bram Moolenaare7eb9272019-06-24 00:58:07 +020019 call setwinvar(winid2, '&wincolor', 'PopupColor2')
20 END
21 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020022 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaar4d784b22019-05-25 19:51:39 +020023 call VerifyScreenDump(buf, 'Test_popupwin_01', {})
24
Bram Moolenaarec583842019-05-26 14:11:23 +020025 " Add a tabpage
26 call term_sendkeys(buf, ":tabnew\<CR>")
Bram Moolenaar60cdb302019-05-27 21:54:10 +020027 call term_sendkeys(buf, ":let popupwin = popup_create(["
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020028 \ .. "#{text: 'other tab'},"
29 \ .. "#{text: 'a comment line', props: [#{"
Bram Moolenaard5abb4c2019-07-13 22:46:10 +020030 \ .. "col: 3, length: 7, minwidth: 20, type: 'comment'"
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020031 \ .. "}]},"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020032 \ .. "], #{line: 4, col: 9, minwidth: 20})\<CR>")
Bram Moolenaarec583842019-05-26 14:11:23 +020033 call VerifyScreenDump(buf, 'Test_popupwin_02', {})
34
35 " switch back to first tabpage
36 call term_sendkeys(buf, "gt")
37 call VerifyScreenDump(buf, 'Test_popupwin_03', {})
38
39 " close that tabpage
40 call term_sendkeys(buf, ":quit!\<CR>")
41 call VerifyScreenDump(buf, 'Test_popupwin_04', {})
42
Bram Moolenaar202d9822019-06-11 21:56:30 +020043 " set 'columns' to a small value, size must be recomputed
44 call term_sendkeys(buf, ":let cols = &columns\<CR>")
45 call term_sendkeys(buf, ":set columns=12\<CR>")
46 call VerifyScreenDump(buf, 'Test_popupwin_04a', {})
47 call term_sendkeys(buf, ":let &columns = cols\<CR>")
48
Bram Moolenaar17146962019-05-30 00:12:11 +020049 " resize popup, show empty line at bottom
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020050 call term_sendkeys(buf, ":call popup_move(popupwin, #{minwidth: 15, maxwidth: 25, minheight: 3, maxheight: 5})\<CR>")
Bram Moolenaar60cdb302019-05-27 21:54:10 +020051 call term_sendkeys(buf, ":redraw\<CR>")
52 call VerifyScreenDump(buf, 'Test_popupwin_05', {})
53
Bram Moolenaar17146962019-05-30 00:12:11 +020054 " show not fitting line at bottom
55 call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>")
56 call term_sendkeys(buf, ":redraw\<CR>")
57 call VerifyScreenDump(buf, 'Test_popupwin_06', {})
58
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020059 " move popup over ruler
60 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020061 call term_sendkeys(buf, ":call popup_move(popupwin, #{line: 7, col: 55})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +020062 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020063 call VerifyScreenDump(buf, 'Test_popupwin_07', {})
64
65 " clear all popups after moving the cursor a bit, so that ruler is updated
66 call term_sendkeys(buf, "axxx\<Esc>")
67 call term_wait(buf)
68 call term_sendkeys(buf, "0")
69 call term_wait(buf)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +020070 call term_sendkeys(buf, ":call popup_clear()\<CR>")
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020071 call VerifyScreenDump(buf, 'Test_popupwin_08', {})
72
Bram Moolenaar4d784b22019-05-25 19:51:39 +020073 " clean up
74 call StopVimInTerminal(buf)
75 call delete('XtestPopup')
76endfunc
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020077
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020078func Test_popup_with_border_and_padding()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +020079 CheckScreendump
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020080
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +020081 for iter in range(0, 1)
Bram Moolenaare7eb9272019-06-24 00:58:07 +020082 let lines =<< trim END
83 call setline(1, range(1, 100))
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020084 call popup_create('hello border', #{line: 2, col: 3, border: []})
85 call popup_create('hello padding', #{line: 2, col: 23, padding: []})
Bram Moolenaarc363fe12019-08-04 18:13:46 +020086 call popup_create('hello both', #{line: 2, col: 43, border: [], padding: [], highlight: 'Normal'})
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020087 call popup_create('border TL', #{line: 6, col: 3, border: [1, 0, 0, 4]})
88 call popup_create('paddings', #{line: 6, col: 23, padding: [1, 3, 2, 4]})
89 call popup_create('wrapped longer text', #{line: 8, col: 55, padding: [0, 3, 0, 3], border: [0, 1, 0, 1]})
90 call popup_create('right aligned text', #{line: 11, col: 56, wrap: 0, padding: [0, 3, 0, 3], border: [0, 1, 0, 1]})
Bram Moolenaare7eb9272019-06-24 00:58:07 +020091 END
92 call insert(lines, iter == 1 ? '' : 'set enc=latin1')
93 call writefile(lines, 'XtestPopupBorder')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020094 let buf = RunVimInTerminal('-S XtestPopupBorder', #{rows: 15})
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +020095 call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {})
96
97 call StopVimInTerminal(buf)
98 call delete('XtestPopupBorder')
99 endfor
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200100
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200101 let lines =<< trim END
102 call setline(1, range(1, 100))
103 hi BlueColor ctermbg=lightblue
104 hi TopColor ctermbg=253
105 hi RightColor ctermbg=245
106 hi BottomColor ctermbg=240
107 hi LeftColor ctermbg=248
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200108 call popup_create('hello border', #{line: 2, col: 3, border: [], borderhighlight: ['BlueColor']})
109 call popup_create(['hello border', 'and more'], #{line: 2, col: 23, border: [], borderhighlight: ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']})
110 call popup_create(['hello border', 'lines only'], #{line: 2, col: 43, border: [], borderhighlight: ['BlueColor'], borderchars: ['x']})
111 call popup_create(['hello border', 'with corners'], #{line: 2, col: 60, border: [], borderhighlight: ['BlueColor'], borderchars: ['x', '#']})
112 let winid = popup_create(['hello border', 'with numbers'], #{line: 6, col: 3, border: [], borderhighlight: ['BlueColor'], borderchars: ['0', '1', '2', '3', '4', '5', '6', '7']})
113 call popup_create(['hello border', 'just blanks'], #{line: 7, col: 23, border: [], borderhighlight: ['BlueColor'], borderchars: [' ']})
Bram Moolenaar3dabd712019-07-08 23:30:22 +0200114 func MultiByte()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200115 call popup_create(['hello'], #{line: 8, col: 43, border: [], borderchars: ['─', '│', '─', '│', '┌', '┐', '┘', '└']})
Bram Moolenaar3dabd712019-07-08 23:30:22 +0200116 endfunc
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200117 END
118 call writefile(lines, 'XtestPopupBorder')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200119 let buf = RunVimInTerminal('-S XtestPopupBorder', #{rows: 12})
Bram Moolenaar790498b2019-06-01 22:15:29 +0200120 call VerifyScreenDump(buf, 'Test_popupwin_22', {})
121
Bram Moolenaarad24a712019-06-17 20:05:45 +0200122 " check that changing borderchars triggers a redraw
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200123 call term_sendkeys(buf, ":call popup_setoptions(winid, #{borderchars: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']})\<CR>")
Bram Moolenaarad24a712019-06-17 20:05:45 +0200124 call VerifyScreenDump(buf, 'Test_popupwin_23', {})
125
Bram Moolenaar3dabd712019-07-08 23:30:22 +0200126 " check multi-byte border only with 'ambiwidth' single
127 if &ambiwidth == 'single'
128 call term_sendkeys(buf, ":call MultiByte()\<CR>")
129 call VerifyScreenDump(buf, 'Test_popupwin_24', {})
130 endif
131
Bram Moolenaar790498b2019-06-01 22:15:29 +0200132 call StopVimInTerminal(buf)
133 call delete('XtestPopupBorder')
134
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200135 let with_border_or_padding = #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200136 \ line: 2,
137 \ core_line: 3,
138 \ col: 3,
139 \ core_col: 4,
140 \ width: 14,
141 \ core_width: 12,
142 \ height: 3,
143 \ core_height: 1,
144 \ firstline: 1,
145 \ scrollbar: 0,
146 \ visible: 1}
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200147 let winid = popup_create('hello border', #{line: 2, col: 3, border: []})",
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200148 call assert_equal(with_border_or_padding, winid->popup_getpos())
Bram Moolenaarae943152019-06-16 22:54:14 +0200149 let options = popup_getoptions(winid)
150 call assert_equal([], options.border)
151 call assert_false(has_key(options, "padding"))
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200152
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200153 let winid = popup_create('hello padding', #{line: 2, col: 3, padding: []})
Bram Moolenaarae943152019-06-16 22:54:14 +0200154 let with_border_or_padding.width = 15
155 let with_border_or_padding.core_width = 13
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200156 call assert_equal(with_border_or_padding, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200157 let options = popup_getoptions(winid)
158 call assert_false(has_key(options, "border"))
159 call assert_equal([], options.padding)
160
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200161 call popup_setoptions(winid, #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200162 \ padding: [1, 2, 3, 4],
163 \ border: [4, 0, 7, 8],
164 \ borderhighlight: ['Top', 'Right', 'Bottom', 'Left'],
165 \ borderchars: ['1', '^', '2', '>', '3', 'v', '4', '<'],
Bram Moolenaarae943152019-06-16 22:54:14 +0200166 \ })
167 let options = popup_getoptions(winid)
168 call assert_equal([1, 0, 1, 1], options.border)
169 call assert_equal([1, 2, 3, 4], options.padding)
170 call assert_equal(['Top', 'Right', 'Bottom', 'Left'], options.borderhighlight)
171 call assert_equal(['1', '^', '2', '>', '3', 'v', '4', '<'], options.borderchars)
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200172
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200173 let winid = popup_create('hello both', #{line: 3, col: 8, border: [], padding: []})
174 call assert_equal(#{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200175 \ line: 3,
176 \ core_line: 5,
177 \ col: 8,
178 \ core_col: 10,
179 \ width: 14,
180 \ core_width: 10,
181 \ height: 5,
182 \ scrollbar: 0,
183 \ core_height: 1,
184 \ firstline: 1,
185 \ visible: 1}, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200186
187 call popup_clear()
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200188endfunc
189
Bram Moolenaarb4230122019-05-30 18:40:53 +0200190func Test_popup_with_syntax_win_execute()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200191 CheckScreendump
192
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200193 let lines =<< trim END
194 call setline(1, range(1, 100))
195 hi PopupColor ctermbg=lightblue
196 let winid = popup_create([
197 \ '#include <stdio.h>',
198 \ 'int main(void)',
199 \ '{',
200 \ ' printf(123);',
201 \ '}',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200202 \], #{line: 3, col: 25, highlight: 'PopupColor'})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200203 call win_execute(winid, 'set syntax=cpp')
204 END
205 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200206 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaarb4230122019-05-30 18:40:53 +0200207 call VerifyScreenDump(buf, 'Test_popupwin_10', {})
208
209 " clean up
210 call StopVimInTerminal(buf)
211 call delete('XtestPopup')
212endfunc
213
214func Test_popup_with_syntax_setbufvar()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200215 CheckScreendump
216
Bram Moolenaar402502d2019-05-30 22:07:36 +0200217 let lines =<< trim END
218 call setline(1, range(1, 100))
219 hi PopupColor ctermbg=lightgrey
220 let winid = popup_create([
221 \ '#include <stdio.h>',
222 \ 'int main(void)',
223 \ '{',
Bram Moolenaare089c3f2019-07-09 20:25:25 +0200224 \ "\tprintf(567);",
Bram Moolenaar402502d2019-05-30 22:07:36 +0200225 \ '}',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200226 \], #{line: 3, col: 21, highlight: 'PopupColor'})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200227 call setbufvar(winbufnr(winid), '&syntax', 'cpp')
228 END
229 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200230 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaarb4230122019-05-30 18:40:53 +0200231 call VerifyScreenDump(buf, 'Test_popupwin_11', {})
232
233 " clean up
234 call StopVimInTerminal(buf)
235 call delete('XtestPopup')
236endfunc
237
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200238func Test_popup_with_matches()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200239 CheckScreendump
240
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200241 let lines =<< trim END
242 call setline(1, ['111 222 333', '444 555 666'])
243 let winid = popup_create([
244 \ '111 222 333',
245 \ '444 555 666',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200246 \], #{line: 3, col: 10, border: []})
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200247 set hlsearch
248 /666
249 call matchadd('ErrorMsg', '111')
250 call matchadd('ErrorMsg', '444')
251 call win_execute(winid, "call matchadd('ErrorMsg', '111')")
252 call win_execute(winid, "call matchadd('ErrorMsg', '555')")
253 END
254 call writefile(lines, 'XtestPopupMatches')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200255 let buf = RunVimInTerminal('-S XtestPopupMatches', #{rows: 10})
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200256 call VerifyScreenDump(buf, 'Test_popupwin_matches', {})
257
258 " clean up
259 call StopVimInTerminal(buf)
260 call delete('XtestPopupMatches')
261endfunc
262
Bram Moolenaar399d8982019-06-02 15:34:29 +0200263func Test_popup_all_corners()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200264 CheckScreendump
265
Bram Moolenaar399d8982019-06-02 15:34:29 +0200266 let lines =<< trim END
267 call setline(1, repeat([repeat('-', 60)], 15))
268 set so=0
269 normal 2G3|r#
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200270 let winid1 = popup_create(['first', 'second'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200271 \ line: 'cursor+1',
272 \ col: 'cursor',
273 \ pos: 'topleft',
274 \ border: [],
275 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200276 \ })
277 normal 25|r@
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200278 let winid1 = popup_create(['First', 'SeconD'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200279 \ line: 'cursor+1',
280 \ col: 'cursor',
281 \ pos: 'topright',
282 \ border: [],
283 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200284 \ })
285 normal 9G29|r%
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200286 let winid1 = popup_create(['fiRSt', 'seCOnd'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200287 \ line: 'cursor-1',
288 \ col: 'cursor',
289 \ pos: 'botleft',
290 \ border: [],
291 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200292 \ })
293 normal 51|r&
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200294 let winid1 = popup_create(['FIrsT', 'SEcoND'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200295 \ line: 'cursor-1',
296 \ col: 'cursor',
297 \ pos: 'botright',
298 \ border: [],
299 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200300 \ })
301 END
302 call writefile(lines, 'XtestPopupCorners')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200303 let buf = RunVimInTerminal('-S XtestPopupCorners', #{rows: 12})
Bram Moolenaar399d8982019-06-02 15:34:29 +0200304 call VerifyScreenDump(buf, 'Test_popupwin_corners', {})
305
306 " clean up
307 call StopVimInTerminal(buf)
308 call delete('XtestPopupCorners')
309endfunc
310
Bram Moolenaar8d241042019-06-12 23:40:01 +0200311func Test_popup_firstline()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200312 CheckScreendump
313
Bram Moolenaar8d241042019-06-12 23:40:01 +0200314 let lines =<< trim END
315 call setline(1, range(1, 20))
Bram Moolenaar8c6173c2019-08-30 22:08:34 +0200316 let winid = popup_create(['1111', '222222', '33333', '44', '5', '666666', '77777', '888', '9999999999999999'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200317 \ maxheight: 4,
318 \ firstline: 3,
Bram Moolenaar8d241042019-06-12 23:40:01 +0200319 \ })
320 END
321 call writefile(lines, 'XtestPopupFirstline')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200322 let buf = RunVimInTerminal('-S XtestPopupFirstline', #{rows: 10})
Bram Moolenaar8c6173c2019-08-30 22:08:34 +0200323 call VerifyScreenDump(buf, 'Test_popupwin_firstline_1', {})
324
325 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: -1})\<CR>")
326 call term_sendkeys(buf, ":\<CR>")
327 call VerifyScreenDump(buf, 'Test_popupwin_firstline_2', {})
Bram Moolenaar8d241042019-06-12 23:40:01 +0200328
329 " clean up
330 call StopVimInTerminal(buf)
331 call delete('XtestPopupFirstline')
Bram Moolenaarae943152019-06-16 22:54:14 +0200332
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200333 let winid = popup_create(['1111', '222222', '33333', '44444'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200334 \ maxheight: 2,
335 \ firstline: 3,
Bram Moolenaarae943152019-06-16 22:54:14 +0200336 \ })
337 call assert_equal(3, popup_getoptions(winid).firstline)
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200338 call popup_setoptions(winid, #{firstline: 1})
Bram Moolenaarae943152019-06-16 22:54:14 +0200339 call assert_equal(1, popup_getoptions(winid).firstline)
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200340 eval winid->popup_close()
Bram Moolenaar9e67b6a2019-08-30 17:34:08 +0200341
342 let winid = popup_create(['xxx']->repeat(50), #{
343 \ maxheight: 3,
344 \ firstline: 11,
345 \ })
346 redraw
347 call assert_equal(11, popup_getoptions(winid).firstline)
348 call assert_equal(11, popup_getpos(winid).firstline)
Bram Moolenaar8e0a8e72019-09-02 22:56:24 +0200349 " check line() works with popup window
350 call assert_equal(11, line('.', winid))
351 call assert_equal(50, line('$', winid))
352 call assert_equal(0, line('$', 123456))
Bram Moolenaar9e67b6a2019-08-30 17:34:08 +0200353
354 " Normal command changes what is displayed but not "firstline"
355 call win_execute(winid, "normal! \<c-y>")
356 call assert_equal(11, popup_getoptions(winid).firstline)
357 call assert_equal(10, popup_getpos(winid).firstline)
358
359 " Making some property change applies "firstline" again
360 call popup_setoptions(winid, #{line: 4})
361 call assert_equal(11, popup_getoptions(winid).firstline)
362 call assert_equal(11, popup_getpos(winid).firstline)
363
364 " Remove "firstline" property and scroll
365 call popup_setoptions(winid, #{firstline: 0})
366 call win_execute(winid, "normal! \<c-y>")
367 call assert_equal(0, popup_getoptions(winid).firstline)
368 call assert_equal(10, popup_getpos(winid).firstline)
369
370 " Making some property change has no side effect
371 call popup_setoptions(winid, #{line: 3})
372 call assert_equal(0, popup_getoptions(winid).firstline)
373 call assert_equal(10, popup_getpos(winid).firstline)
Bram Moolenaarae943152019-06-16 22:54:14 +0200374
375 call popup_close(winid)
Bram Moolenaar8d241042019-06-12 23:40:01 +0200376endfunc
377
Bram Moolenaara112f2d2019-09-01 17:38:09 +0200378func Test_popup_noscrolloff()
379 set scrolloff=5
380 let winid = popup_create(['xxx']->repeat(50), #{
381 \ maxheight: 5,
382 \ firstline: 11,
383 \ })
384 redraw
385 call assert_equal(11, popup_getoptions(winid).firstline)
386 call assert_equal(11, popup_getpos(winid).firstline)
387
388 call popup_setoptions(winid, #{firstline: 0})
389 call win_execute(winid, "normal! \<c-y>")
390 call assert_equal(0, popup_getoptions(winid).firstline)
391 call assert_equal(10, popup_getpos(winid).firstline)
392
393 call popup_close(winid)
394endfunc
395
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200396func Test_popup_drag()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200397 CheckScreendump
398
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200399 " create a popup that covers the command line
400 let lines =<< trim END
401 call setline(1, range(1, 20))
Bram Moolenaar356375f2019-08-24 14:46:29 +0200402 split
403 vsplit
404 $wincmd w
405 vsplit
406 1wincmd w
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200407 let winid = popup_create(['1111', '222222', '33333'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200408 \ drag: 1,
Bram Moolenaar9bcb70c2019-08-01 21:11:05 +0200409 \ resize: 1,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200410 \ border: [],
411 \ line: &lines - 4,
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200412 \ })
413 func Dragit()
414 call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
415 endfunc
416 map <silent> <F3> :call test_setmouse(&lines - 4, &columns / 2)<CR>
Bram Moolenaar356375f2019-08-24 14:46:29 +0200417 map <silent> <F4> :call test_setmouse(&lines - 8, &columns / 2 - 20)<CR>
Bram Moolenaar9bcb70c2019-08-01 21:11:05 +0200418 func Resize()
419 call feedkeys("\<F5>\<LeftMouse>\<F6>\<LeftDrag>\<LeftRelease>", "xt")
420 endfunc
Bram Moolenaar356375f2019-08-24 14:46:29 +0200421 map <silent> <F5> :call test_setmouse(6, 21)<CR>
422 map <silent> <F6> :call test_setmouse(7, 25)<CR>
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200423 END
424 call writefile(lines, 'XtestPopupDrag')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200425 let buf = RunVimInTerminal('-S XtestPopupDrag', #{rows: 10})
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200426 call VerifyScreenDump(buf, 'Test_popupwin_drag_01', {})
427
428 call term_sendkeys(buf, ":call Dragit()\<CR>")
429 call VerifyScreenDump(buf, 'Test_popupwin_drag_02', {})
430
Bram Moolenaar9bcb70c2019-08-01 21:11:05 +0200431 call term_sendkeys(buf, ":call Resize()\<CR>")
432 call VerifyScreenDump(buf, 'Test_popupwin_drag_03', {})
433
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200434 " clean up
435 call StopVimInTerminal(buf)
436 call delete('XtestPopupDrag')
437endfunc
438
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200439func Test_popup_close_with_mouse()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200440 CheckScreendump
441
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200442 let lines =<< trim END
443 call setline(1, range(1, 20))
444 " With border, can click on X
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200445 let winid = popup_create('foobar', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200446 \ close: 'button',
447 \ border: [],
448 \ line: 1,
449 \ col: 1,
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200450 \ })
451 func CloseMsg(id, result)
452 echomsg 'Popup closed with ' .. a:result
453 endfunc
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200454 let winid = popup_create('notification', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200455 \ close: 'click',
456 \ line: 3,
457 \ col: 15,
458 \ callback: 'CloseMsg',
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200459 \ })
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200460 let winid = popup_create('no border here', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200461 \ close: 'button',
462 \ line: 5,
463 \ col: 3,
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200464 \ })
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200465 let winid = popup_create('only padding', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200466 \ close: 'button',
467 \ padding: [],
468 \ line: 5,
469 \ col: 23,
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200470 \ })
471 func CloseWithX()
472 call feedkeys("\<F3>\<LeftMouse>\<LeftRelease>", "xt")
473 endfunc
474 map <silent> <F3> :call test_setmouse(1, len('foobar') + 2)<CR>
475 func CloseWithClick()
476 call feedkeys("\<F4>\<LeftMouse>\<LeftRelease>", "xt")
477 endfunc
478 map <silent> <F4> :call test_setmouse(3, 17)<CR>
Bram Moolenaarf6396232019-08-24 19:36:00 +0200479 func CreateWithMenuFilter()
480 let winid = popup_create('barfoo', #{
481 \ close: 'button',
482 \ filter: 'popup_filter_menu',
483 \ border: [],
484 \ line: 1,
485 \ col: 40,
486 \ })
487 endfunc
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200488 END
489 call writefile(lines, 'XtestPopupClose')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200490 let buf = RunVimInTerminal('-S XtestPopupClose', #{rows: 10})
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200491 call VerifyScreenDump(buf, 'Test_popupwin_close_01', {})
492
493 call term_sendkeys(buf, ":call CloseWithX()\<CR>")
494 call VerifyScreenDump(buf, 'Test_popupwin_close_02', {})
495
496 call term_sendkeys(buf, ":call CloseWithClick()\<CR>")
497 call VerifyScreenDump(buf, 'Test_popupwin_close_03', {})
498
Bram Moolenaarf6396232019-08-24 19:36:00 +0200499 call term_sendkeys(buf, ":call CreateWithMenuFilter()\<CR>")
500 call VerifyScreenDump(buf, 'Test_popupwin_close_04', {})
501
502 " We have to send the actual mouse code, feedkeys() would be caught the
503 " filter.
504 call term_sendkeys(buf, "\<Esc>[<0;47;1M")
505 call VerifyScreenDump(buf, 'Test_popupwin_close_05', {})
506
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200507 " clean up
508 call StopVimInTerminal(buf)
509 call delete('XtestPopupClose')
510endfunction
511
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200512func Test_popup_with_mask()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200513 CheckScreendump
514
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200515 let lines =<< trim END
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200516 call setline(1, repeat([join(range(1, 42), '')], 13))
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200517 hi PopupColor ctermbg=lightgrey
518 let winid = popup_create([
519 \ 'some text',
520 \ 'another line',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200521 \], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200522 \ line: 1,
523 \ col: 10,
524 \ wrap: 0,
525 \ fixed: 1,
526 \ zindex: 90,
527 \ padding: [],
528 \ highlight: 'PopupColor',
529 \ mask: [[1,1,1,1], [-5,-1,4,4], [7,9,2,3], [2,4,3,3]]})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200530 call popup_create([
531 \ 'xxxxxxxxx',
532 \ 'yyyyyyyyy',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200533 \], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200534 \ line: 3,
535 \ col: 18,
536 \ zindex: 20})
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200537 let winidb = popup_create([
538 \ 'just one line',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200539 \], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200540 \ line: 7,
541 \ col: 10,
542 \ wrap: 0,
543 \ fixed: 1,
544 \ close: 'button',
545 \ zindex: 90,
546 \ padding: [],
547 \ border: [],
548 \ mask: [[1,2,1,1], [-5,-1,4,4], [7,9,2,3], [3,5,5,5],[-7,-4,5,5]]})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200549 END
550 call writefile(lines, 'XtestPopupMask')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200551 let buf = RunVimInTerminal('-S XtestPopupMask', #{rows: 13})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200552 call VerifyScreenDump(buf, 'Test_popupwin_mask_1', {})
553
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200554 call term_sendkeys(buf, ":call popup_move(winid, #{col: 11, line: 2})\<CR>")
555 call term_sendkeys(buf, ":call popup_move(winidb, #{col: 12})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200556 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200557 call VerifyScreenDump(buf, 'Test_popupwin_mask_2', {})
558
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200559 call term_sendkeys(buf, ":call popup_move(winid, #{col: 65, line: 2})\<CR>")
560 call term_sendkeys(buf, ":call popup_move(winidb, #{col: 63})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200561 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaard529ba52019-07-02 23:13:53 +0200562 call VerifyScreenDump(buf, 'Test_popupwin_mask_3', {})
563
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200564 call term_sendkeys(buf, ":call popup_move(winid, #{pos: 'topright', col: 12, line: 2})\<CR>")
565 call term_sendkeys(buf, ":call popup_move(winidb, #{pos: 'topright', col: 12})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200566 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaard529ba52019-07-02 23:13:53 +0200567 call VerifyScreenDump(buf, 'Test_popupwin_mask_4', {})
568
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200569 call term_sendkeys(buf, ":call popup_move(winid, #{pos: 'topright', col: 12, line: 11})\<CR>")
570 call term_sendkeys(buf, ":call popup_move(winidb, #{pos: 'topleft', col: 42, line: 11})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200571 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaarb4207472019-07-12 16:05:45 +0200572 call VerifyScreenDump(buf, 'Test_popupwin_mask_5', {})
573
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200574 " clean up
575 call StopVimInTerminal(buf)
576 call delete('XtestPopupMask')
577endfunc
578
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200579func Test_popup_select()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200580 CheckScreendump
581 CheckFeature clipboard_working
582
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200583 " create a popup with some text to be selected
584 let lines =<< trim END
Bram Moolenaar1755ec42019-06-15 13:13:54 +0200585 set clipboard=autoselect
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200586 call setline(1, range(1, 20))
Bram Moolenaar4dd751b2019-08-17 19:10:53 +0200587 let winid = popup_create(['the word', 'some more', 'several words here', 'invisible', '5', '6', '7'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200588 \ drag: 1,
589 \ border: [],
590 \ line: 3,
591 \ col: 10,
Bram Moolenaar4dd751b2019-08-17 19:10:53 +0200592 \ maxheight: 3,
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200593 \ })
594 func Select1()
595 call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
596 endfunc
597 map <silent> <F3> :call test_setmouse(4, 15)<CR>
598 map <silent> <F4> :call test_setmouse(6, 23)<CR>
599 END
600 call writefile(lines, 'XtestPopupSelect')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200601 let buf = RunVimInTerminal('-S XtestPopupSelect', #{rows: 10})
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200602 call term_sendkeys(buf, ":call Select1()\<CR>")
603 call VerifyScreenDump(buf, 'Test_popupwin_select_01', {})
604
605 call term_sendkeys(buf, ":call popup_close(winid)\<CR>")
606 call term_sendkeys(buf, "\"*p")
Bram Moolenaar8ccabf62019-07-12 18:12:51 +0200607 " clean the command line, sometimes it still shows a command
608 call term_sendkeys(buf, ":\<esc>")
609
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200610 call VerifyScreenDump(buf, 'Test_popupwin_select_02', {})
611
612 " clean up
613 call StopVimInTerminal(buf)
614 call delete('XtestPopupSelect')
615endfunc
616
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200617func Test_popup_in_tab()
618 " default popup is local to tab, not visible when in other tab
619 let winid = popup_create("text", {})
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200620 let bufnr = winbufnr(winid)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200621 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200622 call assert_equal(0, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200623 tabnew
624 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200625 call assert_equal(1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200626 quit
627 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200628
629 call assert_equal(1, bufexists(bufnr))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200630 call popup_clear()
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200631 " buffer is gone now
632 call assert_equal(0, bufexists(bufnr))
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200633
634 " global popup is visible in any tab
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200635 let winid = popup_create("text", #{tabpage: -1})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200636 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200637 call assert_equal(-1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200638 tabnew
639 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200640 call assert_equal(-1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200641 quit
642 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200643 call popup_clear()
Bram Moolenaara3fce622019-06-20 02:31:49 +0200644
645 " create popup in other tab
646 tabnew
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200647 let winid = popup_create("text", #{tabpage: 1})
Bram Moolenaara3fce622019-06-20 02:31:49 +0200648 call assert_equal(0, popup_getpos(winid).visible)
649 call assert_equal(1, popup_getoptions(winid).tabpage)
650 quit
651 call assert_equal(1, popup_getpos(winid).visible)
652 call assert_equal(0, popup_getoptions(winid).tabpage)
653 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200654endfunc
655
656func Test_popup_valid_arguments()
657 " Zero value is like the property wasn't there
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200658 let winid = popup_create("text", #{col: 0})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200659 let pos = popup_getpos(winid)
660 call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200661 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200662
663 " using cursor column has minimum value of 1
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200664 let winid = popup_create("text", #{col: 'cursor-100'})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200665 let pos = popup_getpos(winid)
666 call assert_equal(1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200667 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200668
669 " center
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200670 let winid = popup_create("text", #{pos: 'center'})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200671 let pos = popup_getpos(winid)
672 let around = (&columns - pos.width) / 2
673 call assert_inrange(around - 1, around + 1, pos.col)
674 let around = (&lines - pos.height) / 2
675 call assert_inrange(around - 1, around + 1, pos.line)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200676 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200677endfunc
678
679func Test_popup_invalid_arguments()
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +0200680 call assert_fails('call popup_create(666, {})', 'E86:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200681 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200682 call assert_fails('call popup_create("text", "none")', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200683 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200684
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200685 call assert_fails('call popup_create("text", #{col: "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200686 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200687 call assert_fails('call popup_create("text", #{col: "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200688 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200689 call assert_fails('call popup_create("text", #{col: "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200690 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200691 call assert_fails('call popup_create("text", #{col: "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200692 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200693
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200694 call assert_fails('call popup_create("text", #{line: "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200695 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200696 call assert_fails('call popup_create("text", #{line: "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200697 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200698 call assert_fails('call popup_create("text", #{line: "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200699 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200700 call assert_fails('call popup_create("text", #{line: "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200701 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200702
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200703 call assert_fails('call popup_create("text", #{pos: "there"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200704 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200705 call assert_fails('call popup_create("text", #{padding: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200706 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200707 call assert_fails('call popup_create("text", #{border: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200708 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200709 call assert_fails('call popup_create("text", #{borderhighlight: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200710 call popup_clear()
Bram Moolenaar403d0902019-07-17 21:37:32 +0200711 call assert_fails('call popup_create("text", #{borderhighlight: test_null_list()})', 'E714:')
712 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200713 call assert_fails('call popup_create("text", #{borderchars: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200714 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200715
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200716 call assert_fails('call popup_create([#{text: "text"}, 666], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200717 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200718 call assert_fails('call popup_create([#{text: "text", props: "none"}], {})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200719 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200720 call assert_fails('call popup_create([#{text: "text", props: ["none"]}], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200721 call popup_clear()
Bram Moolenaarcfdbc5a2019-07-17 21:27:52 +0200722 call assert_fails('call popup_create("text", #{mask: ["asdf"]})', 'E475:')
723 call popup_clear()
724 call assert_fails('call popup_create("text", #{mask: test_null_list()})', 'E475:')
Bram Moolenaar749fa0a2019-08-03 16:18:07 +0200725 call assert_fails('call popup_create("text", #{mapping: []})', 'E745:')
Bram Moolenaarcfdbc5a2019-07-17 21:27:52 +0200726 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200727endfunc
728
Bram Moolenaareea16992019-05-31 17:34:48 +0200729func Test_win_execute_closing_curwin()
730 split
731 let winid = popup_create('some text', {})
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200732 call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200733 call popup_clear()
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200734endfunc
735
736func Test_win_execute_not_allowed()
737 let winid = popup_create('some text', {})
738 call assert_fails('call win_execute(winid, "split")', 'E994:')
739 call assert_fails('call win_execute(winid, "vsplit")', 'E994:')
740 call assert_fails('call win_execute(winid, "close")', 'E994:')
741 call assert_fails('call win_execute(winid, "bdelete")', 'E994:')
Bram Moolenaar2d247842019-06-01 17:06:25 +0200742 call assert_fails('call win_execute(winid, "bwipe!")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200743 call assert_fails('call win_execute(winid, "tabnew")', 'E994:')
744 call assert_fails('call win_execute(winid, "tabnext")', 'E994:')
745 call assert_fails('call win_execute(winid, "next")', 'E994:')
746 call assert_fails('call win_execute(winid, "rewind")', 'E994:')
747 call assert_fails('call win_execute(winid, "buf")', 'E994:')
748 call assert_fails('call win_execute(winid, "edit")', 'E994:')
749 call assert_fails('call win_execute(winid, "enew")', 'E994:')
750 call assert_fails('call win_execute(winid, "wincmd x")', 'E994:')
751 call assert_fails('call win_execute(winid, "wincmd w")', 'E994:')
752 call assert_fails('call win_execute(winid, "wincmd t")', 'E994:')
753 call assert_fails('call win_execute(winid, "wincmd b")', 'E994:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200754 call popup_clear()
Bram Moolenaareea16992019-05-31 17:34:48 +0200755endfunc
756
Bram Moolenaar402502d2019-05-30 22:07:36 +0200757func Test_popup_with_wrap()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200758 CheckScreendump
759
Bram Moolenaar402502d2019-05-30 22:07:36 +0200760 let lines =<< trim END
761 call setline(1, range(1, 100))
762 let winid = popup_create(
763 \ 'a long line that wont fit',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200764 \ #{line: 3, col: 20, maxwidth: 10, wrap: 1})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200765 END
766 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200767 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200768 call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
769
770 " clean up
771 call StopVimInTerminal(buf)
772 call delete('XtestPopup')
773endfunc
774
775func Test_popup_without_wrap()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200776 CheckScreendump
777
Bram Moolenaar402502d2019-05-30 22:07:36 +0200778 let lines =<< trim END
779 call setline(1, range(1, 100))
780 let winid = popup_create(
781 \ 'a long line that wont fit',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200782 \ #{line: 3, col: 20, maxwidth: 10, wrap: 0})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200783 END
784 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200785 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200786 call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
787
788 " clean up
789 call StopVimInTerminal(buf)
790 call delete('XtestPopup')
791endfunc
792
Bram Moolenaar331bafd2019-07-20 17:46:05 +0200793func Test_popup_with_showbreak()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200794 CheckScreendump
795
Bram Moolenaar331bafd2019-07-20 17:46:05 +0200796 let lines =<< trim END
797 set showbreak=>>\
798 call setline(1, range(1, 20))
799 let winid = popup_dialog(
Bram Moolenaar8ae54372019-09-15 18:11:16 +0200800 \ 'a long line here that wraps',
801 \ #{filter: 'popup_filter_yesno',
802 \ maxwidth: 12})
Bram Moolenaar331bafd2019-07-20 17:46:05 +0200803 END
804 call writefile(lines, 'XtestPopupShowbreak')
805 let buf = RunVimInTerminal('-S XtestPopupShowbreak', #{rows: 10})
806 call VerifyScreenDump(buf, 'Test_popupwin_showbreak', {})
807
808 " clean up
809 call term_sendkeys(buf, "y")
810 call StopVimInTerminal(buf)
811 call delete('XtestPopupShowbreak')
812endfunc
813
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200814func Test_popup_time()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200815 CheckFeature timers
816
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200817 topleft vnew
818 call setline(1, 'hello')
819
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200820 let winid = popup_create('world', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200821 \ line: 1,
822 \ col: 1,
823 \ minwidth: 20,
824 \ time: 500,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200825 \})
826 redraw
827 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
828 call assert_equal('world', line)
829
Bram Moolenaarb4f06282019-07-12 21:07:54 +0200830 call assert_equal(winid, popup_locate(1, 1))
831 call assert_equal(winid, popup_locate(1, 20))
832 call assert_equal(0, popup_locate(1, 21))
833 call assert_equal(0, popup_locate(2, 1))
834
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200835 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200836 redraw
Bram Moolenaar196b4662019-09-06 21:34:30 +0200837 let line = join(map(range(1, 5), '1->screenstring(v:val)'), '')
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200838 call assert_equal('hello', line)
839
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200840 call popup_create('on the command line', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200841 \ line: &lines,
842 \ col: 10,
843 \ minwidth: 20,
844 \ time: 500,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200845 \})
846 redraw
847 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
848 call assert_match('.*on the command line.*', line)
849
850 sleep 700m
851 redraw
852 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
853 call assert_notmatch('.*on the command line.*', line)
854
855 bwipe!
856endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200857
858func Test_popup_hide()
859 topleft vnew
860 call setline(1, 'hello')
861
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200862 let winid = popup_create('world', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200863 \ line: 1,
864 \ col: 1,
865 \ minwidth: 20,
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200866 \})
867 redraw
868 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
869 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200870 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200871 " buffer is still listed and active
872 call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200873
874 call popup_hide(winid)
875 redraw
876 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
877 call assert_equal('hello', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200878 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +0200879 " buffer is still listed but hidden
880 call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200881
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200882 eval winid->popup_show()
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200883 redraw
884 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
885 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200886 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200887
888
889 call popup_close(winid)
890 redraw
891 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
892 call assert_equal('hello', line)
893
894 " error is given for existing non-popup window
895 call assert_fails('call popup_hide(win_getid())', 'E993:')
896
897 " no error non-existing window
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200898 eval 1234234->popup_hide()
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200899 call popup_show(41234234)
900
901 bwipe!
902endfunc
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200903
904func Test_popup_move()
905 topleft vnew
906 call setline(1, 'hello')
907
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200908 let winid = popup_create('world', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200909 \ line: 1,
910 \ col: 1,
911 \ minwidth: 20,
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200912 \})
913 redraw
914 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
915 call assert_equal('world ', line)
916
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200917 call popup_move(winid, #{line: 2, col: 2})
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200918 redraw
919 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
920 call assert_equal('hello ', line)
921 let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
922 call assert_equal('~world', line)
923
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200924 eval winid->popup_move(#{line: 1})
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200925 redraw
926 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
927 call assert_equal('hworld', line)
928
929 call popup_close(winid)
930
931 bwipe!
932endfunc
Bram Moolenaarbc133542019-05-29 20:26:46 +0200933
Bram Moolenaar402502d2019-05-30 22:07:36 +0200934func Test_popup_getpos()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200935 let winid = popup_create('hello', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200936 \ line: 2,
937 \ col: 3,
938 \ minwidth: 10,
939 \ minheight: 11,
Bram Moolenaarbc133542019-05-29 20:26:46 +0200940 \})
941 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200942 let res = popup_getpos(winid)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200943 call assert_equal(2, res.line)
944 call assert_equal(3, res.col)
945 call assert_equal(10, res.width)
946 call assert_equal(11, res.height)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200947 call assert_equal(1, res.visible)
Bram Moolenaarbc133542019-05-29 20:26:46 +0200948
949 call popup_close(winid)
950endfunc
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200951
952func Test_popup_width_longest()
953 let tests = [
954 \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
955 \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
956 \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
957 \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
958 \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
959 \ ]
960
961 for test in tests
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200962 let winid = popup_create(test[0], #{line: 2, col: 3})
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200963 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200964 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200965 call assert_equal(test[1], position.width)
966 call popup_close(winid)
967 endfor
968endfunc
969
970func Test_popup_wraps()
971 let tests = [
972 \ ['nowrap', 6, 1],
973 \ ['a line that wraps once', 12, 2],
974 \ ['a line that wraps two times', 12, 3],
975 \ ]
976 for test in tests
977 let winid = popup_create(test[0],
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200978 \ #{line: 2, col: 3, maxwidth: 12})
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200979 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +0200980 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200981 call assert_equal(test[1], position.width)
982 call assert_equal(test[2], position.height)
983
984 call popup_close(winid)
Bram Moolenaar402502d2019-05-30 22:07:36 +0200985 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200986 endfor
987endfunc
Bram Moolenaar8c2a6002019-05-30 14:29:45 +0200988
989func Test_popup_getoptions()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200990 let winid = popup_create('hello', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200991 \ line: 2,
992 \ col: 3,
993 \ minwidth: 10,
994 \ minheight: 11,
995 \ maxwidth: 20,
996 \ maxheight: 21,
997 \ zindex: 100,
998 \ time: 5000,
999 \ fixed: 1
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001000 \})
1001 redraw
1002 let res = popup_getoptions(winid)
1003 call assert_equal(2, res.line)
1004 call assert_equal(3, res.col)
1005 call assert_equal(10, res.minwidth)
1006 call assert_equal(11, res.minheight)
1007 call assert_equal(20, res.maxwidth)
1008 call assert_equal(21, res.maxheight)
1009 call assert_equal(100, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001010 call assert_equal(1, res.fixed)
Bram Moolenaarb8350ab2019-08-04 17:59:49 +02001011 call assert_equal(1, res.mapping)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001012 if has('timers')
1013 call assert_equal(5000, res.time)
1014 endif
1015 call popup_close(winid)
1016
1017 let winid = popup_create('hello', {})
1018 redraw
1019 let res = popup_getoptions(winid)
1020 call assert_equal(0, res.line)
1021 call assert_equal(0, res.col)
1022 call assert_equal(0, res.minwidth)
1023 call assert_equal(0, res.minheight)
1024 call assert_equal(0, res.maxwidth)
1025 call assert_equal(0, res.maxheight)
1026 call assert_equal(50, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001027 call assert_equal(0, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001028 if has('timers')
1029 call assert_equal(0, res.time)
1030 endif
1031 call popup_close(winid)
1032 call assert_equal({}, popup_getoptions(winid))
1033endfunc
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02001034
1035func Test_popup_option_values()
1036 new
1037 " window-local
1038 setlocal number
1039 setlocal nowrap
1040 " buffer-local
1041 setlocal omnifunc=Something
1042 " global/buffer-local
1043 setlocal path=/there
1044 " global/window-local
Bram Moolenaara112f2d2019-09-01 17:38:09 +02001045 setlocal statusline=2
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02001046
1047 let winid = popup_create('hello', {})
1048 call assert_equal(0, getwinvar(winid, '&number'))
1049 call assert_equal(1, getwinvar(winid, '&wrap'))
1050 call assert_equal('', getwinvar(winid, '&omnifunc'))
1051 call assert_equal(&g:path, getwinvar(winid, '&path'))
Bram Moolenaara112f2d2019-09-01 17:38:09 +02001052 call assert_equal(&g:statusline, getwinvar(winid, '&statusline'))
1053
1054 " 'scrolloff' is reset to zero
1055 call assert_equal(5, &scrolloff)
1056 call assert_equal(0, getwinvar(winid, '&scrolloff'))
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02001057
1058 call popup_close(winid)
1059 bwipe
1060endfunc
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001061
1062func Test_popup_atcursor()
1063 topleft vnew
1064 call setline(1, [
1065 \ 'xxxxxxxxxxxxxxxxx',
1066 \ 'xxxxxxxxxxxxxxxxx',
1067 \ 'xxxxxxxxxxxxxxxxx',
1068 \])
1069
1070 call cursor(2, 2)
1071 redraw
1072 let winid = popup_atcursor('vim', {})
1073 redraw
1074 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
1075 call assert_equal('xvimxxxxxxxxxxxxx', line)
1076 call popup_close(winid)
1077
1078 call cursor(3, 4)
1079 redraw
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001080 let winid = 'vim'->popup_atcursor({})
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001081 redraw
1082 let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
1083 call assert_equal('xxxvimxxxxxxxxxxx', line)
1084 call popup_close(winid)
1085
1086 call cursor(1, 1)
1087 redraw
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001088 let winid = popup_create('vim', #{
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001089 \ line: 'cursor+2',
1090 \ col: 'cursor+1',
1091 \})
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001092 redraw
1093 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '')
1094 call assert_equal('xvimxxxxxxxxxxxxx', line)
1095 call popup_close(winid)
1096
1097 call cursor(3, 3)
1098 redraw
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001099 let winid = popup_create('vim', #{
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001100 \ line: 'cursor-2',
1101 \ col: 'cursor-1',
1102 \})
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001103 redraw
1104 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
1105 call assert_equal('xvimxxxxxxxxxxxxx', line)
1106 call popup_close(winid)
1107
Bram Moolenaar402502d2019-05-30 22:07:36 +02001108 " just enough room above
1109 call cursor(3, 3)
1110 redraw
1111 let winid = popup_atcursor(['vim', 'is great'], {})
1112 redraw
1113 let pos = popup_getpos(winid)
1114 call assert_equal(1, pos.line)
1115 call popup_close(winid)
1116
1117 " not enough room above, popup goes below the cursor
1118 call cursor(3, 3)
1119 redraw
1120 let winid = popup_atcursor(['vim', 'is', 'great'], {})
1121 redraw
1122 let pos = popup_getpos(winid)
1123 call assert_equal(4, pos.line)
1124 call popup_close(winid)
1125
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +02001126 " cursor in first line, popup in line 2
1127 call cursor(1, 1)
1128 redraw
1129 let winid = popup_atcursor(['vim', 'is', 'great'], {})
1130 redraw
1131 let pos = popup_getpos(winid)
1132 call assert_equal(2, pos.line)
1133 call popup_close(winid)
1134
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001135 bwipe!
1136endfunc
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001137
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001138func Test_popup_beval()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001139 CheckScreendump
Bram Moolenaar1e82a782019-09-21 22:57:06 +02001140 CheckFeature balloon_eval_term
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001141
1142 let lines =<< trim END
1143 call setline(1, range(1, 20))
1144 call setline(5, 'here is some text to hover over')
1145 set balloonevalterm
1146 set balloonexpr=BalloonExpr()
1147 set balloondelay=100
1148 func BalloonExpr()
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001149 let s:winid = [v:beval_text]->popup_beval({})
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001150 return ''
1151 endfunc
1152 func Hover()
1153 call test_setmouse(5, 15)
1154 call feedkeys("\<MouseMove>\<Ignore>", "xt")
1155 sleep 100m
1156 endfunc
1157 func MoveOntoPopup()
1158 call test_setmouse(4, 17)
1159 call feedkeys("\<F4>\<MouseMove>\<Ignore>", "xt")
1160 endfunc
1161 func MoveAway()
1162 call test_setmouse(5, 13)
1163 call feedkeys("\<F5>\<MouseMove>\<Ignore>", "xt")
1164 endfunc
1165 END
1166 call writefile(lines, 'XtestPopupBeval')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001167 let buf = RunVimInTerminal('-S XtestPopupBeval', #{rows: 10})
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001168 call term_wait(buf, 100)
1169 call term_sendkeys(buf, 'j')
1170 call term_sendkeys(buf, ":call Hover()\<CR>")
1171 call VerifyScreenDump(buf, 'Test_popupwin_beval_1', {})
1172
1173 call term_sendkeys(buf, ":call MoveOntoPopup()\<CR>")
1174 call VerifyScreenDump(buf, 'Test_popupwin_beval_2', {})
1175
1176 call term_sendkeys(buf, ":call MoveAway()\<CR>")
1177 call VerifyScreenDump(buf, 'Test_popupwin_beval_3', {})
1178
1179 " clean up
1180 call StopVimInTerminal(buf)
1181 call delete('XtestPopupBeval')
1182endfunc
1183
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001184func Test_popup_filter()
1185 new
1186 call setline(1, 'some text')
1187
1188 func MyPopupFilter(winid, c)
1189 if a:c == 'e'
1190 let g:eaten = 'e'
1191 return 1
1192 endif
1193 if a:c == '0'
1194 let g:ignored = '0'
1195 return 0
1196 endif
1197 if a:c == 'x'
1198 call popup_close(a:winid)
1199 return 1
1200 endif
1201 return 0
1202 endfunc
1203
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001204 let winid = 'something'->popup_create(#{filter: 'MyPopupFilter'})
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001205 redraw
1206
1207 " e is consumed by the filter
1208 call feedkeys('e', 'xt')
1209 call assert_equal('e', g:eaten)
1210
1211 " 0 is ignored by the filter
1212 normal $
1213 call assert_equal(9, getcurpos()[2])
1214 call feedkeys('0', 'xt')
1215 call assert_equal('0', g:ignored)
1216 call assert_equal(1, getcurpos()[2])
1217
1218 " x closes the popup
1219 call feedkeys('x', 'xt')
1220 call assert_equal('e', g:eaten)
1221 call assert_equal(-1, winbufnr(winid))
1222
1223 delfunc MyPopupFilter
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001224 call popup_clear()
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001225endfunc
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001226
Bram Moolenaara42d9452019-06-15 21:46:30 +02001227func ShowDialog(key, result)
1228 let s:cb_res = 999
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001229 let winid = popup_dialog('do you want to quit (Yes/no)?', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001230 \ filter: 'popup_filter_yesno',
1231 \ callback: 'QuitCallback',
Bram Moolenaara42d9452019-06-15 21:46:30 +02001232 \ })
1233 redraw
1234 call feedkeys(a:key, "xt")
1235 call assert_equal(winid, s:cb_winid)
1236 call assert_equal(a:result, s:cb_res)
1237endfunc
1238
1239func Test_popup_dialog()
1240 func QuitCallback(id, res)
1241 let s:cb_winid = a:id
1242 let s:cb_res = a:res
1243 endfunc
1244
1245 let winid = ShowDialog("y", 1)
1246 let winid = ShowDialog("Y", 1)
1247 let winid = ShowDialog("n", 0)
1248 let winid = ShowDialog("N", 0)
1249 let winid = ShowDialog("x", 0)
1250 let winid = ShowDialog("X", 0)
1251 let winid = ShowDialog("\<Esc>", 0)
1252 let winid = ShowDialog("\<C-C>", -1)
1253
1254 delfunc QuitCallback
1255endfunc
1256
Bram Moolenaara730e552019-06-16 19:05:31 +02001257func ShowMenu(key, result)
1258 let s:cb_res = 999
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001259 let winid = popup_menu(['one', 'two', 'something else'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001260 \ callback: 'QuitCallback',
Bram Moolenaara730e552019-06-16 19:05:31 +02001261 \ })
1262 redraw
1263 call feedkeys(a:key, "xt")
1264 call assert_equal(winid, s:cb_winid)
1265 call assert_equal(a:result, s:cb_res)
1266endfunc
1267
1268func Test_popup_menu()
1269 func QuitCallback(id, res)
1270 let s:cb_winid = a:id
1271 let s:cb_res = a:res
1272 endfunc
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02001273 " mapping won't be used in popup
1274 map j k
Bram Moolenaara730e552019-06-16 19:05:31 +02001275
1276 let winid = ShowMenu(" ", 1)
1277 let winid = ShowMenu("j \<CR>", 2)
1278 let winid = ShowMenu("JjK \<CR>", 2)
1279 let winid = ShowMenu("jjjjjj ", 3)
1280 let winid = ShowMenu("kkk ", 1)
1281 let winid = ShowMenu("x", -1)
1282 let winid = ShowMenu("X", -1)
1283 let winid = ShowMenu("\<Esc>", -1)
1284 let winid = ShowMenu("\<C-C>", -1)
1285
1286 delfunc QuitCallback
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02001287 unmap j
Bram Moolenaara730e552019-06-16 19:05:31 +02001288endfunc
1289
1290func Test_popup_menu_screenshot()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001291 CheckScreendump
Bram Moolenaara730e552019-06-16 19:05:31 +02001292
1293 let lines =<< trim END
1294 call setline(1, range(1, 20))
1295 hi PopupSelected ctermbg=lightblue
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001296 call popup_menu(['one', 'two', 'another'], #{callback: 'MenuDone', title: ' make a choice from the list '})
Bram Moolenaara730e552019-06-16 19:05:31 +02001297 func MenuDone(id, res)
1298 echomsg "selected " .. a:res
1299 endfunc
1300 END
1301 call writefile(lines, 'XtestPopupMenu')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001302 let buf = RunVimInTerminal('-S XtestPopupMenu', #{rows: 10})
Bram Moolenaara730e552019-06-16 19:05:31 +02001303 call VerifyScreenDump(buf, 'Test_popupwin_menu_01', {})
1304
1305 call term_sendkeys(buf, "jj")
1306 call VerifyScreenDump(buf, 'Test_popupwin_menu_02', {})
1307
1308 call term_sendkeys(buf, " ")
1309 call VerifyScreenDump(buf, 'Test_popupwin_menu_03', {})
1310
1311 " clean up
1312 call StopVimInTerminal(buf)
1313 call delete('XtestPopupMenu')
1314endfunc
1315
Bram Moolenaarf914a332019-07-20 15:09:56 +02001316func Test_popup_menu_narrow()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001317 CheckScreendump
Bram Moolenaarf914a332019-07-20 15:09:56 +02001318
1319 let lines =<< trim END
1320 call setline(1, range(1, 20))
1321 hi PopupSelected ctermbg=green
1322 call popup_menu(['one', 'two', 'three'], #{callback: 'MenuDone'})
1323 func MenuDone(id, res)
1324 echomsg "selected " .. a:res
1325 endfunc
1326 END
1327 call writefile(lines, 'XtestPopupNarrowMenu')
1328 let buf = RunVimInTerminal('-S XtestPopupNarrowMenu', #{rows: 10})
1329 call VerifyScreenDump(buf, 'Test_popupwin_menu_04', {})
1330
1331 " clean up
1332 call term_sendkeys(buf, "x")
1333 call StopVimInTerminal(buf)
1334 call delete('XtestPopupNarrowMenu')
1335endfunc
1336
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001337func Test_popup_title()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001338 CheckScreendump
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001339
1340 " Create a popup without title or border, a line of padding will be added to
1341 " put the title on.
1342 let lines =<< trim END
1343 call setline(1, range(1, 20))
Bram Moolenaar5d458a72019-08-04 21:12:15 +02001344 let winid = popup_create(['one', 'two', 'another'], #{title: 'Title String'})
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001345 END
1346 call writefile(lines, 'XtestPopupTitle')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001347 let buf = RunVimInTerminal('-S XtestPopupTitle', #{rows: 10})
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001348 call VerifyScreenDump(buf, 'Test_popupwin_title', {})
1349
Bram Moolenaar5d458a72019-08-04 21:12:15 +02001350 call term_sendkeys(buf, ":call popup_setoptions(winid, #{maxwidth: 20, title: 'a very long title that is not going to fit'})\<CR>")
1351 call term_sendkeys(buf, ":\<CR>")
1352 call VerifyScreenDump(buf, 'Test_popupwin_longtitle_1', {})
1353
1354 call term_sendkeys(buf, ":call popup_setoptions(winid, #{border: []})\<CR>")
1355 call term_sendkeys(buf, ":\<CR>")
1356 call VerifyScreenDump(buf, 'Test_popupwin_longtitle_2', {})
1357
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001358 " clean up
1359 call StopVimInTerminal(buf)
1360 call delete('XtestPopupTitle')
Bram Moolenaarae943152019-06-16 22:54:14 +02001361
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001362 let winid = popup_create('something', #{title: 'Some Title'})
Bram Moolenaarae943152019-06-16 22:54:14 +02001363 call assert_equal('Some Title', popup_getoptions(winid).title)
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001364 call popup_setoptions(winid, #{title: 'Another Title'})
Bram Moolenaarae943152019-06-16 22:54:14 +02001365 call assert_equal('Another Title', popup_getoptions(winid).title)
1366
1367 call popup_clear()
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001368endfunc
1369
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001370func Test_popup_close_callback()
1371 func PopupDone(id, result)
1372 let g:result = a:result
1373 endfunc
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001374 let winid = popup_create('something', #{callback: 'PopupDone'})
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001375 redraw
1376 call popup_close(winid, 'done')
1377 call assert_equal('done', g:result)
1378endfunc
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001379
1380func Test_popup_empty()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001381 let winid = popup_create('', #{padding: [2,2,2,2]})
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001382 redraw
1383 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001384 call assert_equal(5, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001385 call assert_equal(5, pos.height)
1386
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001387 let winid = popup_create([], #{border: []})
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001388 redraw
1389 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001390 call assert_equal(3, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001391 call assert_equal(3, pos.height)
1392endfunc
Bram Moolenaar988c4332019-06-02 14:12:11 +02001393
1394func Test_popup_never_behind()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001395 CheckScreendump
1396
Bram Moolenaar988c4332019-06-02 14:12:11 +02001397 " +-----------------------------+
1398 " | | |
1399 " | | |
1400 " | | |
1401 " | line1 |
1402 " |------------line2------------|
1403 " | line3 |
1404 " | line4 |
1405 " | |
1406 " | |
1407 " +-----------------------------+
1408 let lines =<< trim END
Bram Moolenaar988c4332019-06-02 14:12:11 +02001409 split
1410 vsplit
1411 let info_window1 = getwininfo()[0]
1412 let line = info_window1['height']
1413 let col = info_window1['width']
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001414 call popup_create(['line1', 'line2', 'line3', 'line4'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001415 \ line : line,
1416 \ col : col,
Bram Moolenaar988c4332019-06-02 14:12:11 +02001417 \ })
1418 END
1419 call writefile(lines, 'XtestPopupBehind')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001420 let buf = RunVimInTerminal('-S XtestPopupBehind', #{rows: 10})
Bram Moolenaar988c4332019-06-02 14:12:11 +02001421 call term_sendkeys(buf, "\<C-W>w")
1422 call VerifyScreenDump(buf, 'Test_popupwin_behind', {})
1423
1424 " clean up
1425 call StopVimInTerminal(buf)
1426 call delete('XtestPopupBehind')
1427endfunc
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001428
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001429func s:VerifyPosition(p, msg, line, col, width, height)
1430 call assert_equal(a:line, popup_getpos(a:p).line, a:msg . ' (l)')
1431 call assert_equal(a:col, popup_getpos(a:p).col, a:msg . ' (c)')
1432 call assert_equal(a:width, popup_getpos(a:p).width, a:msg . ' (w)')
1433 call assert_equal(a:height, popup_getpos(a:p).height, a:msg . ' (h)')
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001434endfunc
1435
1436func Test_popup_position_adjust()
1437 " Anything placed past 2 cells from of the right of the screen is moved to the
1438 " left.
1439 "
1440 " When wrapping is disabled, we also shift to the left to display on the
1441 " screen, unless fixed is set.
1442
1443 " Entries for cases which don't vary based on wrapping.
1444 " Format is per tests described below
1445 let both_wrap_tests = [
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001446 \ ['a', 5, &columns, 5, &columns - 2, 1, 1],
1447 \ ['b', 5, &columns + 1, 5, &columns - 2, 1, 1],
1448 \ ['c', 5, &columns - 1, 5, &columns - 2, 1, 1],
1449 \ ['d', 5, &columns - 2, 5, &columns - 2, 1, 1],
1450 \ ['e', 5, &columns - 3, 5, &columns - 3, 1, 1],
1451 \
1452 \ ['aa', 5, &columns, 5, &columns - 2, 2, 1],
1453 \ ['bb', 5, &columns + 1, 5, &columns - 2, 2, 1],
1454 \ ['cc', 5, &columns - 1, 5, &columns - 2, 2, 1],
1455 \ ['dd', 5, &columns - 2, 5, &columns - 2, 2, 1],
1456 \ ['ee', 5, &columns - 3, 5, &columns - 3, 2, 1],
1457 \
1458 \ ['aaa', 5, &columns, 5, &columns - 2, 3, 1],
1459 \ ['bbb', 5, &columns + 1, 5, &columns - 2, 3, 1],
1460 \ ['ccc', 5, &columns - 1, 5, &columns - 2, 3, 1],
1461 \ ['ddd', 5, &columns - 2, 5, &columns - 2, 3, 1],
1462 \ ['eee', 5, &columns - 3, 5, &columns - 3, 3, 1],
1463 \ ]
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001464
1465 " these test groups are dicts with:
1466 " - comment: something to identify the group of tests by
1467 " - options: dict of options to merge with the row/col in tests
1468 " - tests: list of cases. Each one is a list with elements:
1469 " - text
1470 " - row
1471 " - col
1472 " - expected row
1473 " - expected col
1474 " - expected width
1475 " - expected height
1476 let tests = [
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001477 \ #{
1478 \ comment: 'left-aligned with wrapping',
1479 \ options: #{
1480 \ wrap: 1,
1481 \ pos: 'botleft',
1482 \ },
1483 \ tests: both_wrap_tests + [
1484 \ ['aaaa', 5, &columns, 4, &columns - 2, 3, 2],
1485 \ ['bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2],
1486 \ ['cccc', 5, &columns - 1, 4, &columns - 2, 3, 2],
1487 \ ['dddd', 5, &columns - 2, 4, &columns - 2, 3, 2],
1488 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1],
1489 \ ],
1490 \ },
1491 \ #{
1492 \ comment: 'left aligned without wrapping',
1493 \ options: #{
1494 \ wrap: 0,
1495 \ pos: 'botleft',
1496 \ },
1497 \ tests: both_wrap_tests + [
1498 \ ['aaaa', 5, &columns, 5, &columns - 3, 4, 1],
1499 \ ['bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1],
1500 \ ['cccc', 5, &columns - 1, 5, &columns - 3, 4, 1],
1501 \ ['dddd', 5, &columns - 2, 5, &columns - 3, 4, 1],
1502 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1],
1503 \ ],
1504 \ },
1505 \ #{
1506 \ comment: 'left aligned with fixed position',
1507 \ options: #{
1508 \ wrap: 0,
1509 \ fixed: 1,
1510 \ pos: 'botleft',
1511 \ },
1512 \ tests: both_wrap_tests + [
1513 \ ['aaaa', 5, &columns, 5, &columns - 2, 3, 1],
1514 \ ['bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1],
1515 \ ['cccc', 5, &columns - 1, 5, &columns - 2, 3, 1],
1516 \ ['dddd', 5, &columns - 2, 5, &columns - 2, 3, 1],
1517 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1],
1518 \ ],
1519 \ },
1520 \ ]
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001521
1522 for test_group in tests
1523 for test in test_group.tests
1524 let [ text, line, col, e_line, e_col, e_width, e_height ] = test
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001525 let options = #{
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001526 \ line: line,
1527 \ col: col,
1528 \ }
1529 call extend(options, test_group.options)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001530
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001531 let p = popup_create(text, options)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001532
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001533 let msg = string(extend(options, #{text: text}))
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001534 call s:VerifyPosition(p, msg, e_line, e_col, e_width, e_height)
1535 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001536 endfor
1537 endfor
1538
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001539 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001540 %bwipe!
1541endfunc
1542
Bram Moolenaar3397f742019-06-02 18:40:06 +02001543func Test_adjust_left_past_screen_width()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001544 " width of screen
1545 let X = join(map(range(&columns), {->'X'}), '')
1546
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001547 let p = popup_create(X, #{line: 1, col: 1, wrap: 0})
1548 call s:VerifyPosition(p, 'full width topleft', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001549
1550 redraw
1551 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1552 call assert_equal(X, line)
1553
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001554 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001555 redraw
1556
1557 " Same if placed on the right hand side
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001558 let p = popup_create(X, #{line: 1, col: &columns, wrap: 0})
1559 call s:VerifyPosition(p, 'full width topright', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001560
1561 redraw
1562 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1563 call assert_equal(X, line)
1564
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001565 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001566 redraw
1567
1568 " Extend so > window width
1569 let X .= 'x'
1570
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001571 let p = popup_create(X, #{line: 1, col: 1, wrap: 0})
1572 call s:VerifyPosition(p, 'full width + 1 topleft', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001573
1574 redraw
1575 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1576 call assert_equal(X[ : -2 ], line)
1577
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001578 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001579 redraw
1580
1581 " Shifted then truncated (the x is not visible)
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001582 let p = popup_create(X, #{line: 1, col: &columns - 3, wrap: 0})
1583 call s:VerifyPosition(p, 'full width + 1 topright', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001584
1585 redraw
1586 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1587 call assert_equal(X[ : -2 ], line)
1588
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001589 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001590 redraw
1591
1592 " Not shifted, just truncated
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001593 let p = popup_create(X,
1594 \ #{line: 1, col: 2, wrap: 0, fixed: 1})
1595 call s:VerifyPosition(p, 'full width + 1 fixed', 1, 2, &columns - 1, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001596
1597 redraw
1598 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1599 let e_line = ' ' . X[ 1 : -2 ]
1600 call assert_equal(e_line, line)
1601
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001602 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001603 redraw
1604
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001605 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001606 %bwipe!
Bram Moolenaar3397f742019-06-02 18:40:06 +02001607endfunc
1608
1609func Test_popup_moved()
1610 new
1611 call test_override('char_avail', 1)
1612 call setline(1, ['one word to move around', 'a WORD.and->some thing'])
1613
1614 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001615 let winid = popup_atcursor('text', #{moved: 'any'})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001616 redraw
1617 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001618 call assert_equal([1, 4, 4], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001619 " trigger the check for last_cursormoved by going into insert mode
1620 call feedkeys("li\<Esc>", 'xt')
1621 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001622 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001623
1624 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001625 let winid = popup_atcursor('text', #{moved: 'word'})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001626 redraw
1627 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001628 call assert_equal([1, 4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001629 call feedkeys("hi\<Esc>", 'xt')
1630 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001631 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001632
1633 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001634 let winid = popup_atcursor('text', #{moved: 'word'})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001635 redraw
1636 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001637 call assert_equal([1, 4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001638 call feedkeys("li\<Esc>", 'xt')
1639 call assert_equal(1, popup_getpos(winid).visible)
1640 call feedkeys("ei\<Esc>", 'xt')
1641 call assert_equal(1, popup_getpos(winid).visible)
1642 call feedkeys("eli\<Esc>", 'xt')
1643 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001644 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001645
Bram Moolenaar17627312019-06-02 19:53:44 +02001646 " WORD is the default
Bram Moolenaar3397f742019-06-02 18:40:06 +02001647 exe "normal gg0/WORD\<CR>"
Bram Moolenaar17627312019-06-02 19:53:44 +02001648 let winid = popup_atcursor('text', {})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001649 redraw
1650 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001651 call assert_equal([2, 2, 15], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001652 call feedkeys("eli\<Esc>", 'xt')
1653 call assert_equal(1, popup_getpos(winid).visible)
1654 call feedkeys("wi\<Esc>", 'xt')
1655 call assert_equal(1, popup_getpos(winid).visible)
1656 call feedkeys("Eli\<Esc>", 'xt')
1657 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001658 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001659
1660 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001661 let winid = popup_atcursor('text', #{moved: [5, 10]})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001662 redraw
1663 call assert_equal(1, popup_getpos(winid).visible)
1664 call feedkeys("eli\<Esc>", 'xt')
1665 call feedkeys("ei\<Esc>", 'xt')
1666 call assert_equal(1, popup_getpos(winid).visible)
1667 call feedkeys("eli\<Esc>", 'xt')
1668 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001669 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001670
1671 bwipe!
1672 call test_override('ALL', 0)
1673endfunc
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001674
1675func Test_notifications()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001676 CheckFeature timers
1677 CheckScreendump
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001678
Bram Moolenaar0fdddee2019-09-01 15:26:23 +02001679 let lines =<< trim END
1680 call setline(1, range(1, 20))
1681 hi Notification ctermbg=lightblue
1682 call popup_notification('first notification', {})
1683 END
1684 call writefile(lines, 'XtestNotifications')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001685 let buf = RunVimInTerminal('-S XtestNotifications', #{rows: 10})
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001686 call VerifyScreenDump(buf, 'Test_popupwin_notify_01', {})
1687
1688 " second one goes below the first one
Bram Moolenaardfa97f22019-06-15 14:31:55 +02001689 call term_sendkeys(buf, ":hi link PopupNotification Notification\<CR>")
1690 call term_sendkeys(buf, ":call popup_notification('another important notification', {})\<CR>")
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001691 call VerifyScreenDump(buf, 'Test_popupwin_notify_02', {})
1692
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001693 " clean up
1694 call StopVimInTerminal(buf)
1695 call delete('XtestNotifications')
1696endfunc
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001697
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001698func Test_popup_scrollbar()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001699 CheckScreendump
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001700
1701 let lines =<< trim END
1702 call setline(1, range(1, 20))
Bram Moolenaar8da41812019-06-26 18:04:54 +02001703 hi ScrollThumb ctermbg=blue
1704 hi ScrollBar ctermbg=red
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001705 let winid = popup_create(['one', 'two', 'three', 'four', 'five',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001706 \ 'six', 'seven', 'eight', 'nine'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001707 \ minwidth: 8,
1708 \ maxheight: 4,
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001709 \ })
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001710 func ScrollUp()
1711 call feedkeys("\<F3>\<ScrollWheelUp>", "xt")
1712 endfunc
1713 func ScrollDown()
1714 call feedkeys("\<F3>\<ScrollWheelDown>", "xt")
1715 endfunc
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001716 func ClickTop()
1717 call feedkeys("\<F4>\<LeftMouse>", "xt")
1718 endfunc
1719 func ClickBot()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001720 call popup_setoptions(g:winid, #{border: [], close: 'button'})
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001721 call feedkeys("\<F5>\<LeftMouse>", "xt")
1722 endfunc
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001723 map <silent> <F3> :call test_setmouse(5, 36)<CR>
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001724 map <silent> <F4> :call test_setmouse(4, 42)<CR>
1725 map <silent> <F5> :call test_setmouse(7, 42)<CR>
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001726 END
1727 call writefile(lines, 'XtestPopupScroll')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001728 let buf = RunVimInTerminal('-S XtestPopupScroll', #{rows: 10})
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001729 call VerifyScreenDump(buf, 'Test_popupwin_scroll_1', {})
1730
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001731 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 2})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +02001732 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001733 call VerifyScreenDump(buf, 'Test_popupwin_scroll_2', {})
1734
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001735 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 6})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +02001736 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001737 call VerifyScreenDump(buf, 'Test_popupwin_scroll_3', {})
1738
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001739 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 9})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +02001740 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001741 call VerifyScreenDump(buf, 'Test_popupwin_scroll_4', {})
1742
Bram Moolenaar9e67b6a2019-08-30 17:34:08 +02001743 call term_sendkeys(buf, ":call popup_setoptions(winid, #{scrollbarhighlight: 'ScrollBar', thumbhighlight: 'ScrollThumb', firstline: 5})\<CR>")
Bram Moolenaara112f2d2019-09-01 17:38:09 +02001744 " this scrolls two lines (half the window height)
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001745 call term_sendkeys(buf, ":call ScrollUp()\<CR>")
1746 call VerifyScreenDump(buf, 'Test_popupwin_scroll_5', {})
1747
1748 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
1749 call VerifyScreenDump(buf, 'Test_popupwin_scroll_6', {})
1750
1751 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
Bram Moolenaar13b47c32019-06-28 21:55:48 +02001752 " wait a bit, otherwise it fails sometimes (double click recognized?)
1753 sleep 100m
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001754 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
1755 call VerifyScreenDump(buf, 'Test_popupwin_scroll_7', {})
1756
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001757 call term_sendkeys(buf, ":call ClickTop()\<CR>")
1758 sleep 100m
1759 call term_sendkeys(buf, ":call ClickTop()\<CR>")
1760 call VerifyScreenDump(buf, 'Test_popupwin_scroll_8', {})
1761
1762 call term_sendkeys(buf, ":call ClickBot()\<CR>")
1763 call VerifyScreenDump(buf, 'Test_popupwin_scroll_9', {})
1764
Bram Moolenaar8c6173c2019-08-30 22:08:34 +02001765 " remove the minwidth and maxheight
1766 call term_sendkeys(buf, ":call popup_setoptions(winid, #{maxheight: 0, minwidth: 0})\<CR>")
Bram Moolenaar7e0f4622019-09-17 21:23:39 +02001767 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar8c6173c2019-08-30 22:08:34 +02001768 call VerifyScreenDump(buf, 'Test_popupwin_scroll_10', {})
1769
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001770 " clean up
1771 call StopVimInTerminal(buf)
1772 call delete('XtestPopupScroll')
1773endfunc
1774
Bram Moolenaar437a7462019-07-05 20:17:22 +02001775func Test_popup_fitting_scrollbar()
1776 " this was causing a crash, divide by zero
1777 let winid = popup_create([
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001778 \ 'one', 'two', 'longer line that wraps', 'four', 'five'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001779 \ scrollbar: 1,
1780 \ maxwidth: 10,
1781 \ maxheight: 5,
1782 \ firstline: 2})
Bram Moolenaar437a7462019-07-05 20:17:22 +02001783 redraw
1784 call popup_clear()
1785endfunc
1786
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001787func Test_popup_settext()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001788 CheckScreendump
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001789
1790 let lines =<< trim END
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001791 let opts = #{wrap: 0}
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001792 let p = popup_create('test', opts)
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001793 eval p->popup_settext('this is a text')
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001794 END
1795
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001796 call writefile(lines, 'XtestPopupSetText')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001797 let buf = RunVimInTerminal('-S XtestPopupSetText', #{rows: 10})
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001798 call VerifyScreenDump(buf, 'Test_popup_settext_01', {})
1799
1800 " Setting to empty string clears it
1801 call term_sendkeys(buf, ":call popup_settext(p, '')\<CR>")
1802 call VerifyScreenDump(buf, 'Test_popup_settext_02', {})
1803
1804 " Setting a list
1805 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
1806 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
1807
1808 " Shrinking with a list
1809 call term_sendkeys(buf, ":call popup_settext(p, ['a'])\<CR>")
1810 call VerifyScreenDump(buf, 'Test_popup_settext_04', {})
1811
1812 " Growing with a list
1813 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
1814 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
1815
1816 " Empty list clears
1817 call term_sendkeys(buf, ":call popup_settext(p, [])\<CR>")
1818 call VerifyScreenDump(buf, 'Test_popup_settext_05', {})
1819
1820 " Dicts
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001821 call term_sendkeys(buf, ":call popup_settext(p, [#{text: 'aaaa'}, #{text: 'bbbb'}, #{text: 'cccc'}])\<CR>")
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001822 call VerifyScreenDump(buf, 'Test_popup_settext_06', {})
1823
1824 " clean up
1825 call StopVimInTerminal(buf)
1826 call delete('XtestPopupSetText')
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001827endfunc
1828
1829func Test_popup_hidden()
1830 new
1831
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001832 let winid = popup_atcursor('text', #{hidden: 1})
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001833 redraw
1834 call assert_equal(0, popup_getpos(winid).visible)
1835 call popup_close(winid)
1836
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001837 let winid = popup_create('text', #{hidden: 1})
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001838 redraw
1839 call assert_equal(0, popup_getpos(winid).visible)
1840 call popup_close(winid)
1841
1842 func QuitCallback(id, res)
1843 let s:cb_winid = a:id
1844 let s:cb_res = a:res
1845 endfunc
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001846 let winid = 'make a choice'->popup_dialog(#{hidden: 1,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001847 \ filter: 'popup_filter_yesno',
1848 \ callback: 'QuitCallback',
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001849 \ })
1850 redraw
1851 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02001852 call assert_equal(function('popup_filter_yesno'), popup_getoptions(winid).filter)
1853 call assert_equal(function('QuitCallback'), popup_getoptions(winid).callback)
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02001854 exe "normal anot used by filter\<Esc>"
1855 call assert_equal('not used by filter', getline(1))
1856
1857 call popup_show(winid)
1858 call feedkeys('y', "xt")
1859 call assert_equal(1, s:cb_res)
1860
1861 bwipe!
1862 delfunc QuitCallback
1863endfunc
Bram Moolenaarae943152019-06-16 22:54:14 +02001864
1865" Test options not checked elsewhere
1866func Test_set_get_options()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001867 let winid = popup_create('some text', #{highlight: 'Beautiful'})
Bram Moolenaarae943152019-06-16 22:54:14 +02001868 let options = popup_getoptions(winid)
1869 call assert_equal(1, options.wrap)
1870 call assert_equal(0, options.drag)
1871 call assert_equal('Beautiful', options.highlight)
1872
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001873 call popup_setoptions(winid, #{wrap: 0, drag: 1, highlight: 'Another'})
Bram Moolenaarae943152019-06-16 22:54:14 +02001874 let options = popup_getoptions(winid)
1875 call assert_equal(0, options.wrap)
1876 call assert_equal(1, options.drag)
1877 call assert_equal('Another', options.highlight)
1878
1879 call popup_close(winid)
1880endfunc
Bram Moolenaar75a1a942019-06-20 03:45:36 +02001881
1882func Test_popupwin_garbage_collect()
1883 func MyPopupFilter(x, winid, c)
1884 " NOP
1885 endfunc
1886
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001887 let winid = popup_create('something', #{filter: function('MyPopupFilter', [{}])})
Bram Moolenaar75a1a942019-06-20 03:45:36 +02001888 call test_garbagecollect_now()
1889 redraw
Bram Moolenaar1bc353b2019-09-01 14:45:28 +02001890 " Must not crash caused by invalid memory access
Bram Moolenaar75a1a942019-06-20 03:45:36 +02001891 call feedkeys('j', 'xt')
1892 call assert_true(v:true)
1893
1894 call popup_close(winid)
1895 delfunc MyPopupFilter
1896endfunc
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02001897
Bram Moolenaar581ba392019-09-03 22:08:33 +02001898func Test_popupwin_filter_mode()
1899 func MyPopupFilter(winid, c)
1900 let s:typed = a:c
1901 if a:c == ':' || a:c == "\r" || a:c == 'v'
1902 " can start cmdline mode, get out, and start/stop Visual mode
1903 return 0
1904 endif
1905 return 1
1906 endfunc
1907
1908 " Normal, Visual and Insert mode
1909 let winid = popup_create('something', #{filter: 'MyPopupFilter', filtermode: 'nvi'})
1910 redraw
1911 call feedkeys('x', 'xt')
1912 call assert_equal('x', s:typed)
1913
1914 call feedkeys(":let g:foo = 'foo'\<CR>", 'xt')
1915 call assert_equal(':', s:typed)
1916 call assert_equal('foo', g:foo)
1917
1918 let @x = 'something'
1919 call feedkeys('v$"xy', 'xt')
1920 call assert_equal('y', s:typed)
1921 call assert_equal('something', @x) " yank command is filtered out
1922 call feedkeys('v', 'xt') " end Visual mode
1923
1924 call popup_close(winid)
1925
1926 " only Normal mode
1927 let winid = popup_create('something', #{filter: 'MyPopupFilter', filtermode: 'n'})
1928 redraw
1929 call feedkeys('x', 'xt')
1930 call assert_equal('x', s:typed)
1931
1932 call feedkeys(":let g:foo = 'foo'\<CR>", 'xt')
1933 call assert_equal(':', s:typed)
1934 call assert_equal('foo', g:foo)
1935
1936 let @x = 'something'
1937 call feedkeys('v$"xy', 'xt')
1938 call assert_equal('v', s:typed)
1939 call assert_notequal('something', @x)
1940
1941 call popup_close(winid)
1942
1943 " default: all modes
1944 let winid = popup_create('something', #{filter: 'MyPopupFilter'})
1945 redraw
1946 call feedkeys('x', 'xt')
1947 call assert_equal('x', s:typed)
1948
1949 let g:foo = 'bar'
1950 call feedkeys(":let g:foo = 'foo'\<CR>", 'xt')
1951 call assert_equal("\r", s:typed)
1952 call assert_equal('bar', g:foo)
1953
1954 let @x = 'something'
1955 call feedkeys('v$"xy', 'xt')
1956 call assert_equal('y', s:typed)
1957 call assert_equal('something', @x) " yank command is filtered out
1958 call feedkeys('v', 'xt') " end Visual mode
1959
1960 call popup_close(winid)
1961 delfunc MyPopupFilter
1962endfunc
1963
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02001964func Test_popupwin_with_buffer()
1965 call writefile(['some text', 'in a buffer'], 'XsomeFile')
1966 let buf = bufadd('XsomeFile')
1967 call assert_equal(0, bufloaded(buf))
Bram Moolenaar46451042019-08-24 15:50:46 +02001968
1969 setlocal number
1970 call setbufvar(buf, "&wrapmargin", 13)
1971
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02001972 let winid = popup_create(buf, {})
1973 call assert_notequal(0, winid)
1974 let pos = popup_getpos(winid)
1975 call assert_equal(2, pos.height)
1976 call assert_equal(1, bufloaded(buf))
Bram Moolenaar46451042019-08-24 15:50:46 +02001977
1978 " window-local option is set to default, buffer-local is not
1979 call assert_equal(0, getwinvar(winid, '&number'))
1980 call assert_equal(13, getbufvar(buf, '&wrapmargin'))
1981
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02001982 call popup_close(winid)
1983 call assert_equal({}, popup_getpos(winid))
1984 call assert_equal(1, bufloaded(buf))
1985 exe 'bwipe! ' .. buf
Bram Moolenaar46451042019-08-24 15:50:46 +02001986 setlocal nonumber
Bram Moolenaar7866b872019-07-01 22:21:01 +02001987
1988 edit test_popupwin.vim
1989 let winid = popup_create(bufnr(''), {})
1990 redraw
1991 call popup_close(winid)
Bram Moolenaar3940ec62019-07-05 21:53:24 +02001992 call delete('XsomeFile')
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02001993endfunc
Bram Moolenaare296e312019-07-03 23:20:18 +02001994
Bram Moolenaare0d749a2019-09-25 22:14:48 +02001995func Test_popupwin_terminal_buffer()
1996 let ptybuf = term_start(&shell, #{hidden: 1})
1997 call assert_fails('let winnr = popup_create(ptybuf, #{})', 'E278:')
1998 exe 'bwipe! ' .. ptybuf
1999endfunc
2000
Bram Moolenaar934470e2019-09-01 23:27:05 +02002001func Test_popupwin_with_buffer_and_filter()
2002 new Xwithfilter
2003 call setline(1, range(100))
2004 let bufnr = bufnr()
2005 hide
2006
2007 func BufferFilter(win, key)
2008 if a:key == 'G'
2009 " recursive use of "G" does not cause problems.
2010 call win_execute(a:win, 'normal! G')
2011 return 1
2012 endif
2013 return 0
2014 endfunc
2015
2016 let winid = popup_create(bufnr, #{maxheight: 5, filter: 'BufferFilter'})
2017 call assert_equal(1, popup_getpos(winid).firstline)
2018 redraw
2019 call feedkeys("G", 'xt')
2020 call assert_equal(99, popup_getpos(winid).firstline)
2021
2022 call popup_close(winid)
2023 exe 'bwipe! ' .. bufnr
2024endfunc
2025
Bram Moolenaare296e312019-07-03 23:20:18 +02002026func Test_popupwin_width()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002027 let winid = popup_create(repeat(['short', 'long long long line', 'medium width'], 50), #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002028 \ maxwidth: 40,
2029 \ maxheight: 10,
Bram Moolenaare296e312019-07-03 23:20:18 +02002030 \ })
2031 for top in range(1, 20)
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002032 eval winid->popup_setoptions(#{firstline: top})
Bram Moolenaare296e312019-07-03 23:20:18 +02002033 redraw
2034 call assert_equal(19, popup_getpos(winid).width)
2035 endfor
2036 call popup_clear()
2037endfunc
Bram Moolenaar5ca1ac32019-07-04 15:39:28 +02002038
2039func Test_popupwin_buf_close()
2040 let buf = bufadd('Xtestbuf')
2041 call bufload(buf)
2042 call setbufline(buf, 1, ['just', 'some', 'lines'])
2043 let winid = popup_create(buf, {})
2044 redraw
2045 call assert_equal(3, popup_getpos(winid).height)
2046 let bufinfo = getbufinfo(buf)[0]
2047 call assert_equal(1, bufinfo.changed)
2048 call assert_equal(0, bufinfo.hidden)
2049 call assert_equal(0, bufinfo.listed)
2050 call assert_equal(1, bufinfo.loaded)
2051 call assert_equal([], bufinfo.windows)
2052 call assert_equal([winid], bufinfo.popups)
2053
2054 call popup_close(winid)
2055 call assert_equal({}, popup_getpos(winid))
2056 let bufinfo = getbufinfo(buf)[0]
2057 call assert_equal(1, bufinfo.changed)
2058 call assert_equal(1, bufinfo.hidden)
2059 call assert_equal(0, bufinfo.listed)
2060 call assert_equal(1, bufinfo.loaded)
2061 call assert_equal([], bufinfo.windows)
2062 call assert_equal([], bufinfo.popups)
2063 exe 'bwipe! ' .. buf
2064endfunc
Bram Moolenaar017c2692019-07-13 14:17:51 +02002065
2066func Test_popup_menu_with_maxwidth()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002067 CheckScreendump
Bram Moolenaar017c2692019-07-13 14:17:51 +02002068
2069 let lines =<< trim END
2070 call setline(1, range(1, 10))
2071 hi ScrollThumb ctermbg=blue
2072 hi ScrollBar ctermbg=red
2073 func PopupMenu(lines, line, col, scrollbar = 0)
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002074 return popup_menu(a:lines, #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002075 \ maxwidth: 10,
2076 \ maxheight: 3,
2077 \ pos : 'topleft',
2078 \ col : a:col,
2079 \ line : a:line,
2080 \ scrollbar : a:scrollbar,
Bram Moolenaar017c2692019-07-13 14:17:51 +02002081 \ })
2082 endfunc
2083 call PopupMenu(['x'], 1, 1)
2084 call PopupMenu(['123456789|'], 1, 16)
2085 call PopupMenu(['123456789|' .. ' '], 7, 1)
2086 call PopupMenu([repeat('123456789|', 100)], 7, 16)
2087 call PopupMenu(repeat(['123456789|' .. ' '], 5), 1, 33, 1)
2088 END
2089 call writefile(lines, 'XtestPopupMenuMaxWidth')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002090 let buf = RunVimInTerminal('-S XtestPopupMenuMaxWidth', #{rows: 13})
Bram Moolenaar017c2692019-07-13 14:17:51 +02002091 call VerifyScreenDump(buf, 'Test_popupwin_menu_maxwidth_1', {})
2092
2093 " close the menu popupwin.
2094 call term_sendkeys(buf, " ")
2095 call term_sendkeys(buf, " ")
2096 call term_sendkeys(buf, " ")
2097 call term_sendkeys(buf, " ")
2098 call term_sendkeys(buf, " ")
2099
2100 " clean up
2101 call StopVimInTerminal(buf)
2102 call delete('XtestPopupMenuMaxWidth')
2103endfunc
2104
Bram Moolenaara901a372019-07-13 16:38:50 +02002105func Test_popup_menu_with_scrollbar()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002106 CheckScreendump
Bram Moolenaara901a372019-07-13 16:38:50 +02002107
2108 let lines =<< trim END
2109 call setline(1, range(1, 20))
2110 hi ScrollThumb ctermbg=blue
2111 hi ScrollBar ctermbg=red
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002112 eval ['one', 'two', 'three', 'four', 'five',
2113 \ 'six', 'seven', 'eight', 'nine']
2114 \ ->popup_menu(#{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002115 \ minwidth: 8,
2116 \ maxheight: 3,
Bram Moolenaara901a372019-07-13 16:38:50 +02002117 \ })
2118 END
2119 call writefile(lines, 'XtestPopupMenuScroll')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002120 let buf = RunVimInTerminal('-S XtestPopupMenuScroll', #{rows: 10})
Bram Moolenaara901a372019-07-13 16:38:50 +02002121
2122 call term_sendkeys(buf, "j")
2123 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_1', {})
2124
2125 call term_sendkeys(buf, "jjj")
2126 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_2', {})
2127
2128 " if the cursor is the bottom line, it stays at the bottom line.
2129 call term_sendkeys(buf, repeat("j", 20))
2130 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_3', {})
2131
2132 call term_sendkeys(buf, "kk")
2133 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_4', {})
2134
2135 call term_sendkeys(buf, "k")
2136 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_5', {})
2137
2138 " if the cursor is in the top line, it stays in the top line.
2139 call term_sendkeys(buf, repeat("k", 20))
2140 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_6', {})
2141
2142 " close the menu popupwin.
2143 call term_sendkeys(buf, " ")
2144
2145 " clean up
2146 call StopVimInTerminal(buf)
2147 call delete('XtestPopupMenuScroll')
2148endfunc
2149
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002150func Test_popup_menu_filter()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002151 CheckScreendump
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002152
2153 let lines =<< trim END
2154 function! MyFilter(winid, key) abort
2155 if a:key == "0"
2156 call win_execute(a:winid, "call setpos('.', [0, 1, 1, 0])")
2157 return 1
2158 endif
2159 if a:key == "G"
2160 call win_execute(a:winid, "call setpos('.', [0, line('$'), 1, 0])")
2161 return 1
2162 endif
2163 if a:key == "j"
2164 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0])")
2165 return 1
2166 endif
2167 if a:key == "k"
2168 call win_execute(a:winid, "call setpos('.', [0, line('.') - 1, 1, 0])")
2169 return 1
2170 endif
Bram Moolenaarbcb4c8f2019-09-07 14:06:52 +02002171 if a:key == ':'
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002172 call popup_close(a:winid)
Bram Moolenaarbcb4c8f2019-09-07 14:06:52 +02002173 return 0
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002174 endif
2175 return 0
2176 endfunction
2177 call popup_menu(['111', '222', '333', '444', '555', '666', '777', '888', '999'], #{
2178 \ maxheight : 3,
2179 \ filter : 'MyFilter'
2180 \ })
2181 END
2182 call writefile(lines, 'XtestPopupMenuFilter')
2183 let buf = RunVimInTerminal('-S XtestPopupMenuFilter', #{rows: 10})
2184
2185 call term_sendkeys(buf, "j")
2186 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_1', {})
2187
2188 call term_sendkeys(buf, "k")
2189 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_2', {})
2190
2191 call term_sendkeys(buf, "G")
2192 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_3', {})
2193
2194 call term_sendkeys(buf, "0")
2195 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_4', {})
2196
Bram Moolenaarbcb4c8f2019-09-07 14:06:52 +02002197 " check that when the popup is closed in the filter the screen is redrawn
2198 call term_sendkeys(buf, ":")
2199 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_5', {})
2200 call term_sendkeys(buf, "\<CR>")
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002201
2202 " clean up
2203 call StopVimInTerminal(buf)
2204 call delete('XtestPopupMenuFilter')
2205endfunc
2206
2207func Test_popup_cursorline()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002208 CheckScreendump
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002209
2210 let winid = popup_create('some text', {})
2211 call assert_equal(0, popup_getoptions(winid).cursorline)
2212 call popup_close(winid)
2213
2214 let winid = popup_create('some text', #{ cursorline: 1, })
2215 call assert_equal(1, popup_getoptions(winid).cursorline)
2216 call popup_close(winid)
2217
2218 let winid = popup_create('some text', #{ cursorline: 0, })
2219 call assert_equal(0, popup_getoptions(winid).cursorline)
2220 call popup_close(winid)
2221
2222 let winid = popup_menu('some text', {})
2223 call assert_equal(1, popup_getoptions(winid).cursorline)
2224 call popup_close(winid)
2225
2226 let winid = popup_menu('some text', #{ cursorline: 1, })
2227 call assert_equal(1, popup_getoptions(winid).cursorline)
2228 call popup_close(winid)
2229
2230 let winid = popup_menu('some text', #{ cursorline: 0, })
2231 call assert_equal(0, popup_getoptions(winid).cursorline)
2232 call popup_close(winid)
2233
2234 " ---------
2235 " Pattern 1
2236 " ---------
2237 let lines =<< trim END
2238 call popup_create(['111', '222', '333'], #{ cursorline : 0 })
2239 END
2240 call writefile(lines, 'XtestPopupCursorLine')
2241 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2242 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_1', {})
2243 call term_sendkeys(buf, ":call popup_clear()\<cr>")
2244 call StopVimInTerminal(buf)
2245
2246 " ---------
2247 " Pattern 2
2248 " ---------
2249 let lines =<< trim END
2250 call popup_create(['111', '222', '333'], #{ cursorline : 1 })
2251 END
2252 call writefile(lines, 'XtestPopupCursorLine')
2253 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2254 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_2', {})
2255 call term_sendkeys(buf, ":call popup_clear()\<cr>")
2256 call StopVimInTerminal(buf)
2257
2258 " ---------
2259 " Pattern 3
2260 " ---------
2261 let lines =<< trim END
2262 function! MyFilter(winid, key) abort
2263 if a:key == "j"
2264 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0]) | redraw")
2265 return 1
2266 endif
2267 if a:key == 'x'
2268 call popup_close(a:winid)
2269 return 1
2270 endif
2271 return 0
2272 endfunction
2273 call popup_menu(['111', '222', '333'], #{
2274 \ cursorline : 0,
2275 \ maxheight : 2,
2276 \ filter : 'MyFilter',
2277 \ })
2278 END
2279 call writefile(lines, 'XtestPopupCursorLine')
2280 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2281 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_3', {})
2282 call term_sendkeys(buf, "j")
2283 call term_sendkeys(buf, "j")
2284 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_4', {})
2285 call term_sendkeys(buf, "x")
2286 call StopVimInTerminal(buf)
2287
2288 " ---------
2289 " Pattern 4
2290 " ---------
2291 let lines =<< trim END
2292 function! MyFilter(winid, key) abort
2293 if a:key == "j"
2294 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0]) | redraw")
2295 return 1
2296 endif
2297 if a:key == 'x'
2298 call popup_close(a:winid)
2299 return 1
2300 endif
2301 return 0
2302 endfunction
2303 call popup_menu(['111', '222', '333'], #{
2304 \ cursorline : 1,
2305 \ maxheight : 2,
2306 \ filter : 'MyFilter',
2307 \ })
2308 END
2309 call writefile(lines, 'XtestPopupCursorLine')
2310 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2311 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_5', {})
2312 call term_sendkeys(buf, "j")
2313 call term_sendkeys(buf, "j")
2314 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_6', {})
2315 call term_sendkeys(buf, "x")
2316 call StopVimInTerminal(buf)
2317
Bram Moolenaar3d2a3cb2019-09-08 17:12:01 +02002318 " ---------
2319 " Cursor in second line when creating the popup
2320 " ---------
2321 let lines =<< trim END
2322 let winid = popup_create(['111', '222', '333'], #{
2323 \ cursorline : 1,
2324 \ })
2325 call win_execute(winid, "2")
2326 END
2327 call writefile(lines, 'XtestPopupCursorLine')
2328 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2329 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_7', {})
2330 call StopVimInTerminal(buf)
2331
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002332 call delete('XtestPopupCursorLine')
2333endfunc
2334
Bram Moolenaarf914a332019-07-20 15:09:56 +02002335func Test_previewpopup()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002336 CheckScreendump
2337
Bram Moolenaarf914a332019-07-20 15:09:56 +02002338 call writefile([
2339 \ "!_TAG_FILE_ENCODING\tutf-8\t//",
2340 \ "another\tXtagfile\t/^this is another",
2341 \ "theword\tXtagfile\t/^theword"],
2342 \ 'Xtags')
2343 call writefile(range(1,20)
2344 \ + ['theword is here']
2345 \ + range(22, 27)
2346 \ + ['this is another place']
2347 \ + range(29, 40),
2348 \ "Xtagfile")
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002349 call writefile(range(1,10)
2350 \ + ['searched word is here']
2351 \ + range(12, 20),
2352 \ "Xheader.h")
Bram Moolenaarf914a332019-07-20 15:09:56 +02002353 let lines =<< trim END
2354 set tags=Xtags
2355 call setline(1, [
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02002356 \ 'one',
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002357 \ '#include "Xheader.h"',
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02002358 \ 'three',
2359 \ 'four',
2360 \ 'five',
2361 \ 'six',
2362 \ 'seven',
2363 \ 'find theword somewhere',
2364 \ 'nine',
2365 \ 'this is another word',
2366 \ 'very long line where the word is also another'])
Bram Moolenaarf914a332019-07-20 15:09:56 +02002367 set previewpopup=height:4,width:40
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002368 set path=.
Bram Moolenaarf914a332019-07-20 15:09:56 +02002369 END
2370 call writefile(lines, 'XtestPreviewPopup')
2371 let buf = RunVimInTerminal('-S XtestPreviewPopup', #{rows: 14})
2372
2373 call term_sendkeys(buf, "/theword\<CR>\<C-W>}")
2374 call term_sendkeys(buf, ":\<CR>")
2375 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_1', {})
2376
2377 call term_sendkeys(buf, "/another\<CR>\<C-W>}")
2378 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_2', {})
2379
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002380 call term_sendkeys(buf, ":call popup_move(popup_findpreview(), #{col: 15})\<CR>")
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02002381 call term_sendkeys(buf, ":\<CR>")
2382 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_3', {})
2383
2384 call term_sendkeys(buf, "/another\<CR>\<C-W>}")
2385 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_4', {})
2386
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02002387 call term_sendkeys(buf, ":cd ..\<CR>:\<CR>")
2388 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_5', {})
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002389 call term_sendkeys(buf, ":cd testdir\<CR>")
2390
2391 call term_sendkeys(buf, ":pclose\<CR>")
Bram Moolenaar78d629a2019-08-16 17:31:15 +02002392 call term_sendkeys(buf, ":\<BS>")
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002393 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_6', {})
2394
2395 call term_sendkeys(buf, ":pedit +/theword Xtagfile\<CR>")
2396 call term_sendkeys(buf, ":\<CR>")
2397 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_7', {})
2398
2399 call term_sendkeys(buf, ":pclose\<CR>")
2400 call term_sendkeys(buf, ":psearch searched\<CR>")
2401 call term_sendkeys(buf, ":\<CR>")
2402 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_8', {})
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02002403
Bram Moolenaarf914a332019-07-20 15:09:56 +02002404 call StopVimInTerminal(buf)
2405 call delete('Xtags')
2406 call delete('Xtagfile')
2407 call delete('XtestPreviewPopup')
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002408 call delete('Xheader.h')
Bram Moolenaarf914a332019-07-20 15:09:56 +02002409endfunc
2410
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002411func Get_popupmenu_lines()
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002412 let lines =<< trim END
2413 set completeopt+=preview,popup
2414 set completefunc=CompleteFuncDict
Bram Moolenaar62a0cb42019-08-18 16:35:23 +02002415 hi InfoPopup ctermbg=yellow
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002416
2417 func CompleteFuncDict(findstart, base)
2418 if a:findstart
2419 if col('.') > 10
2420 return col('.') - 10
2421 endif
2422 return 0
2423 endif
2424
2425 return {
2426 \ 'words': [
2427 \ {
2428 \ 'word': 'aword',
2429 \ 'abbr': 'wrd',
2430 \ 'menu': 'extra text',
2431 \ 'info': 'words are cool',
2432 \ 'kind': 'W',
2433 \ 'user_data': 'test'
2434 \ },
2435 \ {
2436 \ 'word': 'anotherword',
2437 \ 'abbr': 'anotwrd',
2438 \ 'menu': 'extra text',
2439 \ 'info': "other words are\ncooler than this and some more text\nto make wrap",
2440 \ 'kind': 'W',
2441 \ 'user_data': 'notest'
2442 \ },
2443 \ {
2444 \ 'word': 'noinfo',
2445 \ 'abbr': 'noawrd',
2446 \ 'menu': 'extra text',
Bram Moolenaar62a0cb42019-08-18 16:35:23 +02002447 \ 'info': "lets\nshow\na\nscrollbar\nhere",
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002448 \ 'kind': 'W',
2449 \ 'user_data': 'notest'
2450 \ },
2451 \ {
2452 \ 'word': 'thatword',
2453 \ 'abbr': 'thatwrd',
2454 \ 'menu': 'extra text',
2455 \ 'info': 'that word is cool',
2456 \ 'kind': 'W',
2457 \ 'user_data': 'notest'
2458 \ },
2459 \ ]
2460 \ }
2461 endfunc
2462 call setline(1, 'text text text text text text text ')
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002463 func ChangeColor()
2464 let id = popup_findinfo()
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002465 eval id->popup_setoptions(#{highlight: 'InfoPopup'})
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002466 endfunc
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002467 END
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002468 return lines
2469endfunc
2470
2471func Test_popupmenu_info_border()
2472 CheckScreendump
2473
2474 let lines = Get_popupmenu_lines()
2475 call add(lines, 'set completepopup=height:4,highlight:InfoPopup')
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002476 call writefile(lines, 'XtestInfoPopup')
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002477
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002478 let buf = RunVimInTerminal('-S XtestInfoPopup', #{rows: 14})
2479 call term_wait(buf, 50)
2480
2481 call term_sendkeys(buf, "A\<C-X>\<C-U>")
2482 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_1', {})
2483
2484 call term_sendkeys(buf, "\<C-N>")
2485 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_2', {})
2486
2487 call term_sendkeys(buf, "\<C-N>")
2488 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_3', {})
2489
2490 call term_sendkeys(buf, "\<C-N>\<C-N>")
2491 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_4', {})
2492
Bram Moolenaarfe6e7612019-08-21 20:57:20 +02002493 " info on the left with scrollbar
2494 call term_sendkeys(buf, "test text test text\<C-X>\<C-U>")
2495 call term_sendkeys(buf, "\<C-N>\<C-N>")
2496 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_5', {})
2497
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002498 call StopVimInTerminal(buf)
2499 call delete('XtestInfoPopup')
2500endfunc
2501
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002502func Test_popupmenu_info_noborder()
2503 CheckScreendump
2504
2505 let lines = Get_popupmenu_lines()
2506 call add(lines, 'set completepopup=height:4,border:off')
2507 call writefile(lines, 'XtestInfoPopupNb')
2508
2509 let buf = RunVimInTerminal('-S XtestInfoPopupNb', #{rows: 14})
2510 call term_wait(buf, 50)
2511
2512 call term_sendkeys(buf, "A\<C-X>\<C-U>")
2513 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_nb_1', {})
2514
2515 call StopVimInTerminal(buf)
2516 call delete('XtestInfoPopupNb')
2517endfunc
2518
Bram Moolenaar258cef52019-08-21 17:29:29 +02002519func Test_popupmenu_info_align_menu()
2520 CheckScreendump
2521
2522 let lines = Get_popupmenu_lines()
2523 call add(lines, 'set completepopup=height:4,border:off,align:menu')
2524 call writefile(lines, 'XtestInfoPopupNb')
2525
2526 let buf = RunVimInTerminal('-S XtestInfoPopupNb', #{rows: 14})
2527 call term_wait(buf, 50)
2528
2529 call term_sendkeys(buf, "A\<C-X>\<C-U>")
2530 call term_sendkeys(buf, "\<C-N>")
2531 call term_sendkeys(buf, "\<C-N>")
2532 call term_sendkeys(buf, "\<C-N>")
2533 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_1', {})
2534
2535 call term_sendkeys(buf, "test text test text test\<C-X>\<C-U>")
2536 call term_sendkeys(buf, "\<C-N>")
2537 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_2', {})
2538
2539 call term_sendkeys(buf, "\<Esc>")
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002540 call term_sendkeys(buf, ":call ChangeColor()\<CR>")
Bram Moolenaar258cef52019-08-21 17:29:29 +02002541 call term_sendkeys(buf, ":call setline(2, ['x']->repeat(10))\<CR>")
2542 call term_sendkeys(buf, "Gotest text test text\<C-X>\<C-U>")
2543 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_3', {})
2544
2545 call StopVimInTerminal(buf)
2546 call delete('XtestInfoPopupNb')
2547endfunc
2548
Bram Moolenaar00b0d6d2019-08-21 22:25:30 +02002549func Test_popupwin_recycle_bnr()
Bram Moolenaare49fbff2019-08-21 22:50:07 +02002550 let bufnr = popup_notification('nothing wrong', {})->winbufnr()
Bram Moolenaar00b0d6d2019-08-21 22:25:30 +02002551 call popup_clear()
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002552 let winid = 'nothing wrong'->popup_notification({})
Bram Moolenaar00b0d6d2019-08-21 22:25:30 +02002553 call assert_equal(bufnr, winbufnr(winid))
2554 call popup_clear()
2555endfunc
2556
Bram Moolenaar331bafd2019-07-20 17:46:05 +02002557" vim: shiftwidth=2 sts=2