blob: 2ae01656ff43082849cea33813abbf8fd3741b6e [file] [log] [blame]
Bram Moolenaar00672e12016-06-26 18:38:13 +02001" Test for completion menu
2
Christian Brabandteb380b92025-07-07 20:53:55 +02003source util/screendump.vim
Bram Moolenaara5e66212017-09-29 22:42:33 +02004
Bram Moolenaar00672e12016-06-26 18:38:13 +02005let g:months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
6let g:setting = ''
7
Bram Moolenaarae0f30b2018-06-12 15:22:43 +02008func ListMonths()
Bram Moolenaar47247282016-08-02 22:36:02 +02009 if g:setting != ''
10 exe ":set" g:setting
11 endif
Bram Moolenaaraed6d0b2017-01-27 21:48:54 +010012 let mth = copy(g:months)
Bram Moolenaar47247282016-08-02 22:36:02 +020013 let entered = strcharpart(getline('.'),0,col('.'))
14 if !empty(entered)
Bram Moolenaaraed6d0b2017-01-27 21:48:54 +010015 let mth = filter(mth, 'v:val=~"^".entered')
Bram Moolenaar47247282016-08-02 22:36:02 +020016 endif
Bram Moolenaar94722c52023-01-28 19:19:03 +000017 call complete(1, mth)
Bram Moolenaar47247282016-08-02 22:36:02 +020018 return ''
Bram Moolenaar00672e12016-06-26 18:38:13 +020019endfunc
20
Bram Moolenaarae0f30b2018-06-12 15:22:43 +020021func Test_popup_complete2()
Bram Moolenaar9e02cfa2016-09-22 21:27:11 +020022 " Although the popupmenu is not visible, this does not mean completion mode
23 " has ended. After pressing <f5> to complete the currently typed char, Vim
24 " still stays in the first state of the completion (:h ins-completion-menu),
25 " although the popupmenu wasn't shown <c-e> will remove the inserted
26 " completed text (:h complete_CTRL-E), while the following <c-e> will behave
27 " like expected (:h i_CTRL-E)
Bram Moolenaardac19472016-09-03 22:35:40 +020028 new
29 inoremap <f5> <c-r>=ListMonths()<cr>
30 call append(1, ["December2015"])
31 :1
32 call feedkeys("aD\<f5>\<C-E>\<C-E>\<C-E>\<C-E>\<enter>\<esc>", 'tx')
Bram Moolenaar9e02cfa2016-09-22 21:27:11 +020033 call assert_equal(["Dece", "", "December2015"], getline(1,3))
Bram Moolenaardac19472016-09-03 22:35:40 +020034 %d
35 bw!
Bram Moolenaarae0f30b2018-06-12 15:22:43 +020036endfunc
Bram Moolenaardac19472016-09-03 22:35:40 +020037
Bram Moolenaarae0f30b2018-06-12 15:22:43 +020038func Test_popup_complete()
Bram Moolenaar47247282016-08-02 22:36:02 +020039 new
40 inoremap <f5> <c-r>=ListMonths()<cr>
41
42 " <C-E> - select original typed text before the completion started
43 call feedkeys("aJu\<f5>\<down>\<c-e>\<esc>", 'tx')
44 call assert_equal(["Ju"], getline(1,2))
45 %d
46
47 " <C-Y> - accept current match
48 call feedkeys("a\<f5>". repeat("\<down>",7). "\<c-y>\<esc>", 'tx')
49 call assert_equal(["August"], getline(1,2))
50 %d
51
52 " <BS> - Delete one character from the inserted text (state: 1)
53 " TODO: This should not end the completion, but it does.
54 " This should according to the documentation:
55 " January
56 " but instead, this does
57 " Januar
58 " (idea is, C-L inserts the match from the popup menu
59 " but if the menu is closed, it will insert the character <c-l>
60 call feedkeys("aJ\<f5>\<bs>\<c-l>\<esc>", 'tx')
61 call assert_equal(["Januar "], getline(1,2))
62 %d
63
64 " any-non special character: Stop completion without changing the match
65 " and insert the typed character
66 call feedkeys("a\<f5>20", 'tx')
67 call assert_equal(["January20"], getline(1,2))
68 %d
69
70 " any-non printable, non-white character: Add this character and
71 " reduce number of matches
72 call feedkeys("aJu\<f5>\<c-p>l\<c-y>", 'tx')
73 call assert_equal(["Jul"], getline(1,2))
74 %d
Bram Moolenaar94722c52023-01-28 19:19:03 +000075
Bram Moolenaar47247282016-08-02 22:36:02 +020076 " any-non printable, non-white character: Add this character and
77 " reduce number of matches
78 call feedkeys("aJu\<f5>\<c-p>l\<c-n>\<c-y>", 'tx')
79 call assert_equal(["July"], getline(1,2))
80 %d
81
82 " any-non printable, non-white character: Add this character and
83 " reduce number of matches
84 call feedkeys("aJu\<f5>\<c-p>l\<c-e>", 'tx')
85 call assert_equal(["Jul"], getline(1,2))
86 %d
87
88 " <BS> - Delete one character from the inserted text (state: 2)
89 call feedkeys("a\<f5>\<c-n>\<bs>", 'tx')
90 call assert_equal(["Februar"], getline(1,2))
91 %d
92
93 " <c-l> - Insert one character from the current match
94 call feedkeys("aJ\<f5>".repeat("\<c-n>",3)."\<c-l>\<esc>", 'tx')
95 call assert_equal(["J "], getline(1,2))
96 %d
Bram Moolenaar94722c52023-01-28 19:19:03 +000097
Bram Moolenaar47247282016-08-02 22:36:02 +020098 " <c-l> - Insert one character from the current match
99 call feedkeys("aJ\<f5>".repeat("\<c-n>",4)."\<c-l>\<esc>", 'tx')
100 call assert_equal(["January "], getline(1,2))
101 %d
102
103 " <c-y> - Accept current selected match
104 call feedkeys("aJ\<f5>\<c-y>\<esc>", 'tx')
105 call assert_equal(["January"], getline(1,2))
106 %d
107
108 " <c-e> - End completion, go back to what was there before selecting a match
109 call feedkeys("aJu\<f5>\<c-e>\<esc>", 'tx')
110 call assert_equal(["Ju"], getline(1,2))
111 %d
112
113 " <PageUp> - Select a match several entries back
114 call feedkeys("a\<f5>\<PageUp>\<c-y>\<esc>", 'tx')
115 call assert_equal([""], getline(1,2))
116 %d
117
118 " <PageUp><PageUp> - Select a match several entries back
119 call feedkeys("a\<f5>\<PageUp>\<PageUp>\<c-y>\<esc>", 'tx')
120 call assert_equal(["December"], getline(1,2))
121 %d
122
123 " <PageUp><PageUp><PageUp> - Select a match several entries back
124 call feedkeys("a\<f5>\<PageUp>\<PageUp>\<PageUp>\<c-y>\<esc>", 'tx')
125 call assert_equal(["February"], getline(1,2))
126 %d
127
128 " <PageDown> - Select a match several entries further
129 call feedkeys("a\<f5>\<PageDown>\<c-y>\<esc>", 'tx')
130 call assert_equal(["November"], getline(1,2))
131 %d
132
133 " <PageDown><PageDown> - Select a match several entries further
134 call feedkeys("a\<f5>\<PageDown>\<PageDown>\<c-y>\<esc>", 'tx')
135 call assert_equal(["December"], getline(1,2))
136 %d
137
138 " <PageDown><PageDown><PageDown> - Select a match several entries further
139 call feedkeys("a\<f5>\<PageDown>\<PageDown>\<PageDown>\<c-y>\<esc>", 'tx')
140 call assert_equal([""], getline(1,2))
141 %d
142
143 " <PageDown><PageDown><PageDown><PageDown> - Select a match several entries further
144 call feedkeys("a\<f5>".repeat("\<PageDown>",4)."\<c-y>\<esc>", 'tx')
145 call assert_equal(["October"], getline(1,2))
146 %d
147
148 " <Up> - Select a match don't insert yet
149 call feedkeys("a\<f5>\<Up>\<c-y>\<esc>", 'tx')
150 call assert_equal([""], getline(1,2))
151 %d
152
153 " <Up><Up> - Select a match don't insert yet
154 call feedkeys("a\<f5>\<Up>\<Up>\<c-y>\<esc>", 'tx')
155 call assert_equal(["December"], getline(1,2))
156 %d
157
158 " <Up><Up><Up> - Select a match don't insert yet
159 call feedkeys("a\<f5>\<Up>\<Up>\<Up>\<c-y>\<esc>", 'tx')
160 call assert_equal(["November"], getline(1,2))
161 %d
162
163 " <Tab> - Stop completion and insert the match
164 call feedkeys("a\<f5>\<Tab>\<c-y>\<esc>", 'tx')
165 call assert_equal(["January "], getline(1,2))
166 %d
167
168 " <Space> - Stop completion and insert the match
169 call feedkeys("a\<f5>".repeat("\<c-p>",5)." \<esc>", 'tx')
170 call assert_equal(["September "], getline(1,2))
171 %d
172
173 " <Enter> - Use the text and insert line break (state: 1)
174 call feedkeys("a\<f5>\<enter>\<esc>", 'tx')
175 call assert_equal(["January", ''], getline(1,2))
176 %d
177
178 " <Enter> - Insert the current selected text (state: 2)
179 call feedkeys("a\<f5>".repeat("\<Up>",5)."\<enter>\<esc>", 'tx')
180 call assert_equal(["September"], getline(1,2))
181 %d
182
183 " Insert match immediately, if there is only one match
184 " <c-y> selects a character from the line above
185 call append(0, ["December2015"])
186 call feedkeys("aD\<f5>\<C-Y>\<C-Y>\<C-Y>\<C-Y>\<enter>\<esc>", 'tx')
187 call assert_equal(["December2015", "December2015", ""], getline(1,3))
188 %d
189
Bram Moolenaar47247282016-08-02 22:36:02 +0200190 " use menuone for 'completeopt'
191 " Since for the first <c-y> the menu is still shown, will only select
192 " three letters from the line above
193 set completeopt&vim
194 set completeopt+=menuone
195 call append(0, ["December2015"])
196 call feedkeys("aD\<f5>\<C-Y>\<C-Y>\<C-Y>\<C-Y>\<enter>\<esc>", 'tx')
197 call assert_equal(["December2015", "December201", ""], getline(1,3))
198 %d
199
200 " use longest for 'completeopt'
201 set completeopt&vim
202 call feedkeys("aM\<f5>\<C-N>\<C-P>\<c-e>\<enter>\<esc>", 'tx')
203 set completeopt+=longest
204 call feedkeys("aM\<f5>\<C-N>\<C-P>\<c-e>\<enter>\<esc>", 'tx')
205 call assert_equal(["M", "Ma", ""], getline(1,3))
206 %d
207
208 " use noselect/noinsert for 'completeopt'
209 set completeopt&vim
210 call feedkeys("aM\<f5>\<enter>\<esc>", 'tx')
211 set completeopt+=noselect
212 call feedkeys("aM\<f5>\<enter>\<esc>", 'tx')
213 set completeopt-=noselect completeopt+=noinsert
214 call feedkeys("aM\<f5>\<enter>\<esc>", 'tx')
215 call assert_equal(["March", "M", "March"], getline(1,4))
216 %d
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200217endfunc
Bram Moolenaar47247282016-08-02 22:36:02 +0200218
219
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200220func Test_popup_completion_insertmode()
Bram Moolenaar67081e52016-07-09 21:49:03 +0200221 new
222 inoremap <F5> <C-R>=ListMonths()<CR>
223
224 call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx')
225 call assert_equal('February', getline(1))
226 %d
Bram Moolenaar47247282016-08-02 22:36:02 +0200227 " Set noinsertmode
Bram Moolenaar67081e52016-07-09 21:49:03 +0200228 let g:setting = 'noinsertmode'
229 call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx')
230 call assert_equal('February', getline(1))
231 call assert_false(pumvisible())
232 %d
Bram Moolenaar47247282016-08-02 22:36:02 +0200233 " Go through all matches, until none is selected
Bram Moolenaar67081e52016-07-09 21:49:03 +0200234 let g:setting = ''
235 call feedkeys("a\<f5>". repeat("\<c-n>",12)."\<enter>\<esc>", 'tx')
236 call assert_equal('', getline(1))
237 %d
Bram Moolenaar47247282016-08-02 22:36:02 +0200238 " select previous entry
Bram Moolenaar67081e52016-07-09 21:49:03 +0200239 call feedkeys("a\<f5>\<c-p>\<enter>\<esc>", 'tx')
240 call assert_equal('', getline(1))
241 %d
Bram Moolenaar47247282016-08-02 22:36:02 +0200242 " select last entry
Bram Moolenaar67081e52016-07-09 21:49:03 +0200243 call feedkeys("a\<f5>\<c-p>\<c-p>\<enter>\<esc>", 'tx')
244 call assert_equal('December', getline(1))
245
Bram Moolenaar67081e52016-07-09 21:49:03 +0200246 iunmap <F5>
247endfunc
248
Bram Moolenaar67081e52016-07-09 21:49:03 +0200249func Test_noinsert_complete()
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200250 func! s:complTest1() abort
Bram Moolenaar1a3a8912019-08-23 22:31:37 +0200251 eval ['source', 'soundfold']->complete(1)
Bram Moolenaar33a80ee2016-09-05 21:51:14 +0200252 return ''
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200253 endfunc
Bram Moolenaar33a80ee2016-09-05 21:51:14 +0200254
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200255 func! s:complTest2() abort
Bram Moolenaar33a80ee2016-09-05 21:51:14 +0200256 call complete(1, ['source', 'soundfold'])
257 return ''
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200258 endfunc
Bram Moolenaar33a80ee2016-09-05 21:51:14 +0200259
Bram Moolenaar67081e52016-07-09 21:49:03 +0200260 new
261 set completeopt+=noinsert
Bram Moolenaar33a80ee2016-09-05 21:51:14 +0200262 inoremap <F5> <C-R>=s:complTest1()<CR>
Bram Moolenaar67081e52016-07-09 21:49:03 +0200263 call feedkeys("i\<F5>soun\<CR>\<CR>\<ESC>.", 'tx')
264 call assert_equal('soundfold', getline(1))
265 call assert_equal('soundfold', getline(2))
Bram Moolenaar67081e52016-07-09 21:49:03 +0200266 bwipe!
Bram Moolenaar32b808a2016-07-09 21:57:20 +0200267
268 new
Bram Moolenaar33a80ee2016-09-05 21:51:14 +0200269 inoremap <F5> <C-R>=s:complTest2()<CR>
Bram Moolenaar32b808a2016-07-09 21:57:20 +0200270 call feedkeys("i\<F5>\<CR>\<ESC>", 'tx')
271 call assert_equal('source', getline(1))
272 bwipe!
273
Bram Moolenaar67081e52016-07-09 21:49:03 +0200274 set completeopt-=noinsert
275 iunmap <F5>
Bram Moolenaar00672e12016-06-26 18:38:13 +0200276endfunc
Bram Moolenaar32b808a2016-07-09 21:57:20 +0200277
Bram Moolenaar73655cf2019-04-06 13:45:55 +0200278func Test_complete_no_filter()
279 func! s:complTest1() abort
280 call complete(1, [{'word': 'foobar'}])
281 return ''
282 endfunc
283 func! s:complTest2() abort
284 call complete(1, [{'word': 'foobar', 'equal': 1}])
285 return ''
286 endfunc
287
288 let completeopt = &completeopt
289
290 " without equal=1
291 new
292 set completeopt=menuone,noinsert,menu
293 inoremap <F5> <C-R>=s:complTest1()<CR>
294 call feedkeys("i\<F5>z\<CR>\<CR>\<ESC>.", 'tx')
295 call assert_equal('z', getline(1))
296 bwipe!
297
298 " with equal=1
299 new
300 set completeopt=menuone,noinsert,menu
301 inoremap <F5> <C-R>=s:complTest2()<CR>
302 call feedkeys("i\<F5>z\<CR>\<CR>\<ESC>.", 'tx')
303 call assert_equal('foobar', getline(1))
304 bwipe!
305
306 let &completeopt = completeopt
307 iunmap <F5>
308endfunc
309
Bram Moolenaar33a80ee2016-09-05 21:51:14 +0200310func Test_compl_vim_cmds_after_register_expr()
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200311 func! s:test_func()
Bram Moolenaar33a80ee2016-09-05 21:51:14 +0200312 return 'autocmd '
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200313 endfunc
Bram Moolenaar33a80ee2016-09-05 21:51:14 +0200314 augroup AAAAA_Group
315 au!
316 augroup END
Bram Moolenaar32b808a2016-07-09 21:57:20 +0200317
Bram Moolenaar33a80ee2016-09-05 21:51:14 +0200318 new
319 call feedkeys("i\<c-r>=s:test_func()\<CR>\<C-x>\<C-v>\<Esc>", 'tx')
320 call assert_equal('autocmd AAAAA_Group', getline(1))
321 autocmd! AAAAA_Group
322 augroup! AAAAA_Group
323 bwipe!
324endfunc
Bram Moolenaar47247282016-08-02 22:36:02 +0200325
zeertzjqee446032022-04-30 15:02:22 +0100326func Test_compl_ignore_mappings()
327 call setline(1, ['foo', 'bar', 'baz', 'foobar'])
328 inoremap <C-P> (C-P)
329 inoremap <C-N> (C-N)
330 normal! G
331 call feedkeys("o\<C-X>\<C-N>\<C-N>\<C-N>\<C-P>\<C-N>\<C-Y>", 'tx')
332 call assert_equal('baz', getline('.'))
333 " Also test with unsimplified keys
334 call feedkeys("o\<C-X>\<*C-N>\<*C-N>\<*C-N>\<*C-P>\<*C-N>\<C-Y>", 'tx')
335 call assert_equal('baz', getline('.'))
336 iunmap <C-P>
337 iunmap <C-N>
338 bwipe!
339endfunc
340
Bram Moolenaar472e8592016-10-15 17:06:47 +0200341func DummyCompleteOne(findstart, base)
342 if a:findstart
343 return 0
344 else
345 wincmd n
346 return ['onedef', 'oneDEF']
347 endif
348endfunc
349
Bram Moolenaarff06f282020-04-21 22:01:14 +0200350" Test that nothing happens if the 'completefunc' tries to open
351" a new window (fails to open window, continues)
Bram Moolenaar472e8592016-10-15 17:06:47 +0200352func Test_completefunc_opens_new_window_one()
353 new
354 let winid = win_getid()
355 setlocal completefunc=DummyCompleteOne
356 call setline(1, 'one')
357 /^one
Bram Moolenaar28976e22021-01-29 21:07:07 +0100358 call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E565:')
Bram Moolenaar472e8592016-10-15 17:06:47 +0200359 call assert_equal(winid, win_getid())
Bram Moolenaar28ee8922020-10-28 20:20:00 +0100360 call assert_equal('onedef', getline(1))
Bram Moolenaar472e8592016-10-15 17:06:47 +0200361 q!
362endfunc
363
364" Test that nothing happens if the 'completefunc' opens
365" a new window (no completion, no crash)
366func DummyCompleteTwo(findstart, base)
367 if a:findstart
368 wincmd n
369 return 0
370 else
371 return ['twodef', 'twoDEF']
372 endif
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200373endfunc
Bram Moolenaar472e8592016-10-15 17:06:47 +0200374
375" Test that nothing happens if the 'completefunc' opens
376" a new window (no completion, no crash)
377func Test_completefunc_opens_new_window_two()
378 new
379 let winid = win_getid()
380 setlocal completefunc=DummyCompleteTwo
381 call setline(1, 'two')
382 /^two
Bram Moolenaar3eb6bd92021-01-29 21:47:24 +0100383 call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E565:')
Bram Moolenaar472e8592016-10-15 17:06:47 +0200384 call assert_equal(winid, win_getid())
Bram Moolenaar3eb6bd92021-01-29 21:47:24 +0100385 call assert_equal('twodef', getline(1))
Bram Moolenaar472e8592016-10-15 17:06:47 +0200386 q!
387endfunc
388
389func DummyCompleteThree(findstart, base)
390 if a:findstart
391 return 0
392 else
393 return ['threedef', 'threeDEF']
394 endif
395endfunc
396
397:"Test that 'completefunc' works when it's OK.
398func Test_completefunc_works()
399 new
400 let winid = win_getid()
401 setlocal completefunc=DummyCompleteThree
402 call setline(1, 'three')
403 /^three
404 call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")
405 call assert_equal(winid, win_getid())
406 call assert_equal('threeDEF', getline(1))
407 q!
408endfunc
409
410func DummyCompleteFour(findstart, base)
411 if a:findstart
412 return 0
413 else
414 call complete_add('four1')
Bram Moolenaar1a3a8912019-08-23 22:31:37 +0200415 eval 'four2'->complete_add()
Bram Moolenaar472e8592016-10-15 17:06:47 +0200416 call complete_check()
417 call complete_add('four3')
418 call complete_add('four4')
419 call complete_check()
420 call complete_add('four5')
421 call complete_add('four6')
422 return []
423 endif
424endfunc
425
Bram Moolenaar60ef3e82016-10-29 14:37:56 +0200426" Test that 'omnifunc' works when it's OK.
Bram Moolenaar472e8592016-10-15 17:06:47 +0200427func Test_omnifunc_with_check()
428 new
429 setlocal omnifunc=DummyCompleteFour
430 call setline(1, 'four')
431 /^four
432 call feedkeys("A\<C-X>\<C-O>\<C-N>\<Esc>", "x")
433 call assert_equal('four2', getline(1))
434
435 call setline(1, 'four')
436 /^four
437 call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<Esc>", "x")
438 call assert_equal('four3', getline(1))
439
440 call setline(1, 'four')
441 /^four
442 call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<C-N>\<Esc>", "x")
443 call assert_equal('four5', getline(1))
444
445 q!
446endfunc
447
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200448func UndoComplete()
Bram Moolenaar869e3522016-10-16 15:35:47 +0200449 call complete(1, ['January', 'February', 'March',
450 \ 'April', 'May', 'June', 'July', 'August', 'September',
451 \ 'October', 'November', 'December'])
452 return ''
453endfunc
454
455" Test that no undo item is created when no completion is inserted
456func Test_complete_no_undo()
457 set completeopt=menu,preview,noinsert,noselect
458 inoremap <Right> <C-R>=UndoComplete()<CR>
459 new
460 call feedkeys("ixxx\<CR>\<CR>yyy\<Esc>k", 'xt')
461 call feedkeys("iaaa\<Esc>0", 'xt')
462 call assert_equal('aaa', getline(2))
463 call feedkeys("i\<Right>\<Esc>", 'xt')
464 call assert_equal('aaa', getline(2))
465 call feedkeys("u", 'xt')
466 call assert_equal('', getline(2))
467
Bram Moolenaarcbd3bd62016-10-17 20:47:02 +0200468 call feedkeys("ibbb\<Esc>0", 'xt')
469 call assert_equal('bbb', getline(2))
470 call feedkeys("A\<Right>\<Down>\<CR>\<Esc>", 'xt')
471 call assert_equal('January', getline(2))
472 call feedkeys("u", 'xt')
473 call assert_equal('bbb', getline(2))
474
Bram Moolenaar9ec7fa82016-10-18 13:06:41 +0200475 call feedkeys("A\<Right>\<C-N>\<Esc>", 'xt')
476 call assert_equal('January', getline(2))
477 call feedkeys("u", 'xt')
478 call assert_equal('bbb', getline(2))
479
Bram Moolenaar869e3522016-10-16 15:35:47 +0200480 iunmap <Right>
481 set completeopt&
482 q!
483endfunc
484
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200485func DummyCompleteFive(findstart, base)
Bram Moolenaar60ef3e82016-10-29 14:37:56 +0200486 if a:findstart
487 return 0
488 else
489 return [
490 \ { 'word': 'January', 'info': "info1-1\n1-2\n1-3" },
491 \ { 'word': 'February', 'info': "info2-1\n2-2\n2-3" },
492 \ { 'word': 'March', 'info': "info3-1\n3-2\n3-3" },
493 \ { 'word': 'April', 'info': "info4-1\n4-2\n4-3" },
494 \ { 'word': 'May', 'info': "info5-1\n5-2\n5-3" },
495 \ ]
496 endif
497endfunc
498
499" Test that 'completefunc' on Scratch buffer with preview window works when
500" it's OK.
501func Test_completefunc_with_scratch_buffer()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100502 CheckFeature quickfix
503
Bram Moolenaar60ef3e82016-10-29 14:37:56 +0200504 new +setlocal\ buftype=nofile\ bufhidden=wipe\ noswapfile
505 set completeopt+=preview
506 setlocal completefunc=DummyCompleteFive
507 call feedkeys("A\<C-X>\<C-U>\<C-N>\<C-N>\<C-N>\<Esc>", "x")
508 call assert_equal(['April'], getline(1, '$'))
509 pclose
510 q!
511 set completeopt&
512endfunc
Bram Moolenaar869e3522016-10-16 15:35:47 +0200513
Bram Moolenaar73fd4982016-12-09 19:36:56 +0100514" <C-E> - select original typed text before the completion started without
515" auto-wrap text.
516func Test_completion_ctrl_e_without_autowrap()
517 new
Bram Moolenaaraed6d0b2017-01-27 21:48:54 +0100518 let tw_save = &tw
Bram Moolenaar73fd4982016-12-09 19:36:56 +0100519 set tw=78
520 let li = [
521 \ '" zzz',
522 \ '" zzzyyyyyyyyyyyyyyyyyyy']
523 call setline(1, li)
524 0
525 call feedkeys("A\<C-X>\<C-N>\<C-E>\<Esc>", "tx")
526 call assert_equal(li, getline(1, '$'))
527
Bram Moolenaaraed6d0b2017-01-27 21:48:54 +0100528 let &tw = tw_save
Bram Moolenaar73fd4982016-12-09 19:36:56 +0100529 q!
530endfunc
531
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200532func DummyCompleteSix()
Bram Moolenaaraed6d0b2017-01-27 21:48:54 +0100533 call complete(1, ['Hello', 'World'])
534 return ''
535endfunction
536
537" complete() correctly clears the list of autocomplete candidates
538" See #1411
539func Test_completion_clear_candidate_list()
540 new
541 %d
542 " select first entry from the completion popup
543 call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>", "tx")
544 call assert_equal('Hello', getline(1))
545 %d
546 " select second entry from the completion popup
547 call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>", "tx")
548 call assert_equal('World', getline(1))
549 %d
550 " select original text
551 call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>", "tx")
552 call assert_equal(' xxx', getline(1))
553 %d
554 " back at first entry from completion list
555 call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>\<C-N>", "tx")
556 call assert_equal('Hello', getline(1))
557
558 bw!
559endfunc
560
Bram Moolenaar190b04c2017-02-09 17:37:03 +0100561func Test_completion_respect_bs_option()
562 new
563 let li = ["aaa", "aaa12345", "aaaabcdef", "aaaABC"]
564
565 set bs=indent,eol
566 call setline(1, li)
567 1
568 call feedkeys("A\<C-X>\<C-N>\<C-P>\<BS>\<BS>\<BS>\<Esc>", "tx")
569 call assert_equal('aaa', getline(1))
570
571 %d
572 set bs=indent,eol,start
573 call setline(1, li)
574 1
575 call feedkeys("A\<C-X>\<C-N>\<C-P>\<BS>\<BS>\<BS>\<Esc>", "tx")
576 call assert_equal('', getline(1))
577
578 bw!
579endfunc
580
Bram Moolenaard56a79d2017-02-19 15:26:18 +0100581func CompleteUndo() abort
582 call complete(1, g:months)
583 return ''
584endfunc
585
586func Test_completion_can_undo()
587 inoremap <Right> <c-r>=CompleteUndo()<cr>
588 set completeopt+=noinsert,noselect
589
590 new
591 call feedkeys("a\<Right>a\<Esc>", 'xt')
592 call assert_equal('a', getline(1))
593 undo
594 call assert_equal('', getline(1))
595
596 bwipe!
597 set completeopt&
598 iunmap <Right>
599endfunc
600
Bram Moolenaard099e032017-02-21 23:00:36 +0100601func Test_completion_comment_formatting()
602 new
603 setl formatoptions=tcqro
604 call feedkeys("o/*\<cr>\<cr>/\<esc>", 'tx')
605 call assert_equal(['', '/*', ' *', ' */'], getline(1,4))
606 %d
607 call feedkeys("o/*\<cr>foobar\<cr>/\<esc>", 'tx')
608 call assert_equal(['', '/*', ' * foobar', ' */'], getline(1,4))
609 %d
610 try
611 call feedkeys("o/*\<cr>\<cr>\<c-x>\<c-u>/\<esc>", 'tx')
Bram Moolenaar37175402017-03-18 20:18:45 +0100612 call assert_report('completefunc not set, should have failed')
Bram Moolenaard099e032017-02-21 23:00:36 +0100613 catch
614 call assert_exception('E764:')
615 endtry
616 call assert_equal(['', '/*', ' *', ' */'], getline(1,4))
617 bwipe!
618endfunc
619
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200620func MessCompleteMonths()
Bram Moolenaar4475b622017-05-01 20:46:52 +0200621 for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep")
622 call complete_add(m)
623 if complete_check()
624 break
625 endif
626 endfor
627 return []
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200628endfunc
Bram Moolenaar4475b622017-05-01 20:46:52 +0200629
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200630func MessCompleteMore()
Bram Moolenaar4475b622017-05-01 20:46:52 +0200631 call complete(1, split("Oct Nov Dec"))
632 return []
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200633endfunc
Bram Moolenaar4475b622017-05-01 20:46:52 +0200634
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200635func MessComplete(findstart, base)
Bram Moolenaar4475b622017-05-01 20:46:52 +0200636 if a:findstart
637 let line = getline('.')
638 let start = col('.') - 1
639 while start > 0 && line[start - 1] =~ '\a'
640 let start -= 1
641 endwhile
642 return start
643 else
644 call MessCompleteMonths()
645 call MessCompleteMore()
646 return []
647 endif
Bram Moolenaarae0f30b2018-06-12 15:22:43 +0200648endfunc
Bram Moolenaar4475b622017-05-01 20:46:52 +0200649
650func Test_complete_func_mess()
651 " Calling complete() after complete_add() in 'completefunc' is wrong, but it
652 " should not crash.
653 set completefunc=MessComplete
654 new
655 call setline(1, 'Ju')
zeertzjqcfe45652022-05-27 17:26:55 +0100656 call assert_fails('call feedkeys("A\<c-x>\<c-u>/\<esc>", "tx")', 'E565:')
Bram Moolenaar28976e22021-01-29 21:07:07 +0100657 call assert_equal('Jan/', getline(1))
Bram Moolenaar4475b622017-05-01 20:46:52 +0200658 bwipe!
659 set completefunc=
660endfunc
661
Bram Moolenaar24a9e342017-06-24 15:39:07 +0200662func Test_complete_CTRLN_startofbuffer()
663 new
664 call setline(1, [ 'organize(cupboard, 3, 2);',
665 \ 'prioritize(bureau, 8, 7);',
666 \ 'realize(bannister, 4, 4);',
667 \ 'moralize(railing, 3,9);'])
668 let expected=['cupboard.organize(3, 2);',
669 \ 'bureau.prioritize(8, 7);',
670 \ 'bannister.realize(4, 4);',
671 \ 'railing.moralize(3,9);']
672 call feedkeys("qai\<c-n>\<c-n>.\<esc>3wdW\<cr>q3@a", 'tx')
673 call assert_equal(expected, getline(1,'$'))
Bram Moolenaara5e66212017-09-29 22:42:33 +0200674 bwipe!
675endfunc
676
677func Test_popup_and_window_resize()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200678 CheckFeature terminal
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100679 CheckFeature quickfix
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200680 CheckNotGui
Bram Moolenaarf08b0eb2021-10-16 13:00:14 +0100681 let g:test_is_flaky = 1
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200682
Bram Moolenaara5e66212017-09-29 22:42:33 +0200683 let h = winheight(0)
684 if h < 15
685 return
686 endif
Bram Moolenaarb3158762017-11-02 17:50:14 +0100687 let rows = h / 3
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100688 let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': rows})
689 call term_sendkeys(buf, (h / 3 - 1) . "o\<esc>")
Bram Moolenaarb3158762017-11-02 17:50:14 +0100690 " Wait for the nested Vim to exit insert mode, where it will show the ruler.
691 " Need to trigger a redraw.
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100692 call WaitFor({-> execute("redraw") == "" && term_getline(buf, rows) =~ '\<' . rows . ',.*Bot'})
Bram Moolenaarb3158762017-11-02 17:50:14 +0100693
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100694 call term_sendkeys(buf, "Gi\<c-x>")
695 call term_sendkeys(buf, "\<c-v>")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200696 call TermWait(buf, 50)
Bram Moolenaarf52c3832017-09-30 16:49:19 +0200697 " popup first entry "!" must be at the top
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200698 call WaitForAssert({-> assert_match('^!\s*$', term_getline(buf, 1))})
Bram Moolenaara5e66212017-09-29 22:42:33 +0200699 exe 'resize +' . (h - 1)
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200700 call TermWait(buf, 50)
Bram Moolenaara5e66212017-09-29 22:42:33 +0200701 redraw!
Bram Moolenaarf52c3832017-09-30 16:49:19 +0200702 " popup shifted down, first line is now empty
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200703 call WaitForAssert({-> assert_equal('', term_getline(buf, 1))})
Bram Moolenaara5e66212017-09-29 22:42:33 +0200704 sleep 100m
Bram Moolenaarf52c3832017-09-30 16:49:19 +0200705 " popup is below cursor line and shows first match "!"
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200706 call WaitForAssert({-> assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0] + 1))})
Bram Moolenaarf52c3832017-09-30 16:49:19 +0200707 " cursor line also shows !
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100708 call assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0]))
Bram Moolenaar24a9e342017-06-24 15:39:07 +0200709 bwipe!
710endfunc
Bram Moolenaar4475b622017-05-01 20:46:52 +0200711
Bram Moolenaar9ad89c62017-10-26 22:04:04 +0200712func Test_popup_and_preview_autocommand()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100713 CheckFeature python
714 CheckFeature quickfix
715 if winheight(0) < 15
716 throw 'Skipped: window height insufficient'
717 endif
718
Bram Moolenaar9ad89c62017-10-26 22:04:04 +0200719 " This used to crash Vim
Bram Moolenaar9ad89c62017-10-26 22:04:04 +0200720 new
721 augroup MyBufAdd
722 au!
723 au BufAdd * nested tab sball
724 augroup END
725 set omnifunc=pythoncomplete#Complete
726 call setline(1, 'import os')
727 " make the line long
728 call setline(2, ' os.')
729 $
730 call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<enter>\<esc>", 'tx')
Bram Moolenaar2a45d642017-10-27 01:35:00 +0200731 call assert_equal("import os", getline(1))
732 call assert_match(' os.\(EX_IOERR\|O_CREAT\)$', getline(2))
Bram Moolenaar9ad89c62017-10-26 22:04:04 +0200733 call assert_equal(1, winnr('$'))
734 " previewwindow option is not set
735 call assert_equal(0, &previewwindow)
736 norm! gt
737 call assert_equal(0, &previewwindow)
738 norm! gT
Bram Moolenaar02ae9b42018-02-09 15:06:02 +0100739 call assert_equal(10, tabpagenr('$'))
Bram Moolenaar9ad89c62017-10-26 22:04:04 +0200740 tabonly
741 pclose
742 augroup MyBufAdd
743 au!
744 augroup END
745 augroup! MyBufAdd
746 bw!
747endfunc
748
Yinzuo Jianga2a2fe82024-12-16 21:22:09 +0100749func s:run_popup_and_previewwindow_dump(lines, dumpfile)
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100750 CheckScreendump
751 CheckFeature quickfix
752
Yinzuo Jianga2a2fe82024-12-16 21:22:09 +0100753 call writefile(a:lines, 'Xscript', 'D')
Bram Moolenaar614ab8a2018-12-01 11:59:00 +0100754 let buf = RunVimInTerminal('-S Xscript', {})
755
Bram Moolenaar37bb0302020-03-27 20:24:14 +0100756 " wait for the script to finish
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200757 call TermWait(buf)
Bram Moolenaar37bb0302020-03-27 20:24:14 +0100758
Bram Moolenaar614ab8a2018-12-01 11:59:00 +0100759 " Test that popup and previewwindow do not overlap.
Bram Moolenaar37bb0302020-03-27 20:24:14 +0100760 call term_sendkeys(buf, "o")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200761 call TermWait(buf, 50)
Bram Moolenaar37bb0302020-03-27 20:24:14 +0100762 call term_sendkeys(buf, "\<C-X>\<C-N>")
Yinzuo Jianga2a2fe82024-12-16 21:22:09 +0100763 call VerifyScreenDump(buf, a:dumpfile, {})
Bram Moolenaar614ab8a2018-12-01 11:59:00 +0100764
765 call term_sendkeys(buf, "\<Esc>u")
766 call StopVimInTerminal(buf)
Bram Moolenaar614ab8a2018-12-01 11:59:00 +0100767endfunc
768
Yinzuo Jianga2a2fe82024-12-16 21:22:09 +0100769func Test_popup_and_previewwindow_dump_pedit()
770 let lines =<< trim END
771 set previewheight=9
772 silent! pedit
773 call setline(1, map(repeat(["ab"], 10), "v:val .. v:key"))
774 exec "norm! G\<C-E>\<C-E>"
775 END
776 call s:run_popup_and_previewwindow_dump(lines, 'Test_popup_and_previewwindow_pedit')
777endfunc
778
779func Test_popup_and_previewwindow_dump_pbuffer()
780 let lines =<< trim END
781 set previewheight=9
782 silent! pbuffer
783 call setline(1, map(repeat(["ab"], 10), "v:val .. v:key"))
784 exec "norm! G\<C-E>\<C-E>\<C-E>"
785 END
786 call s:run_popup_and_previewwindow_dump(lines, 'Test_popup_and_previewwindow_pbuffer')
787endfunc
788
Bram Moolenaar246fe032017-11-19 19:56:27 +0100789func Test_balloon_split()
Bram Moolenaar073e4b92019-08-18 23:01:56 +0200790 CheckFunction balloon_split
791
Bram Moolenaar246fe032017-11-19 19:56:27 +0100792 call assert_equal([
Bram Moolenaara3571eb2017-11-26 16:53:16 +0100793 \ 'tempname: 0x555555e380a0 "/home/mool/.viminfz.tmp"',
794 \ ], balloon_split(
795 \ 'tempname: 0x555555e380a0 "/home/mool/.viminfz.tmp"'))
796 call assert_equal([
Bram Moolenaar246fe032017-11-19 19:56:27 +0100797 \ 'one two three four one two three four one two thre',
798 \ 'e four',
799 \ ], balloon_split(
800 \ 'one two three four one two three four one two three four'))
801
Bram Moolenaar073e4b92019-08-18 23:01:56 +0200802 eval 'struct = {one = 1, two = 2, three = 3}'
803 \ ->balloon_split()
804 \ ->assert_equal([
805 \ 'struct = {',
806 \ ' one = 1,',
807 \ ' two = 2,',
808 \ ' three = 3}',
809 \ ])
Bram Moolenaar246fe032017-11-19 19:56:27 +0100810
811 call assert_equal([
812 \ 'struct = {',
813 \ ' one = 1,',
814 \ ' nested = {',
815 \ ' n1 = "yes",',
816 \ ' n2 = "no"}',
817 \ ' two = 2}',
818 \ ], balloon_split(
819 \ 'struct = {one = 1, nested = {n1 = "yes", n2 = "no"} two = 2}'))
820 call assert_equal([
821 \ 'struct = 0x234 {',
822 \ ' long = 2343 "\\"some long string that will be wr',
823 \ 'apped in two\\"",',
824 \ ' next = 123}',
825 \ ], balloon_split(
826 \ 'struct = 0x234 {long = 2343 "\\"some long string that will be wrapped in two\\"", next = 123}'))
Bram Moolenaar9ae862e2019-11-21 13:27:06 +0100827 call assert_equal([
828 \ 'Some comment',
829 \ '',
830 \ 'typedef this that;',
831 \ ], balloon_split(
832 \ "Some comment\n\ntypedef this that;"))
Bram Moolenaar246fe032017-11-19 19:56:27 +0100833endfunc
834
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +0100835func Test_popup_position()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100836 CheckScreendump
837
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200838 let lines =<< trim END
839 123456789_123456789_123456789_a
840 123456789_123456789_123456789_b
841 123
842 END
Bram Moolenaar7dd5a782022-09-29 21:01:57 +0100843 call writefile(lines, 'Xtest', 'D')
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +0100844 let buf = RunVimInTerminal('Xtest', {})
845 call term_sendkeys(buf, ":vsplit\<CR>")
846
847 " default pumwidth in left window: overlap in right window
848 call term_sendkeys(buf, "GA\<C-N>")
849 call VerifyScreenDump(buf, 'Test_popup_position_01', {'rows': 8})
850 call term_sendkeys(buf, "\<Esc>u")
851
852 " default pumwidth: fill until right of window
853 call term_sendkeys(buf, "\<C-W>l")
854 call term_sendkeys(buf, "GA\<C-N>")
855 call VerifyScreenDump(buf, 'Test_popup_position_02', {'rows': 8})
856
857 " larger pumwidth: used as minimum width
858 call term_sendkeys(buf, "\<Esc>u")
859 call term_sendkeys(buf, ":set pumwidth=30\<CR>")
860 call term_sendkeys(buf, "GA\<C-N>")
861 call VerifyScreenDump(buf, 'Test_popup_position_03', {'rows': 8})
862
Bram Moolenaar2b10bcb2018-02-24 21:25:44 +0100863 " completed text wider than the window and 'pumwidth' smaller than available
864 " space
865 call term_sendkeys(buf, "\<Esc>u")
866 call term_sendkeys(buf, ":set pumwidth=20\<CR>")
867 call term_sendkeys(buf, "ggI123456789_\<Esc>")
868 call term_sendkeys(buf, "jI123456789_\<Esc>")
869 call term_sendkeys(buf, "GA\<C-N>")
870 call VerifyScreenDump(buf, 'Test_popup_position_04', {'rows': 10})
Bram Moolenaar94722c52023-01-28 19:19:03 +0000871
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +0100872 call term_sendkeys(buf, "\<Esc>u")
873 call StopVimInTerminal(buf)
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +0100874endfunc
875
Bram Moolenaar69f5a302018-03-06 13:23:08 +0100876func Test_popup_command()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +0100877 CheckFeature menu
Bram Moolenaar69f5a302018-03-06 13:23:08 +0100878
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +0100879 menu Test.Foo Foo
880 call assert_fails('popup Test.Foo', 'E336:')
881 call assert_fails('popup Test.Foo.X', 'E327:')
882 call assert_fails('popup Foo', 'E337:')
883 unmenu Test.Foo
zeertzjqf7570f22022-11-12 17:30:25 +0000884endfunc
885
886func Test_popup_command_dump()
887 CheckFeature menu
888 CheckScreendump
Bram Moolenaar0eabd4d2020-03-15 16:13:53 +0100889
Bram Moolenaar38455a92020-12-24 18:39:02 +0100890 let script =<< trim END
891 func StartTimer()
892 call timer_start(100, {-> ChangeMenu()})
893 endfunc
894 func ChangeMenu()
zeertzjqf7570f22022-11-12 17:30:25 +0000895 aunmenu PopUp.&Paste
Bram Moolenaar38455a92020-12-24 18:39:02 +0100896 nnoremenu 1.40 PopUp.&Paste :echomsg "pasted"<CR>
897 echomsg 'changed'
898 endfunc
899 END
Bram Moolenaar7dd5a782022-09-29 21:01:57 +0100900 call writefile(script, 'XtimerScript', 'D')
Bram Moolenaar38455a92020-12-24 18:39:02 +0100901
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200902 let lines =<< trim END
903 one two three four five
904 and one two Xthree four five
905 one more two three four five
906 END
Bram Moolenaar7dd5a782022-09-29 21:01:57 +0100907 call writefile(lines, 'Xtest', 'D')
Bram Moolenaar38455a92020-12-24 18:39:02 +0100908 let buf = RunVimInTerminal('-S XtimerScript Xtest', {})
Bram Moolenaar69f5a302018-03-06 13:23:08 +0100909 call term_sendkeys(buf, ":source $VIMRUNTIME/menu.vim\<CR>")
910 call term_sendkeys(buf, "/X\<CR>:popup PopUp\<CR>")
911 call VerifyScreenDump(buf, 'Test_popup_command_01', {})
912
Bram Moolenaar38455a92020-12-24 18:39:02 +0100913 " go to the Paste entry in the menu
Bram Moolenaar69f5a302018-03-06 13:23:08 +0100914 call term_sendkeys(buf, "jj")
915 call VerifyScreenDump(buf, 'Test_popup_command_02', {})
916
917 " Select a word
918 call term_sendkeys(buf, "j\<CR>")
919 call VerifyScreenDump(buf, 'Test_popup_command_03', {})
920
921 call term_sendkeys(buf, "\<Esc>")
Bram Moolenaar38455a92020-12-24 18:39:02 +0100922
zeertzjq883018f2024-06-15 15:37:11 +0200923 if has('rightleft')
924 call term_sendkeys(buf, ":set rightleft\<CR>")
925 call term_sendkeys(buf, "/X\<CR>:popup PopUp\<CR>")
926 call VerifyScreenDump(buf, 'Test_popup_command_rl', {})
927 call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>")
928 endif
929
Bram Moolenaar38455a92020-12-24 18:39:02 +0100930 " Set a timer to change a menu entry while it's displayed. The text should
931 " not change but the command does. Making the screendump also verifies that
zeertzjq4e1ca0d2023-04-27 19:36:55 +0100932 " "changed" shows up, which means the timer triggered.
Bram Moolenaar38455a92020-12-24 18:39:02 +0100933 call term_sendkeys(buf, "/X\<CR>:call StartTimer() | popup PopUp\<CR>")
934 call VerifyScreenDump(buf, 'Test_popup_command_04', {})
935
936 " Select the Paste entry, executes the changed menu item.
937 call term_sendkeys(buf, "jj\<CR>")
938 call VerifyScreenDump(buf, 'Test_popup_command_05', {})
939
zeertzjq4e1ca0d2023-04-27 19:36:55 +0100940 call term_sendkeys(buf, "\<Esc>")
941
942 " Add a window toolbar to the window and check the :popup menu position.
943 call term_sendkeys(buf, ":nnoremenu WinBar.TEST :\<CR>")
944 call term_sendkeys(buf, "/X\<CR>:popup PopUp\<CR>")
945 call VerifyScreenDump(buf, 'Test_popup_command_06', {})
946
947 call term_sendkeys(buf, "\<Esc>")
948
Bram Moolenaar69f5a302018-03-06 13:23:08 +0100949 call StopVimInTerminal(buf)
Bram Moolenaar69f5a302018-03-06 13:23:08 +0100950endfunc
951
zeertzjq883018f2024-06-15 15:37:11 +0200952" Test position of right-click menu when clicking near window edge.
953func Test_mouse_popup_position()
954 CheckFeature menu
955 CheckScreendump
956
957 let script =<< trim END
958 set mousemodel=popup_setpos
959 source $VIMRUNTIME/menu.vim
960 call setline(1, join(range(20)))
961 func Trigger(col)
962 call test_setmouse(1, a:col)
963 call feedkeys("\<RightMouse>", 't')
964 endfunc
965 END
966 call writefile(script, 'XmousePopupPosition', 'D')
967 let buf = RunVimInTerminal('-S XmousePopupPosition', #{rows: 20, cols: 50})
968
969 call term_sendkeys(buf, ":call Trigger(45)\<CR>")
970 call VerifyScreenDump(buf, 'Test_mouse_popup_position_01', {})
971 call term_sendkeys(buf, "\<Esc>")
972
973 if has('rightleft')
974 call term_sendkeys(buf, ":set rightleft\<CR>")
975 call term_sendkeys(buf, ":call Trigger(50 + 1 - 45)\<CR>")
976 call VerifyScreenDump(buf, 'Test_mouse_popup_position_02', {})
977 call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>")
978 endif
979
980 call StopVimInTerminal(buf)
981endfunc
982
Bram Moolenaare87edf32018-04-17 22:14:32 +0200983func Test_popup_complete_backwards()
984 new
985 call setline(1, ['Post', 'Port', 'Po'])
986 let expected=['Post', 'Port', 'Port']
987 call cursor(3,2)
glepnir07f0dbe2025-02-18 20:27:30 +0100988 call feedkeys("A\<C-X>". repeat("\<C-P>", 3). "rt\<C-Y>", 'tx')
Bram Moolenaare87edf32018-04-17 22:14:32 +0200989 call assert_equal(expected, getline(1,'$'))
990 bwipe!
991endfunc
Bram Moolenaar69f5a302018-03-06 13:23:08 +0100992
Bram Moolenaarbad0ce72018-04-17 23:31:05 +0200993func Test_popup_complete_backwards_ctrl_p()
994 new
995 call setline(1, ['Post', 'Port', 'Po'])
996 let expected=['Post', 'Port', 'Port']
997 call cursor(3,2)
glepnir07f0dbe2025-02-18 20:27:30 +0100998 call feedkeys("A\<C-P>\<C-N>rt\<C-Y>", 'tx')
Bram Moolenaarbad0ce72018-04-17 23:31:05 +0200999 call assert_equal(expected, getline(1,'$'))
1000 bwipe!
1001endfunc
1002
Bram Moolenaarae0f30b2018-06-12 15:22:43 +02001003func Test_complete_o_tab()
Bram Moolenaar39de9522018-05-08 22:48:00 +02001004 let s:o_char_pressed = 0
1005
1006 fun! s:act_on_text_changed()
1007 if s:o_char_pressed
1008 let s:o_char_pressed = 0
1009 call feedkeys("\<c-x>\<c-n>", 'i')
1010 endif
Bram Moolenaarae0f30b2018-06-12 15:22:43 +02001011 endfunc
Bram Moolenaar39de9522018-05-08 22:48:00 +02001012
1013 set completeopt=menu,noselect
1014 new
1015 imap <expr> <buffer> <tab> pumvisible() ? "\<c-p>" : "X"
1016 autocmd! InsertCharPre <buffer> let s:o_char_pressed = (v:char ==# 'o')
1017 autocmd! TextChangedI <buffer> call <sid>act_on_text_changed()
1018 call setline(1, ['hoard', 'hoax', 'hoarse', ''])
1019 let l:expected = ['hoard', 'hoax', 'hoarse', 'hoax', 'hoax']
1020 call cursor(4,1)
1021 call test_override("char_avail", 1)
1022 call feedkeys("Ahoa\<tab>\<tab>\<c-y>\<esc>", 'tx')
1023 call feedkeys("oho\<tab>\<tab>\<c-y>\<esc>", 'tx')
1024 call assert_equal(l:expected, getline(1,'$'))
1025
1026 call test_override("char_avail", 0)
1027 bwipe!
1028 set completeopt&
1029 delfunc s:act_on_text_changed
Bram Moolenaarae0f30b2018-06-12 15:22:43 +02001030endfunc
Bram Moolenaar39de9522018-05-08 22:48:00 +02001031
Bram Moolenaarf42b45d2019-01-06 13:11:05 +01001032func Test_menu_only_exists_in_terminal()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001033 CheckCommand tlmenu
1034 CheckNotGui
1035
Bram Moolenaarf42b45d2019-01-06 13:11:05 +01001036 tlnoremenu &Edit.&Paste<Tab>"+gP <C-W>"+
1037 aunmenu *
1038 try
1039 popup Edit
1040 call assert_false(1, 'command should have failed')
1041 catch
1042 call assert_exception('E328:')
1043 endtry
1044endfunc
Bram Moolenaar39de9522018-05-08 22:48:00 +02001045
zeertzjq92a16782022-07-26 12:24:41 +01001046" This used to crash before patch 8.1.1424
1047func Test_popup_delete_when_shown()
1048 CheckFeature menu
1049 CheckNotGui
1050
1051 func Func()
1052 popup Foo
1053 return "\<Ignore>"
1054 endfunc
1055
1056 nmenu Foo.Bar :
1057 nnoremap <expr> <F2> Func()
1058 call feedkeys("\<F2>\<F2>\<Esc>", 'xt')
1059
1060 delfunc Func
1061 nunmenu Foo.Bar
1062 nunmap <F2>
1063endfunc
1064
Bram Moolenaarfd133322019-03-29 12:20:27 +01001065func Test_popup_complete_info_01()
1066 new
1067 inoremap <buffer><F5> <C-R>=complete_info().mode<CR>
1068 func s:complTestEval() abort
1069 call complete(1, ['aa', 'ab'])
1070 return ''
1071 endfunc
1072 inoremap <buffer><F6> <C-R>=s:complTestEval()<CR>
1073 call writefile([
1074 \ 'dummy dummy.txt 1',
Bram Moolenaar7dd5a782022-09-29 21:01:57 +01001075 \], 'Xdummy.txt', 'D')
Bram Moolenaarfd133322019-03-29 12:20:27 +01001076 setlocal tags=Xdummy.txt
1077 setlocal dictionary=Xdummy.txt
1078 setlocal thesaurus=Xdummy.txt
1079 setlocal omnifunc=syntaxcomplete#Complete
1080 setlocal completefunc=syntaxcomplete#Complete
1081 setlocal spell
1082 for [keys, mode_name] in [
1083 \ ["", ''],
1084 \ ["\<C-X>", 'ctrl_x'],
1085 \ ["\<C-X>\<C-N>", 'keyword'],
1086 \ ["\<C-X>\<C-P>", 'keyword'],
zeertzjq27fef592021-10-03 12:01:27 +01001087 \ ["\<C-X>\<C-E>", 'scroll'],
1088 \ ["\<C-X>\<C-Y>", 'scroll'],
1089 \ ["\<C-X>\<C-E>\<C-E>\<C-Y>", 'scroll'],
1090 \ ["\<C-X>\<C-Y>\<C-E>\<C-Y>", 'scroll'],
Bram Moolenaarfd133322019-03-29 12:20:27 +01001091 \ ["\<C-X>\<C-L>", 'whole_line'],
1092 \ ["\<C-X>\<C-F>", 'files'],
1093 \ ["\<C-X>\<C-]>", 'tags'],
1094 \ ["\<C-X>\<C-D>", 'path_defines'],
1095 \ ["\<C-X>\<C-I>", 'path_patterns'],
1096 \ ["\<C-X>\<C-K>", 'dictionary'],
1097 \ ["\<C-X>\<C-T>", 'thesaurus'],
1098 \ ["\<C-X>\<C-V>", 'cmdline'],
1099 \ ["\<C-X>\<C-U>", 'function'],
1100 \ ["\<C-X>\<C-O>", 'omni'],
1101 \ ["\<C-X>s", 'spell'],
1102 \ ["\<F6>", 'eval'],
1103 \]
1104 call feedkeys("i" . keys . "\<F5>\<Esc>", 'tx')
1105 call assert_equal(mode_name, getline('.'))
1106 %d
1107 endfor
Bram Moolenaar7dd5a782022-09-29 21:01:57 +01001108
Bram Moolenaarfd133322019-03-29 12:20:27 +01001109 bwipe!
1110endfunc
1111
1112func UserDefinedComplete(findstart, base)
1113 if a:findstart
1114 return 0
1115 else
1116 return [
1117 \ { 'word': 'Jan', 'menu': 'January' },
1118 \ { 'word': 'Feb', 'menu': 'February' },
1119 \ { 'word': 'Mar', 'menu': 'March' },
1120 \ { 'word': 'Apr', 'menu': 'April' },
1121 \ { 'word': 'May', 'menu': 'May' },
1122 \ ]
1123 endif
1124endfunc
1125
1126func GetCompleteInfo()
1127 if empty(g:compl_what)
1128 let g:compl_info = complete_info()
1129 else
Bram Moolenaar1a3a8912019-08-23 22:31:37 +02001130 let g:compl_info = g:compl_what->complete_info()
Bram Moolenaarfd133322019-03-29 12:20:27 +01001131 endif
1132 return ''
1133endfunc
1134
1135func Test_popup_complete_info_02()
1136 new
1137 inoremap <buffer><F5> <C-R>=GetCompleteInfo()<CR>
1138 setlocal completefunc=UserDefinedComplete
1139
1140 let d = {
1141 \ 'mode': 'function',
1142 \ 'pum_visible': 1,
1143 \ 'items': [
1144 \ {'word': 'Jan', 'menu': 'January', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''},
1145 \ {'word': 'Feb', 'menu': 'February', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''},
1146 \ {'word': 'Mar', 'menu': 'March', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''},
1147 \ {'word': 'Apr', 'menu': 'April', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''},
1148 \ {'word': 'May', 'menu': 'May', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}
1149 \ ],
1150 \ 'selected': 0,
1151 \ }
1152
1153 let g:compl_what = []
1154 call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx')
1155 call assert_equal(d, g:compl_info)
1156
1157 let g:compl_what = ['mode', 'pum_visible', 'selected']
1158 call remove(d, 'items')
1159 call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx')
1160 call assert_equal(d, g:compl_info)
1161
1162 let g:compl_what = ['mode']
1163 call remove(d, 'selected')
1164 call remove(d, 'pum_visible')
1165 call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx')
1166 call assert_equal(d, g:compl_info)
1167 bwipe!
1168endfunc
1169
Bram Moolenaare9bd5722019-08-17 19:36:06 +02001170func Test_popup_complete_info_no_pum()
1171 new
1172 call assert_false( pumvisible() )
1173 let no_pum_info = complete_info()
1174 let d = {
1175 \ 'mode': '',
1176 \ 'pum_visible': 0,
1177 \ 'items': [],
1178 \ 'selected': -1,
1179 \ }
1180 call assert_equal( d, complete_info() )
1181 bwipe!
1182endfunc
1183
Bram Moolenaard7f246c2019-04-08 18:15:41 +02001184func Test_CompleteChanged()
1185 new
1186 call setline(1, ['foo', 'bar', 'foobar', ''])
1187 set complete=. completeopt=noinsert,noselect,menuone
1188 function! OnPumChange()
1189 let g:event = copy(v:event)
1190 let g:item = get(v:event, 'completed_item', {})
1191 let g:word = get(g:item, 'word', v:null)
glepnir0d3c0a62024-02-11 17:52:40 +01001192 let l:line = getline('.')
1193 if g:word == v:null && l:line == "bc"
1194 let g:word = l:line
1195 endif
Bram Moolenaard7f246c2019-04-08 18:15:41 +02001196 endfunction
1197 augroup AAAAA_Group
1198 au!
1199 autocmd CompleteChanged * :call OnPumChange()
1200 augroup END
1201 call cursor(4, 1)
1202
1203 call feedkeys("Sf\<C-N>", 'tx')
1204 call assert_equal({'completed_item': {}, 'width': 15,
1205 \ 'height': 2, 'size': 2,
1206 \ 'col': 0, 'row': 4, 'scrollbar': v:false}, g:event)
1207 call feedkeys("a\<C-N>\<C-N>\<C-E>", 'tx')
1208 call assert_equal('foo', g:word)
1209 call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-E>", 'tx')
1210 call assert_equal('foobar', g:word)
1211 call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-N>\<C-E>", 'tx')
1212 call assert_equal(v:null, g:word)
1213 call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-N>\<C-P>", 'tx')
1214 call assert_equal('foobar', g:word)
glepnir0d3c0a62024-02-11 17:52:40 +01001215 call feedkeys("S\<C-N>bc", 'tx')
1216 call assert_equal("bc", g:word)
Bram Moolenaard7f246c2019-04-08 18:15:41 +02001217
glepnircbb46b42024-02-03 18:11:13 +01001218 func Omni_test(findstart, base)
1219 if a:findstart
1220 return col(".")
1221 endif
1222 return [#{word: "one"}, #{word: "two"}, #{word: "five"}]
1223 endfunc
1224 set omnifunc=Omni_test
1225 set completeopt=menu,menuone
1226 call feedkeys("i\<C-X>\<C-O>\<BS>\<BS>\<BS>f", 'tx')
1227 call assert_equal('five', g:word)
glepnir53387c52024-05-27 15:11:01 +02001228 call feedkeys("i\<C-X>\<C-O>\<BS>\<BS>\<BS>f\<BS>", 'tx')
1229 call assert_equal('one', g:word)
glepnircbb46b42024-02-03 18:11:13 +01001230
Bram Moolenaard7f246c2019-04-08 18:15:41 +02001231 autocmd! AAAAA_Group
1232 set complete& completeopt&
Bram Moolenaare9bd5722019-08-17 19:36:06 +02001233 delfunc! OnPumChange
glepnircbb46b42024-02-03 18:11:13 +01001234 delfunc! Omni_test
Bram Moolenaard7f246c2019-04-08 18:15:41 +02001235 bw!
1236endfunc
1237
Bram Moolenaar97f0eb12022-10-06 19:49:13 +01001238func GetPumPosition()
Bram Moolenaare9bd5722019-08-17 19:36:06 +02001239 call assert_true( pumvisible() )
1240 let g:pum_pos = pum_getpos()
1241 return ''
Bram Moolenaar97f0eb12022-10-06 19:49:13 +01001242endfunc
Bram Moolenaare9bd5722019-08-17 19:36:06 +02001243
1244func Test_pum_getpos()
1245 new
1246 inoremap <buffer><F5> <C-R>=GetPumPosition()<CR>
1247 setlocal completefunc=UserDefinedComplete
1248
1249 let d = {
1250 \ 'height': 5,
1251 \ 'width': 15,
1252 \ 'row': 1,
1253 \ 'col': 0,
1254 \ 'size': 5,
1255 \ 'scrollbar': v:false,
1256 \ }
1257 call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx')
1258 call assert_equal(d, g:pum_pos)
1259
1260 call assert_false( pumvisible() )
1261 call assert_equal( {}, pum_getpos() )
1262 bw!
1263 unlet g:pum_pos
1264endfunc
1265
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001266" Test for the popup menu with the 'rightleft' option set
1267func Test_pum_rightleft()
Dominique Pelle56cddb32021-06-04 21:09:55 +02001268 CheckFeature rightleft
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001269 CheckScreendump
Dominique Pelle56cddb32021-06-04 21:09:55 +02001270
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001271 let lines =<< trim END
1272 abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
1273 vim
1274 victory
1275 END
Bram Moolenaar7dd5a782022-09-29 21:01:57 +01001276 call writefile(lines, 'Xtest1', 'D')
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001277 let buf = RunVimInTerminal('--cmd "set rightleft" Xtest1', {})
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001278 call term_sendkeys(buf, "Go\<C-P>")
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001279 call VerifyScreenDump(buf, 'Test_pum_rightleft_01', {'rows': 8})
1280 call term_sendkeys(buf, "\<C-P>\<C-Y>")
Bram Moolenaar37bb3b12022-06-21 17:40:47 +01001281 call TermWait(buf, 30)
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001282 redraw!
Bram Moolenaar37bb3b12022-06-21 17:40:47 +01001283 call WaitForAssert({-> assert_match('\s*miv', Screenline(5))})
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001284
1285 " Test for expanding tabs to spaces in the popup menu
1286 let lines =<< trim END
1287 one two
1288 one three
1289 four
1290 END
Bram Moolenaar7dd5a782022-09-29 21:01:57 +01001291 call writefile(lines, 'Xtest2', 'D')
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001292 call term_sendkeys(buf, "\<Esc>:e! Xtest2\<CR>")
Bram Moolenaar37bb3b12022-06-21 17:40:47 +01001293 call TermWait(buf, 30)
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001294 call term_sendkeys(buf, "Goone\<C-X>\<C-L>")
Bram Moolenaar37bb3b12022-06-21 17:40:47 +01001295 call TermWait(buf, 30)
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001296 redraw!
1297 call VerifyScreenDump(buf, 'Test_pum_rightleft_02', {'rows': 7})
1298 call term_sendkeys(buf, "\<C-Y>")
Bram Moolenaar37bb3b12022-06-21 17:40:47 +01001299 call TermWait(buf, 30)
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001300 redraw!
Bram Moolenaar37bb3b12022-06-21 17:40:47 +01001301 call WaitForAssert({-> assert_match('\s*eerht eno', Screenline(4))})
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001302
1303 call StopVimInTerminal(buf)
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001304endfunc
1305
1306" Test for a popup menu with a scrollbar
1307func Test_pum_scrollbar()
1308 CheckScreendump
1309 let lines =<< trim END
1310 one
1311 two
1312 three
1313 END
Bram Moolenaar7dd5a782022-09-29 21:01:57 +01001314 call writefile(lines, 'Xtest1', 'D')
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001315 let buf = RunVimInTerminal('--cmd "set pumheight=2" Xtest1', {})
Bram Moolenaar37bb3b12022-06-21 17:40:47 +01001316 call TermWait(buf)
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001317 call term_sendkeys(buf, "Go\<C-P>\<C-P>\<C-P>")
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001318 call VerifyScreenDump(buf, 'Test_pum_scrollbar_01', {'rows': 7})
1319 call term_sendkeys(buf, "\<C-E>\<Esc>dd")
Bram Moolenaar37bb3b12022-06-21 17:40:47 +01001320 call TermWait(buf)
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001321
Dominique Pelle56cddb32021-06-04 21:09:55 +02001322 if has('rightleft')
1323 call term_sendkeys(buf, ":set rightleft\<CR>")
Bram Moolenaar37bb3b12022-06-21 17:40:47 +01001324 call TermWait(buf)
Dominique Pelle56cddb32021-06-04 21:09:55 +02001325 call term_sendkeys(buf, "Go\<C-P>\<C-P>\<C-P>")
Dominique Pelle56cddb32021-06-04 21:09:55 +02001326 call VerifyScreenDump(buf, 'Test_pum_scrollbar_02', {'rows': 7})
1327 endif
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001328
1329 call StopVimInTerminal(buf)
Yegappan Lakshmanan1e615662021-05-22 17:12:46 +02001330endfunc
1331
Gianmaria Bajo6a7c7742023-03-10 16:35:53 +00001332" Test default highlight groups for popup menu
1333func Test_pum_highlights_default()
1334 CheckScreendump
1335 let lines =<< trim END
1336 func CompleteFunc( findstart, base )
1337 if a:findstart
1338 return 0
1339 endif
1340 return {
1341 \ 'words': [
1342 \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', },
1343 \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
1344 \ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', },
1345 \]}
1346 endfunc
1347 set completeopt=menu
1348 set completefunc=CompleteFunc
1349 END
1350 call writefile(lines, 'Xscript', 'D')
1351 let buf = RunVimInTerminal('-S Xscript', {})
1352 call TermWait(buf)
1353 call term_sendkeys(buf, "iaw\<C-X>\<C-u>")
1354 call TermWait(buf, 50)
1355 call VerifyScreenDump(buf, 'Test_pum_highlights_01', {})
1356 call term_sendkeys(buf, "\<C-E>\<Esc>u")
1357 call TermWait(buf)
1358 call StopVimInTerminal(buf)
1359endfunc
1360
1361" Test custom highlight groups for popup menu
1362func Test_pum_highlights_custom()
1363 CheckScreendump
1364 let lines =<< trim END
1365 func CompleteFunc( findstart, base )
1366 if a:findstart
1367 return 0
1368 endif
1369 return {
1370 \ 'words': [
1371 \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', },
1372 \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
1373 \ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', },
1374 \]}
1375 endfunc
1376 set completeopt=menu
1377 set completefunc=CompleteFunc
1378 hi PmenuKind ctermfg=1 ctermbg=225
1379 hi PmenuKindSel ctermfg=1 ctermbg=7
1380 hi PmenuExtra ctermfg=243 ctermbg=225
1381 hi PmenuExtraSel ctermfg=0 ctermbg=7
1382 END
1383 call writefile(lines, 'Xscript', 'D')
1384 let buf = RunVimInTerminal('-S Xscript', {})
1385 call TermWait(buf)
1386 call term_sendkeys(buf, "iaw\<C-X>\<C-u>")
1387 call TermWait(buf, 50)
1388 call VerifyScreenDump(buf, 'Test_pum_highlights_02', {})
1389 call term_sendkeys(buf, "\<C-E>\<Esc>u")
1390 call TermWait(buf)
1391 call StopVimInTerminal(buf)
1392endfunc
1393
glepnir40c1c332024-06-11 19:37:04 +02001394" Test match relate highlight group in pmenu
1395func Test_pum_highlights_match()
1396 CheckScreendump
1397 let lines =<< trim END
1398 func Omni_test(findstart, base)
1399 if a:findstart
1400 return col(".")
1401 endif
1402 return {
1403 \ 'words': [
zeertzjqafbe5352024-06-14 20:24:22 +02001404 \ { 'word': 'foo', 'kind': 'fookind' },
zeertzjq63901e82024-06-16 16:51:25 +02001405 \ { 'word': 'foofoo', 'kind': 'fookind' },
zeertzjqafbe5352024-06-14 20:24:22 +02001406 \ { 'word': 'foobar', 'kind': 'fookind' },
1407 \ { 'word': 'fooBaz', 'kind': 'fookind' },
1408 \ { 'word': 'foobala', 'kind': 'fookind' },
1409 \ { 'word': '你好' },
1410 \ { 'word': '你好吗' },
1411 \ { 'word': '你不好吗' },
1412 \ { 'word': '你可好吗' },
glepnir40c1c332024-06-11 19:37:04 +02001413 \]}
1414 endfunc
glepnirf1891382024-06-17 18:35:25 +02001415
1416 func Comp()
1417 let col = col('.')
1418 if getline('.') == 'f'
1419 let col -= 1
1420 endif
1421 call complete(col, [
1422 \ #{word: "foo", icase: 1},
1423 \ #{word: "Foobar", icase: 1},
1424 \ #{word: "fooBaz", icase: 1},
1425 \])
1426 return ''
1427 endfunc
1428
glepnir40c1c332024-06-11 19:37:04 +02001429 set omnifunc=Omni_test
1430 set completeopt=menu,noinsert,fuzzy
zeertzjq63901e82024-06-16 16:51:25 +02001431 hi PmenuMatchSel ctermfg=6 ctermbg=7
glepnir40c1c332024-06-11 19:37:04 +02001432 hi PmenuMatch ctermfg=4 ctermbg=225
1433 END
1434 call writefile(lines, 'Xscript', 'D')
1435 let buf = RunVimInTerminal('-S Xscript', {})
1436 call TermWait(buf)
1437 call term_sendkeys(buf, "i\<C-X>\<C-O>")
1438 call TermWait(buf, 50)
1439 call term_sendkeys(buf, "fo")
1440 call TermWait(buf, 50)
1441 call VerifyScreenDump(buf, 'Test_pum_highlights_03', {})
zeertzjq63901e82024-06-16 16:51:25 +02001442 call term_sendkeys(buf, "\<Esc>S\<C-X>\<C-O>")
glepnir40c1c332024-06-11 19:37:04 +02001443 call TermWait(buf, 50)
1444 call term_sendkeys(buf, "你")
1445 call TermWait(buf, 50)
1446 call VerifyScreenDump(buf, 'Test_pum_highlights_04', {})
1447 call term_sendkeys(buf, "吗")
1448 call TermWait(buf, 50)
1449 call VerifyScreenDump(buf, 'Test_pum_highlights_05', {})
zeertzjq63901e82024-06-16 16:51:25 +02001450 call term_sendkeys(buf, "\<C-E>\<Esc>")
glepnir40c1c332024-06-11 19:37:04 +02001451
1452 if has('rightleft')
zeertzjq63901e82024-06-16 16:51:25 +02001453 call term_sendkeys(buf, ":set rightleft\<CR>")
glepnir40c1c332024-06-11 19:37:04 +02001454 call TermWait(buf, 50)
zeertzjq63901e82024-06-16 16:51:25 +02001455 call term_sendkeys(buf, "S\<C-X>\<C-O>")
glepnir40c1c332024-06-11 19:37:04 +02001456 call TermWait(buf, 50)
1457 call term_sendkeys(buf, "fo")
1458 call TermWait(buf, 50)
1459 call VerifyScreenDump(buf, 'Test_pum_highlights_06', {})
zeertzjq63901e82024-06-16 16:51:25 +02001460 call term_sendkeys(buf, "\<Esc>S\<C-X>\<C-O>")
1461 call TermWait(buf, 50)
1462 call term_sendkeys(buf, "你")
1463 call VerifyScreenDump(buf, 'Test_pum_highlights_06a', {})
1464 call term_sendkeys(buf, "吗")
1465 call VerifyScreenDump(buf, 'Test_pum_highlights_06b', {})
1466 call term_sendkeys(buf, "\<C-E>\<Esc>")
1467 call term_sendkeys(buf, ":set norightleft\<CR>")
glepnir40c1c332024-06-11 19:37:04 +02001468 call TermWait(buf)
1469 endif
1470
1471 call term_sendkeys(buf, ":set completeopt-=fuzzy\<CR>")
1472 call TermWait(buf)
zeertzjq63901e82024-06-16 16:51:25 +02001473 call term_sendkeys(buf, "S\<C-X>\<C-O>")
glepnir40c1c332024-06-11 19:37:04 +02001474 call TermWait(buf, 50)
1475 call term_sendkeys(buf, "fo")
1476 call TermWait(buf, 50)
1477 call VerifyScreenDump(buf, 'Test_pum_highlights_07', {})
zeertzjq63901e82024-06-16 16:51:25 +02001478 call term_sendkeys(buf, "\<C-E>\<Esc>")
glepnir40c1c332024-06-11 19:37:04 +02001479
zeertzjq63901e82024-06-16 16:51:25 +02001480 if has('rightleft')
1481 call term_sendkeys(buf, ":set rightleft\<CR>")
1482 call TermWait(buf, 50)
1483 call term_sendkeys(buf, "S\<C-X>\<C-O>")
1484 call TermWait(buf, 50)
1485 call term_sendkeys(buf, "fo")
1486 call TermWait(buf, 50)
1487 call VerifyScreenDump(buf, 'Test_pum_highlights_08', {})
1488 call term_sendkeys(buf, "\<C-E>\<Esc>")
1489 call term_sendkeys(buf, ":set norightleft\<CR>")
1490 endif
1491
glepnirf1891382024-06-17 18:35:25 +02001492 call term_sendkeys(buf, "S\<C-R>=Comp()\<CR>f")
1493 call VerifyScreenDump(buf, 'Test_pum_highlights_09', {})
1494 call term_sendkeys(buf, "o\<BS>\<C-R>=Comp()\<CR>")
1495 call VerifyScreenDump(buf, 'Test_pum_highlights_09', {})
glepnir9eff3ee2025-01-11 16:47:34 +01001496 call term_sendkeys(buf, "\<C-E>\<Esc>")
1497
zeertzjqfaf250c2025-01-12 09:32:27 +01001498 call term_sendkeys(buf, ":hi PmenuMatchSel ctermfg=14 ctermbg=NONE\<CR>")
glepnir9eff3ee2025-01-11 16:47:34 +01001499 call TermWait(buf, 50)
zeertzjqfaf250c2025-01-12 09:32:27 +01001500 call term_sendkeys(buf, ":hi PmenuMatch ctermfg=12 ctermbg=NONE\<CR>")
glepnir9eff3ee2025-01-11 16:47:34 +01001501 call term_sendkeys(buf, ":set cot=menu,noinsert,fuzzy\<CR>")
1502 call term_sendkeys(buf, "S\<C-X>\<C-O>")
1503 call TermWait(buf, 50)
1504 call term_sendkeys(buf, "fb")
1505 call VerifyScreenDump(buf, 'Test_pum_highlights_18', {})
glepnir6b6280c2024-07-27 16:25:45 +02001506
glepnirf1891382024-06-17 18:35:25 +02001507 call term_sendkeys(buf, "\<C-E>\<Esc>")
glepnir40c1c332024-06-11 19:37:04 +02001508 call TermWait(buf)
glepnirf31cfa22025-03-06 21:59:13 +01001509 call StopVimInTerminal(buf)
1510endfunc
glepnirf1891382024-06-17 18:35:25 +02001511
glepnirf31cfa22025-03-06 21:59:13 +01001512func Test_pum_completefuzzycollect()
1513 CheckScreendump
1514 let lines =<< trim END
1515 set completefuzzycollect=keyword,files
1516 set completeopt=menu,menuone
1517 END
1518 call writefile(lines, 'Xscript', 'D')
1519 let buf = RunVimInTerminal('-S Xscript', {})
1520
1521 " issue #15095 wrong select
1522 call term_sendkeys(buf, "S hello helio hero h\<C-X>\<C-P>")
1523 call TermWait(buf, 50)
1524 call VerifyScreenDump(buf, 'Test_pum_completefuzzycollect_01', {})
1525
1526 call term_sendkeys(buf, "\<ESC>S hello helio hero h\<C-X>\<C-P>\<C-P>")
1527 call TermWait(buf, 50)
1528 call VerifyScreenDump(buf, 'Test_pum_completefuzzycollect_02', {})
1529
1530 " issue #15357
1531 call term_sendkeys(buf, "\<ESC>S/non_existing_folder\<C-X>\<C-F>")
1532 call TermWait(buf, 50)
1533 call VerifyScreenDump(buf, 'Test_pum_completefuzzycollect_03', {})
1534 call term_sendkeys(buf, "\<C-E>\<Esc>")
1535
1536 call TermWait(buf)
glepnir40c1c332024-06-11 19:37:04 +02001537 call StopVimInTerminal(buf)
1538endfunc
1539
zeertzjq3a0cc362025-01-13 07:27:43 +01001540func Test_pum_highlights_match_with_abbr()
1541 CheckScreendump
1542 let lines =<< trim END
1543 func Omni_test(findstart, base)
1544 if a:findstart
1545 return col(".")
1546 endif
1547 return {
1548 \ 'words': [
1549 \ { 'word': 'foobar', 'abbr': "foobar\t\t!" },
1550 \ { 'word': 'foobaz', 'abbr': "foobaz\t\t!" },
1551 \]}
1552 endfunc
1553
1554 set omnifunc=Omni_test
1555 set completeopt=menuone,noinsert
1556 hi PmenuMatchSel ctermfg=6 ctermbg=7
1557 hi PmenuMatch ctermfg=4 ctermbg=225
1558 END
1559 call writefile(lines, 'Xscript', 'D')
1560 let buf = RunVimInTerminal('-S Xscript', {})
1561 call TermWait(buf)
1562 call term_sendkeys(buf, "i\<C-X>\<C-O>")
1563 call TermWait(buf, 50)
1564 call term_sendkeys(buf, "foo")
1565 call VerifyScreenDump(buf, 'Test_pum_highlights_19', {})
1566
1567 call term_sendkeys(buf, "\<C-E>\<Esc>")
1568 call TermWait(buf)
1569
1570 call StopVimInTerminal(buf)
1571endfunc
1572
glepnir0fe17f82024-10-08 22:26:44 +02001573func Test_pum_user_abbr_hlgroup()
glepnir508e7852024-07-25 21:39:08 +02001574 CheckScreendump
1575 let lines =<< trim END
glepnirbc10be72024-11-02 16:45:01 +01001576 let s:var = 0
1577 func CompleteFunc(findstart, base)
glepnir508e7852024-07-25 21:39:08 +02001578 if a:findstart
1579 return 0
1580 endif
glepnirbc10be72024-11-02 16:45:01 +01001581 if s:var == 1
1582 return {
1583 \ 'words': [
1584 \ { 'word': 'aword1', 'abbr_hlgroup': 'StrikeFake' },
1585 \ { 'word': '你好', 'abbr_hlgroup': 'StrikeFake' },
1586 \]}
1587 endif
glepnir508e7852024-07-25 21:39:08 +02001588 return {
1589 \ 'words': [
glepnir0fe17f82024-10-08 22:26:44 +02001590 \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' },
glepnir508e7852024-07-25 21:39:08 +02001591 \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
glepnir0fe17f82024-10-08 22:26:44 +02001592 \ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' },
glepnir508e7852024-07-25 21:39:08 +02001593 \]}
1594 endfunc
glepnirbc10be72024-11-02 16:45:01 +01001595 func ChangeVar()
1596 let s:var = 1
1597 endfunc
glepnir508e7852024-07-25 21:39:08 +02001598 set completeopt=menu
1599 set completefunc=CompleteFunc
zeertzjq41008522024-07-27 13:21:49 +02001600
1601 hi StrikeFake ctermfg=9
1602 func HlMatch()
1603 hi PmenuMatchSel ctermfg=6 ctermbg=7 cterm=underline
1604 hi PmenuMatch ctermfg=4 ctermbg=225 cterm=underline
1605 endfunc
glepnir508e7852024-07-25 21:39:08 +02001606 END
1607 call writefile(lines, 'Xscript', 'D')
1608 let buf = RunVimInTerminal('-S Xscript', {})
zeertzjq41008522024-07-27 13:21:49 +02001609
glepnir508e7852024-07-25 21:39:08 +02001610 call TermWait(buf)
zeertzjq41008522024-07-27 13:21:49 +02001611 call term_sendkeys(buf, "Saw\<C-X>\<C-U>")
glepnir508e7852024-07-25 21:39:08 +02001612 call VerifyScreenDump(buf, 'Test_pum_highlights_12', {})
zeertzjq41008522024-07-27 13:21:49 +02001613 call term_sendkeys(buf, "\<C-E>\<Esc>")
1614
glepnir508e7852024-07-25 21:39:08 +02001615 call TermWait(buf)
zeertzjq41008522024-07-27 13:21:49 +02001616 call term_sendkeys(buf, ":call HlMatch()\<CR>")
1617
1618 call TermWait(buf)
1619 call term_sendkeys(buf, "Saw\<C-X>\<C-U>")
1620 call VerifyScreenDump(buf, 'Test_pum_highlights_13', {})
1621 call term_sendkeys(buf, "\<C-N>")
1622 call VerifyScreenDump(buf, 'Test_pum_highlights_14', {})
1623 call term_sendkeys(buf, "\<C-E>\<Esc>")
1624
glepnirbc10be72024-11-02 16:45:01 +01001625 call TermWait(buf)
1626 call term_sendkeys(buf, ":call ChangeVar()\<CR>")
1627 call TermWait(buf)
1628 call term_sendkeys(buf, "S\<C-X>\<C-U>")
1629 call VerifyScreenDump(buf, 'Test_pum_highlights_17', {})
1630 call term_sendkeys(buf, "\<C-E>\<Esc>")
1631
glepnir508e7852024-07-25 21:39:08 +02001632 call StopVimInTerminal(buf)
1633endfunc
1634
glepnir38f99a12024-08-23 18:31:06 +02001635func Test_pum_user_kind_hlgroup()
1636 CheckScreendump
1637 let lines =<< trim END
glepnirbc10be72024-11-02 16:45:01 +01001638 func CompleteFunc(findstart, base)
glepnir38f99a12024-08-23 18:31:06 +02001639 if a:findstart
1640 return 0
1641 endif
1642 return {
1643 \ 'words': [
glepnir0fe17f82024-10-08 22:26:44 +02001644 \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'variable', 'kind_hlgroup': 'KindVar', 'abbr_hlgroup': 'StrikeFake' },
glepnir38f99a12024-08-23 18:31:06 +02001645 \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'function', 'kind_hlgroup': 'KindFunc' },
1646 \ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'class', 'kind_hlgroup': 'KindClass' },
1647 \]}
1648 endfunc
1649 set completeopt=menu
1650 set completefunc=CompleteFunc
1651
1652 hi StrikeFake ctermfg=9
1653 hi KindVar ctermfg=yellow
1654 hi KindFunc ctermfg=blue
1655 hi KindClass ctermfg=green
1656 END
1657 call writefile(lines, 'Xscript', 'D')
1658 let buf = RunVimInTerminal('-S Xscript', {})
1659
1660 call TermWait(buf)
1661 call term_sendkeys(buf, "S\<C-X>\<C-U>")
1662 call VerifyScreenDump(buf, 'Test_pum_highlights_16', {})
1663 call term_sendkeys(buf, "\<C-E>\<Esc>")
1664
1665 call StopVimInTerminal(buf)
1666endfunc
1667
glepnir6a89c942024-10-01 20:32:12 +02001668func Test_pum_completeitemalign()
1669 CheckScreendump
1670 let lines =<< trim END
1671 func Omni_test(findstart, base)
1672 if a:findstart
1673 return col(".")
1674 endif
1675 return {
1676 \ 'words': [
1677 \ { 'word': 'foo', 'kind': 'S', 'menu': 'menu' },
1678 \ { 'word': 'bar', 'kind': 'T', 'menu': 'menu' },
1679 \ { 'word': '你好', 'kind': 'C', 'menu': '中文' },
1680 \]}
1681 endfunc
glepnira6d9e3c2024-10-03 11:01:19 +02001682
1683 func Omni_long(findstart, base)
1684 if a:findstart
1685 return col(".")
1686 endif
1687 return {
1688 \ 'words': [
1689 \ { 'word': 'loooong_foo', 'kind': 'S', 'menu': 'menu' },
1690 \ { 'word': 'loooong_bar', 'kind': 'T', 'menu': 'menu' },
1691 \]}
1692 endfunc
glepnir6a89c942024-10-01 20:32:12 +02001693 set omnifunc=Omni_test
1694 command! -nargs=0 T1 set cia=abbr,kind,menu
1695 command! -nargs=0 T2 set cia=abbr,menu,kind
1696 command! -nargs=0 T3 set cia=kind,abbr,menu
1697 command! -nargs=0 T4 set cia=kind,menu,abbr
1698 command! -nargs=0 T5 set cia=menu,abbr,kind
1699 command! -nargs=0 T6 set cia=menu,kind,abbr
1700 command! -nargs=0 T7 set cia&
1701 END
1702 call writefile(lines, 'Xscript', 'D')
1703 let buf = RunVimInTerminal('-S Xscript', {})
1704 call TermWait(buf)
1705
1706 " T1 is default
1707 call term_sendkeys(buf, ":T1\<CR>S\<C-X>\<C-O>")
1708 call VerifyScreenDump(buf, 'Test_pum_completeitemalign_01', {})
1709 call term_sendkeys(buf, "\<C-E>\<Esc>")
1710
1711 " T2
1712 call term_sendkeys(buf, ":T2\<CR>S\<C-X>\<C-O>")
1713 call VerifyScreenDump(buf, 'Test_pum_completeitemalign_02', {})
1714 call term_sendkeys(buf, "\<C-E>\<Esc>")
1715
1716 " T3
1717 call term_sendkeys(buf, ":T3\<CR>S\<C-X>\<C-O>")
1718 call VerifyScreenDump(buf, 'Test_pum_completeitemalign_03', {})
1719 call term_sendkeys(buf, "\<C-E>\<Esc>")
1720
1721 " T4
1722 call term_sendkeys(buf, ":T4\<CR>S\<C-X>\<C-O>")
1723 call VerifyScreenDump(buf, 'Test_pum_completeitemalign_04', {})
1724 call term_sendkeys(buf, "\<C-E>\<Esc>")
1725
1726 " T5
1727 call term_sendkeys(buf, ":T5\<CR>S\<C-X>\<C-O>")
1728 call VerifyScreenDump(buf, 'Test_pum_completeitemalign_05', {})
1729 call term_sendkeys(buf, "\<C-E>\<Esc>")
1730
1731 " T6
1732 call term_sendkeys(buf, ":T6\<CR>S\<C-X>\<C-O>")
1733 call VerifyScreenDump(buf, 'Test_pum_completeitemalign_06', {})
glepnira6d9e3c2024-10-03 11:01:19 +02001734 call term_sendkeys(buf, "\<C-E>\<Esc>")
glepnir6a89c942024-10-01 20:32:12 +02001735
glepnira6d9e3c2024-10-03 11:01:19 +02001736 call term_sendkeys(buf, ":set columns=12 cmdheight=2 omnifunc=Omni_long\<CR>S\<C-X>\<C-O>")
1737 call VerifyScreenDump(buf, 'Test_pum_completeitemalign_07', {})
1738 call term_sendkeys(buf, "\<C-E>\<Esc>:T7\<CR>")
glepnir6a89c942024-10-01 20:32:12 +02001739 call StopVimInTerminal(buf)
1740endfunc
1741
glepnira49c0772024-11-30 10:56:30 +01001742func Test_pum_keep_select()
1743 CheckScreendump
1744 let lines =<< trim END
1745 set completeopt=menu,menuone,noinsert
1746 END
1747 call writefile(lines, 'Xscript', 'D')
1748 let buf = RunVimInTerminal('-S Xscript', {})
1749 call TermWait(buf)
1750
1751 call term_sendkeys(buf, "ggSFab\<CR>Five\<CR>find\<CR>film\<CR>\<C-X>\<C-P>")
1752 call TermWait(buf, 50)
1753 call VerifyScreenDump(buf, 'Test_pum_keep_select_01', {})
1754 call term_sendkeys(buf, "\<C-E>\<Esc>")
1755 call TermWait(buf, 50)
1756
1757 call term_sendkeys(buf, "S\<C-X>\<C-P>")
1758 call TermWait(buf, 50)
1759 call term_sendkeys(buf, "F")
1760 call VerifyScreenDump(buf, 'Test_pum_keep_select_02', {})
1761 call term_sendkeys(buf, "\<C-E>\<Esc>")
1762
1763 call TermWait(buf, 50)
1764 call StopVimInTerminal(buf)
1765endfunc
1766
zeertzjqd32bf0a2024-12-17 20:55:13 +01001767func Test_pum_matchins_highlight()
glepnir6a38aff2024-12-16 21:56:16 +01001768 CheckScreendump
1769 let lines =<< trim END
glepnir8d0bb6d2024-12-24 09:44:35 +01001770 let g:change = 0
glepnir6a38aff2024-12-16 21:56:16 +01001771 func Omni_test(findstart, base)
1772 if a:findstart
1773 return col(".")
1774 endif
glepnir8d0bb6d2024-12-24 09:44:35 +01001775 if g:change == 0
1776 return [#{word: "foo"}, #{word: "bar"}, #{word: "你好"}]
1777 endif
1778 return [#{word: "foo", info: "info"}, #{word: "bar"}, #{word: "你好"}]
glepnir6a38aff2024-12-16 21:56:16 +01001779 endfunc
1780 set omnifunc=Omni_test
1781 hi ComplMatchIns ctermfg=red
1782 END
1783 call writefile(lines, 'Xscript', 'D')
1784 let buf = RunVimInTerminal('-S Xscript', {})
1785
1786 call TermWait(buf)
zeertzjqf4ccada2024-12-17 20:50:19 +01001787 call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>")
glepnir6a38aff2024-12-16 21:56:16 +01001788 call VerifyScreenDump(buf, 'Test_pum_matchins_01', {})
1789 call term_sendkeys(buf, "\<C-E>\<Esc>")
1790
1791 call TermWait(buf)
zeertzjqf4ccada2024-12-17 20:50:19 +01001792 call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<C-N>")
glepnir6a38aff2024-12-16 21:56:16 +01001793 call VerifyScreenDump(buf, 'Test_pum_matchins_02', {})
1794 call term_sendkeys(buf, "\<C-E>\<Esc>")
1795
1796 call TermWait(buf)
zeertzjqf4ccada2024-12-17 20:50:19 +01001797 call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<C-N>\<C-N>")
glepnir6a38aff2024-12-16 21:56:16 +01001798 call VerifyScreenDump(buf, 'Test_pum_matchins_03', {})
1799 call term_sendkeys(buf, "\<C-E>\<Esc>")
1800
1801 " restore after accept
1802 call TermWait(buf)
zeertzjqf4ccada2024-12-17 20:50:19 +01001803 call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<C-Y>")
glepnir6a38aff2024-12-16 21:56:16 +01001804 call VerifyScreenDump(buf, 'Test_pum_matchins_04', {})
zeertzjqf25d8f92024-12-18 21:12:25 +01001805 call term_sendkeys(buf, "\<Esc>")
glepnir6a38aff2024-12-16 21:56:16 +01001806
1807 " restore after cancel completion
1808 call TermWait(buf)
zeertzjqf4ccada2024-12-17 20:50:19 +01001809 call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<Space>")
glepnir6a38aff2024-12-16 21:56:16 +01001810 call VerifyScreenDump(buf, 'Test_pum_matchins_05', {})
zeertzjqf25d8f92024-12-18 21:12:25 +01001811 call term_sendkeys(buf, "\<Esc>")
1812
1813 " text after the inserted text shouldn't be highlighted
1814 call TermWait(buf)
1815 call term_sendkeys(buf, "0ea \<C-X>\<C-O>")
1816 call VerifyScreenDump(buf, 'Test_pum_matchins_07', {})
1817 call term_sendkeys(buf, "\<C-P>")
1818 call VerifyScreenDump(buf, 'Test_pum_matchins_08', {})
1819 call term_sendkeys(buf, "\<C-P>")
1820 call VerifyScreenDump(buf, 'Test_pum_matchins_09', {})
1821 call term_sendkeys(buf, "\<C-Y>")
1822 call VerifyScreenDump(buf, 'Test_pum_matchins_10', {})
1823 call term_sendkeys(buf, "\<Esc>")
1824
glepnir8d0bb6d2024-12-24 09:44:35 +01001825 call term_sendkeys(buf, ":let g:change=1\<CR>S\<C-X>\<C-O>")
1826 call VerifyScreenDump(buf, 'Test_pum_matchins_11', {})
1827 call term_sendkeys(buf, "\<Esc>")
1828
zeertzjqf25d8f92024-12-18 21:12:25 +01001829 call StopVimInTerminal(buf)
1830endfunc
1831
1832func Test_pum_matchins_highlight_combine()
1833 CheckScreendump
1834 let lines =<< trim END
1835 func Omni_test(findstart, base)
1836 if a:findstart
1837 return col(".")
1838 endif
1839 return [#{word: "foo"}, #{word: "bar"}, #{word: "你好"}]
1840 endfunc
1841 set omnifunc=Omni_test
1842 hi Normal ctermbg=blue
1843 hi CursorLine cterm=underline ctermbg=green
1844 set cursorline
1845 call setline(1, 'aaa bbb')
1846 END
1847 call writefile(lines, 'Xscript', 'D')
1848 let buf = RunVimInTerminal('-S Xscript', {})
1849
1850 " when ComplMatchIns is not set, CursorLine applies normally
1851 call term_sendkeys(buf, "0ea \<C-X>\<C-O>")
1852 call VerifyScreenDump(buf, 'Test_pum_matchins_combine_01', {})
1853 call term_sendkeys(buf, "\<C-E>")
1854 call VerifyScreenDump(buf, 'Test_pum_matchins_combine_02', {})
1855 call term_sendkeys(buf, "\<BS>\<Esc>")
1856
1857 " when ComplMatchIns is set, it is applied over CursorLine
1858 call TermWait(buf)
1859 call term_sendkeys(buf, ":hi ComplMatchIns ctermbg=red ctermfg=yellow\<CR>")
1860 call TermWait(buf)
1861 call term_sendkeys(buf, "0ea \<C-X>\<C-O>")
1862 call VerifyScreenDump(buf, 'Test_pum_matchins_combine_03', {})
1863 call term_sendkeys(buf, "\<C-P>")
1864 call VerifyScreenDump(buf, 'Test_pum_matchins_combine_04', {})
1865 call term_sendkeys(buf, "\<C-P>")
1866 call VerifyScreenDump(buf, 'Test_pum_matchins_combine_05', {})
1867 call term_sendkeys(buf, "\<C-E>")
1868 call VerifyScreenDump(buf, 'Test_pum_matchins_combine_06', {})
1869 call term_sendkeys(buf, "\<Esc>")
glepnir6a38aff2024-12-16 21:56:16 +01001870
glepnire8908872025-01-08 18:30:45 +01001871 " Does not highlight the compl leader
1872 call TermWait(buf)
1873 call term_sendkeys(buf, ":set cot+=menuone,noselect\<CR>")
1874 call TermWait(buf)
1875 call term_sendkeys(buf, "S\<C-X>\<C-O>f\<C-N>")
1876 call VerifyScreenDump(buf, 'Test_pum_matchins_combine_07', {})
1877 call term_sendkeys(buf, "\<C-E>\<Esc>")
1878
1879 call term_sendkeys(buf, ":set cot+=fuzzy\<CR>")
1880 call TermWait(buf)
1881 call term_sendkeys(buf, "S\<C-X>\<C-O>f\<C-N>")
1882 call VerifyScreenDump(buf, 'Test_pum_matchins_combine_08', {})
1883 call term_sendkeys(buf, "\<C-E>\<Esc>")
glepnir9fddb8a2025-01-11 16:42:50 +01001884 call TermWait(buf)
1885
1886 call term_sendkeys(buf, ":set cot-=fuzzy\<CR>")
1887 call TermWait(buf)
1888 call term_sendkeys(buf, "Sf\<C-N>")
1889 call VerifyScreenDump(buf, 'Test_pum_matchins_combine_09', {})
1890 call term_sendkeys(buf, "\<C-E>\<Esc>")
glepnire8908872025-01-08 18:30:45 +01001891
glepnir6a38aff2024-12-16 21:56:16 +01001892 call StopVimInTerminal(buf)
1893endfunc
1894
glepnir8d0bb6d2024-12-24 09:44:35 +01001895" this used to crash
1896func Test_popup_completion_many_ctrlp()
1897 new
1898 let candidates=repeat(['a0'], 99)
1899 call setline(1, candidates)
1900 exe ":norm! VGg\<C-A>"
1901 norm! G
1902 call feedkeys("o" .. repeat("\<c-p>", 100), 'tx')
1903 bw!
1904endfunc
1905
glepnir76bdb822025-02-08 19:04:51 +01001906func Test_pum_complete_with_special_characters()
1907 CheckScreendump
1908
1909 let lines =<< trim END
1910 func Omni_test(findstart, base)
1911 if a:findstart
1912 return col(".")
1913 endif
1914 return [#{word: "func ()\n\t\nend", abbr: "function ()",}, #{word: "foobar"}, #{word: "你好\n\t\n我好"}]
1915 endfunc
1916 set omnifunc=Omni_test
glepnir34a7d822025-03-05 21:18:20 +01001917 inoremap <F5> <Cmd>call complete(col('.'), [ "my\n\tmulti\nline", "my\n\t\tmulti\nline" ])<CR>
glepnir76bdb822025-02-08 19:04:51 +01001918 END
1919
1920 call writefile(lines, 'Xpreviewscript', 'D')
1921 let buf = RunVimInTerminal('-S Xpreviewscript', #{rows: 12})
1922 call term_sendkeys(buf, "S\<C-X>\<C-O>")
1923 call TermWait(buf, 50)
1924 call VerifyScreenDump(buf, 'Test_pum_with_special_characters_01', {})
1925
1926 call term_sendkeys(buf, "\<C-N>")
1927 call TermWait(buf, 50)
1928 call VerifyScreenDump(buf, 'Test_pum_with_special_characters_02', {})
1929 call term_sendkeys(buf, "\<C-E>\<Esc>")
1930
1931 call term_sendkeys(buf, "Shello hero\<ESC>hhhhha\<C-X>\<C-O>")
1932 call TermWait(buf, 50)
1933 call VerifyScreenDump(buf, 'Test_pum_with_special_characters_03', {})
1934
1935 call term_sendkeys(buf, "\<C-N>")
1936 call TermWait(buf, 50)
1937 call VerifyScreenDump(buf, 'Test_pum_with_special_characters_04', {})
1938
1939 call term_sendkeys(buf, "\<C-N>")
1940 call TermWait(buf, 50)
1941 call VerifyScreenDump(buf, 'Test_pum_with_special_characters_05', {})
1942
1943 call term_sendkeys(buf, "\<C-N>")
1944 call TermWait(buf, 50)
1945 call VerifyScreenDump(buf, 'Test_pum_with_special_characters_06', {})
1946 call term_sendkeys(buf, "\<C-E>\<Esc>")
1947
1948 call term_sendkeys(buf, ":hi ComplMatchIns ctermfg=red\<CR>")
1949 call TermWait(buf, 50)
1950 call term_sendkeys(buf, "S\<C-X>\<C-O>")
1951 call VerifyScreenDump(buf, 'Test_pum_with_special_characters_07', {})
1952 call term_sendkeys(buf, "\<C-E>\<Esc>")
1953
1954 call term_sendkeys(buf, "Shello hero\<ESC>hhhhha\<C-X>\<C-O>")
1955 call TermWait(buf, 50)
1956 call VerifyScreenDump(buf, 'Test_pum_with_special_characters_08', {})
1957 call term_sendkeys(buf, "\<C-E>\<Esc>")
1958
glepnir5090a1f2025-02-24 19:10:37 +01001959 call term_sendkeys(buf, ":setlocal autoindent tabstop=2 shiftwidth=2\<CR>")
1960 call term_sendkeys(buf, "Slocal a = \<C-X>\<C-O>")
1961 call TermWait(buf, 50)
1962 call VerifyScreenDump(buf, 'Test_pum_with_special_characters_09', {})
1963
1964 call term_sendkeys(buf, "\<C-Y>")
1965 call TermWait(buf, 50)
1966 call VerifyScreenDump(buf, 'Test_pum_with_special_characters_10', {})
1967
1968 call term_sendkeys(buf, "\<ESC>kAlocal b = \<C-X>\<C-O>")
1969 call TermWait(buf, 50)
1970 call VerifyScreenDump(buf, 'Test_pum_with_special_characters_11', {})
1971
1972 call term_sendkeys(buf, "\<C-Y>")
1973 call TermWait(buf, 50)
1974 call VerifyScreenDump(buf, 'Test_pum_with_special_characters_12', {})
1975
glepnir34a7d822025-03-05 21:18:20 +01001976 call term_sendkeys(buf, "\<ESC>ggVGd")
1977 call term_sendkeys(buf, ":filetype indent on\<CR>")
1978 call term_sendkeys(buf, ":set nocompatible autoindent& shiftwidth& tabstop&\<CR>")
1979 call term_sendkeys(buf, ":setlocal ft=lua\<CR>")
1980 call term_sendkeys(buf, "S\<F5>")
1981 call TermWait(buf, 50)
1982 call VerifyScreenDump(buf, 'Test_pum_with_special_characters_13', {})
1983
glepnir76bdb822025-02-08 19:04:51 +01001984 call StopVimInTerminal(buf)
1985endfunc
1986
glepnir88d75932025-03-27 20:09:07 +01001987func Test_pum_maxwidth()
1988 CheckScreendump
1989
1990 let lines =<< trim END
1991 123456789_123456789_123456789_a
1992 123456789_123456789_123456789_b
1993 123
1994 END
1995 call writefile(lines, 'Xtest', 'D')
1996 let buf = RunVimInTerminal('Xtest', {})
1997
1998 call term_sendkeys(buf, "G\"zyy")
1999 call term_sendkeys(buf, "A\<C-N>")
2000 call VerifyScreenDump(buf, 'Test_pum_maxwidth_01', {'rows': 8})
2001 call term_sendkeys(buf, "\<Esc>3Gdd\"zp")
2002
2003 call term_sendkeys(buf, ":set pummaxwidth=10\<CR>")
2004 call term_sendkeys(buf, "GA\<C-N>")
2005 call VerifyScreenDump(buf, 'Test_pum_maxwidth_02', {'rows': 8})
2006 call term_sendkeys(buf, "\<Esc>3Gdd\"zp")
2007
2008 call term_sendkeys(buf, ":set pummaxwidth=20\<CR>")
2009 call term_sendkeys(buf, "GA\<C-N>")
2010 call VerifyScreenDump(buf, 'Test_pum_maxwidth_03', {'rows': 8})
2011 call term_sendkeys(buf, "\<Esc>3Gdd\"zp")
2012
2013 call term_sendkeys(buf, ":set pumwidth=20 pummaxwidth=8\<CR>")
2014 call term_sendkeys(buf, "GA\<C-N>")
2015 call VerifyScreenDump(buf, 'Test_pum_maxwidth_04', {'rows': 8})
2016 call term_sendkeys(buf, "\<Esc>3Gdd\"zp")
2017
glepnir532c5ae2025-03-28 19:21:59 +01002018 call term_sendkeys(buf, ":set lines=10 columns=32\<CR>")
glepnirb8762042025-04-07 20:57:14 +02002019 call TermWait(buf, 50)
glepnir532c5ae2025-03-28 19:21:59 +01002020 call term_sendkeys(buf, "GA\<C-N>")
glepnirb8762042025-04-07 20:57:14 +02002021 call VerifyScreenDump(buf, 'Test_pum_maxwidth_05', {'rows': 10, 'cols': 32})
glepnir532c5ae2025-03-28 19:21:59 +01002022 call term_sendkeys(buf, "\<Esc>3Gdd\"zp")
2023
glepnir88d75932025-03-27 20:09:07 +01002024 call StopVimInTerminal(buf)
2025endfunc
2026
2027func Test_pum_maxwidth_multibyte()
2028 CheckScreendump
2029
2030 let lines =<< trim END
glepnir0816f172025-05-18 20:14:53 +02002031 hi StrikeFake ctermfg=9
glepnirb8762042025-04-07 20:57:14 +02002032 let g:change = 0
glepnir88d75932025-03-27 20:09:07 +01002033 func Omni_test(findstart, base)
2034 if a:findstart
2035 return col(".")
2036 endif
glepnirb8762042025-04-07 20:57:14 +02002037 if g:change == 0
2038 return [
2039 \ #{word: "123456789_123456789_123456789_"},
2040 \ #{word: "一二三四五六七八九十"},
2041 \ #{word: "abcdefghij"},
2042 \ #{word: "上下左右"},
2043 \ ]
2044 elseif g:change == 1
2045 return [
2046 \ #{word: "foo", menu: "fooMenu", kind: "fooKind"},
2047 \ #{word: "bar", menu: "barMenu", kind: "barKind"},
2048 \ #{word: "baz", menu: "bazMenu", kind: "bazKind"},
2049 \ ]
2050 elseif g:change == 2
2051 return [
2052 \ #{word: "foo", menu: "fooMenu", kind: "fooKind"},
2053 \ #{word: "bar", menu: "fooMenu", kind: "一二三四"},
2054 \ #{word: "一二三四五", kind: "multi"},
2055 \ ]
glepnirb8762042025-04-07 20:57:14 +02002056 return [#{word: "bar", menu: "fooMenu", kind: "一二三"}]
glepnir0816f172025-05-18 20:14:53 +02002057 elseif g:change == 3
2058 return [#{word: "bar", menu: "fooMenu", kind: "一二三"}]
2059 else
2060 return [
2061 \ #{word: "一二三四五六七八九十", abbr_hlgroup: "StrikeFake"},
2062 \ #{word: "123456789_123456789_123456789_", abbr_hlgroup: "StrikeFake"},
2063 \ ]
glepnirb8762042025-04-07 20:57:14 +02002064 endif
glepnir88d75932025-03-27 20:09:07 +01002065 endfunc
2066 set omnifunc=Omni_test
glepnirb8762042025-04-07 20:57:14 +02002067 set cot+=menuone
glepnir88d75932025-03-27 20:09:07 +01002068 END
2069 call writefile(lines, 'Xtest', 'D')
2070 let buf = RunVimInTerminal('-S Xtest', {})
2071 call TermWait(buf)
2072
2073 call term_sendkeys(buf, "S\<C-X>\<C-O>")
glepnirb8762042025-04-07 20:57:14 +02002074 call VerifyScreenDump(buf, 'Test_pum_maxwidth_06', {'rows': 8})
glepnir88d75932025-03-27 20:09:07 +01002075 call term_sendkeys(buf, "\<ESC>")
2076
2077 call term_sendkeys(buf, ":set pummaxwidth=10\<CR>")
2078 call term_sendkeys(buf, "S\<C-X>\<C-O>")
glepnirb8762042025-04-07 20:57:14 +02002079 call VerifyScreenDump(buf, 'Test_pum_maxwidth_07', {'rows': 8})
glepnir88d75932025-03-27 20:09:07 +01002080 call term_sendkeys(buf, "\<ESC>")
2081
2082 if has('rightleft')
2083 call term_sendkeys(buf, ":set rightleft\<CR>")
2084 call term_sendkeys(buf, "S\<C-X>\<C-O>")
glepnirb8762042025-04-07 20:57:14 +02002085 call VerifyScreenDump(buf, 'Test_pum_maxwidth_08', {'rows': 8})
glepnir88d75932025-03-27 20:09:07 +01002086 call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>")
2087 endif
2088
2089 call term_sendkeys(buf, ":set pummaxwidth=2\<CR>")
2090 call term_sendkeys(buf, "S\<C-X>\<C-O>")
glepnirb8762042025-04-07 20:57:14 +02002091 call VerifyScreenDump(buf, 'Test_pum_maxwidth_09', {'rows': 8})
glepnir88d75932025-03-27 20:09:07 +01002092 call term_sendkeys(buf, "\<ESC>")
2093
glepnirb8762042025-04-07 20:57:14 +02002094 call term_sendkeys(buf, ":set pummaxwidth=14\<CR>")
2095 call term_sendkeys(buf, ":let g:change=1\<CR>S\<C-X>\<C-O>")
2096 call VerifyScreenDump(buf, 'Test_pum_maxwidth_10', {'rows': 8})
2097 call term_sendkeys(buf, "\<ESC>")
glepnir88d75932025-03-27 20:09:07 +01002098
glepnirb8762042025-04-07 20:57:14 +02002099 " Unicode Character U+2026 but one cell
2100 call term_sendkeys(buf, ":set fcs+=trunc:…\<CR>")
Hirohito Higashif13c8562025-03-30 15:19:05 +02002101 call term_sendkeys(buf, "S\<C-X>\<C-O>")
glepnirb8762042025-04-07 20:57:14 +02002102 call VerifyScreenDump(buf, 'Test_pum_maxwidth_11', {'rows': 8})
Hirohito Higashif13c8562025-03-30 15:19:05 +02002103 call term_sendkeys(buf, "\<ESC>")
2104
glepnirb8762042025-04-07 20:57:14 +02002105 call term_sendkeys(buf, ":let g:change=2\<CR>S\<C-X>\<C-O>")
2106 call VerifyScreenDump(buf, 'Test_pum_maxwidth_12', {'rows': 8})
Hirohito Higashif13c8562025-03-30 15:19:05 +02002107 call term_sendkeys(buf, "\<ESC>")
2108
glepnirb8762042025-04-07 20:57:14 +02002109 call term_sendkeys(buf, ":set fcs&\<CR>")
Hirohito Higashif13c8562025-03-30 15:19:05 +02002110 call term_sendkeys(buf, "S\<C-X>\<C-O>")
glepnirb8762042025-04-07 20:57:14 +02002111 call VerifyScreenDump(buf, 'Test_pum_maxwidth_13', {'rows': 8})
Hirohito Higashif13c8562025-03-30 15:19:05 +02002112 call term_sendkeys(buf, "\<ESC>")
2113
glepnirb8762042025-04-07 20:57:14 +02002114 call term_sendkeys(buf, ":set fcs=trunc:_\<CR>")
2115 call term_sendkeys(buf, ":let g:change=1\<CR>")
2116 call TermWait(buf, 50)
Hirohito Higashif13c8562025-03-30 15:19:05 +02002117 call term_sendkeys(buf, "S\<C-X>\<C-O>")
glepnirb8762042025-04-07 20:57:14 +02002118 call VerifyScreenDump(buf, 'Test_pum_maxwidth_14', {'rows': 8})
2119 call term_sendkeys(buf, "\<ESC>")
2120 call term_sendkeys(buf, ":set fcs&\<CR>")
2121
2122 if has('rightleft')
2123 call term_sendkeys(buf, ":set rightleft\<CR>")
2124 call term_sendkeys(buf, "S\<C-X>\<C-O>")
2125 call VerifyScreenDump(buf, 'Test_pum_maxwidth_15', {'rows': 8})
2126 call term_sendkeys(buf, "\<ESC>")
2127
2128 call term_sendkeys(buf, ":let g:change=2\<CR>")
2129 call TermWait(buf, 50)
2130 call term_sendkeys(buf, "S\<C-X>\<C-O>")
2131 call VerifyScreenDump(buf, 'Test_pum_maxwidth_16', {'rows': 8})
2132 call term_sendkeys(buf, "\<ESC>")
2133
glepnird4dbf822025-04-12 18:35:34 +02002134 call term_sendkeys(buf, ":set fcs+=truncrl:…\<CR>")
glepnirb8762042025-04-07 20:57:14 +02002135 call term_sendkeys(buf, "S\<C-X>\<C-O>")
2136 call VerifyScreenDump(buf, 'Test_pum_maxwidth_17', {'rows': 8})
2137 call term_sendkeys(buf, "\<ESC>")
2138
2139 call term_sendkeys(buf, ":set fcs&\<CR>")
2140 call term_sendkeys(buf, ":let g:change=3\<CR>")
2141 call TermWait(buf, 50)
2142 call term_sendkeys(buf, "S\<C-X>\<C-O>")
2143 call VerifyScreenDump(buf, 'Test_pum_maxwidth_18', {'rows': 8})
2144 call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>")
2145 endif
2146
2147 call term_sendkeys(buf, ":set pummaxwidth=4\<CR>")
2148 call term_sendkeys(buf, ":let g:change=2\<CR>")
2149 call TermWait(buf, 50)
2150 call term_sendkeys(buf, "S\<C-X>\<C-O>")
2151 call VerifyScreenDump(buf, 'Test_pum_maxwidth_19', {'rows': 8})
Hirohito Higashif13c8562025-03-30 15:19:05 +02002152 call term_sendkeys(buf, "\<ESC>")
2153
glepnirb8762042025-04-07 20:57:14 +02002154 if has('rightleft')
2155 call term_sendkeys(buf, ":set rightleft\<CR>")
2156 call TermWait(buf, 50)
2157 call term_sendkeys(buf, "S\<C-X>\<C-O>")
2158 call VerifyScreenDump(buf, 'Test_pum_maxwidth_20', {'rows': 8})
2159 call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>")
2160 endif
Hirohito Higashif13c8562025-03-30 15:19:05 +02002161
zeertzjq031919c2025-04-16 18:23:23 +02002162 call term_sendkeys(buf, ":set pummaxwidth=16\<CR>")
2163 call TermWait(buf, 50)
2164 call term_sendkeys(buf, "S\<C-X>\<C-O>")
2165 call VerifyScreenDump(buf, 'Test_pum_maxwidth_21', {'rows': 8})
2166 call term_sendkeys(buf, "\<ESC>")
2167
2168 if has('rightleft')
2169 call term_sendkeys(buf, ":set rightleft\<CR>")
2170 call TermWait(buf, 50)
2171 call term_sendkeys(buf, "S\<C-X>\<C-O>")
2172 call VerifyScreenDump(buf, 'Test_pum_maxwidth_22', {'rows': 8})
2173 call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>")
2174 endif
2175
glepnir0816f172025-05-18 20:14:53 +02002176 call term_sendkeys(buf, ":let g:change=4\<CR>")
2177 call TermWait(buf, 50)
2178 call term_sendkeys(buf, "S\<C-X>\<C-O>")
2179 call VerifyScreenDump(buf, 'Test_pum_maxwidth_23', {'rows': 8})
2180 call term_sendkeys(buf, "\<ESC>")
2181
Hirohito Higashif13c8562025-03-30 15:19:05 +02002182 call StopVimInTerminal(buf)
2183endfunc
2184
glepnircf7f0122025-04-15 19:02:00 +02002185func Test_pum_clear_when_switch_tab_or_win()
2186 CheckScreendump
2187
2188 let lines =<< trim END
2189 inoremap <F4> <Cmd>wincmd w<CR>
2190 inoremap <F5> <Cmd>tabnext<CR>
2191 END
2192
2193 call writefile(lines, 'Xtest', 'D')
2194 let buf = RunVimInTerminal('-S Xtest', {})
2195
2196 call term_sendkeys(buf, ":tabe\<CR>")
2197 call TermWait(buf, 50)
2198 call term_sendkeys(buf, "Aaa aaa \<C-N>")
2199 call VerifyScreenDump(buf, 'Test_tabnext_clear_pum_01', {})
2200 call term_sendkeys(buf, "\<F5>")
2201 call TermWait(buf, 50)
2202 call VerifyScreenDump(buf, 'Test_tabnext_clear_pum_02', {})
2203 call term_sendkeys(buf, "\<ESC>:tabclose!\<CR>")
2204
2205 call term_sendkeys(buf, ":vnew win_b\<CR>")
2206 call TermWait(buf, 50)
2207 call term_sendkeys(buf, "Abb bbb \<C-N>")
2208 call VerifyScreenDump(buf, 'Test_switchwin_clear_pum_01', {})
2209 call term_sendkeys(buf, "\<F4>")
2210 call TermWait(buf, 50)
2211 call VerifyScreenDump(buf, 'Test_switchwin_clear_pum_02', {})
2212
2213 call StopVimInTerminal(buf)
2214endfunc
2215
glepnir6cc9bd42025-06-11 21:14:02 +02002216func Test_pum_position_when_wrap()
2217 CheckScreendump
2218 let lines =<< trim END
2219 func Omni_test(findstart, base)
2220 if a:findstart
2221 return col(".")
2222 endif
2223 return ['foo', 'bar', 'foobar']
2224 endfunc
2225 set omnifunc=Omni_test
2226 set wrap
2227 set cot+=noinsert
2228 END
2229 call writefile(lines, 'Xtest', 'D')
2230 let buf = RunVimInTerminal('-S Xtest', #{rows: 15, cols: 25})
2231
2232 let long_text = repeat('abcde ', 20)
2233 call term_sendkeys(buf, "i" .. long_text)
2234 call TermWait(buf, 50)
2235 call term_sendkeys(buf, "\<ESC>")
2236 call TermWait(buf, 50)
2237
2238 call term_sendkeys(buf, "5|")
2239 call TermWait(buf, 50)
2240 call term_sendkeys(buf, "a\<C-X>\<C-O>")
2241 call TermWait(buf, 100)
2242 call VerifyScreenDump(buf, 'Test_pum_wrap_line1', {})
2243 call term_sendkeys(buf, "\<ESC>")
2244 call TermWait(buf, 50)
2245
2246 call term_sendkeys(buf, "30|")
2247 call TermWait(buf, 50)
2248 call term_sendkeys(buf, "a\<C-X>\<C-O>")
2249 call TermWait(buf, 100)
2250 call VerifyScreenDump(buf, 'Test_pum_wrap_line2', {})
2251 call term_sendkeys(buf, "\<ESC>")
2252 call TermWait(buf, 50)
2253
2254 call term_sendkeys(buf, "55|")
2255 call TermWait(buf, 50)
2256 call term_sendkeys(buf, "a\<C-X>\<C-O>")
2257 call TermWait(buf, 100)
2258 call VerifyScreenDump(buf, 'Test_pum_wrap_line3', {})
2259 call term_sendkeys(buf, "\<C-E>\<ESC>")
2260 call TermWait(buf, 50)
2261
2262 call term_sendkeys(buf, "85|")
2263 call TermWait(buf, 50)
2264 call term_sendkeys(buf, "a\<C-X>\<C-O>")
2265 call TermWait(buf, 100)
2266 call VerifyScreenDump(buf, 'Test_pum_wrap_line4', {})
2267 call term_sendkeys(buf, "\<C-E>\<ESC>")
2268 call TermWait(buf, 100)
2269
2270 call term_sendkeys(buf, "108|")
2271 call TermWait(buf, 50)
2272 call term_sendkeys(buf, "a\<C-X>\<C-O>")
2273 call TermWait(buf, 100)
2274 call VerifyScreenDump(buf, 'Test_pum_wrap_line5', {})
2275 call term_sendkeys(buf, "\<C-E>\<ESC>")
2276 call TermWait(buf, 100)
2277
2278 call StopVimInTerminal(buf)
2279endfunc
2280
glepnircf7f0122025-04-15 19:02:00 +02002281
Bram Moolenaar47247282016-08-02 22:36:02 +02002282" vim: shiftwidth=2 sts=2 expandtab