blob: 4992837a89bb79b87092d9c7b93a732b713b05e9 [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
Bram Moolenaar1666ac92019-11-10 17:22:31 +010015 hi EndOfBuffer ctermbg=lightgrey
Bram Moolenaare7eb9272019-06-24 00:58:07 +020016 hi Comment ctermfg=red
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020017 call prop_type_add('comment', #{highlight: 'Comment'})
18 let winid = popup_create('hello there', #{line: 3, col: 11, minwidth: 20, highlight: 'PopupColor1'})
19 let winid2 = popup_create(['another one', 'another two', 'another three'], #{line: 3, col: 25, minwidth: 20})
Bram Moolenaare7eb9272019-06-24 00:58:07 +020020 call setwinvar(winid2, '&wincolor', 'PopupColor2')
21 END
22 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020023 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaar4d784b22019-05-25 19:51:39 +020024 call VerifyScreenDump(buf, 'Test_popupwin_01', {})
25
Bram Moolenaarec583842019-05-26 14:11:23 +020026 " Add a tabpage
27 call term_sendkeys(buf, ":tabnew\<CR>")
Bram Moolenaar60cdb302019-05-27 21:54:10 +020028 call term_sendkeys(buf, ":let popupwin = popup_create(["
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020029 \ .. "#{text: 'other tab'},"
30 \ .. "#{text: 'a comment line', props: [#{"
Bram Moolenaard5abb4c2019-07-13 22:46:10 +020031 \ .. "col: 3, length: 7, minwidth: 20, type: 'comment'"
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020032 \ .. "}]},"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020033 \ .. "], #{line: 4, col: 9, minwidth: 20})\<CR>")
Bram Moolenaarec583842019-05-26 14:11:23 +020034 call VerifyScreenDump(buf, 'Test_popupwin_02', {})
35
36 " switch back to first tabpage
37 call term_sendkeys(buf, "gt")
38 call VerifyScreenDump(buf, 'Test_popupwin_03', {})
39
40 " close that tabpage
41 call term_sendkeys(buf, ":quit!\<CR>")
42 call VerifyScreenDump(buf, 'Test_popupwin_04', {})
43
Bram Moolenaar202d9822019-06-11 21:56:30 +020044 " set 'columns' to a small value, size must be recomputed
45 call term_sendkeys(buf, ":let cols = &columns\<CR>")
46 call term_sendkeys(buf, ":set columns=12\<CR>")
47 call VerifyScreenDump(buf, 'Test_popupwin_04a', {})
48 call term_sendkeys(buf, ":let &columns = cols\<CR>")
49
Bram Moolenaar17146962019-05-30 00:12:11 +020050 " resize popup, show empty line at bottom
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020051 call term_sendkeys(buf, ":call popup_move(popupwin, #{minwidth: 15, maxwidth: 25, minheight: 3, maxheight: 5})\<CR>")
Bram Moolenaar60cdb302019-05-27 21:54:10 +020052 call term_sendkeys(buf, ":redraw\<CR>")
53 call VerifyScreenDump(buf, 'Test_popupwin_05', {})
54
Bram Moolenaar17146962019-05-30 00:12:11 +020055 " show not fitting line at bottom
56 call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>")
57 call term_sendkeys(buf, ":redraw\<CR>")
58 call VerifyScreenDump(buf, 'Test_popupwin_06', {})
59
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020060 " move popup over ruler
61 call term_sendkeys(buf, ":set cmdheight=2\<CR>")
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020062 call term_sendkeys(buf, ":call popup_move(popupwin, #{line: 7, col: 55})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +020063 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020064 call VerifyScreenDump(buf, 'Test_popupwin_07', {})
65
66 " clear all popups after moving the cursor a bit, so that ruler is updated
67 call term_sendkeys(buf, "axxx\<Esc>")
68 call term_wait(buf)
69 call term_sendkeys(buf, "0")
70 call term_wait(buf)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +020071 call term_sendkeys(buf, ":call popup_clear()\<CR>")
Bram Moolenaar24a5ac52019-06-08 19:01:18 +020072 call VerifyScreenDump(buf, 'Test_popupwin_08', {})
73
Bram Moolenaar4d784b22019-05-25 19:51:39 +020074 " clean up
75 call StopVimInTerminal(buf)
76 call delete('XtestPopup')
77endfunc
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020078
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020079func Test_popup_with_border_and_padding()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +020080 CheckScreendump
Bram Moolenaar2fd8e352019-06-01 20:16:48 +020081
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +020082 for iter in range(0, 1)
Bram Moolenaare7eb9272019-06-24 00:58:07 +020083 let lines =<< trim END
84 call setline(1, range(1, 100))
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020085 call popup_create('hello border', #{line: 2, col: 3, border: []})
86 call popup_create('hello padding', #{line: 2, col: 23, padding: []})
Bram Moolenaarc363fe12019-08-04 18:13:46 +020087 call popup_create('hello both', #{line: 2, col: 43, border: [], padding: [], highlight: 'Normal'})
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020088 call popup_create('border TL', #{line: 6, col: 3, border: [1, 0, 0, 4]})
89 call popup_create('paddings', #{line: 6, col: 23, padding: [1, 3, 2, 4]})
90 call popup_create('wrapped longer text', #{line: 8, col: 55, padding: [0, 3, 0, 3], border: [0, 1, 0, 1]})
91 call popup_create('right aligned text', #{line: 11, col: 56, wrap: 0, padding: [0, 3, 0, 3], border: [0, 1, 0, 1]})
Bram Moolenaare7eb9272019-06-24 00:58:07 +020092 END
93 call insert(lines, iter == 1 ? '' : 'set enc=latin1')
94 call writefile(lines, 'XtestPopupBorder')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +020095 let buf = RunVimInTerminal('-S XtestPopupBorder', #{rows: 15})
Bram Moolenaar3bfd04e2019-06-01 20:45:21 +020096 call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {})
97
98 call StopVimInTerminal(buf)
99 call delete('XtestPopupBorder')
100 endfor
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200101
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200102 let lines =<< trim END
103 call setline(1, range(1, 100))
104 hi BlueColor ctermbg=lightblue
105 hi TopColor ctermbg=253
106 hi RightColor ctermbg=245
107 hi BottomColor ctermbg=240
108 hi LeftColor ctermbg=248
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200109 call popup_create('hello border', #{line: 2, col: 3, border: [], borderhighlight: ['BlueColor']})
110 call popup_create(['hello border', 'and more'], #{line: 2, col: 23, border: [], borderhighlight: ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']})
111 call popup_create(['hello border', 'lines only'], #{line: 2, col: 43, border: [], borderhighlight: ['BlueColor'], borderchars: ['x']})
112 call popup_create(['hello border', 'with corners'], #{line: 2, col: 60, border: [], borderhighlight: ['BlueColor'], borderchars: ['x', '#']})
113 let winid = popup_create(['hello border', 'with numbers'], #{line: 6, col: 3, border: [], borderhighlight: ['BlueColor'], borderchars: ['0', '1', '2', '3', '4', '5', '6', '7']})
114 call popup_create(['hello border', 'just blanks'], #{line: 7, col: 23, border: [], borderhighlight: ['BlueColor'], borderchars: [' ']})
Bram Moolenaar3dabd712019-07-08 23:30:22 +0200115 func MultiByte()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200116 call popup_create(['hello'], #{line: 8, col: 43, border: [], borderchars: ['─', '│', '─', '│', '┌', '┐', '┘', '└']})
Bram Moolenaar3dabd712019-07-08 23:30:22 +0200117 endfunc
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200118 END
119 call writefile(lines, 'XtestPopupBorder')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200120 let buf = RunVimInTerminal('-S XtestPopupBorder', #{rows: 12})
Bram Moolenaar790498b2019-06-01 22:15:29 +0200121 call VerifyScreenDump(buf, 'Test_popupwin_22', {})
122
Bram Moolenaarad24a712019-06-17 20:05:45 +0200123 " check that changing borderchars triggers a redraw
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200124 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 +0200125 call VerifyScreenDump(buf, 'Test_popupwin_23', {})
126
Bram Moolenaar3dabd712019-07-08 23:30:22 +0200127 " check multi-byte border only with 'ambiwidth' single
128 if &ambiwidth == 'single'
129 call term_sendkeys(buf, ":call MultiByte()\<CR>")
130 call VerifyScreenDump(buf, 'Test_popupwin_24', {})
131 endif
132
Bram Moolenaar790498b2019-06-01 22:15:29 +0200133 call StopVimInTerminal(buf)
134 call delete('XtestPopupBorder')
135
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200136 let with_border_or_padding = #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200137 \ line: 2,
138 \ core_line: 3,
139 \ col: 3,
140 \ core_col: 4,
141 \ width: 14,
142 \ core_width: 12,
143 \ height: 3,
144 \ core_height: 1,
145 \ firstline: 1,
Bram Moolenaar30efcf32019-11-03 22:29:38 +0100146 \ lastline: 1,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200147 \ scrollbar: 0,
148 \ visible: 1}
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200149 let winid = popup_create('hello border', #{line: 2, col: 3, border: []})",
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200150 call assert_equal(with_border_or_padding, winid->popup_getpos())
Bram Moolenaarae943152019-06-16 22:54:14 +0200151 let options = popup_getoptions(winid)
152 call assert_equal([], options.border)
153 call assert_false(has_key(options, "padding"))
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200154
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200155 let winid = popup_create('hello padding', #{line: 2, col: 3, padding: []})
Bram Moolenaarae943152019-06-16 22:54:14 +0200156 let with_border_or_padding.width = 15
157 let with_border_or_padding.core_width = 13
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200158 call assert_equal(with_border_or_padding, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200159 let options = popup_getoptions(winid)
160 call assert_false(has_key(options, "border"))
161 call assert_equal([], options.padding)
162
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200163 call popup_setoptions(winid, #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200164 \ padding: [1, 2, 3, 4],
165 \ border: [4, 0, 7, 8],
166 \ borderhighlight: ['Top', 'Right', 'Bottom', 'Left'],
167 \ borderchars: ['1', '^', '2', '>', '3', 'v', '4', '<'],
Bram Moolenaarae943152019-06-16 22:54:14 +0200168 \ })
169 let options = popup_getoptions(winid)
170 call assert_equal([1, 0, 1, 1], options.border)
171 call assert_equal([1, 2, 3, 4], options.padding)
172 call assert_equal(['Top', 'Right', 'Bottom', 'Left'], options.borderhighlight)
173 call assert_equal(['1', '^', '2', '>', '3', 'v', '4', '<'], options.borderchars)
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200174
Bram Moolenaara1396152019-10-20 18:46:05 +0200175 " Check that popup_setoptions() takes the output of popup_getoptions()
176 call popup_setoptions(winid, options)
177 call assert_equal(options, popup_getoptions(winid))
178
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200179 let winid = popup_create('hello both', #{line: 3, col: 8, border: [], padding: []})
180 call assert_equal(#{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200181 \ line: 3,
182 \ core_line: 5,
183 \ col: 8,
184 \ core_col: 10,
185 \ width: 14,
186 \ core_width: 10,
187 \ height: 5,
188 \ scrollbar: 0,
189 \ core_height: 1,
190 \ firstline: 1,
Bram Moolenaar30efcf32019-11-03 22:29:38 +0100191 \ lastline: 1,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200192 \ visible: 1}, popup_getpos(winid))
Bram Moolenaarae943152019-06-16 22:54:14 +0200193
194 call popup_clear()
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200195endfunc
196
Bram Moolenaarb4230122019-05-30 18:40:53 +0200197func Test_popup_with_syntax_win_execute()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200198 CheckScreendump
199
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200200 let lines =<< trim END
201 call setline(1, range(1, 100))
202 hi PopupColor ctermbg=lightblue
203 let winid = popup_create([
204 \ '#include <stdio.h>',
205 \ 'int main(void)',
206 \ '{',
207 \ ' printf(123);',
208 \ '}',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200209 \], #{line: 3, col: 25, highlight: 'PopupColor'})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200210 call win_execute(winid, 'set syntax=cpp')
211 END
212 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200213 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaarb4230122019-05-30 18:40:53 +0200214 call VerifyScreenDump(buf, 'Test_popupwin_10', {})
215
216 " clean up
217 call StopVimInTerminal(buf)
218 call delete('XtestPopup')
219endfunc
220
221func Test_popup_with_syntax_setbufvar()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200222 CheckScreendump
223
Bram Moolenaar402502d2019-05-30 22:07:36 +0200224 let lines =<< trim END
225 call setline(1, range(1, 100))
226 hi PopupColor ctermbg=lightgrey
227 let winid = popup_create([
228 \ '#include <stdio.h>',
229 \ 'int main(void)',
230 \ '{',
Bram Moolenaare089c3f2019-07-09 20:25:25 +0200231 \ "\tprintf(567);",
Bram Moolenaar402502d2019-05-30 22:07:36 +0200232 \ '}',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200233 \], #{line: 3, col: 21, highlight: 'PopupColor'})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200234 call setbufvar(winbufnr(winid), '&syntax', 'cpp')
235 END
236 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200237 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaarb4230122019-05-30 18:40:53 +0200238 call VerifyScreenDump(buf, 'Test_popupwin_11', {})
239
240 " clean up
241 call StopVimInTerminal(buf)
242 call delete('XtestPopup')
243endfunc
244
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200245func Test_popup_with_matches()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200246 CheckScreendump
247
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200248 let lines =<< trim END
249 call setline(1, ['111 222 333', '444 555 666'])
250 let winid = popup_create([
251 \ '111 222 333',
252 \ '444 555 666',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200253 \], #{line: 3, col: 10, border: []})
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200254 set hlsearch
Bram Moolenaar024dbd22019-11-02 22:00:15 +0100255 hi VeryBlue ctermfg=blue guifg=blue
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200256 /666
257 call matchadd('ErrorMsg', '111')
Bram Moolenaar024dbd22019-11-02 22:00:15 +0100258 call matchadd('VeryBlue', '444')
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200259 call win_execute(winid, "call matchadd('ErrorMsg', '111')")
Bram Moolenaar024dbd22019-11-02 22:00:15 +0100260 call win_execute(winid, "call matchadd('VeryBlue', '555')")
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200261 END
262 call writefile(lines, 'XtestPopupMatches')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200263 let buf = RunVimInTerminal('-S XtestPopupMatches', #{rows: 10})
Bram Moolenaarac2450a2019-06-09 18:04:28 +0200264 call VerifyScreenDump(buf, 'Test_popupwin_matches', {})
265
266 " clean up
267 call StopVimInTerminal(buf)
268 call delete('XtestPopupMatches')
269endfunc
270
Bram Moolenaar399d8982019-06-02 15:34:29 +0200271func Test_popup_all_corners()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200272 CheckScreendump
273
Bram Moolenaar399d8982019-06-02 15:34:29 +0200274 let lines =<< trim END
275 call setline(1, repeat([repeat('-', 60)], 15))
276 set so=0
277 normal 2G3|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: 'topleft',
282 \ border: [],
283 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200284 \ })
Bram Moolenaarb754b5b2019-10-24 19:25:00 +0200285 normal 24|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: 'topright',
290 \ border: [],
291 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200292 \ })
Bram Moolenaarb754b5b2019-10-24 19:25:00 +0200293 normal 9G27|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: 'botleft',
298 \ border: [],
299 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200300 \ })
Bram Moolenaarb754b5b2019-10-24 19:25:00 +0200301 normal 48|r&
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200302 let winid1 = popup_create(['FIrsT', 'SEcoND'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200303 \ line: 'cursor-1',
304 \ col: 'cursor',
305 \ pos: 'botright',
306 \ border: [],
307 \ padding: [],
Bram Moolenaar399d8982019-06-02 15:34:29 +0200308 \ })
Bram Moolenaarb754b5b2019-10-24 19:25:00 +0200309 normal 1G51|r*
310 let winid1 = popup_create(['one', 'two'], #{
311 \ line: 'cursor-1',
312 \ col: 'cursor',
313 \ pos: 'botleft',
314 \ border: [],
315 \ padding: [],
316 \ })
Bram Moolenaar399d8982019-06-02 15:34:29 +0200317 END
318 call writefile(lines, 'XtestPopupCorners')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200319 let buf = RunVimInTerminal('-S XtestPopupCorners', #{rows: 12})
Bram Moolenaar399d8982019-06-02 15:34:29 +0200320 call VerifyScreenDump(buf, 'Test_popupwin_corners', {})
321
322 " clean up
323 call StopVimInTerminal(buf)
324 call delete('XtestPopupCorners')
325endfunc
326
Bram Moolenaar638a4a72019-11-06 19:25:22 +0100327func Test_popup_nospace()
328 CheckScreendump
329
330 let lines =<< trim END
331 call setline(1, repeat([repeat('-', 60)], 15))
332 set so=0
333
334 " cursor in a line in top half, using "botleft" with popup that
335 " does fit
336 normal 5G2|r@
337 let winid1 = popup_create(['one', 'two'], #{
338 \ line: 'cursor-1',
339 \ col: 'cursor',
340 \ pos: 'botleft',
341 \ border: [],
342 \ })
343 " cursor in a line in top half, using "botleft" with popup that
344 " doesn't fit: gets truncated
345 normal 5G9|r#
346 let winid1 = popup_create(['one', 'two', 'tee'], #{
347 \ line: 'cursor-1',
348 \ col: 'cursor',
349 \ pos: 'botleft',
350 \ posinvert: 0,
351 \ border: [],
352 \ })
353 " cursor in a line in top half, using "botleft" with popup that
354 " doesn't fit and 'posinvert' set: flips to below.
355 normal 5G16|r%
356 let winid1 = popup_create(['one', 'two', 'tee'], #{
357 \ line: 'cursor-1',
358 \ col: 'cursor',
359 \ pos: 'botleft',
360 \ border: [],
361 \ })
362 " cursor in a line in bottom half, using "botleft" with popup that
363 " doesn't fit: does not flip.
364 normal 8G23|r*
365 let winid1 = popup_create(['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'], #{
366 \ line: 'cursor-1',
367 \ col: 'cursor',
368 \ pos: 'botleft',
369 \ border: [],
370 \ })
371
372 " cursor in a line in bottom half, using "topleft" with popup that
373 " does fit
374 normal 8G30|r@
375 let winid1 = popup_create(['one', 'two'], #{
376 \ line: 'cursor+1',
377 \ col: 'cursor',
378 \ pos: 'topleft',
379 \ border: [],
380 \ })
381 " cursor in a line in top half, using "topleft" with popup that
382 " doesn't fit: truncated
383 normal 8G37|r#
384 let winid1 = popup_create(['one', 'two', 'tee'], #{
385 \ line: 'cursor+1',
386 \ col: 'cursor',
387 \ pos: 'topleft',
388 \ posinvert: 0,
389 \ border: [],
390 \ })
391 " cursor in a line in top half, using "topleft" with popup that
Bram Moolenaar5c6b6182019-11-10 17:51:38 +0100392 " doesn't fit and "posinvert" set: flips to above.
Bram Moolenaar638a4a72019-11-06 19:25:22 +0100393 normal 8G44|r%
Bram Moolenaar5c6b6182019-11-10 17:51:38 +0100394 let winid1 = popup_create(['one', 'two', 'tee', 'fou', 'fiv'], #{
Bram Moolenaar638a4a72019-11-06 19:25:22 +0100395 \ line: 'cursor+1',
396 \ col: 'cursor',
397 \ pos: 'topleft',
398 \ border: [],
399 \ })
400 " cursor in a line in top half, using "topleft" with popup that
401 " doesn't fit: does not flip.
402 normal 5G51|r*
403 let winid1 = popup_create(['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'], #{
404 \ line: 'cursor+1',
405 \ col: 'cursor',
406 \ pos: 'topleft',
407 \ border: [],
408 \ })
409 END
410 call writefile(lines, 'XtestPopupNospace')
411 let buf = RunVimInTerminal('-S XtestPopupNospace', #{rows: 12})
412 call VerifyScreenDump(buf, 'Test_popupwin_nospace', {})
413
414 " clean up
415 call StopVimInTerminal(buf)
416 call delete('XtestPopupNospace')
417endfunc
418
Bram Moolenaar8d241042019-06-12 23:40:01 +0200419func Test_popup_firstline()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200420 CheckScreendump
421
Bram Moolenaar8d241042019-06-12 23:40:01 +0200422 let lines =<< trim END
423 call setline(1, range(1, 20))
Bram Moolenaar8c6173c2019-08-30 22:08:34 +0200424 let winid = popup_create(['1111', '222222', '33333', '44', '5', '666666', '77777', '888', '9999999999999999'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200425 \ maxheight: 4,
426 \ firstline: 3,
Bram Moolenaar8d241042019-06-12 23:40:01 +0200427 \ })
428 END
429 call writefile(lines, 'XtestPopupFirstline')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200430 let buf = RunVimInTerminal('-S XtestPopupFirstline', #{rows: 10})
Bram Moolenaar8c6173c2019-08-30 22:08:34 +0200431 call VerifyScreenDump(buf, 'Test_popupwin_firstline_1', {})
432
433 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: -1})\<CR>")
434 call term_sendkeys(buf, ":\<CR>")
435 call VerifyScreenDump(buf, 'Test_popupwin_firstline_2', {})
Bram Moolenaar8d241042019-06-12 23:40:01 +0200436
437 " clean up
438 call StopVimInTerminal(buf)
439 call delete('XtestPopupFirstline')
Bram Moolenaarae943152019-06-16 22:54:14 +0200440
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200441 let winid = popup_create(['1111', '222222', '33333', '44444'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200442 \ maxheight: 2,
443 \ firstline: 3,
Bram Moolenaarae943152019-06-16 22:54:14 +0200444 \ })
445 call assert_equal(3, popup_getoptions(winid).firstline)
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200446 call popup_setoptions(winid, #{firstline: 1})
Bram Moolenaarae943152019-06-16 22:54:14 +0200447 call assert_equal(1, popup_getoptions(winid).firstline)
Bram Moolenaar6a124e62019-09-04 18:15:19 +0200448 eval winid->popup_close()
Bram Moolenaar9e67b6a2019-08-30 17:34:08 +0200449
450 let winid = popup_create(['xxx']->repeat(50), #{
451 \ maxheight: 3,
452 \ firstline: 11,
453 \ })
454 redraw
455 call assert_equal(11, popup_getoptions(winid).firstline)
456 call assert_equal(11, popup_getpos(winid).firstline)
Bram Moolenaar8e0a8e72019-09-02 22:56:24 +0200457 " check line() works with popup window
458 call assert_equal(11, line('.', winid))
459 call assert_equal(50, line('$', winid))
460 call assert_equal(0, line('$', 123456))
Bram Moolenaar9e67b6a2019-08-30 17:34:08 +0200461
462 " Normal command changes what is displayed but not "firstline"
463 call win_execute(winid, "normal! \<c-y>")
464 call assert_equal(11, popup_getoptions(winid).firstline)
465 call assert_equal(10, popup_getpos(winid).firstline)
466
467 " Making some property change applies "firstline" again
468 call popup_setoptions(winid, #{line: 4})
469 call assert_equal(11, popup_getoptions(winid).firstline)
470 call assert_equal(11, popup_getpos(winid).firstline)
471
472 " Remove "firstline" property and scroll
473 call popup_setoptions(winid, #{firstline: 0})
474 call win_execute(winid, "normal! \<c-y>")
475 call assert_equal(0, popup_getoptions(winid).firstline)
476 call assert_equal(10, popup_getpos(winid).firstline)
477
478 " Making some property change has no side effect
479 call popup_setoptions(winid, #{line: 3})
480 call assert_equal(0, popup_getoptions(winid).firstline)
481 call assert_equal(10, popup_getpos(winid).firstline)
Bram Moolenaarae943152019-06-16 22:54:14 +0200482
Bram Moolenaar30efcf32019-11-03 22:29:38 +0100483 " CTRL-D scrolls down half a page
484 let winid = popup_create(['xxx']->repeat(50), #{
485 \ maxheight: 8,
486 \ })
487 redraw
488 call assert_equal(1, popup_getpos(winid).firstline)
489 call win_execute(winid, "normal! \<C-D>")
490 call assert_equal(5, popup_getpos(winid).firstline)
491 call win_execute(winid, "normal! \<C-D>")
492 call assert_equal(9, popup_getpos(winid).firstline)
493 call win_execute(winid, "normal! \<C-U>")
494 call assert_equal(5, popup_getpos(winid).firstline)
495
496 call win_execute(winid, "normal! \<C-F>")
497 call assert_equal(11, popup_getpos(winid).firstline)
498 call win_execute(winid, "normal! \<C-B>")
499 call assert_equal(5, popup_getpos(winid).firstline)
500
Bram Moolenaarae943152019-06-16 22:54:14 +0200501 call popup_close(winid)
Bram Moolenaar8d241042019-06-12 23:40:01 +0200502endfunc
503
Bram Moolenaara112f2d2019-09-01 17:38:09 +0200504func Test_popup_noscrolloff()
505 set scrolloff=5
506 let winid = popup_create(['xxx']->repeat(50), #{
507 \ maxheight: 5,
508 \ firstline: 11,
509 \ })
510 redraw
511 call assert_equal(11, popup_getoptions(winid).firstline)
512 call assert_equal(11, popup_getpos(winid).firstline)
513
514 call popup_setoptions(winid, #{firstline: 0})
515 call win_execute(winid, "normal! \<c-y>")
516 call assert_equal(0, popup_getoptions(winid).firstline)
517 call assert_equal(10, popup_getpos(winid).firstline)
518
519 call popup_close(winid)
520endfunc
521
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200522func Test_popup_drag()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200523 CheckScreendump
524
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200525 " create a popup that covers the command line
526 let lines =<< trim END
527 call setline(1, range(1, 20))
Bram Moolenaar356375f2019-08-24 14:46:29 +0200528 split
529 vsplit
530 $wincmd w
531 vsplit
532 1wincmd w
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200533 let winid = popup_create(['1111', '222222', '33333'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200534 \ drag: 1,
Bram Moolenaar9bcb70c2019-08-01 21:11:05 +0200535 \ resize: 1,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200536 \ border: [],
537 \ line: &lines - 4,
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200538 \ })
539 func Dragit()
540 call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
541 endfunc
542 map <silent> <F3> :call test_setmouse(&lines - 4, &columns / 2)<CR>
Bram Moolenaar356375f2019-08-24 14:46:29 +0200543 map <silent> <F4> :call test_setmouse(&lines - 8, &columns / 2 - 20)<CR>
Bram Moolenaar9bcb70c2019-08-01 21:11:05 +0200544 func Resize()
545 call feedkeys("\<F5>\<LeftMouse>\<F6>\<LeftDrag>\<LeftRelease>", "xt")
546 endfunc
Bram Moolenaar356375f2019-08-24 14:46:29 +0200547 map <silent> <F5> :call test_setmouse(6, 21)<CR>
548 map <silent> <F6> :call test_setmouse(7, 25)<CR>
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200549 END
550 call writefile(lines, 'XtestPopupDrag')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200551 let buf = RunVimInTerminal('-S XtestPopupDrag', #{rows: 10})
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200552 call VerifyScreenDump(buf, 'Test_popupwin_drag_01', {})
553
554 call term_sendkeys(buf, ":call Dragit()\<CR>")
555 call VerifyScreenDump(buf, 'Test_popupwin_drag_02', {})
556
Bram Moolenaar9bcb70c2019-08-01 21:11:05 +0200557 call term_sendkeys(buf, ":call Resize()\<CR>")
558 call VerifyScreenDump(buf, 'Test_popupwin_drag_03', {})
559
Bram Moolenaara540f8a2019-06-14 19:23:57 +0200560 " clean up
561 call StopVimInTerminal(buf)
562 call delete('XtestPopupDrag')
563endfunc
564
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200565func Test_popup_close_with_mouse()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200566 CheckScreendump
567
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200568 let lines =<< trim END
569 call setline(1, range(1, 20))
570 " With border, can click on X
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200571 let winid = popup_create('foobar', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200572 \ close: 'button',
573 \ border: [],
574 \ line: 1,
575 \ col: 1,
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200576 \ })
577 func CloseMsg(id, result)
578 echomsg 'Popup closed with ' .. a:result
579 endfunc
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200580 let winid = popup_create('notification', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200581 \ close: 'click',
582 \ line: 3,
583 \ col: 15,
584 \ callback: 'CloseMsg',
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200585 \ })
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200586 let winid = popup_create('no border here', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200587 \ close: 'button',
588 \ line: 5,
589 \ col: 3,
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200590 \ })
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200591 let winid = popup_create('only padding', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200592 \ close: 'button',
593 \ padding: [],
594 \ line: 5,
595 \ col: 23,
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200596 \ })
597 func CloseWithX()
598 call feedkeys("\<F3>\<LeftMouse>\<LeftRelease>", "xt")
599 endfunc
600 map <silent> <F3> :call test_setmouse(1, len('foobar') + 2)<CR>
601 func CloseWithClick()
602 call feedkeys("\<F4>\<LeftMouse>\<LeftRelease>", "xt")
603 endfunc
604 map <silent> <F4> :call test_setmouse(3, 17)<CR>
Bram Moolenaarf6396232019-08-24 19:36:00 +0200605 func CreateWithMenuFilter()
606 let winid = popup_create('barfoo', #{
607 \ close: 'button',
608 \ filter: 'popup_filter_menu',
609 \ border: [],
610 \ line: 1,
611 \ col: 40,
612 \ })
613 endfunc
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200614 END
615 call writefile(lines, 'XtestPopupClose')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200616 let buf = RunVimInTerminal('-S XtestPopupClose', #{rows: 10})
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200617 call VerifyScreenDump(buf, 'Test_popupwin_close_01', {})
618
619 call term_sendkeys(buf, ":call CloseWithX()\<CR>")
620 call VerifyScreenDump(buf, 'Test_popupwin_close_02', {})
621
622 call term_sendkeys(buf, ":call CloseWithClick()\<CR>")
623 call VerifyScreenDump(buf, 'Test_popupwin_close_03', {})
624
Bram Moolenaarf6396232019-08-24 19:36:00 +0200625 call term_sendkeys(buf, ":call CreateWithMenuFilter()\<CR>")
626 call VerifyScreenDump(buf, 'Test_popupwin_close_04', {})
627
628 " We have to send the actual mouse code, feedkeys() would be caught the
629 " filter.
630 call term_sendkeys(buf, "\<Esc>[<0;47;1M")
631 call VerifyScreenDump(buf, 'Test_popupwin_close_05', {})
632
Bram Moolenaar2e62b562019-06-30 18:07:00 +0200633 " clean up
634 call StopVimInTerminal(buf)
635 call delete('XtestPopupClose')
636endfunction
637
Bram Moolenaar7b3d9392019-10-16 22:17:07 +0200638func Test_popup_menu_wrap()
639 CheckScreendump
640
641 let lines =<< trim END
642 call setline(1, range(1, 20))
643 call popup_create([
644 \ 'one',
645 \ 'asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfas',
646 \ 'three',
647 \ 'four',
648 \ ], #{
649 \ pos: "botleft",
650 \ border: [],
651 \ padding: [0,1,0,1],
652 \ maxheight: 3,
653 \ cursorline: 1,
654 \ filter: 'popup_filter_menu',
655 \ })
656 END
657 call writefile(lines, 'XtestPopupWrap')
658 let buf = RunVimInTerminal('-S XtestPopupWrap', #{rows: 10})
659 call VerifyScreenDump(buf, 'Test_popupwin_wrap_1', {})
660
661 call term_sendkeys(buf, "jj")
662 call VerifyScreenDump(buf, 'Test_popupwin_wrap_2', {})
663
664 " clean up
665 call term_sendkeys(buf, "\<Esc>")
666 call StopVimInTerminal(buf)
667 call delete('XtestPopupWrap')
668endfunction
669
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200670func Test_popup_with_mask()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200671 CheckScreendump
672
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200673 let lines =<< trim END
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200674 call setline(1, repeat([join(range(1, 42), '')], 13))
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200675 hi PopupColor ctermbg=lightgrey
676 let winid = popup_create([
677 \ 'some text',
678 \ 'another line',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200679 \], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200680 \ line: 1,
681 \ col: 10,
Bram Moolenaar638a4a72019-11-06 19:25:22 +0100682 \ posinvert: 0,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200683 \ wrap: 0,
684 \ fixed: 1,
685 \ zindex: 90,
686 \ padding: [],
687 \ highlight: 'PopupColor',
688 \ mask: [[1,1,1,1], [-5,-1,4,4], [7,9,2,3], [2,4,3,3]]})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200689 call popup_create([
690 \ 'xxxxxxxxx',
691 \ 'yyyyyyyyy',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200692 \], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200693 \ line: 3,
694 \ col: 18,
695 \ zindex: 20})
Bram Moolenaarba45f1f2019-07-03 22:50:41 +0200696 let winidb = popup_create([
697 \ 'just one line',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200698 \], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200699 \ line: 7,
700 \ col: 10,
Bram Moolenaar638a4a72019-11-06 19:25:22 +0100701 \ posinvert: 0,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200702 \ wrap: 0,
703 \ fixed: 1,
704 \ close: 'button',
705 \ zindex: 90,
706 \ padding: [],
707 \ border: [],
708 \ 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 +0200709 END
710 call writefile(lines, 'XtestPopupMask')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200711 let buf = RunVimInTerminal('-S XtestPopupMask', #{rows: 13})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200712 call VerifyScreenDump(buf, 'Test_popupwin_mask_1', {})
713
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200714 call term_sendkeys(buf, ":call popup_move(winid, #{col: 11, line: 2})\<CR>")
715 call term_sendkeys(buf, ":call popup_move(winidb, #{col: 12})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200716 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200717 call VerifyScreenDump(buf, 'Test_popupwin_mask_2', {})
718
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200719 call term_sendkeys(buf, ":call popup_move(winid, #{col: 65, line: 2})\<CR>")
720 call term_sendkeys(buf, ":call popup_move(winidb, #{col: 63})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200721 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaard529ba52019-07-02 23:13:53 +0200722 call VerifyScreenDump(buf, 'Test_popupwin_mask_3', {})
723
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200724 call term_sendkeys(buf, ":call popup_move(winid, #{pos: 'topright', col: 12, line: 2})\<CR>")
725 call term_sendkeys(buf, ":call popup_move(winidb, #{pos: 'topright', col: 12})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200726 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaard529ba52019-07-02 23:13:53 +0200727 call VerifyScreenDump(buf, 'Test_popupwin_mask_4', {})
728
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200729 call term_sendkeys(buf, ":call popup_move(winid, #{pos: 'topright', col: 12, line: 11})\<CR>")
730 call term_sendkeys(buf, ":call popup_move(winidb, #{pos: 'topleft', col: 42, line: 11})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +0200731 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaarb4207472019-07-12 16:05:45 +0200732 call VerifyScreenDump(buf, 'Test_popupwin_mask_5', {})
733
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200734 " clean up
735 call StopVimInTerminal(buf)
736 call delete('XtestPopupMask')
737endfunc
738
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200739func Test_popup_select()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200740 CheckScreendump
741 CheckFeature clipboard_working
742
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200743 " create a popup with some text to be selected
744 let lines =<< trim END
Bram Moolenaar1755ec42019-06-15 13:13:54 +0200745 set clipboard=autoselect
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200746 call setline(1, range(1, 20))
Bram Moolenaar4dd751b2019-08-17 19:10:53 +0200747 let winid = popup_create(['the word', 'some more', 'several words here', 'invisible', '5', '6', '7'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200748 \ drag: 1,
749 \ border: [],
750 \ line: 3,
751 \ col: 10,
Bram Moolenaar4dd751b2019-08-17 19:10:53 +0200752 \ maxheight: 3,
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200753 \ })
754 func Select1()
755 call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt")
756 endfunc
757 map <silent> <F3> :call test_setmouse(4, 15)<CR>
758 map <silent> <F4> :call test_setmouse(6, 23)<CR>
759 END
760 call writefile(lines, 'XtestPopupSelect')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200761 let buf = RunVimInTerminal('-S XtestPopupSelect', #{rows: 10})
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200762 call term_sendkeys(buf, ":call Select1()\<CR>")
763 call VerifyScreenDump(buf, 'Test_popupwin_select_01', {})
764
765 call term_sendkeys(buf, ":call popup_close(winid)\<CR>")
766 call term_sendkeys(buf, "\"*p")
Bram Moolenaar8ccabf62019-07-12 18:12:51 +0200767 " clean the command line, sometimes it still shows a command
768 call term_sendkeys(buf, ":\<esc>")
769
Bram Moolenaarbd75b532019-06-14 23:41:55 +0200770 call VerifyScreenDump(buf, 'Test_popupwin_select_02', {})
771
772 " clean up
773 call StopVimInTerminal(buf)
774 call delete('XtestPopupSelect')
775endfunc
776
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200777func Test_popup_in_tab()
778 " default popup is local to tab, not visible when in other tab
779 let winid = popup_create("text", {})
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200780 let bufnr = winbufnr(winid)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200781 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200782 call assert_equal(0, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200783 tabnew
784 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200785 call assert_equal(1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200786 quit
787 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200788
789 call assert_equal(1, bufexists(bufnr))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200790 call popup_clear()
Bram Moolenaar7c7f01e2019-06-12 21:06:32 +0200791 " buffer is gone now
792 call assert_equal(0, bufexists(bufnr))
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200793
794 " global popup is visible in any tab
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200795 let winid = popup_create("text", #{tabpage: -1})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200796 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200797 call assert_equal(-1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200798 tabnew
799 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaara3fce622019-06-20 02:31:49 +0200800 call assert_equal(-1, popup_getoptions(winid).tabpage)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200801 quit
802 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200803 call popup_clear()
Bram Moolenaara3fce622019-06-20 02:31:49 +0200804
805 " create popup in other tab
806 tabnew
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200807 let winid = popup_create("text", #{tabpage: 1})
Bram Moolenaara3fce622019-06-20 02:31:49 +0200808 call assert_equal(0, popup_getpos(winid).visible)
809 call assert_equal(1, popup_getoptions(winid).tabpage)
810 quit
811 call assert_equal(1, popup_getpos(winid).visible)
812 call assert_equal(0, popup_getoptions(winid).tabpage)
813 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200814endfunc
815
816func Test_popup_valid_arguments()
817 " Zero value is like the property wasn't there
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200818 let winid = popup_create("text", #{col: 0})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200819 let pos = popup_getpos(winid)
820 call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200821 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200822
823 " using cursor column has minimum value of 1
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200824 let winid = popup_create("text", #{col: 'cursor-100'})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200825 let pos = popup_getpos(winid)
826 call assert_equal(1, pos.col)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200827 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200828
829 " center
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200830 let winid = popup_create("text", #{pos: 'center'})
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200831 let pos = popup_getpos(winid)
832 let around = (&columns - pos.width) / 2
833 call assert_inrange(around - 1, around + 1, pos.col)
834 let around = (&lines - pos.height) / 2
835 call assert_inrange(around - 1, around + 1, pos.line)
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200836 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200837endfunc
838
839func Test_popup_invalid_arguments()
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +0200840 call assert_fails('call popup_create(666, {})', 'E86:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200841 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200842 call assert_fails('call popup_create("text", "none")', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200843 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200844
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200845 call assert_fails('call popup_create("text", #{col: "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200846 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200847 call assert_fails('call popup_create("text", #{col: "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200848 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200849 call assert_fails('call popup_create("text", #{col: "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200850 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200851 call assert_fails('call popup_create("text", #{col: "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200852 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200853
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200854 call assert_fails('call popup_create("text", #{line: "xxx"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200855 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200856 call assert_fails('call popup_create("text", #{line: "cursor8"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200857 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200858 call assert_fails('call popup_create("text", #{line: "cursor+x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200859 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200860 call assert_fails('call popup_create("text", #{line: "cursor+8x"})', 'E15:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200861 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200862
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200863 call assert_fails('call popup_create("text", #{pos: "there"})', 'E475:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200864 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200865 call assert_fails('call popup_create("text", #{padding: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200866 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200867 call assert_fails('call popup_create("text", #{border: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200868 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200869 call assert_fails('call popup_create("text", #{borderhighlight: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200870 call popup_clear()
Bram Moolenaar403d0902019-07-17 21:37:32 +0200871 call assert_fails('call popup_create("text", #{borderhighlight: test_null_list()})', 'E714:')
872 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200873 call assert_fails('call popup_create("text", #{borderchars: "none"})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200874 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200875
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200876 call assert_fails('call popup_create([#{text: "text"}, 666], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200877 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200878 call assert_fails('call popup_create([#{text: "text", props: "none"}], {})', 'E714:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200879 call popup_clear()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200880 call assert_fails('call popup_create([#{text: "text", props: ["none"]}], {})', 'E715:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200881 call popup_clear()
Bram Moolenaarcfdbc5a2019-07-17 21:27:52 +0200882 call assert_fails('call popup_create("text", #{mask: ["asdf"]})', 'E475:')
883 call popup_clear()
884 call assert_fails('call popup_create("text", #{mask: test_null_list()})', 'E475:')
Bram Moolenaar749fa0a2019-08-03 16:18:07 +0200885 call assert_fails('call popup_create("text", #{mapping: []})', 'E745:')
Bram Moolenaarcfdbc5a2019-07-17 21:27:52 +0200886 call popup_clear()
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +0200887endfunc
888
Bram Moolenaareea16992019-05-31 17:34:48 +0200889func Test_win_execute_closing_curwin()
890 split
891 let winid = popup_create('some text', {})
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200892 call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200893 call popup_clear()
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200894endfunc
895
896func Test_win_execute_not_allowed()
897 let winid = popup_create('some text', {})
898 call assert_fails('call win_execute(winid, "split")', 'E994:')
899 call assert_fails('call win_execute(winid, "vsplit")', 'E994:')
900 call assert_fails('call win_execute(winid, "close")', 'E994:')
901 call assert_fails('call win_execute(winid, "bdelete")', 'E994:')
Bram Moolenaar2d247842019-06-01 17:06:25 +0200902 call assert_fails('call win_execute(winid, "bwipe!")', 'E994:')
Bram Moolenaar815b76b2019-06-01 14:15:52 +0200903 call assert_fails('call win_execute(winid, "tabnew")', 'E994:')
904 call assert_fails('call win_execute(winid, "tabnext")', 'E994:')
905 call assert_fails('call win_execute(winid, "next")', 'E994:')
906 call assert_fails('call win_execute(winid, "rewind")', 'E994:')
907 call assert_fails('call win_execute(winid, "buf")', 'E994:')
908 call assert_fails('call win_execute(winid, "edit")', 'E994:')
909 call assert_fails('call win_execute(winid, "enew")', 'E994:')
910 call assert_fails('call win_execute(winid, "wincmd x")', 'E994:')
911 call assert_fails('call win_execute(winid, "wincmd w")', 'E994:')
912 call assert_fails('call win_execute(winid, "wincmd t")', 'E994:')
913 call assert_fails('call win_execute(winid, "wincmd b")', 'E994:')
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200914 call popup_clear()
Bram Moolenaareea16992019-05-31 17:34:48 +0200915endfunc
916
Bram Moolenaar402502d2019-05-30 22:07:36 +0200917func Test_popup_with_wrap()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200918 CheckScreendump
919
Bram Moolenaar402502d2019-05-30 22:07:36 +0200920 let lines =<< trim END
921 call setline(1, range(1, 100))
922 let winid = popup_create(
923 \ 'a long line that wont fit',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200924 \ #{line: 3, col: 20, maxwidth: 10, wrap: 1})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200925 END
926 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200927 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200928 call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
929
930 " clean up
931 call StopVimInTerminal(buf)
932 call delete('XtestPopup')
933endfunc
934
935func Test_popup_without_wrap()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200936 CheckScreendump
937
Bram Moolenaar402502d2019-05-30 22:07:36 +0200938 let lines =<< trim END
939 call setline(1, range(1, 100))
940 let winid = popup_create(
941 \ 'a long line that wont fit',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200942 \ #{line: 3, col: 20, maxwidth: 10, wrap: 0})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200943 END
944 call writefile(lines, 'XtestPopup')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200945 let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10})
Bram Moolenaar402502d2019-05-30 22:07:36 +0200946 call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
947
948 " clean up
949 call StopVimInTerminal(buf)
950 call delete('XtestPopup')
951endfunc
952
Bram Moolenaar331bafd2019-07-20 17:46:05 +0200953func Test_popup_with_showbreak()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200954 CheckScreendump
955
Bram Moolenaar331bafd2019-07-20 17:46:05 +0200956 let lines =<< trim END
957 set showbreak=>>\
958 call setline(1, range(1, 20))
959 let winid = popup_dialog(
Bram Moolenaar8ae54372019-09-15 18:11:16 +0200960 \ 'a long line here that wraps',
961 \ #{filter: 'popup_filter_yesno',
962 \ maxwidth: 12})
Bram Moolenaar331bafd2019-07-20 17:46:05 +0200963 END
964 call writefile(lines, 'XtestPopupShowbreak')
965 let buf = RunVimInTerminal('-S XtestPopupShowbreak', #{rows: 10})
966 call VerifyScreenDump(buf, 'Test_popupwin_showbreak', {})
967
968 " clean up
969 call term_sendkeys(buf, "y")
970 call StopVimInTerminal(buf)
971 call delete('XtestPopupShowbreak')
972endfunc
973
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200974func Test_popup_time()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +0200975 CheckFeature timers
976
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200977 topleft vnew
978 call setline(1, 'hello')
979
Bram Moolenaar4c6d9042019-07-16 22:04:02 +0200980 let winid = popup_create('world', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +0200981 \ line: 1,
982 \ col: 1,
983 \ minwidth: 20,
984 \ time: 500,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200985 \})
986 redraw
987 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
988 call assert_equal('world', line)
989
Bram Moolenaarb4f06282019-07-12 21:07:54 +0200990 call assert_equal(winid, popup_locate(1, 1))
991 call assert_equal(winid, popup_locate(1, 20))
992 call assert_equal(0, popup_locate(1, 21))
993 call assert_equal(0, popup_locate(2, 1))
994
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200995 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +0200996 redraw
Bram Moolenaar196b4662019-09-06 21:34:30 +0200997 let line = join(map(range(1, 5), '1->screenstring(v:val)'), '')
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200998 call assert_equal('hello', line)
999
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001000 call popup_create('on the command line', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001001 \ line: &lines,
1002 \ col: 10,
1003 \ minwidth: 20,
1004 \ time: 500,
Bram Moolenaar51fe3b12019-05-26 20:10:06 +02001005 \})
1006 redraw
1007 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
1008 call assert_match('.*on the command line.*', line)
1009
1010 sleep 700m
1011 redraw
1012 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
1013 call assert_notmatch('.*on the command line.*', line)
1014
1015 bwipe!
1016endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001017
1018func Test_popup_hide()
1019 topleft vnew
1020 call setline(1, 'hello')
1021
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001022 let winid = popup_create('world', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001023 \ line: 1,
1024 \ col: 1,
1025 \ minwidth: 20,
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001026 \})
1027 redraw
1028 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
1029 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +02001030 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +02001031 " buffer is still listed and active
1032 call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001033
1034 call popup_hide(winid)
1035 redraw
1036 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
1037 call assert_equal('hello', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +02001038 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarc6896e22019-05-30 22:32:34 +02001039 " buffer is still listed but hidden
1040 call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u'))
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001041
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001042 eval winid->popup_show()
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001043 redraw
1044 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
1045 call assert_equal('world', line)
Bram Moolenaar402502d2019-05-30 22:07:36 +02001046 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001047
1048
1049 call popup_close(winid)
1050 redraw
1051 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
1052 call assert_equal('hello', line)
1053
1054 " error is given for existing non-popup window
1055 call assert_fails('call popup_hide(win_getid())', 'E993:')
1056
1057 " no error non-existing window
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001058 eval 1234234->popup_hide()
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001059 call popup_show(41234234)
1060
1061 bwipe!
1062endfunc
Bram Moolenaar60cdb302019-05-27 21:54:10 +02001063
1064func Test_popup_move()
1065 topleft vnew
1066 call setline(1, 'hello')
1067
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001068 let winid = popup_create('world', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001069 \ line: 1,
1070 \ col: 1,
1071 \ minwidth: 20,
Bram Moolenaar60cdb302019-05-27 21:54:10 +02001072 \})
1073 redraw
1074 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
1075 call assert_equal('world ', line)
1076
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001077 call popup_move(winid, #{line: 2, col: 2})
Bram Moolenaar60cdb302019-05-27 21:54:10 +02001078 redraw
1079 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
1080 call assert_equal('hello ', line)
1081 let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
1082 call assert_equal('~world', line)
1083
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001084 eval winid->popup_move(#{line: 1})
Bram Moolenaar60cdb302019-05-27 21:54:10 +02001085 redraw
1086 let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
1087 call assert_equal('hworld', line)
1088
1089 call popup_close(winid)
1090
1091 bwipe!
1092endfunc
Bram Moolenaarbc133542019-05-29 20:26:46 +02001093
Bram Moolenaar402502d2019-05-30 22:07:36 +02001094func Test_popup_getpos()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001095 let winid = popup_create('hello', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001096 \ line: 2,
1097 \ col: 3,
1098 \ minwidth: 10,
1099 \ minheight: 11,
Bram Moolenaarbc133542019-05-29 20:26:46 +02001100 \})
1101 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +02001102 let res = popup_getpos(winid)
Bram Moolenaarbc133542019-05-29 20:26:46 +02001103 call assert_equal(2, res.line)
1104 call assert_equal(3, res.col)
1105 call assert_equal(10, res.width)
1106 call assert_equal(11, res.height)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001107 call assert_equal(1, res.visible)
Bram Moolenaarbc133542019-05-29 20:26:46 +02001108
1109 call popup_close(winid)
1110endfunc
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +02001111
1112func Test_popup_width_longest()
1113 let tests = [
1114 \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
1115 \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
1116 \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
1117 \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
1118 \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
1119 \ ]
1120
1121 for test in tests
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001122 let winid = popup_create(test[0], #{line: 2, col: 3})
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +02001123 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +02001124 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +02001125 call assert_equal(test[1], position.width)
1126 call popup_close(winid)
1127 endfor
1128endfunc
1129
1130func Test_popup_wraps()
1131 let tests = [
1132 \ ['nowrap', 6, 1],
1133 \ ['a line that wraps once', 12, 2],
1134 \ ['a line that wraps two times', 12, 3],
1135 \ ]
1136 for test in tests
1137 let winid = popup_create(test[0],
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001138 \ #{line: 2, col: 3, maxwidth: 12})
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +02001139 redraw
Bram Moolenaar402502d2019-05-30 22:07:36 +02001140 let position = popup_getpos(winid)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +02001141 call assert_equal(test[1], position.width)
1142 call assert_equal(test[2], position.height)
1143
1144 call popup_close(winid)
Bram Moolenaar402502d2019-05-30 22:07:36 +02001145 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +02001146 endfor
1147endfunc
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001148
1149func Test_popup_getoptions()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001150 let winid = popup_create('hello', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001151 \ line: 2,
1152 \ col: 3,
1153 \ minwidth: 10,
1154 \ minheight: 11,
1155 \ maxwidth: 20,
1156 \ maxheight: 21,
1157 \ zindex: 100,
1158 \ time: 5000,
1159 \ fixed: 1
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001160 \})
1161 redraw
1162 let res = popup_getoptions(winid)
1163 call assert_equal(2, res.line)
1164 call assert_equal(3, res.col)
1165 call assert_equal(10, res.minwidth)
1166 call assert_equal(11, res.minheight)
1167 call assert_equal(20, res.maxwidth)
1168 call assert_equal(21, res.maxheight)
1169 call assert_equal(100, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001170 call assert_equal(1, res.fixed)
Bram Moolenaarb8350ab2019-08-04 17:59:49 +02001171 call assert_equal(1, res.mapping)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001172 if has('timers')
1173 call assert_equal(5000, res.time)
1174 endif
1175 call popup_close(winid)
1176
1177 let winid = popup_create('hello', {})
1178 redraw
1179 let res = popup_getoptions(winid)
1180 call assert_equal(0, res.line)
1181 call assert_equal(0, res.col)
1182 call assert_equal(0, res.minwidth)
1183 call assert_equal(0, res.minheight)
1184 call assert_equal(0, res.maxwidth)
1185 call assert_equal(0, res.maxheight)
1186 call assert_equal(50, res.zindex)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001187 call assert_equal(0, res.fixed)
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001188 if has('timers')
1189 call assert_equal(0, res.time)
1190 endif
1191 call popup_close(winid)
1192 call assert_equal({}, popup_getoptions(winid))
1193endfunc
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02001194
1195func Test_popup_option_values()
1196 new
1197 " window-local
1198 setlocal number
1199 setlocal nowrap
1200 " buffer-local
1201 setlocal omnifunc=Something
1202 " global/buffer-local
1203 setlocal path=/there
1204 " global/window-local
Bram Moolenaara112f2d2019-09-01 17:38:09 +02001205 setlocal statusline=2
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02001206
1207 let winid = popup_create('hello', {})
1208 call assert_equal(0, getwinvar(winid, '&number'))
1209 call assert_equal(1, getwinvar(winid, '&wrap'))
1210 call assert_equal('', getwinvar(winid, '&omnifunc'))
1211 call assert_equal(&g:path, getwinvar(winid, '&path'))
Bram Moolenaara112f2d2019-09-01 17:38:09 +02001212 call assert_equal(&g:statusline, getwinvar(winid, '&statusline'))
1213
1214 " 'scrolloff' is reset to zero
1215 call assert_equal(5, &scrolloff)
1216 call assert_equal(0, getwinvar(winid, '&scrolloff'))
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02001217
1218 call popup_close(winid)
1219 bwipe
1220endfunc
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001221
1222func Test_popup_atcursor()
1223 topleft vnew
1224 call setline(1, [
1225 \ 'xxxxxxxxxxxxxxxxx',
1226 \ 'xxxxxxxxxxxxxxxxx',
1227 \ 'xxxxxxxxxxxxxxxxx',
1228 \])
1229
1230 call cursor(2, 2)
1231 redraw
1232 let winid = popup_atcursor('vim', {})
1233 redraw
1234 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
1235 call assert_equal('xvimxxxxxxxxxxxxx', line)
1236 call popup_close(winid)
1237
1238 call cursor(3, 4)
1239 redraw
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001240 let winid = 'vim'->popup_atcursor({})
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001241 redraw
1242 let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
1243 call assert_equal('xxxvimxxxxxxxxxxx', line)
1244 call popup_close(winid)
1245
1246 call cursor(1, 1)
1247 redraw
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001248 let winid = popup_create('vim', #{
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001249 \ line: 'cursor+2',
1250 \ col: 'cursor+1',
1251 \})
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001252 redraw
1253 let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '')
1254 call assert_equal('xvimxxxxxxxxxxxxx', line)
1255 call popup_close(winid)
1256
1257 call cursor(3, 3)
1258 redraw
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001259 let winid = popup_create('vim', #{
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001260 \ line: 'cursor-2',
1261 \ col: 'cursor-1',
1262 \})
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001263 redraw
1264 let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '')
1265 call assert_equal('xvimxxxxxxxxxxxxx', line)
1266 call popup_close(winid)
1267
Bram Moolenaar402502d2019-05-30 22:07:36 +02001268 " just enough room above
1269 call cursor(3, 3)
1270 redraw
1271 let winid = popup_atcursor(['vim', 'is great'], {})
1272 redraw
1273 let pos = popup_getpos(winid)
1274 call assert_equal(1, pos.line)
1275 call popup_close(winid)
1276
1277 " not enough room above, popup goes below the cursor
1278 call cursor(3, 3)
1279 redraw
1280 let winid = popup_atcursor(['vim', 'is', 'great'], {})
1281 redraw
1282 let pos = popup_getpos(winid)
1283 call assert_equal(4, pos.line)
1284 call popup_close(winid)
1285
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +02001286 " cursor in first line, popup in line 2
1287 call cursor(1, 1)
1288 redraw
1289 let winid = popup_atcursor(['vim', 'is', 'great'], {})
1290 redraw
1291 let pos = popup_getpos(winid)
1292 call assert_equal(2, pos.line)
1293 call popup_close(winid)
1294
Bram Moolenaarcc31ad92019-05-30 19:25:06 +02001295 bwipe!
1296endfunc
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001297
Bram Moolenaar4dd8fe02019-11-09 15:33:31 +01001298func Test_popup_atcursor_pos()
1299 CheckScreendump
1300
1301 let lines =<< trim END
1302 call setline(1, repeat([repeat('-', 60)], 15))
1303 set so=0
1304
1305 normal 9G3|r#
1306 let winid1 = popup_atcursor(['first', 'second'], #{
1307 \ moved: [0, 0, 0],
1308 \ })
1309 normal 9G21|r&
1310 let winid1 = popup_atcursor(['FIrsT', 'SEcoND'], #{
1311 \ pos: 'botright',
1312 \ moved: [0, 0, 0],
1313 \ })
1314 normal 3G27|r%
1315 let winid1 = popup_atcursor(['fiRSt', 'seCOnd'], #{
1316 \ pos: 'topleft',
1317 \ moved: [0, 0, 0],
1318 \ })
1319 normal 3G45|r@
1320 let winid1 = popup_atcursor(['First', 'SeconD'], #{
1321 \ pos: 'topright',
1322 \ moved: [0, 0, 0],
1323 \ })
1324 END
1325 call writefile(lines, 'XtestPopupAtcursorPos')
1326 let buf = RunVimInTerminal('-S XtestPopupAtcursorPos', #{rows: 12})
1327 call VerifyScreenDump(buf, 'Test_popupwin_atcursor_pos', {})
1328
1329 " clean up
1330 call StopVimInTerminal(buf)
1331 call delete('XtestPopupAtcursorPos')
1332endfunc
1333
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001334func Test_popup_beval()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001335 CheckScreendump
Bram Moolenaar1e82a782019-09-21 22:57:06 +02001336 CheckFeature balloon_eval_term
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001337
1338 let lines =<< trim END
1339 call setline(1, range(1, 20))
1340 call setline(5, 'here is some text to hover over')
1341 set balloonevalterm
1342 set balloonexpr=BalloonExpr()
1343 set balloondelay=100
1344 func BalloonExpr()
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001345 let s:winid = [v:beval_text]->popup_beval({})
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001346 return ''
1347 endfunc
1348 func Hover()
1349 call test_setmouse(5, 15)
1350 call feedkeys("\<MouseMove>\<Ignore>", "xt")
1351 sleep 100m
1352 endfunc
1353 func MoveOntoPopup()
1354 call test_setmouse(4, 17)
1355 call feedkeys("\<F4>\<MouseMove>\<Ignore>", "xt")
1356 endfunc
1357 func MoveAway()
1358 call test_setmouse(5, 13)
1359 call feedkeys("\<F5>\<MouseMove>\<Ignore>", "xt")
1360 endfunc
1361 END
1362 call writefile(lines, 'XtestPopupBeval')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001363 let buf = RunVimInTerminal('-S XtestPopupBeval', #{rows: 10})
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001364 call term_wait(buf, 100)
1365 call term_sendkeys(buf, 'j')
1366 call term_sendkeys(buf, ":call Hover()\<CR>")
1367 call VerifyScreenDump(buf, 'Test_popupwin_beval_1', {})
1368
1369 call term_sendkeys(buf, ":call MoveOntoPopup()\<CR>")
1370 call VerifyScreenDump(buf, 'Test_popupwin_beval_2', {})
1371
1372 call term_sendkeys(buf, ":call MoveAway()\<CR>")
1373 call VerifyScreenDump(buf, 'Test_popupwin_beval_3', {})
1374
1375 " clean up
1376 call StopVimInTerminal(buf)
1377 call delete('XtestPopupBeval')
1378endfunc
1379
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001380func Test_popup_filter()
1381 new
1382 call setline(1, 'some text')
1383
1384 func MyPopupFilter(winid, c)
1385 if a:c == 'e'
1386 let g:eaten = 'e'
1387 return 1
1388 endif
1389 if a:c == '0'
1390 let g:ignored = '0'
1391 return 0
1392 endif
1393 if a:c == 'x'
1394 call popup_close(a:winid)
1395 return 1
1396 endif
1397 return 0
1398 endfunc
1399
Bram Moolenaar6a124e62019-09-04 18:15:19 +02001400 let winid = 'something'->popup_create(#{filter: 'MyPopupFilter'})
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001401 redraw
1402
1403 " e is consumed by the filter
1404 call feedkeys('e', 'xt')
1405 call assert_equal('e', g:eaten)
1406
1407 " 0 is ignored by the filter
1408 normal $
1409 call assert_equal(9, getcurpos()[2])
1410 call feedkeys('0', 'xt')
1411 call assert_equal('0', g:ignored)
1412 call assert_equal(1, getcurpos()[2])
1413
1414 " x closes the popup
1415 call feedkeys('x', 'xt')
1416 call assert_equal('e', g:eaten)
1417 call assert_equal(-1, winbufnr(winid))
1418
1419 delfunc MyPopupFilter
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001420 call popup_clear()
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001421endfunc
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001422
Bram Moolenaara42d9452019-06-15 21:46:30 +02001423func ShowDialog(key, result)
1424 let s:cb_res = 999
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001425 let winid = popup_dialog('do you want to quit (Yes/no)?', #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001426 \ filter: 'popup_filter_yesno',
1427 \ callback: 'QuitCallback',
Bram Moolenaara42d9452019-06-15 21:46:30 +02001428 \ })
1429 redraw
1430 call feedkeys(a:key, "xt")
1431 call assert_equal(winid, s:cb_winid)
1432 call assert_equal(a:result, s:cb_res)
1433endfunc
1434
1435func Test_popup_dialog()
1436 func QuitCallback(id, res)
1437 let s:cb_winid = a:id
1438 let s:cb_res = a:res
1439 endfunc
1440
1441 let winid = ShowDialog("y", 1)
1442 let winid = ShowDialog("Y", 1)
1443 let winid = ShowDialog("n", 0)
1444 let winid = ShowDialog("N", 0)
1445 let winid = ShowDialog("x", 0)
1446 let winid = ShowDialog("X", 0)
1447 let winid = ShowDialog("\<Esc>", 0)
1448 let winid = ShowDialog("\<C-C>", -1)
1449
1450 delfunc QuitCallback
1451endfunc
1452
Bram Moolenaara730e552019-06-16 19:05:31 +02001453func ShowMenu(key, result)
1454 let s:cb_res = 999
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001455 let winid = popup_menu(['one', 'two', 'something else'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001456 \ callback: 'QuitCallback',
Bram Moolenaara730e552019-06-16 19:05:31 +02001457 \ })
1458 redraw
1459 call feedkeys(a:key, "xt")
1460 call assert_equal(winid, s:cb_winid)
1461 call assert_equal(a:result, s:cb_res)
1462endfunc
1463
1464func Test_popup_menu()
1465 func QuitCallback(id, res)
1466 let s:cb_winid = a:id
1467 let s:cb_res = a:res
1468 endfunc
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02001469 " mapping won't be used in popup
1470 map j k
Bram Moolenaara730e552019-06-16 19:05:31 +02001471
1472 let winid = ShowMenu(" ", 1)
1473 let winid = ShowMenu("j \<CR>", 2)
1474 let winid = ShowMenu("JjK \<CR>", 2)
1475 let winid = ShowMenu("jjjjjj ", 3)
1476 let winid = ShowMenu("kkk ", 1)
1477 let winid = ShowMenu("x", -1)
1478 let winid = ShowMenu("X", -1)
1479 let winid = ShowMenu("\<Esc>", -1)
1480 let winid = ShowMenu("\<C-C>", -1)
1481
1482 delfunc QuitCallback
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02001483 unmap j
Bram Moolenaara730e552019-06-16 19:05:31 +02001484endfunc
1485
1486func Test_popup_menu_screenshot()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001487 CheckScreendump
Bram Moolenaara730e552019-06-16 19:05:31 +02001488
1489 let lines =<< trim END
1490 call setline(1, range(1, 20))
1491 hi PopupSelected ctermbg=lightblue
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001492 call popup_menu(['one', 'two', 'another'], #{callback: 'MenuDone', title: ' make a choice from the list '})
Bram Moolenaara730e552019-06-16 19:05:31 +02001493 func MenuDone(id, res)
1494 echomsg "selected " .. a:res
1495 endfunc
1496 END
1497 call writefile(lines, 'XtestPopupMenu')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001498 let buf = RunVimInTerminal('-S XtestPopupMenu', #{rows: 10})
Bram Moolenaara730e552019-06-16 19:05:31 +02001499 call VerifyScreenDump(buf, 'Test_popupwin_menu_01', {})
1500
1501 call term_sendkeys(buf, "jj")
1502 call VerifyScreenDump(buf, 'Test_popupwin_menu_02', {})
1503
1504 call term_sendkeys(buf, " ")
1505 call VerifyScreenDump(buf, 'Test_popupwin_menu_03', {})
1506
1507 " clean up
1508 call StopVimInTerminal(buf)
1509 call delete('XtestPopupMenu')
1510endfunc
1511
Bram Moolenaarf914a332019-07-20 15:09:56 +02001512func Test_popup_menu_narrow()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001513 CheckScreendump
Bram Moolenaarf914a332019-07-20 15:09:56 +02001514
1515 let lines =<< trim END
1516 call setline(1, range(1, 20))
1517 hi PopupSelected ctermbg=green
1518 call popup_menu(['one', 'two', 'three'], #{callback: 'MenuDone'})
1519 func MenuDone(id, res)
1520 echomsg "selected " .. a:res
1521 endfunc
1522 END
1523 call writefile(lines, 'XtestPopupNarrowMenu')
1524 let buf = RunVimInTerminal('-S XtestPopupNarrowMenu', #{rows: 10})
1525 call VerifyScreenDump(buf, 'Test_popupwin_menu_04', {})
1526
1527 " clean up
1528 call term_sendkeys(buf, "x")
1529 call StopVimInTerminal(buf)
1530 call delete('XtestPopupNarrowMenu')
1531endfunc
1532
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001533func Test_popup_title()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001534 CheckScreendump
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001535
1536 " Create a popup without title or border, a line of padding will be added to
1537 " put the title on.
1538 let lines =<< trim END
1539 call setline(1, range(1, 20))
Bram Moolenaar5d458a72019-08-04 21:12:15 +02001540 let winid = popup_create(['one', 'two', 'another'], #{title: 'Title String'})
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001541 END
1542 call writefile(lines, 'XtestPopupTitle')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001543 let buf = RunVimInTerminal('-S XtestPopupTitle', #{rows: 10})
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001544 call VerifyScreenDump(buf, 'Test_popupwin_title', {})
1545
Bram Moolenaar5d458a72019-08-04 21:12:15 +02001546 call term_sendkeys(buf, ":call popup_setoptions(winid, #{maxwidth: 20, title: 'a very long title that is not going to fit'})\<CR>")
1547 call term_sendkeys(buf, ":\<CR>")
1548 call VerifyScreenDump(buf, 'Test_popupwin_longtitle_1', {})
1549
1550 call term_sendkeys(buf, ":call popup_setoptions(winid, #{border: []})\<CR>")
1551 call term_sendkeys(buf, ":\<CR>")
1552 call VerifyScreenDump(buf, 'Test_popupwin_longtitle_2', {})
1553
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001554 " clean up
1555 call StopVimInTerminal(buf)
1556 call delete('XtestPopupTitle')
Bram Moolenaarae943152019-06-16 22:54:14 +02001557
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001558 let winid = popup_create('something', #{title: 'Some Title'})
Bram Moolenaarae943152019-06-16 22:54:14 +02001559 call assert_equal('Some Title', popup_getoptions(winid).title)
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001560 call popup_setoptions(winid, #{title: 'Another Title'})
Bram Moolenaarae943152019-06-16 22:54:14 +02001561 call assert_equal('Another Title', popup_getoptions(winid).title)
1562
1563 call popup_clear()
Bram Moolenaareb2310d2019-06-16 20:09:10 +02001564endfunc
1565
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001566func Test_popup_close_callback()
1567 func PopupDone(id, result)
1568 let g:result = a:result
1569 endfunc
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001570 let winid = popup_create('something', #{callback: 'PopupDone'})
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001571 redraw
1572 call popup_close(winid, 'done')
1573 call assert_equal('done', g:result)
1574endfunc
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001575
1576func Test_popup_empty()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001577 let winid = popup_create('', #{padding: [2,2,2,2]})
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001578 redraw
1579 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001580 call assert_equal(5, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001581 call assert_equal(5, pos.height)
1582
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001583 let winid = popup_create([], #{border: []})
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001584 redraw
1585 let pos = popup_getpos(winid)
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001586 call assert_equal(3, pos.width)
Bram Moolenaar7b29dd82019-06-02 13:22:11 +02001587 call assert_equal(3, pos.height)
1588endfunc
Bram Moolenaar988c4332019-06-02 14:12:11 +02001589
1590func Test_popup_never_behind()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001591 CheckScreendump
1592
Bram Moolenaar988c4332019-06-02 14:12:11 +02001593 " +-----------------------------+
1594 " | | |
1595 " | | |
1596 " | | |
1597 " | line1 |
1598 " |------------line2------------|
1599 " | line3 |
1600 " | line4 |
1601 " | |
1602 " | |
1603 " +-----------------------------+
1604 let lines =<< trim END
Bram Moolenaar988c4332019-06-02 14:12:11 +02001605 split
1606 vsplit
1607 let info_window1 = getwininfo()[0]
1608 let line = info_window1['height']
1609 let col = info_window1['width']
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001610 call popup_create(['line1', 'line2', 'line3', 'line4'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001611 \ line : line,
1612 \ col : col,
Bram Moolenaar988c4332019-06-02 14:12:11 +02001613 \ })
1614 END
1615 call writefile(lines, 'XtestPopupBehind')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001616 let buf = RunVimInTerminal('-S XtestPopupBehind', #{rows: 10})
Bram Moolenaar988c4332019-06-02 14:12:11 +02001617 call term_sendkeys(buf, "\<C-W>w")
1618 call VerifyScreenDump(buf, 'Test_popupwin_behind', {})
1619
1620 " clean up
1621 call StopVimInTerminal(buf)
1622 call delete('XtestPopupBehind')
1623endfunc
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001624
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001625func s:VerifyPosition(p, msg, line, col, width, height)
1626 call assert_equal(a:line, popup_getpos(a:p).line, a:msg . ' (l)')
1627 call assert_equal(a:col, popup_getpos(a:p).col, a:msg . ' (c)')
1628 call assert_equal(a:width, popup_getpos(a:p).width, a:msg . ' (w)')
1629 call assert_equal(a:height, popup_getpos(a:p).height, a:msg . ' (h)')
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001630endfunc
1631
1632func Test_popup_position_adjust()
1633 " Anything placed past 2 cells from of the right of the screen is moved to the
1634 " left.
1635 "
1636 " When wrapping is disabled, we also shift to the left to display on the
1637 " screen, unless fixed is set.
1638
1639 " Entries for cases which don't vary based on wrapping.
1640 " Format is per tests described below
1641 let both_wrap_tests = [
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001642 \ ['a', 5, &columns, 5, &columns - 2, 1, 1],
1643 \ ['b', 5, &columns + 1, 5, &columns - 2, 1, 1],
1644 \ ['c', 5, &columns - 1, 5, &columns - 2, 1, 1],
1645 \ ['d', 5, &columns - 2, 5, &columns - 2, 1, 1],
1646 \ ['e', 5, &columns - 3, 5, &columns - 3, 1, 1],
1647 \
1648 \ ['aa', 5, &columns, 5, &columns - 2, 2, 1],
1649 \ ['bb', 5, &columns + 1, 5, &columns - 2, 2, 1],
1650 \ ['cc', 5, &columns - 1, 5, &columns - 2, 2, 1],
1651 \ ['dd', 5, &columns - 2, 5, &columns - 2, 2, 1],
1652 \ ['ee', 5, &columns - 3, 5, &columns - 3, 2, 1],
1653 \
1654 \ ['aaa', 5, &columns, 5, &columns - 2, 3, 1],
1655 \ ['bbb', 5, &columns + 1, 5, &columns - 2, 3, 1],
1656 \ ['ccc', 5, &columns - 1, 5, &columns - 2, 3, 1],
1657 \ ['ddd', 5, &columns - 2, 5, &columns - 2, 3, 1],
1658 \ ['eee', 5, &columns - 3, 5, &columns - 3, 3, 1],
1659 \ ]
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001660
1661 " these test groups are dicts with:
1662 " - comment: something to identify the group of tests by
1663 " - options: dict of options to merge with the row/col in tests
1664 " - tests: list of cases. Each one is a list with elements:
1665 " - text
1666 " - row
1667 " - col
1668 " - expected row
1669 " - expected col
1670 " - expected width
1671 " - expected height
1672 let tests = [
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001673 \ #{
1674 \ comment: 'left-aligned with wrapping',
1675 \ options: #{
1676 \ wrap: 1,
1677 \ pos: 'botleft',
1678 \ },
1679 \ tests: both_wrap_tests + [
1680 \ ['aaaa', 5, &columns, 4, &columns - 2, 3, 2],
1681 \ ['bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2],
1682 \ ['cccc', 5, &columns - 1, 4, &columns - 2, 3, 2],
1683 \ ['dddd', 5, &columns - 2, 4, &columns - 2, 3, 2],
1684 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1],
1685 \ ],
1686 \ },
1687 \ #{
1688 \ comment: 'left aligned without wrapping',
1689 \ options: #{
1690 \ wrap: 0,
1691 \ pos: 'botleft',
1692 \ },
1693 \ tests: both_wrap_tests + [
1694 \ ['aaaa', 5, &columns, 5, &columns - 3, 4, 1],
1695 \ ['bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1],
1696 \ ['cccc', 5, &columns - 1, 5, &columns - 3, 4, 1],
1697 \ ['dddd', 5, &columns - 2, 5, &columns - 3, 4, 1],
1698 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1],
1699 \ ],
1700 \ },
1701 \ #{
1702 \ comment: 'left aligned with fixed position',
1703 \ options: #{
1704 \ wrap: 0,
1705 \ fixed: 1,
1706 \ pos: 'botleft',
1707 \ },
1708 \ tests: both_wrap_tests + [
1709 \ ['aaaa', 5, &columns, 5, &columns - 2, 3, 1],
1710 \ ['bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1],
1711 \ ['cccc', 5, &columns - 1, 5, &columns - 2, 3, 1],
1712 \ ['dddd', 5, &columns - 2, 5, &columns - 2, 3, 1],
1713 \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1],
1714 \ ],
1715 \ },
1716 \ ]
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001717
1718 for test_group in tests
1719 for test in test_group.tests
1720 let [ text, line, col, e_line, e_col, e_width, e_height ] = test
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001721 let options = #{
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001722 \ line: line,
1723 \ col: col,
1724 \ }
1725 call extend(options, test_group.options)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001726
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001727 let p = popup_create(text, options)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001728
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001729 let msg = string(extend(options, #{text: text}))
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001730 call s:VerifyPosition(p, msg, e_line, e_col, e_width, e_height)
1731 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001732 endfor
1733 endfor
1734
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001735 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001736 %bwipe!
1737endfunc
1738
Bram Moolenaar3397f742019-06-02 18:40:06 +02001739func Test_adjust_left_past_screen_width()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001740 " width of screen
1741 let X = join(map(range(&columns), {->'X'}), '')
1742
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001743 let p = popup_create(X, #{line: 1, col: 1, wrap: 0})
1744 call s:VerifyPosition(p, 'full width topleft', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001745
1746 redraw
1747 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1748 call assert_equal(X, line)
1749
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001750 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001751 redraw
1752
1753 " Same if placed on the right hand side
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001754 let p = popup_create(X, #{line: 1, col: &columns, wrap: 0})
1755 call s:VerifyPosition(p, 'full width topright', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001756
1757 redraw
1758 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1759 call assert_equal(X, line)
1760
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001761 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001762 redraw
1763
1764 " Extend so > window width
1765 let X .= 'x'
1766
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001767 let p = popup_create(X, #{line: 1, col: 1, wrap: 0})
1768 call s:VerifyPosition(p, 'full width + 1 topleft', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001769
1770 redraw
1771 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1772 call assert_equal(X[ : -2 ], line)
1773
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001774 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001775 redraw
1776
1777 " Shifted then truncated (the x is not visible)
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001778 let p = popup_create(X, #{line: 1, col: &columns - 3, wrap: 0})
1779 call s:VerifyPosition(p, 'full width + 1 topright', 1, 1, &columns, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001780
1781 redraw
1782 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1783 call assert_equal(X[ : -2 ], line)
1784
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001785 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001786 redraw
1787
1788 " Not shifted, just truncated
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001789 let p = popup_create(X,
1790 \ #{line: 1, col: 2, wrap: 0, fixed: 1})
1791 call s:VerifyPosition(p, 'full width + 1 fixed', 1, 2, &columns - 1, 1)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001792
1793 redraw
1794 let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '')
1795 let e_line = ' ' . X[ 1 : -2 ]
1796 call assert_equal(e_line, line)
1797
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02001798 call popup_close(p)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001799 redraw
1800
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001801 call popup_clear()
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001802 %bwipe!
Bram Moolenaar3397f742019-06-02 18:40:06 +02001803endfunc
1804
1805func Test_popup_moved()
1806 new
1807 call test_override('char_avail', 1)
1808 call setline(1, ['one word to move around', 'a WORD.and->some thing'])
1809
1810 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001811 let winid = popup_atcursor('text', #{moved: 'any'})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001812 redraw
1813 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001814 call assert_equal([1, 4, 4], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001815 " trigger the check for last_cursormoved by going into insert mode
1816 call feedkeys("li\<Esc>", 'xt')
1817 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001818 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001819
1820 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001821 let winid = popup_atcursor('text', #{moved: 'word'})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001822 redraw
1823 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001824 call assert_equal([1, 4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001825 call feedkeys("hi\<Esc>", 'xt')
1826 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001827 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001828
1829 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001830 let winid = popup_atcursor('text', #{moved: 'word'})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001831 redraw
1832 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001833 call assert_equal([1, 4, 7], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001834 call feedkeys("li\<Esc>", 'xt')
1835 call assert_equal(1, popup_getpos(winid).visible)
1836 call feedkeys("ei\<Esc>", 'xt')
1837 call assert_equal(1, popup_getpos(winid).visible)
1838 call feedkeys("eli\<Esc>", 'xt')
1839 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001840 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001841
Bram Moolenaar17627312019-06-02 19:53:44 +02001842 " WORD is the default
Bram Moolenaar3397f742019-06-02 18:40:06 +02001843 exe "normal gg0/WORD\<CR>"
Bram Moolenaar17627312019-06-02 19:53:44 +02001844 let winid = popup_atcursor('text', {})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001845 redraw
1846 call assert_equal(1, popup_getpos(winid).visible)
Bram Moolenaarb3d17a22019-07-07 18:28:14 +02001847 call assert_equal([2, 2, 15], popup_getoptions(winid).moved)
Bram Moolenaar3397f742019-06-02 18:40:06 +02001848 call feedkeys("eli\<Esc>", 'xt')
1849 call assert_equal(1, popup_getpos(winid).visible)
1850 call feedkeys("wi\<Esc>", 'xt')
1851 call assert_equal(1, popup_getpos(winid).visible)
1852 call feedkeys("Eli\<Esc>", 'xt')
1853 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001854 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001855
1856 exe "normal gg0/word\<CR>"
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001857 let winid = popup_atcursor('text', #{moved: [5, 10]})
Bram Moolenaar3397f742019-06-02 18:40:06 +02001858 redraw
1859 call assert_equal(1, popup_getpos(winid).visible)
1860 call feedkeys("eli\<Esc>", 'xt')
1861 call feedkeys("ei\<Esc>", 'xt')
1862 call assert_equal(1, popup_getpos(winid).visible)
1863 call feedkeys("eli\<Esc>", 'xt')
1864 call assert_equal({}, popup_getpos(winid))
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +02001865 call popup_clear()
Bram Moolenaar3397f742019-06-02 18:40:06 +02001866
1867 bwipe!
1868 call test_override('ALL', 0)
1869endfunc
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001870
1871func Test_notifications()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001872 CheckFeature timers
1873 CheckScreendump
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001874
Bram Moolenaar0fdddee2019-09-01 15:26:23 +02001875 let lines =<< trim END
1876 call setline(1, range(1, 20))
1877 hi Notification ctermbg=lightblue
1878 call popup_notification('first notification', {})
1879 END
1880 call writefile(lines, 'XtestNotifications')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001881 let buf = RunVimInTerminal('-S XtestNotifications', #{rows: 10})
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001882 call VerifyScreenDump(buf, 'Test_popupwin_notify_01', {})
1883
1884 " second one goes below the first one
Bram Moolenaardfa97f22019-06-15 14:31:55 +02001885 call term_sendkeys(buf, ":hi link PopupNotification Notification\<CR>")
1886 call term_sendkeys(buf, ":call popup_notification('another important notification', {})\<CR>")
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001887 call VerifyScreenDump(buf, 'Test_popupwin_notify_02', {})
1888
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001889 " clean up
1890 call StopVimInTerminal(buf)
1891 call delete('XtestNotifications')
1892endfunc
Bram Moolenaardc2ce582019-06-16 15:32:14 +02001893
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001894func Test_popup_scrollbar()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02001895 CheckScreendump
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001896
1897 let lines =<< trim END
1898 call setline(1, range(1, 20))
Bram Moolenaar8da41812019-06-26 18:04:54 +02001899 hi ScrollThumb ctermbg=blue
1900 hi ScrollBar ctermbg=red
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001901 let winid = popup_create(['one', 'two', 'three', 'four', 'five',
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001902 \ 'six', 'seven', 'eight', 'nine'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02001903 \ minwidth: 8,
1904 \ maxheight: 4,
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001905 \ })
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001906 func ScrollUp()
1907 call feedkeys("\<F3>\<ScrollWheelUp>", "xt")
1908 endfunc
1909 func ScrollDown()
1910 call feedkeys("\<F3>\<ScrollWheelDown>", "xt")
1911 endfunc
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001912 func ClickTop()
1913 call feedkeys("\<F4>\<LeftMouse>", "xt")
1914 endfunc
1915 func ClickBot()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001916 call popup_setoptions(g:winid, #{border: [], close: 'button'})
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001917 call feedkeys("\<F5>\<LeftMouse>", "xt")
1918 endfunc
Bram Moolenaarf2885d32019-11-02 20:21:25 +01001919 func Popup_filter(winid, key)
1920 if a:key == 'j'
1921 let line = popup_getoptions(a:winid).firstline
1922 let nlines = line('$', a:winid)
1923 let newline = line < nlines ? (line + 1) : nlines
1924 call popup_setoptions(a:winid, #{firstline: newline})
1925 return v:true
1926 elseif a:key == 'x'
1927 call popup_close(a:winid)
1928 return v:true
1929 endif
1930 endfunc
1931
1932 func PopupScroll()
1933 call popup_clear()
1934 let text =<< trim END
1935 1
1936 2
1937 3
1938 4
1939 long line long line long line long line long line long line
1940 long line long line long line long line long line long line
1941 long line long line long line long line long line long line
1942 END
1943 call popup_create(text, #{
1944 \ minwidth: 30,
1945 \ maxwidth: 30,
1946 \ minheight: 4,
1947 \ maxheight: 4,
1948 \ firstline: 1,
Bram Moolenaar30efcf32019-11-03 22:29:38 +01001949 \ lastline: 4,
Bram Moolenaarf2885d32019-11-02 20:21:25 +01001950 \ wrap: v:true,
1951 \ scrollbar: v:true,
1952 \ mapping: v:false,
1953 \ filter: funcref('Popup_filter')
1954 \ })
1955 endfunc
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001956 map <silent> <F3> :call test_setmouse(5, 36)<CR>
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001957 map <silent> <F4> :call test_setmouse(4, 42)<CR>
1958 map <silent> <F5> :call test_setmouse(7, 42)<CR>
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001959 END
1960 call writefile(lines, 'XtestPopupScroll')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001961 let buf = RunVimInTerminal('-S XtestPopupScroll', #{rows: 10})
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001962 call VerifyScreenDump(buf, 'Test_popupwin_scroll_1', {})
1963
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001964 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 2})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +02001965 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001966 call VerifyScreenDump(buf, 'Test_popupwin_scroll_2', {})
1967
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001968 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 6})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +02001969 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001970 call VerifyScreenDump(buf, 'Test_popupwin_scroll_3', {})
1971
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02001972 call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 9})\<CR>")
Bram Moolenaarb8be54d2019-07-14 18:22:59 +02001973 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar75fb0852019-06-25 05:15:58 +02001974 call VerifyScreenDump(buf, 'Test_popupwin_scroll_4', {})
1975
Bram Moolenaar9e67b6a2019-08-30 17:34:08 +02001976 call term_sendkeys(buf, ":call popup_setoptions(winid, #{scrollbarhighlight: 'ScrollBar', thumbhighlight: 'ScrollThumb', firstline: 5})\<CR>")
Bram Moolenaara112f2d2019-09-01 17:38:09 +02001977 " this scrolls two lines (half the window height)
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001978 call term_sendkeys(buf, ":call ScrollUp()\<CR>")
1979 call VerifyScreenDump(buf, 'Test_popupwin_scroll_5', {})
1980
1981 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
1982 call VerifyScreenDump(buf, 'Test_popupwin_scroll_6', {})
1983
1984 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
Bram Moolenaar13b47c32019-06-28 21:55:48 +02001985 " wait a bit, otherwise it fails sometimes (double click recognized?)
1986 sleep 100m
Bram Moolenaar53a95d62019-06-26 03:54:08 +02001987 call term_sendkeys(buf, ":call ScrollDown()\<CR>")
1988 call VerifyScreenDump(buf, 'Test_popupwin_scroll_7', {})
1989
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02001990 call term_sendkeys(buf, ":call ClickTop()\<CR>")
1991 sleep 100m
1992 call term_sendkeys(buf, ":call ClickTop()\<CR>")
1993 call VerifyScreenDump(buf, 'Test_popupwin_scroll_8', {})
1994
1995 call term_sendkeys(buf, ":call ClickBot()\<CR>")
1996 call VerifyScreenDump(buf, 'Test_popupwin_scroll_9', {})
1997
Bram Moolenaar8c6173c2019-08-30 22:08:34 +02001998 " remove the minwidth and maxheight
1999 call term_sendkeys(buf, ":call popup_setoptions(winid, #{maxheight: 0, minwidth: 0})\<CR>")
Bram Moolenaar7e0f4622019-09-17 21:23:39 +02002000 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar8c6173c2019-08-30 22:08:34 +02002001 call VerifyScreenDump(buf, 'Test_popupwin_scroll_10', {})
2002
Bram Moolenaarf2885d32019-11-02 20:21:25 +01002003 " check size with non-wrapping lines
2004 call term_sendkeys(buf, ":call PopupScroll()\<CR>")
2005 call VerifyScreenDump(buf, 'Test_popupwin_scroll_11', {})
2006
2007 " check size with wrapping lines
2008 call term_sendkeys(buf, "j")
2009 call VerifyScreenDump(buf, 'Test_popupwin_scroll_12', {})
2010 call term_sendkeys(buf, "x")
2011
Bram Moolenaar75fb0852019-06-25 05:15:58 +02002012 " clean up
2013 call StopVimInTerminal(buf)
2014 call delete('XtestPopupScroll')
2015endfunc
2016
Bram Moolenaar437a7462019-07-05 20:17:22 +02002017func Test_popup_fitting_scrollbar()
2018 " this was causing a crash, divide by zero
2019 let winid = popup_create([
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002020 \ 'one', 'two', 'longer line that wraps', 'four', 'five'], #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002021 \ scrollbar: 1,
2022 \ maxwidth: 10,
2023 \ maxheight: 5,
2024 \ firstline: 2})
Bram Moolenaar437a7462019-07-05 20:17:22 +02002025 redraw
2026 call popup_clear()
2027endfunc
2028
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02002029func Test_popup_settext()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002030 CheckScreendump
Bram Moolenaardc2ce582019-06-16 15:32:14 +02002031
2032 let lines =<< trim END
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002033 let opts = #{wrap: 0}
Bram Moolenaardc2ce582019-06-16 15:32:14 +02002034 let p = popup_create('test', opts)
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002035 eval p->popup_settext('this is a text')
Bram Moolenaardc2ce582019-06-16 15:32:14 +02002036 END
2037
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02002038 call writefile(lines, 'XtestPopupSetText')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002039 let buf = RunVimInTerminal('-S XtestPopupSetText', #{rows: 10})
Bram Moolenaardc2ce582019-06-16 15:32:14 +02002040 call VerifyScreenDump(buf, 'Test_popup_settext_01', {})
2041
2042 " Setting to empty string clears it
2043 call term_sendkeys(buf, ":call popup_settext(p, '')\<CR>")
2044 call VerifyScreenDump(buf, 'Test_popup_settext_02', {})
2045
2046 " Setting a list
2047 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
2048 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
2049
2050 " Shrinking with a list
2051 call term_sendkeys(buf, ":call popup_settext(p, ['a'])\<CR>")
2052 call VerifyScreenDump(buf, 'Test_popup_settext_04', {})
2053
2054 " Growing with a list
2055 call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>")
2056 call VerifyScreenDump(buf, 'Test_popup_settext_03', {})
2057
2058 " Empty list clears
2059 call term_sendkeys(buf, ":call popup_settext(p, [])\<CR>")
2060 call VerifyScreenDump(buf, 'Test_popup_settext_05', {})
2061
2062 " Dicts
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002063 call term_sendkeys(buf, ":call popup_settext(p, [#{text: 'aaaa'}, #{text: 'bbbb'}, #{text: 'cccc'}])\<CR>")
Bram Moolenaardc2ce582019-06-16 15:32:14 +02002064 call VerifyScreenDump(buf, 'Test_popup_settext_06', {})
2065
2066 " clean up
2067 call StopVimInTerminal(buf)
2068 call delete('XtestPopupSetText')
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02002069endfunc
2070
2071func Test_popup_hidden()
2072 new
2073
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002074 let winid = popup_atcursor('text', #{hidden: 1})
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02002075 redraw
2076 call assert_equal(0, popup_getpos(winid).visible)
2077 call popup_close(winid)
2078
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002079 let winid = popup_create('text', #{hidden: 1})
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02002080 redraw
2081 call assert_equal(0, popup_getpos(winid).visible)
2082 call popup_close(winid)
2083
2084 func QuitCallback(id, res)
2085 let s:cb_winid = a:id
2086 let s:cb_res = a:res
2087 endfunc
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002088 let winid = 'make a choice'->popup_dialog(#{hidden: 1,
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002089 \ filter: 'popup_filter_yesno',
2090 \ callback: 'QuitCallback',
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02002091 \ })
2092 redraw
2093 call assert_equal(0, popup_getpos(winid).visible)
Bram Moolenaarae943152019-06-16 22:54:14 +02002094 call assert_equal(function('popup_filter_yesno'), popup_getoptions(winid).filter)
2095 call assert_equal(function('QuitCallback'), popup_getoptions(winid).callback)
Bram Moolenaar6313c4f2019-06-16 20:39:13 +02002096 exe "normal anot used by filter\<Esc>"
2097 call assert_equal('not used by filter', getline(1))
2098
2099 call popup_show(winid)
2100 call feedkeys('y', "xt")
2101 call assert_equal(1, s:cb_res)
2102
2103 bwipe!
2104 delfunc QuitCallback
2105endfunc
Bram Moolenaarae943152019-06-16 22:54:14 +02002106
2107" Test options not checked elsewhere
2108func Test_set_get_options()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002109 let winid = popup_create('some text', #{highlight: 'Beautiful'})
Bram Moolenaarae943152019-06-16 22:54:14 +02002110 let options = popup_getoptions(winid)
2111 call assert_equal(1, options.wrap)
2112 call assert_equal(0, options.drag)
2113 call assert_equal('Beautiful', options.highlight)
2114
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002115 call popup_setoptions(winid, #{wrap: 0, drag: 1, highlight: 'Another'})
Bram Moolenaarae943152019-06-16 22:54:14 +02002116 let options = popup_getoptions(winid)
2117 call assert_equal(0, options.wrap)
2118 call assert_equal(1, options.drag)
2119 call assert_equal('Another', options.highlight)
2120
2121 call popup_close(winid)
2122endfunc
Bram Moolenaar75a1a942019-06-20 03:45:36 +02002123
2124func Test_popupwin_garbage_collect()
2125 func MyPopupFilter(x, winid, c)
2126 " NOP
2127 endfunc
2128
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002129 let winid = popup_create('something', #{filter: function('MyPopupFilter', [{}])})
Bram Moolenaar75a1a942019-06-20 03:45:36 +02002130 call test_garbagecollect_now()
2131 redraw
Bram Moolenaar1bc353b2019-09-01 14:45:28 +02002132 " Must not crash caused by invalid memory access
Bram Moolenaar75a1a942019-06-20 03:45:36 +02002133 call feedkeys('j', 'xt')
2134 call assert_true(v:true)
2135
2136 call popup_close(winid)
2137 delfunc MyPopupFilter
2138endfunc
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02002139
Bram Moolenaar581ba392019-09-03 22:08:33 +02002140func Test_popupwin_filter_mode()
2141 func MyPopupFilter(winid, c)
2142 let s:typed = a:c
2143 if a:c == ':' || a:c == "\r" || a:c == 'v'
2144 " can start cmdline mode, get out, and start/stop Visual mode
2145 return 0
2146 endif
2147 return 1
2148 endfunc
2149
2150 " Normal, Visual and Insert mode
2151 let winid = popup_create('something', #{filter: 'MyPopupFilter', filtermode: 'nvi'})
2152 redraw
2153 call feedkeys('x', 'xt')
2154 call assert_equal('x', s:typed)
2155
2156 call feedkeys(":let g:foo = 'foo'\<CR>", 'xt')
2157 call assert_equal(':', s:typed)
2158 call assert_equal('foo', g:foo)
2159
2160 let @x = 'something'
2161 call feedkeys('v$"xy', 'xt')
2162 call assert_equal('y', s:typed)
2163 call assert_equal('something', @x) " yank command is filtered out
2164 call feedkeys('v', 'xt') " end Visual mode
2165
2166 call popup_close(winid)
2167
2168 " only Normal mode
2169 let winid = popup_create('something', #{filter: 'MyPopupFilter', filtermode: 'n'})
2170 redraw
2171 call feedkeys('x', 'xt')
2172 call assert_equal('x', s:typed)
2173
2174 call feedkeys(":let g:foo = 'foo'\<CR>", 'xt')
2175 call assert_equal(':', s:typed)
2176 call assert_equal('foo', g:foo)
2177
2178 let @x = 'something'
2179 call feedkeys('v$"xy', 'xt')
2180 call assert_equal('v', s:typed)
2181 call assert_notequal('something', @x)
2182
2183 call popup_close(winid)
2184
2185 " default: all modes
2186 let winid = popup_create('something', #{filter: 'MyPopupFilter'})
2187 redraw
2188 call feedkeys('x', 'xt')
2189 call assert_equal('x', s:typed)
2190
2191 let g:foo = 'bar'
2192 call feedkeys(":let g:foo = 'foo'\<CR>", 'xt')
2193 call assert_equal("\r", s:typed)
2194 call assert_equal('bar', g:foo)
2195
2196 let @x = 'something'
2197 call feedkeys('v$"xy', 'xt')
2198 call assert_equal('y', s:typed)
2199 call assert_equal('something', @x) " yank command is filtered out
2200 call feedkeys('v', 'xt') " end Visual mode
2201
2202 call popup_close(winid)
2203 delfunc MyPopupFilter
2204endfunc
2205
Bram Moolenaarf8b036b2019-11-06 21:09:17 +01002206func Test_popupwin_filter_mouse()
2207 func MyPopupFilter(winid, c)
2208 let g:got_mouse_col = v:mouse_col
2209 let g:got_mouse_lnum = v:mouse_lnum
Bram Moolenaard002e412019-11-11 21:45:05 +01002210 let g:got_mouse_winid = v:mouse_winid
Bram Moolenaarf8b036b2019-11-06 21:09:17 +01002211 return 0
2212 endfunc
2213
2214 let winid = popup_create(['short', 'long line that will wrap', 'short'], #{
2215 \ line: 4,
2216 \ col: 8,
2217 \ maxwidth: 12,
2218 \ filter: 'MyPopupFilter',
2219 \ })
2220 redraw
2221 call test_setmouse(4, 8)
2222 call feedkeys("\<LeftMouse>", 'xt')
2223 call assert_equal(1, g:got_mouse_col)
2224 call assert_equal(1, g:got_mouse_lnum)
Bram Moolenaard002e412019-11-11 21:45:05 +01002225 call assert_equal(winid, g:got_mouse_winid)
Bram Moolenaarf8b036b2019-11-06 21:09:17 +01002226
2227 call test_setmouse(5, 8)
2228 call feedkeys("\<LeftMouse>", 'xt')
2229 call assert_equal(1, g:got_mouse_col)
2230 call assert_equal(2, g:got_mouse_lnum)
2231
2232 call test_setmouse(6, 8)
2233 call feedkeys("\<LeftMouse>", 'xt')
2234 call assert_equal(13, g:got_mouse_col)
2235 call assert_equal(2, g:got_mouse_lnum)
2236
2237 call test_setmouse(7, 20)
2238 call feedkeys("\<LeftMouse>", 'xt')
2239 call assert_equal(13, g:got_mouse_col)
2240 call assert_equal(3, g:got_mouse_lnum)
Bram Moolenaard002e412019-11-11 21:45:05 +01002241 call assert_equal(winid, g:got_mouse_winid)
Bram Moolenaarf8b036b2019-11-06 21:09:17 +01002242
2243 call popup_close(winid)
2244 delfunc MyPopupFilter
2245endfunc
2246
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02002247func Test_popupwin_with_buffer()
2248 call writefile(['some text', 'in a buffer'], 'XsomeFile')
2249 let buf = bufadd('XsomeFile')
2250 call assert_equal(0, bufloaded(buf))
Bram Moolenaar46451042019-08-24 15:50:46 +02002251
2252 setlocal number
2253 call setbufvar(buf, "&wrapmargin", 13)
2254
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02002255 let winid = popup_create(buf, {})
2256 call assert_notequal(0, winid)
2257 let pos = popup_getpos(winid)
2258 call assert_equal(2, pos.height)
2259 call assert_equal(1, bufloaded(buf))
Bram Moolenaar46451042019-08-24 15:50:46 +02002260
2261 " window-local option is set to default, buffer-local is not
2262 call assert_equal(0, getwinvar(winid, '&number'))
2263 call assert_equal(13, getbufvar(buf, '&wrapmargin'))
2264
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02002265 call popup_close(winid)
2266 call assert_equal({}, popup_getpos(winid))
2267 call assert_equal(1, bufloaded(buf))
2268 exe 'bwipe! ' .. buf
Bram Moolenaar46451042019-08-24 15:50:46 +02002269 setlocal nonumber
Bram Moolenaar7866b872019-07-01 22:21:01 +02002270
2271 edit test_popupwin.vim
2272 let winid = popup_create(bufnr(''), {})
2273 redraw
2274 call popup_close(winid)
Bram Moolenaar3940ec62019-07-05 21:53:24 +02002275 call delete('XsomeFile')
Bram Moolenaar5b8cfed2019-06-30 22:16:10 +02002276endfunc
Bram Moolenaare296e312019-07-03 23:20:18 +02002277
Bram Moolenaare0d749a2019-09-25 22:14:48 +02002278func Test_popupwin_terminal_buffer()
Bram Moolenaard2c1fb42019-09-25 23:06:40 +02002279 CheckFeature terminal
2280
Bram Moolenaare0d749a2019-09-25 22:14:48 +02002281 let ptybuf = term_start(&shell, #{hidden: 1})
2282 call assert_fails('let winnr = popup_create(ptybuf, #{})', 'E278:')
2283 exe 'bwipe! ' .. ptybuf
2284endfunc
2285
Bram Moolenaar934470e2019-09-01 23:27:05 +02002286func Test_popupwin_with_buffer_and_filter()
2287 new Xwithfilter
2288 call setline(1, range(100))
2289 let bufnr = bufnr()
2290 hide
2291
2292 func BufferFilter(win, key)
2293 if a:key == 'G'
2294 " recursive use of "G" does not cause problems.
2295 call win_execute(a:win, 'normal! G')
2296 return 1
2297 endif
2298 return 0
2299 endfunc
2300
2301 let winid = popup_create(bufnr, #{maxheight: 5, filter: 'BufferFilter'})
2302 call assert_equal(1, popup_getpos(winid).firstline)
2303 redraw
2304 call feedkeys("G", 'xt')
2305 call assert_equal(99, popup_getpos(winid).firstline)
2306
2307 call popup_close(winid)
2308 exe 'bwipe! ' .. bufnr
2309endfunc
2310
Bram Moolenaare296e312019-07-03 23:20:18 +02002311func Test_popupwin_width()
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002312 let winid = popup_create(repeat(['short', 'long long long line', 'medium width'], 50), #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002313 \ maxwidth: 40,
2314 \ maxheight: 10,
Bram Moolenaare296e312019-07-03 23:20:18 +02002315 \ })
2316 for top in range(1, 20)
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002317 eval winid->popup_setoptions(#{firstline: top})
Bram Moolenaare296e312019-07-03 23:20:18 +02002318 redraw
2319 call assert_equal(19, popup_getpos(winid).width)
2320 endfor
2321 call popup_clear()
2322endfunc
Bram Moolenaar5ca1ac32019-07-04 15:39:28 +02002323
2324func Test_popupwin_buf_close()
2325 let buf = bufadd('Xtestbuf')
2326 call bufload(buf)
2327 call setbufline(buf, 1, ['just', 'some', 'lines'])
2328 let winid = popup_create(buf, {})
2329 redraw
2330 call assert_equal(3, popup_getpos(winid).height)
2331 let bufinfo = getbufinfo(buf)[0]
2332 call assert_equal(1, bufinfo.changed)
2333 call assert_equal(0, bufinfo.hidden)
2334 call assert_equal(0, bufinfo.listed)
2335 call assert_equal(1, bufinfo.loaded)
2336 call assert_equal([], bufinfo.windows)
2337 call assert_equal([winid], bufinfo.popups)
2338
2339 call popup_close(winid)
2340 call assert_equal({}, popup_getpos(winid))
2341 let bufinfo = getbufinfo(buf)[0]
2342 call assert_equal(1, bufinfo.changed)
2343 call assert_equal(1, bufinfo.hidden)
2344 call assert_equal(0, bufinfo.listed)
2345 call assert_equal(1, bufinfo.loaded)
2346 call assert_equal([], bufinfo.windows)
2347 call assert_equal([], bufinfo.popups)
2348 exe 'bwipe! ' .. buf
2349endfunc
Bram Moolenaar017c2692019-07-13 14:17:51 +02002350
2351func Test_popup_menu_with_maxwidth()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002352 CheckScreendump
Bram Moolenaar017c2692019-07-13 14:17:51 +02002353
2354 let lines =<< trim END
2355 call setline(1, range(1, 10))
2356 hi ScrollThumb ctermbg=blue
2357 hi ScrollBar ctermbg=red
2358 func PopupMenu(lines, line, col, scrollbar = 0)
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002359 return popup_menu(a:lines, #{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002360 \ maxwidth: 10,
2361 \ maxheight: 3,
2362 \ pos : 'topleft',
2363 \ col : a:col,
2364 \ line : a:line,
2365 \ scrollbar : a:scrollbar,
Bram Moolenaar017c2692019-07-13 14:17:51 +02002366 \ })
2367 endfunc
2368 call PopupMenu(['x'], 1, 1)
2369 call PopupMenu(['123456789|'], 1, 16)
2370 call PopupMenu(['123456789|' .. ' '], 7, 1)
2371 call PopupMenu([repeat('123456789|', 100)], 7, 16)
2372 call PopupMenu(repeat(['123456789|' .. ' '], 5), 1, 33, 1)
2373 END
2374 call writefile(lines, 'XtestPopupMenuMaxWidth')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002375 let buf = RunVimInTerminal('-S XtestPopupMenuMaxWidth', #{rows: 13})
Bram Moolenaar017c2692019-07-13 14:17:51 +02002376 call VerifyScreenDump(buf, 'Test_popupwin_menu_maxwidth_1', {})
2377
2378 " close the menu popupwin.
2379 call term_sendkeys(buf, " ")
2380 call term_sendkeys(buf, " ")
2381 call term_sendkeys(buf, " ")
2382 call term_sendkeys(buf, " ")
2383 call term_sendkeys(buf, " ")
2384
2385 " clean up
2386 call StopVimInTerminal(buf)
2387 call delete('XtestPopupMenuMaxWidth')
2388endfunc
2389
Bram Moolenaara901a372019-07-13 16:38:50 +02002390func Test_popup_menu_with_scrollbar()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002391 CheckScreendump
Bram Moolenaara901a372019-07-13 16:38:50 +02002392
2393 let lines =<< trim END
2394 call setline(1, range(1, 20))
2395 hi ScrollThumb ctermbg=blue
2396 hi ScrollBar ctermbg=red
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002397 eval ['one', 'two', 'three', 'four', 'five',
2398 \ 'six', 'seven', 'eight', 'nine']
2399 \ ->popup_menu(#{
Bram Moolenaard5abb4c2019-07-13 22:46:10 +02002400 \ minwidth: 8,
2401 \ maxheight: 3,
Bram Moolenaara901a372019-07-13 16:38:50 +02002402 \ })
2403 END
2404 call writefile(lines, 'XtestPopupMenuScroll')
Bram Moolenaar4c6d9042019-07-16 22:04:02 +02002405 let buf = RunVimInTerminal('-S XtestPopupMenuScroll', #{rows: 10})
Bram Moolenaara901a372019-07-13 16:38:50 +02002406
2407 call term_sendkeys(buf, "j")
2408 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_1', {})
2409
2410 call term_sendkeys(buf, "jjj")
2411 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_2', {})
2412
2413 " if the cursor is the bottom line, it stays at the bottom line.
2414 call term_sendkeys(buf, repeat("j", 20))
2415 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_3', {})
2416
2417 call term_sendkeys(buf, "kk")
2418 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_4', {})
2419
2420 call term_sendkeys(buf, "k")
2421 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_5', {})
2422
2423 " if the cursor is in the top line, it stays in the top line.
2424 call term_sendkeys(buf, repeat("k", 20))
2425 call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_6', {})
2426
2427 " close the menu popupwin.
2428 call term_sendkeys(buf, " ")
2429
2430 " clean up
2431 call StopVimInTerminal(buf)
2432 call delete('XtestPopupMenuScroll')
2433endfunc
2434
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002435func Test_popup_menu_filter()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002436 CheckScreendump
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002437
2438 let lines =<< trim END
2439 function! MyFilter(winid, key) abort
2440 if a:key == "0"
2441 call win_execute(a:winid, "call setpos('.', [0, 1, 1, 0])")
2442 return 1
2443 endif
2444 if a:key == "G"
2445 call win_execute(a:winid, "call setpos('.', [0, line('$'), 1, 0])")
2446 return 1
2447 endif
2448 if a:key == "j"
2449 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0])")
2450 return 1
2451 endif
2452 if a:key == "k"
2453 call win_execute(a:winid, "call setpos('.', [0, line('.') - 1, 1, 0])")
2454 return 1
2455 endif
Bram Moolenaarbcb4c8f2019-09-07 14:06:52 +02002456 if a:key == ':'
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002457 call popup_close(a:winid)
Bram Moolenaarbcb4c8f2019-09-07 14:06:52 +02002458 return 0
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002459 endif
2460 return 0
2461 endfunction
2462 call popup_menu(['111', '222', '333', '444', '555', '666', '777', '888', '999'], #{
2463 \ maxheight : 3,
2464 \ filter : 'MyFilter'
2465 \ })
2466 END
2467 call writefile(lines, 'XtestPopupMenuFilter')
2468 let buf = RunVimInTerminal('-S XtestPopupMenuFilter', #{rows: 10})
2469
2470 call term_sendkeys(buf, "j")
2471 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_1', {})
2472
2473 call term_sendkeys(buf, "k")
2474 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_2', {})
2475
2476 call term_sendkeys(buf, "G")
2477 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_3', {})
2478
2479 call term_sendkeys(buf, "0")
2480 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_4', {})
2481
Bram Moolenaarbcb4c8f2019-09-07 14:06:52 +02002482 " check that when the popup is closed in the filter the screen is redrawn
2483 call term_sendkeys(buf, ":")
2484 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_5', {})
2485 call term_sendkeys(buf, "\<CR>")
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002486
2487 " clean up
2488 call StopVimInTerminal(buf)
2489 call delete('XtestPopupMenuFilter')
2490endfunc
2491
2492func Test_popup_cursorline()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002493 CheckScreendump
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002494
2495 let winid = popup_create('some text', {})
2496 call assert_equal(0, popup_getoptions(winid).cursorline)
2497 call popup_close(winid)
2498
2499 let winid = popup_create('some text', #{ cursorline: 1, })
2500 call assert_equal(1, popup_getoptions(winid).cursorline)
2501 call popup_close(winid)
2502
2503 let winid = popup_create('some text', #{ cursorline: 0, })
2504 call assert_equal(0, popup_getoptions(winid).cursorline)
2505 call popup_close(winid)
2506
2507 let winid = popup_menu('some text', {})
2508 call assert_equal(1, popup_getoptions(winid).cursorline)
2509 call popup_close(winid)
2510
2511 let winid = popup_menu('some text', #{ cursorline: 1, })
2512 call assert_equal(1, popup_getoptions(winid).cursorline)
2513 call popup_close(winid)
2514
2515 let winid = popup_menu('some text', #{ cursorline: 0, })
2516 call assert_equal(0, popup_getoptions(winid).cursorline)
2517 call popup_close(winid)
2518
2519 " ---------
2520 " Pattern 1
2521 " ---------
2522 let lines =<< trim END
2523 call popup_create(['111', '222', '333'], #{ cursorline : 0 })
2524 END
2525 call writefile(lines, 'XtestPopupCursorLine')
2526 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2527 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_1', {})
2528 call term_sendkeys(buf, ":call popup_clear()\<cr>")
2529 call StopVimInTerminal(buf)
2530
2531 " ---------
2532 " Pattern 2
2533 " ---------
2534 let lines =<< trim END
2535 call popup_create(['111', '222', '333'], #{ cursorline : 1 })
2536 END
2537 call writefile(lines, 'XtestPopupCursorLine')
2538 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2539 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_2', {})
2540 call term_sendkeys(buf, ":call popup_clear()\<cr>")
2541 call StopVimInTerminal(buf)
2542
2543 " ---------
2544 " Pattern 3
2545 " ---------
2546 let lines =<< trim END
2547 function! MyFilter(winid, key) abort
2548 if a:key == "j"
2549 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0]) | redraw")
2550 return 1
2551 endif
2552 if a:key == 'x'
2553 call popup_close(a:winid)
2554 return 1
2555 endif
2556 return 0
2557 endfunction
2558 call popup_menu(['111', '222', '333'], #{
2559 \ cursorline : 0,
2560 \ maxheight : 2,
2561 \ filter : 'MyFilter',
2562 \ })
2563 END
2564 call writefile(lines, 'XtestPopupCursorLine')
2565 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2566 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_3', {})
2567 call term_sendkeys(buf, "j")
2568 call term_sendkeys(buf, "j")
2569 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_4', {})
2570 call term_sendkeys(buf, "x")
2571 call StopVimInTerminal(buf)
2572
2573 " ---------
2574 " Pattern 4
2575 " ---------
2576 let lines =<< trim END
2577 function! MyFilter(winid, key) abort
2578 if a:key == "j"
2579 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0]) | redraw")
2580 return 1
2581 endif
2582 if a:key == 'x'
2583 call popup_close(a:winid)
2584 return 1
2585 endif
2586 return 0
2587 endfunction
2588 call popup_menu(['111', '222', '333'], #{
2589 \ cursorline : 1,
2590 \ maxheight : 2,
2591 \ filter : 'MyFilter',
2592 \ })
2593 END
2594 call writefile(lines, 'XtestPopupCursorLine')
2595 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2596 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_5', {})
2597 call term_sendkeys(buf, "j")
2598 call term_sendkeys(buf, "j")
2599 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_6', {})
2600 call term_sendkeys(buf, "x")
2601 call StopVimInTerminal(buf)
2602
Bram Moolenaar3d2a3cb2019-09-08 17:12:01 +02002603 " ---------
2604 " Cursor in second line when creating the popup
2605 " ---------
2606 let lines =<< trim END
2607 let winid = popup_create(['111', '222', '333'], #{
2608 \ cursorline : 1,
2609 \ })
2610 call win_execute(winid, "2")
2611 END
2612 call writefile(lines, 'XtestPopupCursorLine')
2613 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2614 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_7', {})
2615 call StopVimInTerminal(buf)
2616
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002617 call delete('XtestPopupCursorLine')
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +01002618
2619 " ---------
2620 " Use current buffer for popupmenu
2621 " ---------
2622 let lines =<< trim END
2623 call setline(1, ['one', 'two', 'three'])
2624 let winid = popup_create(bufnr('%'), #{
2625 \ cursorline : 1,
2626 \ })
2627 call win_execute(winid, "2")
2628 END
2629 call writefile(lines, 'XtestPopupCursorLine')
2630 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2631 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_8', {})
2632 call StopVimInTerminal(buf)
2633
2634 call delete('XtestPopupCursorLine')
Bram Moolenaardf9c6ca2019-07-18 13:46:42 +02002635endfunc
2636
Bram Moolenaarf914a332019-07-20 15:09:56 +02002637func Test_previewpopup()
Bram Moolenaar4999a7f2019-08-10 22:21:48 +02002638 CheckScreendump
2639
Bram Moolenaarf914a332019-07-20 15:09:56 +02002640 call writefile([
2641 \ "!_TAG_FILE_ENCODING\tutf-8\t//",
2642 \ "another\tXtagfile\t/^this is another",
2643 \ "theword\tXtagfile\t/^theword"],
2644 \ 'Xtags')
2645 call writefile(range(1,20)
2646 \ + ['theword is here']
2647 \ + range(22, 27)
2648 \ + ['this is another place']
2649 \ + range(29, 40),
2650 \ "Xtagfile")
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002651 call writefile(range(1,10)
2652 \ + ['searched word is here']
2653 \ + range(12, 20),
2654 \ "Xheader.h")
Bram Moolenaarf914a332019-07-20 15:09:56 +02002655 let lines =<< trim END
2656 set tags=Xtags
2657 call setline(1, [
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02002658 \ 'one',
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002659 \ '#include "Xheader.h"',
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02002660 \ 'three',
2661 \ 'four',
2662 \ 'five',
2663 \ 'six',
2664 \ 'seven',
2665 \ 'find theword somewhere',
2666 \ 'nine',
2667 \ 'this is another word',
2668 \ 'very long line where the word is also another'])
Bram Moolenaarf914a332019-07-20 15:09:56 +02002669 set previewpopup=height:4,width:40
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002670 set path=.
Bram Moolenaarf914a332019-07-20 15:09:56 +02002671 END
2672 call writefile(lines, 'XtestPreviewPopup')
2673 let buf = RunVimInTerminal('-S XtestPreviewPopup', #{rows: 14})
2674
2675 call term_sendkeys(buf, "/theword\<CR>\<C-W>}")
2676 call term_sendkeys(buf, ":\<CR>")
2677 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_1', {})
2678
2679 call term_sendkeys(buf, "/another\<CR>\<C-W>}")
2680 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_2', {})
2681
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002682 call term_sendkeys(buf, ":call popup_move(popup_findpreview(), #{col: 15})\<CR>")
Bram Moolenaar13d5c3f2019-07-28 21:42:38 +02002683 call term_sendkeys(buf, ":\<CR>")
2684 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_3', {})
2685
2686 call term_sendkeys(buf, "/another\<CR>\<C-W>}")
2687 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_4', {})
2688
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02002689 call term_sendkeys(buf, ":cd ..\<CR>:\<CR>")
2690 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_5', {})
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002691 call term_sendkeys(buf, ":cd testdir\<CR>")
2692
2693 call term_sendkeys(buf, ":pclose\<CR>")
Bram Moolenaar78d629a2019-08-16 17:31:15 +02002694 call term_sendkeys(buf, ":\<BS>")
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002695 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_6', {})
2696
2697 call term_sendkeys(buf, ":pedit +/theword Xtagfile\<CR>")
2698 call term_sendkeys(buf, ":\<CR>")
2699 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_7', {})
2700
2701 call term_sendkeys(buf, ":pclose\<CR>")
2702 call term_sendkeys(buf, ":psearch searched\<CR>")
2703 call term_sendkeys(buf, ":\<CR>")
2704 call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_8', {})
Bram Moolenaar749fa0a2019-08-03 16:18:07 +02002705
Bram Moolenaarf914a332019-07-20 15:09:56 +02002706 call StopVimInTerminal(buf)
2707 call delete('Xtags')
2708 call delete('Xtagfile')
2709 call delete('XtestPreviewPopup')
Bram Moolenaar1b6d9c42019-08-05 21:52:04 +02002710 call delete('Xheader.h')
Bram Moolenaarf914a332019-07-20 15:09:56 +02002711endfunc
2712
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002713func Get_popupmenu_lines()
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002714 let lines =<< trim END
2715 set completeopt+=preview,popup
2716 set completefunc=CompleteFuncDict
Bram Moolenaar62a0cb42019-08-18 16:35:23 +02002717 hi InfoPopup ctermbg=yellow
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002718
2719 func CompleteFuncDict(findstart, base)
2720 if a:findstart
2721 if col('.') > 10
2722 return col('.') - 10
2723 endif
2724 return 0
2725 endif
2726
2727 return {
2728 \ 'words': [
2729 \ {
2730 \ 'word': 'aword',
2731 \ 'abbr': 'wrd',
2732 \ 'menu': 'extra text',
2733 \ 'info': 'words are cool',
2734 \ 'kind': 'W',
2735 \ 'user_data': 'test'
2736 \ },
2737 \ {
2738 \ 'word': 'anotherword',
2739 \ 'abbr': 'anotwrd',
2740 \ 'menu': 'extra text',
2741 \ 'info': "other words are\ncooler than this and some more text\nto make wrap",
2742 \ 'kind': 'W',
2743 \ 'user_data': 'notest'
2744 \ },
2745 \ {
2746 \ 'word': 'noinfo',
2747 \ 'abbr': 'noawrd',
2748 \ 'menu': 'extra text',
Bram Moolenaar62a0cb42019-08-18 16:35:23 +02002749 \ 'info': "lets\nshow\na\nscrollbar\nhere",
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002750 \ 'kind': 'W',
2751 \ 'user_data': 'notest'
2752 \ },
2753 \ {
2754 \ 'word': 'thatword',
2755 \ 'abbr': 'thatwrd',
2756 \ 'menu': 'extra text',
2757 \ 'info': 'that word is cool',
2758 \ 'kind': 'W',
2759 \ 'user_data': 'notest'
2760 \ },
2761 \ ]
2762 \ }
2763 endfunc
2764 call setline(1, 'text text text text text text text ')
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002765 func ChangeColor()
2766 let id = popup_findinfo()
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002767 eval id->popup_setoptions(#{highlight: 'InfoPopup'})
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002768 endfunc
Bram Moolenaardca7abe2019-10-20 18:17:57 +02002769
2770 func InfoHidden()
2771 set completepopup=height:4,border:off,align:menu
2772 set completeopt-=popup completeopt+=popuphidden
2773 au CompleteChanged * call HandleChange()
2774 endfunc
2775
2776 let s:counter = 0
2777 func HandleChange()
2778 let s:counter += 1
2779 let selected = complete_info(['selected']).selected
2780 if selected <= 0
2781 " First time: do nothing, info remains hidden
2782 return
2783 endif
2784 if selected == 1
2785 " Second time: show info right away
2786 let id = popup_findinfo()
2787 if id
2788 call popup_settext(id, 'immediate info ' .. s:counter)
2789 call popup_show(id)
2790 endif
2791 else
2792 " Third time: show info after a short delay
2793 call timer_start(100, 'ShowInfo')
2794 endif
2795 endfunc
2796
2797 func ShowInfo(...)
2798 let id = popup_findinfo()
2799 if id
2800 call popup_settext(id, 'async info ' .. s:counter)
2801 call popup_show(id)
2802 endif
2803 endfunc
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002804 END
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002805 return lines
2806endfunc
2807
2808func Test_popupmenu_info_border()
2809 CheckScreendump
2810
2811 let lines = Get_popupmenu_lines()
2812 call add(lines, 'set completepopup=height:4,highlight:InfoPopup')
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002813 call writefile(lines, 'XtestInfoPopup')
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002814
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002815 let buf = RunVimInTerminal('-S XtestInfoPopup', #{rows: 14})
2816 call term_wait(buf, 50)
2817
2818 call term_sendkeys(buf, "A\<C-X>\<C-U>")
2819 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_1', {})
2820
2821 call term_sendkeys(buf, "\<C-N>")
2822 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_2', {})
2823
2824 call term_sendkeys(buf, "\<C-N>")
2825 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_3', {})
2826
2827 call term_sendkeys(buf, "\<C-N>\<C-N>")
2828 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_4', {})
2829
Bram Moolenaarfe6e7612019-08-21 20:57:20 +02002830 " info on the left with scrollbar
2831 call term_sendkeys(buf, "test text test text\<C-X>\<C-U>")
2832 call term_sendkeys(buf, "\<C-N>\<C-N>")
2833 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_5', {})
2834
Bram Moolenaar576a4a62019-08-18 15:25:17 +02002835 call StopVimInTerminal(buf)
2836 call delete('XtestInfoPopup')
2837endfunc
2838
Bram Moolenaarbd483b32019-08-21 15:13:41 +02002839func Test_popupmenu_info_noborder()
2840 CheckScreendump
2841
2842 let lines = Get_popupmenu_lines()
2843 call add(lines, 'set completepopup=height:4,border:off')
2844 call writefile(lines, 'XtestInfoPopupNb')
2845
2846 let buf = RunVimInTerminal('-S XtestInfoPopupNb', #{rows: 14})
2847 call term_wait(buf, 50)
2848
2849 call term_sendkeys(buf, "A\<C-X>\<C-U>")
2850 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_nb_1', {})
2851
2852 call StopVimInTerminal(buf)
2853 call delete('XtestInfoPopupNb')
2854endfunc
2855
Bram Moolenaar258cef52019-08-21 17:29:29 +02002856func Test_popupmenu_info_align_menu()
2857 CheckScreendump
2858
2859 let lines = Get_popupmenu_lines()
2860 call add(lines, 'set completepopup=height:4,border:off,align:menu')
2861 call writefile(lines, 'XtestInfoPopupNb')
2862
2863 let buf = RunVimInTerminal('-S XtestInfoPopupNb', #{rows: 14})
2864 call term_wait(buf, 50)
2865
2866 call term_sendkeys(buf, "A\<C-X>\<C-U>")
2867 call term_sendkeys(buf, "\<C-N>")
2868 call term_sendkeys(buf, "\<C-N>")
2869 call term_sendkeys(buf, "\<C-N>")
2870 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_1', {})
2871
2872 call term_sendkeys(buf, "test text test text test\<C-X>\<C-U>")
2873 call term_sendkeys(buf, "\<C-N>")
2874 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_2', {})
2875
2876 call term_sendkeys(buf, "\<Esc>")
Bram Moolenaarc7c5f102019-08-21 18:31:03 +02002877 call term_sendkeys(buf, ":call ChangeColor()\<CR>")
Bram Moolenaar258cef52019-08-21 17:29:29 +02002878 call term_sendkeys(buf, ":call setline(2, ['x']->repeat(10))\<CR>")
2879 call term_sendkeys(buf, "Gotest text test text\<C-X>\<C-U>")
2880 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_3', {})
2881
2882 call StopVimInTerminal(buf)
2883 call delete('XtestInfoPopupNb')
2884endfunc
2885
Bram Moolenaardca7abe2019-10-20 18:17:57 +02002886func Test_popupmenu_info_hidden()
2887 CheckScreendump
2888
2889 let lines = Get_popupmenu_lines()
2890 call add(lines, 'call InfoHidden()')
2891 call writefile(lines, 'XtestInfoPopupHidden')
2892
2893 let buf = RunVimInTerminal('-S XtestInfoPopupHidden', #{rows: 14})
2894 call term_wait(buf, 50)
2895
2896 call term_sendkeys(buf, "A\<C-X>\<C-U>")
2897 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_hidden_1', {})
2898
2899 call term_sendkeys(buf, "\<C-N>")
2900 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_hidden_2', {})
2901
2902 call term_sendkeys(buf, "\<C-N>")
2903 call VerifyScreenDump(buf, 'Test_popupwin_infopopup_hidden_3', {})
2904
2905 call term_sendkeys(buf, "\<Esc>")
2906 call StopVimInTerminal(buf)
2907 call delete('XtestInfoPopupHidden')
2908endfunc
2909
Bram Moolenaar00b0d6d2019-08-21 22:25:30 +02002910func Test_popupwin_recycle_bnr()
Bram Moolenaare49fbff2019-08-21 22:50:07 +02002911 let bufnr = popup_notification('nothing wrong', {})->winbufnr()
Bram Moolenaar00b0d6d2019-08-21 22:25:30 +02002912 call popup_clear()
Bram Moolenaar6a124e62019-09-04 18:15:19 +02002913 let winid = 'nothing wrong'->popup_notification({})
Bram Moolenaar00b0d6d2019-08-21 22:25:30 +02002914 call assert_equal(bufnr, winbufnr(winid))
2915 call popup_clear()
2916endfunc
2917
Bram Moolenaar1824f452019-10-02 23:06:46 +02002918func Test_popupwin_getoptions_tablocal()
2919 topleft split
2920 let win1 = popup_create('nothing', #{maxheight: 8})
2921 let win2 = popup_create('something', #{maxheight: 10})
2922 let win3 = popup_create('something', #{maxheight: 15})
2923 call assert_equal(8, popup_getoptions(win1).maxheight)
2924 call assert_equal(10, popup_getoptions(win2).maxheight)
2925 call assert_equal(15, popup_getoptions(win3).maxheight)
2926 call popup_clear()
2927 quit
2928endfunc
2929
Bram Moolenaare8a7dfe2019-10-03 22:35:52 +02002930func Test_popupwin_cancel()
2931 let win1 = popup_create('one', #{line: 5, filter: {... -> 0}})
2932 let win2 = popup_create('two', #{line: 10, filter: {... -> 0}})
2933 let win3 = popup_create('three', #{line: 15, filter: {... -> 0}})
2934 call assert_equal(5, popup_getpos(win1).line)
2935 call assert_equal(10, popup_getpos(win2).line)
2936 call assert_equal(15, popup_getpos(win3).line)
2937 " TODO: this also works without patch 8.1.2110
2938 call feedkeys("\<C-C>", 'xt')
2939 call assert_equal(5, popup_getpos(win1).line)
2940 call assert_equal(10, popup_getpos(win2).line)
2941 call assert_equal({}, popup_getpos(win3))
2942 call feedkeys("\<C-C>", 'xt')
2943 call assert_equal(5, popup_getpos(win1).line)
2944 call assert_equal({}, popup_getpos(win2))
2945 call assert_equal({}, popup_getpos(win3))
2946 call feedkeys("\<C-C>", 'xt')
2947 call assert_equal({}, popup_getpos(win1))
2948 call assert_equal({}, popup_getpos(win2))
2949 call assert_equal({}, popup_getpos(win3))
2950endfunc
2951
Bram Moolenaar331bafd2019-07-20 17:46:05 +02002952" vim: shiftwidth=2 sts=2