robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
393.8 KiB10213 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local assert_alive = n.assert_alive
7local clear, feed = n.clear, n.feed
8local source = n.source
9local insert = n.insert
10local api = n.api
11local async_meths = n.async_meths
12local command = n.command
13local fn = n.fn
14local eq = t.eq
15local pcall_err = t.pcall_err
16local exec_lua = n.exec_lua
17local exec = n.exec
18local poke_eventloop = n.poke_eventloop
19
20describe('ui/ext_popupmenu', function()
21  local screen
22  before_each(function()
23    clear()
24    screen = Screen.new(60, 8, { rgb = true, ext_popupmenu = true })
25    source([[
26      function! TestComplete() abort
27        call complete(1, [{'word':'foo', 'abbr':'fo', 'menu':'the foo', 'info':'foo-y', 'kind':'x'}, 'bar', 'spam'])
28        return ''
29      endfunction
30    ]])
31  end)
32
33  local expected = {
34    { 'fo', 'x', 'the foo', 'foo-y' },
35    { 'bar', '', '', '' },
36    { 'spam', '', '', '' },
37  }
38
39  it('works', function()
40    feed('o<C-r>=TestComplete()<CR>')
41    screen:expect {
42      grid = [[
43                                                                  |
44      foo^                                                         |
45      {1:~                                                           }|*5
46      {5:-- INSERT --}                                                |
47      ]],
48      popupmenu = { items = expected, pos = 0, anchor = { 1, 1, 0 } },
49    }
50
51    feed('<c-p>')
52    screen:expect {
53      grid = [[
54                                                                    |
55        ^                                                            |
56        {1:~                                                           }|*5
57        {5:-- INSERT --}                                                |
58      ]],
59      popupmenu = { items = expected, pos = -1, anchor = { 1, 1, 0 } },
60    }
61
62    -- down moves the selection in the menu, but does not insert anything
63    feed('<down><down>')
64    screen:expect {
65      grid = [[
66                                                                    |
67        ^                                                            |
68        {1:~                                                           }|*5
69        {5:-- INSERT --}                                                |
70      ]],
71      popupmenu = { items = expected, pos = 1, anchor = { 1, 1, 0 } },
72    }
73
74    feed('<cr>')
75    screen:expect([[
76                                                                  |
77      bar^                                                         |
78      {1:~                                                           }|*5
79      {5:-- INSERT --}                                                |
80    ]])
81  end)
82
83  it('can be controlled by API', function()
84    feed('o<C-r>=TestComplete()<CR>')
85    screen:expect {
86      grid = [[
87                                                                  |
88      foo^                                                         |
89      {1:~                                                           }|*5
90      {5:-- INSERT --}                                                |
91      ]],
92      popupmenu = { items = expected, pos = 0, anchor = { 1, 1, 0 } },
93    }
94
95    api.nvim_select_popupmenu_item(1, false, false, {})
96    screen:expect {
97      grid = [[
98                                                                  |
99      foo^                                                         |
100      {1:~                                                           }|*5
101      {5:-- INSERT --}                                                |
102      ]],
103      popupmenu = { items = expected, pos = 1, anchor = { 1, 1, 0 } },
104    }
105
106    api.nvim_select_popupmenu_item(2, true, false, {})
107    screen:expect {
108      grid = [[
109                                                                  |
110      spam^                                                        |
111      {1:~                                                           }|*5
112      {5:-- INSERT --}                                                |
113      ]],
114      popupmenu = { items = expected, pos = 2, anchor = { 1, 1, 0 } },
115    }
116
117    api.nvim_select_popupmenu_item(0, true, true, {})
118    screen:expect([[
119                                                                  |
120      foo^                                                         |
121      {1:~                                                           }|*5
122      {5:-- INSERT --}                                                |
123    ]])
124
125    feed('<c-w><C-r>=TestComplete()<CR>')
126    screen:expect {
127      grid = [[
128                                                                  |
129      foo^                                                         |
130      {1:~                                                           }|*5
131      {5:-- INSERT --}                                                |
132      ]],
133      popupmenu = { items = expected, pos = 0, anchor = { 1, 1, 0 } },
134    }
135
136    api.nvim_select_popupmenu_item(-1, false, false, {})
137    screen:expect {
138      grid = [[
139                                                                  |
140      foo^                                                         |
141      {1:~                                                           }|*5
142      {5:-- INSERT --}                                                |
143      ]],
144      popupmenu = { items = expected, pos = -1, anchor = { 1, 1, 0 } },
145    }
146
147    api.nvim_select_popupmenu_item(1, true, false, {})
148    screen:expect {
149      grid = [[
150                                                                  |
151      bar^                                                         |
152      {1:~                                                           }|*5
153      {5:-- INSERT --}                                                |
154      ]],
155      popupmenu = { items = expected, pos = 1, anchor = { 1, 1, 0 } },
156    }
157
158    api.nvim_select_popupmenu_item(-1, true, false, {})
159    screen:expect {
160      grid = [[
161                                                                  |
162      ^                                                            |
163      {1:~                                                           }|*5
164      {5:-- INSERT --}                                                |
165      ]],
166      popupmenu = { items = expected, pos = -1, anchor = { 1, 1, 0 } },
167    }
168
169    api.nvim_select_popupmenu_item(0, true, false, {})
170    screen:expect {
171      grid = [[
172                                                                  |
173      foo^                                                         |
174      {1:~                                                           }|*5
175      {5:-- INSERT --}                                                |
176      ]],
177      popupmenu = { items = expected, pos = 0, anchor = { 1, 1, 0 } },
178    }
179
180    api.nvim_select_popupmenu_item(-1, true, true, {})
181    screen:expect([[
182                                                                  |
183      ^                                                            |
184      {1:~                                                           }|*5
185      {5:-- INSERT --}                                                |
186    ]])
187
188    command('set wildmenu')
189    command('set wildoptions=pum')
190    local expected_wildpum = {
191      { 'define', '', '', '' },
192      { 'jump', '', '', '' },
193      { 'list', '', '', '' },
194      { 'place', '', '', '' },
195      { 'undefine', '', '', '' },
196      { 'unplace', '', '', '' },
197    }
198    feed('<Esc>:sign <Tab>')
199    screen:expect({
200      grid = [[
201                                                                  |*2
202      {1:~                                                           }|*5
203      :sign define^                                                |
204    ]],
205      popupmenu = { items = expected_wildpum, pos = 0, anchor = { 1, 7, 6 } },
206    })
207
208    api.nvim_select_popupmenu_item(-1, true, false, {})
209    screen:expect({
210      grid = [[
211                                                                  |*2
212      {1:~                                                           }|*5
213      :sign ^                                                      |
214    ]],
215      popupmenu = { items = expected_wildpum, pos = -1, anchor = { 1, 7, 6 } },
216    })
217
218    api.nvim_select_popupmenu_item(5, true, false, {})
219    screen:expect({
220      grid = [[
221                                                                  |*2
222      {1:~                                                           }|*5
223      :sign unplace^                                               |
224    ]],
225      popupmenu = { items = expected_wildpum, pos = 5, anchor = { 1, 7, 6 } },
226    })
227
228    api.nvim_select_popupmenu_item(-1, true, true, {})
229    screen:expect({
230      grid = [[
231                                                                  |*2
232      {1:~                                                           }|*5
233      :sign ^                                                      |
234    ]],
235    })
236
237    feed('<Tab>')
238    screen:expect({
239      grid = [[
240                                                                  |*2
241      {1:~                                                           }|*5
242      :sign define^                                                |
243    ]],
244      popupmenu = { items = expected_wildpum, pos = 0, anchor = { 1, 7, 6 } },
245    })
246
247    api.nvim_select_popupmenu_item(5, true, true, {})
248    screen:expect([[
249                                                                  |*2
250      {1:~                                                           }|*5
251      :sign unplace^                                               |
252    ]])
253
254    local function test_pum_select_mappings()
255      screen:set_option('ext_popupmenu', true)
256      feed('<Esc>A<C-r>=TestComplete()<CR>')
257      screen:expect {
258        grid = [[
259                                                                    |
260        foo^                                                         |
261        {1:~                                                           }|*5
262        {5:-- INSERT --}                                                |
263      ]],
264        popupmenu = { items = expected, pos = 0, anchor = { 1, 1, 0 } },
265      }
266
267      feed('<f1>')
268      screen:expect {
269        grid = [[
270                                                                    |
271        spam^                                                        |
272        {1:~                                                           }|*5
273        {5:-- INSERT --}                                                |
274      ]],
275        popupmenu = { items = expected, pos = 2, anchor = { 1, 1, 0 } },
276      }
277
278      feed('<f2>')
279      screen:expect {
280        grid = [[
281                                                                    |
282        spam^                                                        |
283        {1:~                                                           }|*5
284        {5:-- INSERT --}                                                |
285      ]],
286        popupmenu = { items = expected, pos = -1, anchor = { 1, 1, 0 } },
287      }
288
289      feed('<f3>')
290      screen:expect([[
291                                                                    |
292        bar^                                                         |
293        {1:~                                                           }|*5
294        {5:-- INSERT --}                                                |
295      ]])
296
297      feed('<Esc>:sign <Tab>')
298      screen:expect({
299        grid = [[
300                                                                    |
301        bar                                                         |
302        {1:~                                                           }|*5
303        :sign define^                                                |
304      ]],
305        popupmenu = { items = expected_wildpum, pos = 0, anchor = { 1, 7, 6 } },
306      })
307
308      feed('<f1>')
309      screen:expect({
310        grid = [[
311                                                                    |
312        bar                                                         |
313        {1:~                                                           }|*5
314        :sign list^                                                  |
315      ]],
316        popupmenu = { items = expected_wildpum, pos = 2, anchor = { 1, 7, 6 } },
317      })
318
319      feed('<f2>')
320      screen:expect({
321        grid = [[
322                                                                    |
323        bar                                                         |
324        {1:~                                                           }|*5
325        :sign ^                                                      |
326      ]],
327        popupmenu = { items = expected_wildpum, pos = -1, anchor = { 1, 7, 6 } },
328      })
329
330      feed('<f3>')
331      screen:expect({
332        grid = [[
333                                                                    |
334        bar                                                         |
335        {1:~                                                           }|*5
336        :sign jump^                                                  |
337      ]],
338      })
339
340      -- also should work for builtin popupmenu
341      screen:set_option('ext_popupmenu', false)
342      feed('<Esc>A<C-r>=TestComplete()<CR>')
343      screen:expect([[
344                                                                    |
345        foo^                                                         |
346        {12:fo   x the foo }{1:                                             }|
347        {4:bar            }{1:                                             }|
348        {4:spam           }{1:                                             }|
349        {1:~                                                           }|*2
350        {5:-- INSERT --}                                                |
351      ]])
352
353      feed('<f1>')
354      screen:expect([[
355                                                                    |
356        spam^                                                        |
357        {4:fo   x the foo }{1:                                             }|
358        {4:bar            }{1:                                             }|
359        {12:spam           }{1:                                             }|
360        {1:~                                                           }|*2
361        {5:-- INSERT --}                                                |
362      ]])
363
364      feed('<f2>')
365      screen:expect([[
366                                                                    |
367        spam^                                                        |
368        {4:fo   x the foo }{1:                                             }|
369        {4:bar            }{1:                                             }|
370        {4:spam           }{1:                                             }|
371        {1:~                                                           }|*2
372        {5:-- INSERT --}                                                |
373      ]])
374
375      feed('<f3>')
376      screen:expect([[
377                                                                    |
378        bar^                                                         |
379        {1:~                                                           }|*5
380        {5:-- INSERT --}                                                |
381      ]])
382
383      feed('<Esc>:sign <Tab>')
384      screen:expect([[
385                                                                    |
386        bar  {12: define         }                                       |
387        {1:~    }{4: jump           }{1:                                       }|
388        {1:~    }{4: list           }{1:                                       }|
389        {1:~    }{4: place          }{1:                                       }|
390        {1:~    }{4: undefine       }{1:                                       }|
391        {1:~    }{4: unplace        }{1:                                       }|
392        :sign define^                                                |
393      ]])
394
395      feed('<f1>')
396      screen:expect([[
397                                                                    |
398        bar  {4: define         }                                       |
399        {1:~    }{4: jump           }{1:                                       }|
400        {1:~    }{12: list           }{1:                                       }|
401        {1:~    }{4: place          }{1:                                       }|
402        {1:~    }{4: undefine       }{1:                                       }|
403        {1:~    }{4: unplace        }{1:                                       }|
404        :sign list^                                                  |
405      ]])
406
407      feed('<f2>')
408      screen:expect([[
409                                                                    |
410        bar  {4: define         }                                       |
411        {1:~    }{4: jump           }{1:                                       }|
412        {1:~    }{4: list           }{1:                                       }|
413        {1:~    }{4: place          }{1:                                       }|
414        {1:~    }{4: undefine       }{1:                                       }|
415        {1:~    }{4: unplace        }{1:                                       }|
416        :sign ^                                                      |
417      ]])
418
419      feed('<f3>')
420      screen:expect([[
421                                                                    |
422        bar                                                         |
423        {1:~                                                           }|*5
424        :sign jump^                                                  |
425      ]])
426    end
427
428    command('map! <f1> <cmd>call nvim_select_popupmenu_item(2,v:true,v:false,{})<cr>')
429    command('map! <f2> <cmd>call nvim_select_popupmenu_item(-1,v:false,v:false,{})<cr>')
430    command('map! <f3> <cmd>call nvim_select_popupmenu_item(1,v:false,v:true,{})<cr>')
431    test_pum_select_mappings()
432
433    command('unmap! <f1>')
434    command('unmap! <f2>')
435    command('unmap! <f3>')
436    exec_lua([[
437      vim.keymap.set('!', '<f1>', function() vim.api.nvim_select_popupmenu_item(2, true, false, {}) end)
438      vim.keymap.set('!', '<f2>', function() vim.api.nvim_select_popupmenu_item(-1, false, false, {}) end)
439      vim.keymap.set('!', '<f3>', function() vim.api.nvim_select_popupmenu_item(1, false, true, {}) end)
440    ]])
441    test_pum_select_mappings()
442
443    feed('<esc>ddiaa bb cc<cr>')
444    feed('<c-x><c-n>')
445    screen:expect([[
446      aa bb cc                                                    |
447      aa^                                                          |
448      {12:aa             }{1:                                             }|
449      {4:bb             }{1:                                             }|
450      {4:cc             }{1:                                             }|
451      {1:~                                                           }|*2
452      {5:-- Keyword Local completion (^N^P) }{6:match 1 of 3}             |
453    ]])
454
455    feed('<f1>')
456    screen:expect([[
457      aa bb cc                                                    |
458      cc^                                                          |
459      {4:aa             }{1:                                             }|
460      {4:bb             }{1:                                             }|
461      {12:cc             }{1:                                             }|
462      {1:~                                                           }|*2
463      {5:-- Keyword Local completion (^N^P) }{6:match 3 of 3}             |
464    ]])
465
466    feed('<f2>')
467    screen:expect([[
468      aa bb cc                                                    |
469      cc^                                                          |
470      {4:aa             }{1:                                             }|
471      {4:bb             }{1:                                             }|
472      {4:cc             }{1:                                             }|
473      {1:~                                                           }|*2
474      {5:-- Keyword Local completion (^N^P) }{19:Back at original}         |
475    ]])
476
477    feed('<f3>')
478    screen:expect([[
479      aa bb cc                                                    |
480      bb^                                                          |
481      {1:~                                                           }|*5
482      {5:-- INSERT --}                                                |
483    ]])
484  end)
485
486  local function source_complete_month()
487    source([[
488    function! TestCompleteMonth() abort
489    call complete(1, ['January', 'February', 'March', 'April',
490    \ 'May', 'June', 'July', 'August',
491    \ 'September', 'October', 'November', 'December'])
492    return ''
493    endfunction
494    ]])
495  end
496
497  describe('pum_set_height', function()
498    it('can set pum height', function()
499      source_complete_month()
500      local month_expected = {
501        { 'January', '', '', '' },
502        { 'February', '', '', '' },
503        { 'March', '', '', '' },
504        { 'April', '', '', '' },
505        { 'May', '', '', '' },
506        { 'June', '', '', '' },
507        { 'July', '', '', '' },
508        { 'August', '', '', '' },
509        { 'September', '', '', '' },
510        { 'October', '', '', '' },
511        { 'November', '', '', '' },
512        { 'December', '', '', '' },
513      }
514      local pum_height = 6
515      feed('o<C-r>=TestCompleteMonth()<CR>')
516      api.nvim_ui_pum_set_height(pum_height)
517      feed('<PageDown>')
518      -- pos becomes pum_height-2 because it is subtracting 2 to keep some
519      -- context in ins_compl_key2count()
520      screen:expect {
521        grid = [[
522                                                                  |
523      January^                                                     |
524      {1:~                                                           }|*5
525      {5:-- INSERT --}                                                |
526      ]],
527        popupmenu = { items = month_expected, pos = pum_height - 2, anchor = { 1, 1, 0 } },
528      }
529    end)
530
531    it('an error occurs if set 0 or less', function()
532      api.nvim_ui_pum_set_height(1)
533      eq('Expected pum height > 0', pcall_err(api.nvim_ui_pum_set_height, 0))
534    end)
535
536    it('an error occurs when ext_popupmenu is false', function()
537      api.nvim_ui_pum_set_height(1)
538      screen:set_option('ext_popupmenu', false)
539      eq('UI must support the ext_popupmenu option', pcall_err(api.nvim_ui_pum_set_height, 1))
540    end)
541  end)
542
543  describe('pum_set_bounds', function()
544    it('can set pum bounds', function()
545      source_complete_month()
546      local month_expected = {
547        { 'January', '', '', '' },
548        { 'February', '', '', '' },
549        { 'March', '', '', '' },
550        { 'April', '', '', '' },
551        { 'May', '', '', '' },
552        { 'June', '', '', '' },
553        { 'July', '', '', '' },
554        { 'August', '', '', '' },
555        { 'September', '', '', '' },
556        { 'October', '', '', '' },
557        { 'November', '', '', '' },
558        { 'December', '', '', '' },
559      }
560      local pum_height = 6
561      feed('o<C-r>=TestCompleteMonth()<CR>')
562      api.nvim_ui_pum_set_height(pum_height)
563      -- set bounds w h r c
564      api.nvim_ui_pum_set_bounds(10.5, 5.2, 6.3, 7.4)
565      feed('<PageDown>')
566      -- pos becomes pum_height-2 because it is subtracting 2 to keep some
567      -- context in ins_compl_key2count()
568      screen:expect {
569        grid = [[
570                                                                  |
571      January^                                                     |
572      {1:~                                                           }|*5
573      {5:-- INSERT --}                                                |
574      ]],
575        popupmenu = { items = month_expected, pos = pum_height - 2, anchor = { 1, 1, 0 } },
576      }
577    end)
578
579    it('no error occurs if row or col set less than 0', function()
580      api.nvim_ui_pum_set_bounds(1.0, 1.0, 0.0, 1.5)
581      api.nvim_ui_pum_set_bounds(1.0, 1.0, -1.0, 0.0)
582      api.nvim_ui_pum_set_bounds(1.0, 1.0, 0.0, -1.0)
583    end)
584
585    it('an error occurs if width or height set 0 or less', function()
586      api.nvim_ui_pum_set_bounds(1.0, 1.0, 0.0, 1.5)
587      eq('Expected width > 0', pcall_err(api.nvim_ui_pum_set_bounds, 0.0, 1.0, 1.0, 0.0))
588      eq('Expected height > 0', pcall_err(api.nvim_ui_pum_set_bounds, 1.0, -1.0, 1.0, 0.0))
589    end)
590
591    it('an error occurs when ext_popupmenu is false', function()
592      api.nvim_ui_pum_set_bounds(1.0, 1.0, 0.0, 1.5)
593      screen:set_option('ext_popupmenu', false)
594      eq(
595        'UI must support the ext_popupmenu option',
596        pcall_err(api.nvim_ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5)
597      )
598    end)
599  end)
600
601  it('<PageUp>, <PageDown> works without ui_pum_set_height', function()
602    source_complete_month()
603    local month_expected = {
604      { 'January', '', '', '' },
605      { 'February', '', '', '' },
606      { 'March', '', '', '' },
607      { 'April', '', '', '' },
608      { 'May', '', '', '' },
609      { 'June', '', '', '' },
610      { 'July', '', '', '' },
611      { 'August', '', '', '' },
612      { 'September', '', '', '' },
613      { 'October', '', '', '' },
614      { 'November', '', '', '' },
615      { 'December', '', '', '' },
616    }
617    feed('o<C-r>=TestCompleteMonth()<CR>')
618    feed('<PageDown>')
619    screen:expect {
620      grid = [[
621                                                                |
622    January^                                                     |
623    {1:~                                                           }|*5
624    {5:-- INSERT --}                                                |
625    ]],
626      popupmenu = { items = month_expected, pos = 3, anchor = { 1, 1, 0 } },
627    }
628    feed('<PageUp>')
629    screen:expect {
630      grid = [[
631                                                                |
632    January^                                                     |
633    {1:~                                                           }|*5
634    {5:-- INSERT --}                                                |
635    ]],
636      popupmenu = { items = month_expected, pos = 0, anchor = { 1, 1, 0 } },
637    }
638  end)
639
640  it('works with wildoptions=pum', function()
641    screen:try_resize(32, 10)
642    command('set wildmenu')
643    command('set wildoptions=pum')
644
645    local wild_expected = {
646      { 'define', '', '', '' },
647      { 'jump', '', '', '' },
648      { 'list', '', '', '' },
649      { 'place', '', '', '' },
650      { 'undefine', '', '', '' },
651      { 'unplace', '', '', '' },
652    }
653
654    feed(':sign ')
655    screen:expect([[
656                                      |
657      {1:~                               }|*8
658      :sign ^                          |
659    ]])
660    eq(0, fn.wildmenumode())
661
662    feed('<tab>')
663    screen:expect {
664      grid = [[
665                                      |
666      {1:~                               }|*8
667      :sign define^                    |
668    ]],
669      popupmenu = { items = wild_expected, pos = 0, anchor = { 1, 9, 6 } },
670    }
671    eq(1, fn.wildmenumode())
672
673    feed('<left>')
674    screen:expect {
675      grid = [[
676                                      |
677      {1:~                               }|*8
678      :sign ^                          |
679    ]],
680      popupmenu = { items = wild_expected, pos = -1, anchor = { 1, 9, 6 } },
681    }
682
683    feed('<left>')
684    screen:expect {
685      grid = [[
686                                      |
687      {1:~                               }|*8
688      :sign unplace^                   |
689    ]],
690      popupmenu = { items = wild_expected, pos = 5, anchor = { 1, 9, 6 } },
691    }
692
693    feed('x')
694    screen:expect([[
695                                      |
696      {1:~                               }|*8
697      :sign unplacex^                  |
698    ]])
699    feed('<esc>')
700
701    -- #10042: make sure shift-tab also triggers the pum
702    feed(':sign <S-tab>')
703    screen:expect {
704      grid = [[
705                                      |
706      {1:~                               }|*8
707      :sign unplace^                   |
708    ]],
709      popupmenu = { items = wild_expected, pos = 5, anchor = { 1, 9, 6 } },
710    }
711    feed('<esc>')
712    eq(0, fn.wildmenumode())
713
714    -- check positioning with multibyte char in pattern
715    command('e långfile1')
716    command('sp långfile2')
717    feed(':b lå<tab>')
718    screen:expect {
719      grid = [[
720                                      |
721      {1:~                               }|*3
722      {3:långfile2                       }|
723                                      |
724      {1:~                               }|*2
725      {2:långfile1                       }|
726      :b långfile1^                    |
727    ]],
728      popupmenu = {
729        anchor = { 1, 9, 3 },
730        items = { { 'långfile1', '', '', '' }, { 'långfile2', '', '', '' } },
731        pos = 0,
732      },
733    }
734  end)
735
736  it('does not interfere with mousemodel=popup', function()
737    exec([[
738      set mouse=a mousemodel=popup
739
740      aunmenu PopUp
741      " Delete the default MenuPopup event handler.
742      autocmd! nvim.popupmenu
743      menu PopUp.foo :let g:menustr = 'foo'<CR>
744      menu PopUp.bar :let g:menustr = 'bar'<CR>
745      menu PopUp.baz :let g:menustr = 'baz'<CR>
746    ]])
747    feed('o<C-r>=TestComplete()<CR>')
748    screen:expect {
749      grid = [[
750                                                                  |
751      foo^                                                         |
752      {1:~                                                           }|*5
753      {5:-- INSERT --}                                                |
754    ]],
755      popupmenu = { items = expected, pos = 0, anchor = { 1, 1, 0 } },
756    }
757
758    feed('<c-p>')
759    screen:expect {
760      grid = [[
761                                                                  |
762      ^                                                            |
763      {1:~                                                           }|*5
764      {5:-- INSERT --}                                                |
765    ]],
766      popupmenu = { items = expected, pos = -1, anchor = { 1, 1, 0 } },
767    }
768
769    feed('<esc>')
770    screen:expect([[
771                                                                  |
772      ^                                                            |
773      {1:~                                                           }|*5
774                                                                  |
775    ]])
776    feed('<RightMouse><0,0>')
777    screen:expect([[
778                                                                  |
779      {4:^foo }                                                        |
780      {4:bar }{1:                                                        }|
781      {4:baz }{1:                                                        }|
782      {1:~                                                           }|*3
783                                                                  |
784    ]])
785    feed('<esc>')
786    screen:expect([[
787                                                                  |
788      ^                                                            |
789      {1:~                                                           }|*5
790                                                                  |
791    ]])
792  end)
793end)
794
795describe("builtin popupmenu 'pumblend'", function()
796  local screen
797  before_each(function()
798    clear()
799    screen = Screen.new(60, 14)
800    screen:add_extra_attr_ids({
801      [100] = { background = Screen.colors.Gray55, foreground = Screen.colors.Grey45 },
802      [101] = { background = Screen.colors.Gray55, foreground = Screen.colors.Grey0 },
803      [102] = { background = tonumber('0x191919'), foreground = Screen.colors.Grey0 },
804      [103] = { background = tonumber('0xffc1ff'), foreground = tonumber('0xe5a8e5') },
805      [104] = { background = tonumber('0xffc1ff'), foreground = Screen.colors.Grey0 },
806      [105] = { foreground = tonumber('0xffc1ff'), background = tonumber('0xe5a8e5'), bold = true },
807      [106] = { foreground = Screen.colors.Grey55, background = Screen.colors.Gray45, bold = true },
808      [107] = { background = tonumber('0xffc1e5'), foreground = Screen.colors.Grey0 },
809      [108] = { background = tonumber('0xffc1e5'), foreground = tonumber('0xe5a8e5') },
810      [109] = { background = tonumber('0xffc1ff'), foreground = tonumber('0x080202') },
811      [110] = { background = tonumber('0xffc1ff'), bold = true, foreground = tonumber('0xf6ace9') },
812      [111] = { background = tonumber('0xffc1ff'), foreground = tonumber('0xe5a8ff') },
813      [112] = { background = tonumber('0xe5a8e5'), foreground = tonumber('0xffc1ff') },
814      [113] = { background = Screen.colors.Gray45, foreground = Screen.colors.Grey55 },
815      [114] = { background = Screen.colors.WebGray },
816      [115] = { background = Screen.colors.Grey0 },
817      [116] = { background = Screen.colors.Gray75, foreground = Screen.colors.Grey25 },
818      [117] = { background = Screen.colors.Gray75, foreground = Screen.colors.Grey0 },
819      [118] = { background = Screen.colors.Gray50, foreground = Screen.colors.Grey0 },
820      [119] = { background = tonumber('0xffddff'), foreground = tonumber('0x7f5d7f') },
821      [120] = { background = tonumber('0xffddff'), foreground = Screen.colors.Grey0 },
822      [121] = { foreground = tonumber('0xffddff'), background = tonumber('0x7f5d7f'), bold = true },
823      [123] = { foreground = tonumber('0xffddff'), background = Screen.colors.Grey0, bold = true },
824      [124] = { foreground = Screen.colors.Gray75, background = Screen.colors.Grey25, bold = true },
825      [125] = { background = tonumber('0xffdd7f'), foreground = Screen.colors.Grey0 },
826      [126] = { background = tonumber('0xffdd7f'), foreground = tonumber('0x7f5d7f') },
827      [127] = { background = tonumber('0xffddff'), bold = true, foreground = tonumber('0x290a0a') },
828      [128] = { background = tonumber('0xffddff'), bold = true, foreground = tonumber('0xd27294') },
829      [129] = { background = tonumber('0xffddff'), foreground = tonumber('0x7f5dff') },
830      [130] = { background = tonumber('0x7f5d7f'), foreground = tonumber('0xffddff') },
831      [131] = { background = Screen.colors.Grey0, foreground = tonumber('0xffddff') },
832      [132] = { background = Screen.colors.Gray25, foreground = Screen.colors.Grey75 },
833      [134] = { background = tonumber('0xffddff'), foreground = tonumber('0x00003f') },
834      [135] = { foreground = tonumber('0x0c0c0c'), background = tonumber('0xe5a8e5') },
835      [136] = { background = tonumber('0x7f5d7f'), bold = true, foreground = tonumber('0x3f3f3f') },
836      [137] = { foreground = tonumber('0x3f3f3f'), background = tonumber('0x7f5d7f') },
837      [138] = { background = Screen.colors.WebGray, blend = 0 },
838      [139] = { background = 7, foreground = Screen.colors.Gray0 },
839      [140] = { background = 7, foreground = 85 },
840      [141] = { background = 225, foreground = Screen.colors.Gray0 },
841      [142] = { background = 225, foreground = 209 },
842      [143] = { foreground = 12 },
843      [144] = { foreground = 2 },
844      [145] = { foreground = tonumber('0x290a0a'), background = tonumber('0xffddff') },
845    })
846  end)
847
848  it('RGB-color', function()
849    command('syntax on')
850    command('set mouse=a')
851    command('set pumblend=10')
852    insert([[
853      Lorem ipsum dolor sit amet, consectetur
854      adipisicing elit, sed do eiusmod tempor
855      incididunt ut labore et dolore magna aliqua.
856      Ut enim ad minim veniam, quis nostrud
857      exercitation ullamco laboris nisi ut aliquip ex
858      ea commodo consequat. Duis aute irure dolor in
859      reprehenderit in voluptate velit esse cillum
860      dolore eu fugiat nulla pariatur. Excepteur sint
861      occaecat cupidatat non proident, sunt in culpa
862      qui officia deserunt mollit anim id est
863      laborum.]])
864    command('match Statement /el/')
865    command('2match Comment /ut/')
866    command('1')
867    command('split')
868    command('/ol')
869    screen:expect([[
870      Lorem ipsum d{10:ol}or sit amet, consectetur                     |
871      adipisicing elit, sed do eiusmod tempor                     |
872      ^incididunt ut labore et d{10:ol}ore magna aliqua.                |
873      Ut enim ad minim veniam, quis nostrud                       |
874      exercitation ullamco laboris nisi ut aliquip ex             |
875      ea commodo consequat. Duis aute irure d{10:ol}or in              |
876      {3:[No Name] [+]                                               }|
877      Lorem ipsum d{10:ol}or sit amet, consectetur                     |
878      adipisicing {15:el}it, sed do eiusmod tempor                     |
879      incididunt {18:ut} labore et d{10:ol}ore magna aliqua.                |
880      Ut enim ad minim veniam, quis nostrud                       |
881      exercitation ullamco laboris nisi {18:ut} aliquip ex             |
882      {2:[No Name] [+]                                               }|
883                                                                  |
884    ]])
885
886    feed('Obla bla <c-x><c-n>')
887    screen:expect([[
888      Lorem ipsum d{10:ol}or sit amet, consectetur                     |
889      adipisicing elit, sed do eiusmod tempor                     |
890      bla bla incididunt^                                          |
891      incidid{100:u}{101:incididunt}{100:re et}{102: }d{10:ol}ore magna aliqua.                |
892      Ut enim{103: }{104:ut}{103: minim veniam}{100:,} quis nostrud                       |
893      exercit{103:a}{104:labore}{103:llamco la}{100:b}oris nisi ut aliquip ex             |
894      {3:[No Nam}{105:e}{135:et}{105:[+]          }{106: }{3:                                    }|
895      Lorem i{103:p}{104:dolor}{107:e}{108:l}{103:or sit a}{100:m}et, consectetur                     |
896      adipisi{103:c}{104:magn}{109:a}{110:l}{103:it, sed d}{100:o} eiusmod tempor                     |
897      bla bla{103: }{104:aliqua}{103:dunt     }{100: }                                    |
898      incidid{103:u}{104:Ut}{103: }{111:ut}{103: labore et}{100: }d{10:ol}ore magna aliqua.                |
899      Ut enim{103: }{104:enim}{103:inim veniam}{100:,} quis nostrud                       |
900      {2:[No Nam}{112:e}{135:ad}{112:[+]          }{113: }{2:                                    }|
901      {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
902    ]])
903
904    command('set pumblend=0')
905    screen:expect([[
906      Lorem ipsum d{10:ol}or sit amet, consectetur                     |
907      adipisicing elit, sed do eiusmod tempor                     |
908      bla bla incididunt^                                          |
909      incidid{114: incididunt     }{115: }d{10:ol}ore magna aliqua.                |
910      Ut enim{4: ut             }{114: } quis nostrud                       |
911      exercit{4: labore         }{114: }oris nisi ut aliquip ex             |
912      {3:[No Nam}{4: et             }{114: }{3:                                    }|
913      Lorem i{4: dolore         }{114: }et, consectetur                     |
914      adipisi{4: magna          }{114: } eiusmod tempor                     |
915      bla bla{4: aliqua         }{114: }                                    |
916      incidid{4: Ut             }{114: }d{10:ol}ore magna aliqua.                |
917      Ut enim{4: enim           }{114: } quis nostrud                       |
918      {2:[No Nam}{4: ad             }{114: }{2:                                    }|
919      {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
920    ]])
921
922    command('set pumblend=50')
923    screen:expect([[
924      Lorem ipsum d{10:ol}or sit amet, consectetur                     |
925      adipisicing elit, sed do eiusmod tempor                     |
926      bla bla incididunt^                                          |
927      incidid{116:u}{117:incididunt}{116:re et}{118: }d{10:ol}ore magna aliqua.                |
928      Ut enim{119: }{120:ut}{119: minim veniam}{116:,} quis nostrud                       |
929      exercit{119:a}{120:labore}{119:llamco la}{116:b}oris nisi ut aliquip ex             |
930      {3:[No Nam}{121:e}{137:et}{121:[+]          }{124: }{3:                                    }|
931      Lorem i{119:p}{120:dolor}{125:e}{126:l}{119:or sit a}{116:m}et, consectetur                     |
932      adipisi{119:c}{120:magn}{145:a}{128:l}{119:it, sed d}{116:o} eiusmod tempor                     |
933      bla bla{119: }{120:aliqua}{119:dunt     }{116: }                                    |
934      incidid{119:u}{120:Ut}{119: }{129:ut}{119: labore et}{116: }d{10:ol}ore magna aliqua.                |
935      Ut enim{119: }{120:enim}{119:inim veniam}{116:,} quis nostrud                       |
936      {2:[No Nam}{130:e}{137:ad}{130:[+]          }{132: }{2:                                    }|
937      {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
938    ]])
939
940    api.nvim_input_mouse('wheel', 'down', '', 0, 9, 40)
941    screen:expect([[
942      Lorem ipsum d{10:ol}or sit amet, consectetur                     |
943      adipisicing elit, sed do eiusmod tempor                     |
944      bla bla incididunt^                                          |
945      incidid{116:u}{117:incididunt}{116:re et}{118: }d{10:ol}ore magna aliqua.                |
946      Ut enim{119: }{120:ut}{119: minim veniam}{116:,} quis nostrud                       |
947      exercit{119:a}{120:labore}{119:llamco la}{116:b}oris nisi ut aliquip ex             |
948      {3:[No Nam}{121:e}{137:et}{121:[+]          }{124: }{3:                                    }|
949      incidid{119:u}{120:dol}{134:or}{120:e}{119:labore et}{116: }d{10:ol}ore magna aliqua.                |
950      Ut enim{119: }{120:magna}{119:nim veniam}{116:,} quis nostrud                       |
951      exercit{119:a}{120:aliqua}{119:llamco la}{116:b}oris nisi {18:ut} aliquip ex             |
952      ea comm{119:o}{120:Ut}{119: consequat. D}{116:u}is a{18:ut}e irure d{10:ol}or in              |
953      reprehe{119:n}{120:enim}{119:t in v}{126:ol}{119:upt}{116:a}te v{15:el}it esse cillum                |
954      {2:[No Nam}{130:e}{137:ad}{130:[+]          }{132: }{2:                                    }|
955      {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
956    ]])
957
958    -- can disable blending for individual attribute. For instance current
959    -- selected item. (also tests that `hi Pmenu*` take immediate effect)
960    command('hi PMenuSel blend=0')
961    screen:expect([[
962      Lorem ipsum d{10:ol}or sit amet, consectetur                     |
963      adipisicing elit, sed do eiusmod tempor                     |
964      bla bla incididunt^                                          |
965      incidid{138: incididunt     }{118: }d{10:ol}ore magna aliqua.                |
966      Ut enim{119: }{120:ut}{119: minim veniam}{116:,} quis nostrud                       |
967      exercit{119:a}{120:labore}{119:llamco la}{116:b}oris nisi ut aliquip ex             |
968      {3:[No Nam}{121:e}{137:et}{121:[+]          }{124: }{3:                                    }|
969      incidid{119:u}{120:dol}{134:or}{120:e}{119:labore et}{116: }d{10:ol}ore magna aliqua.                |
970      Ut enim{119: }{120:magna}{119:nim veniam}{116:,} quis nostrud                       |
971      exercit{119:a}{120:aliqua}{119:llamco la}{116:b}oris nisi {18:ut} aliquip ex             |
972      ea comm{119:o}{120:Ut}{119: consequat. D}{116:u}is a{18:ut}e irure d{10:ol}or in              |
973      reprehe{119:n}{120:enim}{119:t in v}{126:ol}{119:upt}{116:a}te v{15:el}it esse cillum                |
974      {2:[No Nam}{130:e}{137:ad}{130:[+]          }{132: }{2:                                    }|
975      {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
976    ]])
977
978    feed('<c-e>')
979    screen:expect([[
980      Lorem ipsum d{10:ol}or sit amet, consectetur                     |
981      adipisicing elit, sed do eiusmod tempor                     |
982      bla bla ^                                                    |
983      incididunt ut labore et d{10:ol}ore magna aliqua.                |
984      Ut enim ad minim veniam, quis nostrud                       |
985      exercitation ullamco laboris nisi ut aliquip ex             |
986      {3:[No Name] [+]                                               }|
987      incididunt {18:ut} labore et d{10:ol}ore magna aliqua.                |
988      Ut enim ad minim veniam, quis nostrud                       |
989      exercitation ullamco laboris nisi {18:ut} aliquip ex             |
990      ea commodo consequat. Duis a{18:ut}e irure d{10:ol}or in              |
991      reprehenderit in v{10:ol}uptate v{15:el}it esse cillum                |
992      {2:[No Name] [+]                                               }|
993      {5:-- INSERT --}                                                |
994    ]])
995  end)
996
997  it('256-color (non-RGB)', function()
998    screen._options.rgb = false
999    command('set pumblend=10')
1000    insert([[
1001      Lorem ipsum dolor sit amet, consectetur
1002      adipisicing elit, sed do eiusmod tempor
1003      incididunt ut labore et dolore magna aliqua.
1004      Ut enim ad minim veniam, quis nostrud
1005      laborum.]])
1006
1007    feed('ggOdo<c-x><c-n>')
1008    screen:expect([[
1009      dolor^                                                       |
1010      {139:dolor}{140: ipsum dol}or sit amet, consectetur                     |
1011      {141:do}{142:ipisicing eli}t, sed do eiusmod tempor                     |
1012      {141:dolore}{142:dunt ut l}abore et dolore magna aliqua.                |
1013      Ut enim ad minim veniam, quis nostrud                       |
1014      laborum.                                                    |
1015      {143:~                                                           }|*7
1016      {5:-- Keyword Local completion (^N^P) }{144:match 1 of 3}             |
1017    ]])
1018  end)
1019end)
1020
1021describe('builtin popupmenu', function()
1022  before_each(clear)
1023
1024  local function with_ext_multigrid(multigrid, send_mouse_grid)
1025    local screen
1026    before_each(function()
1027      screen = Screen.new(32, 20, { ext_multigrid = multigrid })
1028      screen:add_extra_attr_ids({
1029        [100] = { foreground = Screen.colors.Yellow, background = Screen.colors.Green },
1030        [101] = { foreground = Screen.colors.White, background = Screen.colors.Green },
1031        [102] = { foreground = Screen.colors.Brown, bold = true, background = Screen.colors.Plum1 },
1032        [103] = { foreground = Screen.colors.DarkCyan, background = Screen.colors.Plum1 },
1033        [104] = { foreground = Screen.colors.SlateBlue, background = Screen.colors.Plum1 },
1034        [105] = { foreground = Screen.colors.Magenta1, background = Screen.colors.Plum1 },
1035        [106] = {
1036          foreground = Screen.colors.Red,
1037          italic = true,
1038          background = Screen.colors.Gray,
1039          strikethrough = true,
1040          underline = true,
1041        },
1042        [107] = {
1043          background = Screen.colors.Grey100,
1044          foreground = Screen.colors.Black,
1045          italic = true,
1046          bold = true,
1047          underline = true,
1048          strikethrough = true,
1049        },
1050        [108] = {
1051          italic = true,
1052          background = Screen.colors.Gray,
1053          underline = true,
1054          foreground = Screen.colors.Grey100,
1055        },
1056        [109] = {
1057          foreground = Screen.colors.Yellow,
1058          italic = true,
1059          bold = true,
1060          underline = true,
1061          background = Screen.colors.Pink,
1062        },
1063        [110] = { background = Screen.colors.Grey, foreground = Screen.colors.DarkYellow },
1064        [111] = { background = Screen.colors.Plum1, foreground = Screen.colors.DarkBlue },
1065        [112] = { background = Screen.colors.Plum1, foreground = Screen.colors.DarkGreen },
1066        [113] = { background = Screen.colors.Yellow, foreground = Screen.colors.Black },
1067        [114] = { background = Screen.colors.Black, blend = 100 },
1068        [115] = { background = Screen.colors.Black, blend = 80 },
1069        [116] = { foreground = Screen.colors.Black },
1070        [117] = { background = Screen.colors.Grey80, foreground = Screen.colors.Black },
1071        -- popup non-selected item
1072        n = { background = Screen.colors.Plum1 },
1073        -- popup scrollbar knob
1074        c = { background = Screen.colors.Black },
1075        ks = { foreground = Screen.colors.Red, background = Screen.colors.Grey },
1076        kn = { foreground = Screen.colors.Red, background = Screen.colors.Plum1 },
1077        xs = { foreground = Screen.colors.Black, background = Screen.colors.Grey },
1078        xn = { foreground = Screen.colors.White, background = Screen.colors.Plum1 },
1079        ms = { foreground = Screen.colors.Blue, background = Screen.colors.Grey },
1080        mn = { foreground = Screen.colors.Blue, background = Screen.colors.Plum1 },
1081        ds = { foreground = Screen.colors.DarkRed, background = Screen.colors.Grey },
1082        dn = { foreground = Screen.colors.DarkRed, background = Screen.colors.Plum1 },
1083        ums = {
1084          foreground = Screen.colors.Blue,
1085          background = Screen.colors.Grey,
1086          underline = true,
1087        },
1088        umn = {
1089          foreground = Screen.colors.Blue,
1090          background = Screen.colors.Plum1,
1091          underline = true,
1092        },
1093        uds = {
1094          foreground = Screen.colors.DarkRed,
1095          background = Screen.colors.Grey,
1096          underline = true,
1097        },
1098        udn = {
1099          foreground = Screen.colors.DarkRed,
1100          background = Screen.colors.Plum1,
1101          underline = true,
1102        },
1103      })
1104    end)
1105
1106    -- oldtest: Test_pum_position_with_concealed_text()
1107    it('position with fully concealed text', function()
1108      screen:try_resize(55, 10)
1109      exec([[
1110        call setline(1, ['CONCEALED foobar', 'CONCEALED foo'])
1111        syntax match Hidden /CONCEALED / conceal
1112        setlocal conceallevel=3 concealcursor=nvic
1113        set completeopt=menu,menuone
1114      ]])
1115      feed('2GA')
1116      poke_eventloop()
1117      feed('<C-X><C-N>')
1118      if multigrid then
1119        screen:expect({
1120          float_pos = { [4] = { -1, 'NW', 2, 2, 0, false, 100, 1, 2, 0 } },
1121        })
1122      else
1123        screen:expect([[
1124          foobar                                                 |
1125          foobar^                                                 |
1126          {12:foobar         }{1:                                        }|
1127          {1:~                                                      }|*6
1128          {5:-- Keyword Local completion (^N^P) The only match}      |
1129        ]])
1130      end
1131    end)
1132
1133    -- oldtest: Test_pum_position_with_concealed_match()
1134    it('position with concealed text replacement char', function()
1135      screen:try_resize(55, 10)
1136      exec([[
1137        call setline(1, ['XXX foobar', 'XXX foo'])
1138        call matchadd('Conceal', 'XXX ', 10, -1, {'conceal': '+'})
1139        setlocal conceallevel=2 concealcursor=nvic
1140        set completeopt=menu,menuone
1141      ]])
1142      feed('2GA')
1143      poke_eventloop()
1144      feed('<C-X><C-N>')
1145      if multigrid then
1146        screen:expect({
1147          float_pos = { [4] = { -1, 'NW', 2, 2, 0, false, 100, 1, 2, 0 } },
1148        })
1149      else
1150        screen:expect([[
1151          {14:+}foobar                                                |
1152          {14:+}foobar^                                                |
1153          {12: foobar         }{1:                                       }|
1154          {1:~                                                      }|*6
1155          {5:-- Keyword Local completion (^N^P) The only match}      |
1156        ]])
1157      end
1158    end)
1159
1160    -- oldtest: Test_pum_position_with_concealed_rl()
1161    it('position with concealed text and rightleft', function()
1162      screen:try_resize(55, 10)
1163      exec([[
1164        set rightleft
1165        call setline(1, ['CONCEALED foobar', 'CONCEALED foo'])
1166        syntax match Hidden /CONCEALED / conceal
1167        setlocal conceallevel=3 concealcursor=nvic
1168        set completeopt=menu,menuone
1169      ]])
1170      feed('2GA')
1171      poke_eventloop()
1172      feed('<C-X><C-N>')
1173      if multigrid then
1174        screen:expect({
1175          float_pos = { [4] = { -1, 'NW', 2, 2, 40, false, 100, 1, 2, 40 } },
1176        })
1177      else
1178        screen:expect([[
1179                                                           raboof|
1180                                                          ^ raboof|
1181          {1:                                        }{12:         raboof}|
1182          {1:                                                      ~}|*6
1183          {5:-- Keyword Local completion (^N^P) The only match}      |
1184        ]])
1185      end
1186    end)
1187
1188    -- oldtest: Test_pum_position_with_concealed_wrap()
1189    it('position with wrapped concealed text', function()
1190      screen:try_resize(20, 10)
1191      exec([[
1192        call setline(1, ['foobar', 'aaaaaaaaaaaaaaaaaaaa CONCEALED foo'])
1193        syntax match Hidden /CONCEALED / conceal
1194        setlocal conceallevel=3 concealcursor=nvic
1195        set completeopt=menu,menuone
1196      ]])
1197      feed('2GA')
1198      poke_eventloop()
1199      feed('<C-X><C-N>')
1200      if multigrid then
1201        screen:expect({
1202          float_pos = { [4] = { -1, 'NW', 2, 3, 0, false, 100, 1, 3, 0 } },
1203        })
1204      else
1205        screen:expect([[
1206          foobar              |
1207          aaaaaaaaaaaaaaaaaaaa|
1208           foobar^             |
1209          {12: foobar         }{1:    }|
1210          {1:~                   }|*5
1211          {5:-- The only match}   |
1212        ]])
1213      end
1214    end)
1215
1216    it('with preview-window above', function()
1217      feed(':ped<CR><c-w>4+')
1218      feed('iaa bb cc dd ee ff gg hh ii jj<cr>')
1219      feed('<c-x><c-n>')
1220      if multigrid then
1221        screen:expect {
1222          grid = [[
1223        ## grid 1
1224          [4:--------------------------------]|*8
1225          {2:[No Name] [Preview][+]          }|
1226          [2:--------------------------------]|*9
1227          {3:[No Name] [+]                   }|
1228          [3:--------------------------------]|
1229        ## grid 2
1230          aa bb cc dd ee ff gg hh ii jj   |
1231          aa^                              |
1232          {1:~                               }|*7
1233        ## grid 3
1234          {5:-- }{6:match 1 of 10}                |
1235        ## grid 4
1236          aa bb cc dd ee ff gg hh ii jj   |
1237          aa                              |
1238          {1:~                               }|*6
1239        ## grid 5
1240          {12:aa             }{c: }|
1241          {n:bb             }{c: }|
1242          {n:cc             }{c: }|
1243          {n:dd             }{c: }|
1244          {n:ee             }{c: }|
1245          {n:ff             }{c: }|
1246          {n:gg             }{12: }|
1247          {n:hh             }{12: }|
1248        ]],
1249          float_pos = { [5] = { -1, 'NW', 2, 2, 0, false, 100, 1, 11, 0 } },
1250        }
1251      else
1252        screen:expect([[
1253          aa bb cc dd ee ff gg hh ii jj   |
1254          aa                              |
1255          {1:~                               }|*6
1256          {2:[No Name] [Preview][+]          }|
1257          aa bb cc dd ee ff gg hh ii jj   |
1258          aa^                              |
1259          {12:aa             }{c: }{1:                }|
1260          {n:bb             }{c: }{1:                }|
1261          {n:cc             }{c: }{1:                }|
1262          {n:dd             }{c: }{1:                }|
1263          {n:ee             }{c: }{1:                }|
1264          {n:ff             }{c: }{1:                }|
1265          {n:gg             }{12: }{1:                }|
1266          {n:hh             }{12: }{3:                }|
1267          {5:-- }{6:match 1 of 10}                |
1268        ]])
1269      end
1270    end)
1271
1272    it('with preview-window below', function()
1273      feed(':ped<CR><c-w>4+<c-w>r')
1274      feed('iaa bb cc dd ee ff gg hh ii jj<cr>')
1275      feed('<c-x><c-n>')
1276      if multigrid then
1277        screen:expect {
1278          grid = [[
1279        ## grid 1
1280          [2:--------------------------------]|*9
1281          {3:[No Name] [+]                   }|
1282          [4:--------------------------------]|*8
1283          {2:[No Name] [Preview][+]          }|
1284          [3:--------------------------------]|
1285        ## grid 2
1286          aa bb cc dd ee ff gg hh ii jj   |
1287          aa^                              |
1288          {1:~                               }|*7
1289        ## grid 3
1290          {5:-- }{6:match 1 of 10}                |
1291        ## grid 4
1292          aa bb cc dd ee ff gg hh ii jj   |
1293          aa                              |
1294          {1:~                               }|*6
1295        ## grid 5
1296          {12:aa             }{c: }|
1297          {n:bb             }{c: }|
1298          {n:cc             }{c: }|
1299          {n:dd             }{c: }|
1300          {n:ee             }{c: }|
1301          {n:ff             }{c: }|
1302          {n:gg             }{12: }|
1303          {n:hh             }{12: }|
1304        ]],
1305          float_pos = { [5] = { -1, 'NW', 2, 2, 0, false, 100, 1, 2, 0 } },
1306        }
1307      else
1308        screen:expect([[
1309          aa bb cc dd ee ff gg hh ii jj   |
1310          aa^                              |
1311          {12:aa             }{c: }{1:                }|
1312          {n:bb             }{c: }{1:                }|
1313          {n:cc             }{c: }{1:                }|
1314          {n:dd             }{c: }{1:                }|
1315          {n:ee             }{c: }{1:                }|
1316          {n:ff             }{c: }{1:                }|
1317          {n:gg             }{12: }{1:                }|
1318          {n:hh             }{12: }{3:                }|
1319          aa bb cc dd ee ff gg hh ii jj   |
1320          aa                              |
1321          {1:~                               }|*6
1322          {2:[No Name] [Preview][+]          }|
1323          {5:-- }{6:match 1 of 10}                |
1324        ]])
1325      end
1326    end)
1327
1328    it('with preview-window above, tall and inverted', function()
1329      feed(':ped<CR><c-w>8+')
1330      feed('iaa<cr>bb<cr>cc<cr>dd<cr>ee<cr>')
1331      feed('ff<cr>gg<cr>hh<cr>ii<cr>jj<cr>')
1332      feed('kk<cr>ll<cr>mm<cr>nn<cr>oo<cr>')
1333      feed('<c-x><c-n>')
1334      if multigrid then
1335        screen:expect {
1336          grid = [[
1337        ## grid 1
1338          [4:--------------------------------]|*4
1339          {2:[No Name] [Preview][+]          }|
1340          [2:--------------------------------]|*13
1341          {3:[No Name] [+]                   }|
1342          [3:--------------------------------]|
1343        ## grid 2
1344          dd                              |
1345          ee                              |
1346          ff                              |
1347          gg                              |
1348          hh                              |
1349          ii                              |
1350          jj                              |
1351          kk                              |
1352          ll                              |
1353          mm                              |
1354          nn                              |
1355          oo                              |
1356          aa^                              |
1357        ## grid 3
1358          {5:-- }{6:match 1 of 15}                |
1359        ## grid 4
1360          aa                              |
1361          bb                              |
1362          cc                              |
1363          dd                              |
1364        ## grid 5
1365          {12:aa             }{c: }|
1366          {n:bb             }{c: }|
1367          {n:cc             }{c: }|
1368          {n:dd             }{c: }|
1369          {n:ee             }{c: }|
1370          {n:ff             }{c: }|
1371          {n:gg             }{c: }|
1372          {n:hh             }{c: }|
1373          {n:ii             }{c: }|
1374          {n:jj             }{c: }|
1375          {n:kk             }{c: }|
1376          {n:ll             }{12: }|
1377          {n:mm             }{12: }|
1378        ]],
1379          float_pos = { [5] = { -1, 'SW', 2, 12, 0, false, 100, 1, 4, 0 } },
1380        }
1381      else
1382        screen:expect([[
1383          aa                              |
1384          bb                              |
1385          cc                              |
1386          dd                              |
1387          {12:aa             }{c: }{2:ew][+]          }|
1388          {n:bb             }{c: }                |
1389          {n:cc             }{c: }                |
1390          {n:dd             }{c: }                |
1391          {n:ee             }{c: }                |
1392          {n:ff             }{c: }                |
1393          {n:gg             }{c: }                |
1394          {n:hh             }{c: }                |
1395          {n:ii             }{c: }                |
1396          {n:jj             }{c: }                |
1397          {n:kk             }{c: }                |
1398          {n:ll             }{12: }                |
1399          {n:mm             }{12: }                |
1400          aa^                              |
1401          {3:[No Name] [+]                   }|
1402          {5:-- }{6:match 1 of 15}                |
1403        ]])
1404      end
1405    end)
1406
1407    it('with preview-window above, short and inverted', function()
1408      feed(':ped<CR><c-w>4+')
1409      feed('iaa<cr>bb<cr>cc<cr>dd<cr>ee<cr>')
1410      feed('ff<cr>gg<cr>hh<cr>ii<cr>jj<cr>')
1411      feed('<c-x><c-n>')
1412      if multigrid then
1413        screen:expect {
1414          grid = [[
1415        ## grid 1
1416          [4:--------------------------------]|*8
1417          {2:[No Name] [Preview][+]          }|
1418          [2:--------------------------------]|*9
1419          {3:[No Name] [+]                   }|
1420          [3:--------------------------------]|
1421        ## grid 2
1422          cc                              |
1423          dd                              |
1424          ee                              |
1425          ff                              |
1426          gg                              |
1427          hh                              |
1428          ii                              |
1429          jj                              |
1430          aa^                              |
1431        ## grid 3
1432          {5:-- }{6:match 1 of 10}                |
1433        ## grid 4
1434          aa                              |
1435          bb                              |
1436          cc                              |
1437          dd                              |
1438          ee                              |
1439          ff                              |
1440          gg                              |
1441          hh                              |
1442        ## grid 5
1443          {12:aa             }{c: }|
1444          {n:bb             }{c: }|
1445          {n:cc             }{c: }|
1446          {n:dd             }{c: }|
1447          {n:ee             }{c: }|
1448          {n:ff             }{c: }|
1449          {n:gg             }{c: }|
1450          {n:hh             }{c: }|
1451          {n:ii             }{12: }|
1452        ]],
1453          float_pos = { [5] = { -1, 'SW', 2, 8, 0, false, 100, 1, 8, 0 } },
1454        }
1455      else
1456        screen:expect([[
1457          aa                              |
1458          bb                              |
1459          cc                              |
1460          dd                              |
1461          ee                              |
1462          ff                              |
1463          gg                              |
1464          hh                              |
1465          {12:aa             }{c: }{2:ew][+]          }|
1466          {n:bb             }{c: }                |
1467          {n:cc             }{c: }                |
1468          {n:dd             }{c: }                |
1469          {n:ee             }{c: }                |
1470          {n:ff             }{c: }                |
1471          {n:gg             }{c: }                |
1472          {n:hh             }{c: }                |
1473          {n:ii             }{12: }                |
1474          aa^                              |
1475          {3:[No Name] [+]                   }|
1476          {5:-- }{6:match 1 of 10}                |
1477        ]])
1478      end
1479    end)
1480
1481    it('with preview-window below, inverted', function()
1482      feed(':ped<CR><c-w>4+<c-w>r')
1483      feed('iaa<cr>bb<cr>cc<cr>dd<cr>ee<cr>')
1484      feed('ff<cr>gg<cr>hh<cr>ii<cr>jj<cr>')
1485      feed('<c-x><c-n>')
1486      if multigrid then
1487        screen:expect {
1488          grid = [[
1489        ## grid 1
1490          [2:--------------------------------]|*9
1491          {3:[No Name] [+]                   }|
1492          [4:--------------------------------]|*8
1493          {2:[No Name] [Preview][+]          }|
1494          [3:--------------------------------]|
1495        ## grid 2
1496          cc                              |
1497          dd                              |
1498          ee                              |
1499          ff                              |
1500          gg                              |
1501          hh                              |
1502          ii                              |
1503          jj                              |
1504          aa^                              |
1505        ## grid 3
1506          {5:-- }{6:match 1 of 10}                |
1507        ## grid 4
1508          aa                              |
1509          bb                              |
1510          cc                              |
1511          dd                              |
1512          ee                              |
1513          ff                              |
1514          gg                              |
1515          hh                              |
1516        ## grid 5
1517          {12:aa             }{c: }|
1518          {n:bb             }{c: }|
1519          {n:cc             }{c: }|
1520          {n:dd             }{c: }|
1521          {n:ee             }{c: }|
1522          {n:ff             }{c: }|
1523          {n:gg             }{12: }|
1524          {n:hh             }{12: }|
1525        ]],
1526          float_pos = { [5] = { -1, 'SW', 2, 8, 0, false, 100, 1, 0, 0 } },
1527        }
1528      else
1529        screen:expect([[
1530          {12:aa             }{c: }                |
1531          {n:bb             }{c: }                |
1532          {n:cc             }{c: }                |
1533          {n:dd             }{c: }                |
1534          {n:ee             }{c: }                |
1535          {n:ff             }{c: }                |
1536          {n:gg             }{12: }                |
1537          {n:hh             }{12: }                |
1538          aa^                              |
1539          {3:[No Name] [+]                   }|
1540          aa                              |
1541          bb                              |
1542          cc                              |
1543          dd                              |
1544          ee                              |
1545          ff                              |
1546          gg                              |
1547          hh                              |
1548          {2:[No Name] [Preview][+]          }|
1549          {5:-- }{6:match 1 of 10}                |
1550        ]])
1551      end
1552    end)
1553
1554    describe('popup and preview window do not overlap', function()
1555      before_each(function()
1556        screen:try_resize(53, 20)
1557      end)
1558
1559      -- oldtest: Test_popup_and_previewwindow_dump_pedit()
1560      it('with :pedit', function()
1561        exec([[
1562          set previewheight=9
1563          silent! pedit
1564          call setline(1, map(repeat(["ab"], 10), "v:val .. v:key"))
1565          exec "norm! G\<C-E>\<C-E>"
1566        ]])
1567        feed('o')
1568        n.poke_eventloop()
1569        feed('<C-X><C-N>')
1570        if multigrid then
1571          screen:expect({
1572            grid = [[
1573            ## grid 1
1574              [4:-----------------------------------------------------]|*9
1575              {2:[No Name] [Preview][+]                               }|
1576              [2:-----------------------------------------------------]|*8
1577              {3:[No Name] [+]                                        }|
1578              [3:-----------------------------------------------------]|
1579            ## grid 2
1580              ab4                                                  |
1581              ab5                                                  |
1582              ab6                                                  |
1583              ab7                                                  |
1584              ab8                                                  |
1585              ab9                                                  |
1586              ab0^                                                  |
1587              {1:~                                                    }|
1588            ## grid 3
1589              {5:-- Keyword Local completion (^N^P) }{6:match 1 of 10}     |
1590            ## grid 4
1591              ab0                                                  |
1592              ab1                                                  |
1593              ab2                                                  |
1594              ab3                                                  |
1595              ab4                                                  |
1596              ab5                                                  |
1597              ab6                                                  |
1598              ab7                                                  |
1599              ab8                                                  |
1600            ## grid 5
1601              {12:ab0            }{c: }|
1602              {n:ab1            }{c: }|
1603              {n:ab2            }{c: }|
1604              {n:ab3            }{c: }|
1605              {n:ab4            }{12: }|
1606              {n:ab5            }{12: }|
1607              {n:ab6            }{12: }|
1608            ]],
1609            float_pos = { [5] = { -1, 'SW', 2, 6, 0, false, 100, 1, 9, 0 } },
1610          })
1611        else
1612          screen:expect([[
1613            ab0                                                  |
1614            ab1                                                  |
1615            ab2                                                  |
1616            ab3                                                  |
1617            ab4                                                  |
1618            ab5                                                  |
1619            ab6                                                  |
1620            ab7                                                  |
1621            ab8                                                  |
1622            {12:ab0            }{c: }{2:ew][+]                               }|
1623            {n:ab1            }{c: }                                     |
1624            {n:ab2            }{c: }                                     |
1625            {n:ab3            }{c: }                                     |
1626            {n:ab4            }{12: }                                     |
1627            {n:ab5            }{12: }                                     |
1628            {n:ab6            }{12: }                                     |
1629            ab0^                                                  |
1630            {1:~                                                    }|
1631            {3:[No Name] [+]                                        }|
1632            {5:-- Keyword Local completion (^N^P) }{6:match 1 of 10}     |
1633          ]])
1634        end
1635      end)
1636
1637      -- oldtest: Test_popup_and_previewwindow_dump_pbuffer()
1638      it('with :pbuffer', function()
1639        exec([[
1640          set previewheight=9
1641          silent! pbuffer
1642          call setline(1, map(repeat(["ab"], 10), "v:val .. v:key"))
1643          exec "norm! G\<C-E>\<C-E>\<C-E>"
1644        ]])
1645        feed('o')
1646        n.poke_eventloop()
1647        feed('<C-X><C-N>')
1648        if multigrid then
1649          screen:expect({
1650            grid = [[
1651            ## grid 1
1652              [4:-----------------------------------------------------]|*9
1653              {2:[No Name] [Preview][+]                               }|
1654              [2:-----------------------------------------------------]|*8
1655              {3:[No Name] [+]                                        }|
1656              [3:-----------------------------------------------------]|
1657            ## grid 2
1658              ab5                                                  |
1659              ab6                                                  |
1660              ab7                                                  |
1661              ab8                                                  |
1662              ab9                                                  |
1663              ab0^                                                  |
1664              {1:~                                                    }|*2
1665            ## grid 3
1666              {5:-- Keyword Local completion (^N^P) }{6:match 1 of 10}     |
1667            ## grid 4
1668              ab0                                                  |
1669              ab1                                                  |
1670              ab2                                                  |
1671              ab3                                                  |
1672              ab4                                                  |
1673              ab5                                                  |
1674              ab6                                                  |
1675              ab7                                                  |
1676              ab8                                                  |
1677            ## grid 5
1678              {12:ab0            }{c: }|
1679              {n:ab1            }{c: }|
1680              {n:ab2            }{c: }|
1681              {n:ab3            }{12: }|
1682              {n:ab4            }{12: }|
1683              {n:ab5            }{12: }|
1684            ]],
1685            float_pos = { [5] = { -1, 'SW', 2, 5, 0, false, 100, 1, 9, 0 } },
1686          })
1687        else
1688          screen:expect([[
1689            ab0                                                  |
1690            ab1                                                  |
1691            ab2                                                  |
1692            ab3                                                  |
1693            ab4                                                  |
1694            ab5                                                  |
1695            ab6                                                  |
1696            ab7                                                  |
1697            ab8                                                  |
1698            {12:ab0            }{c: }{2:ew][+]                               }|
1699            {n:ab1            }{c: }                                     |
1700            {n:ab2            }{c: }                                     |
1701            {n:ab3            }{12: }                                     |
1702            {n:ab4            }{12: }                                     |
1703            {n:ab5            }{12: }                                     |
1704            ab0^                                                  |
1705            {1:~                                                    }|*2
1706            {3:[No Name] [+]                                        }|
1707            {5:-- Keyword Local completion (^N^P) }{6:match 1 of 10}     |
1708          ]])
1709        end
1710      end)
1711    end)
1712
1713    -- oldtest: Test_pum_with_preview_win()
1714    it('preview window opened during completion', function()
1715      exec([[
1716        funct Omni_test(findstart, base)
1717          if a:findstart
1718            return col(".") - 1
1719          endif
1720          return [#{word: "one", info: "1info"}, #{word: "two", info: "2info"}, #{word: "three", info: "3info"}]
1721        endfunc
1722        set omnifunc=Omni_test
1723        set completeopt-=popup completeopt+=longest,preview
1724      ]])
1725      feed('Gi<C-X><C-O>')
1726      if multigrid then
1727        screen:expect({
1728          grid = [[
1729          ## grid 1
1730            [2:--------------------------------]|*19
1731            [3:--------------------------------]|
1732          ## grid 2
1733            ^                                |
1734            {1:~                               }|*18
1735          ## grid 3
1736            {5:-- }{19:Back at original}             |
1737          ## grid 4
1738            {n:one            }|
1739            {n:two            }|
1740            {n:three          }|
1741          ]],
1742          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
1743        })
1744      else
1745        screen:expect([[
1746          ^                                |
1747          {n:one            }{1:                 }|
1748          {n:two            }{1:                 }|
1749          {n:three          }{1:                 }|
1750          {1:~                               }|*15
1751          {5:-- }{19:Back at original}             |
1752        ]])
1753      end
1754      feed('<C-N>')
1755      if multigrid then
1756        screen:expect({
1757          grid = [[
1758          ## grid 1
1759            [5:--------------------------------]|*3
1760            {2:[Scratch] [Preview][-]          }|
1761            [2:--------------------------------]|*14
1762            {3:[No Name] [+]                   }|
1763            [3:--------------------------------]|
1764          ## grid 2
1765            one^                             |
1766            {1:~                               }|*13
1767          ## grid 3
1768            {5:-- }{6:match 1 of 3}                 |
1769          ## grid 4
1770            {12:one            }|
1771            {n:two            }|
1772            {n:three          }|
1773          ## grid 5
1774            1info                           |
1775            {1:~                               }|*2
1776          ]],
1777          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 5, 0 } },
1778        })
1779      else
1780        screen:expect([[
1781          1info                           |
1782          {1:~                               }|*2
1783          {2:[Scratch] [Preview][-]          }|
1784          one^                             |
1785          {12:one            }{1:                 }|
1786          {n:two            }{1:                 }|
1787          {n:three          }{1:                 }|
1788          {1:~                               }|*10
1789          {3:[No Name] [+]                   }|
1790          {5:-- }{6:match 1 of 3}                 |
1791        ]])
1792      end
1793    end)
1794
1795    -- oldtest: Test_scrollbar_on_wide_char()
1796    it('scrollbar overwrites half of double-width char below properly', function()
1797      screen:try_resize(32, 10)
1798      exec([[
1799        call setline(1, ['a', '            啊啊啊',
1800                            \ '             哦哦哦',
1801                            \ '              呃呃呃'])
1802        call setline(5, range(10)->map({i, v -> 'aa' .. v .. 'bb'}))
1803      ]])
1804      feed('A<C-X><C-N>')
1805      if multigrid then
1806        screen:expect({
1807          grid = [[
1808          ## grid 1
1809            [2:--------------------------------]|*9
1810            [3:--------------------------------]|
1811          ## grid 2
1812            aa0bb^                           |
1813                        啊啊啊              |
1814                         哦哦哦             |
1815                          呃呃呃            |
1816            aa0bb                           |
1817            aa1bb                           |
1818            aa2bb                           |
1819            aa3bb                           |
1820            aa4bb                           |
1821          ## grid 3
1822            {5:-- }{6:match 1 of 10}                |
1823          ## grid 4
1824            {12:aa0bb          }{c: }|
1825            {n:aa1bb          }{c: }|
1826            {n:aa2bb          }{c: }|
1827            {n:aa3bb          }{c: }|
1828            {n:aa4bb          }{c: }|
1829            {n:aa5bb          }{c: }|
1830            {n:aa6bb          }{12: }|
1831            {n:aa7bb          }{12: }|
1832          ]],
1833          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
1834        })
1835      else
1836        screen:expect([[
1837          aa0bb^                           |
1838          {12:aa0bb          }{c: }啊              |
1839          {n:aa1bb          }{c: } 哦             |
1840          {n:aa2bb          }{c: }呃呃            |
1841          {n:aa3bb          }{c: }                |
1842          {n:aa4bb          }{c: }                |
1843          {n:aa5bb          }{c: }                |
1844          {n:aa6bb          }{12: }                |
1845          {n:aa7bb          }{12: }                |
1846          {5:-- }{6:match 1 of 10}                |
1847        ]])
1848      end
1849    end)
1850
1851    describe('completeopt=popup shows preview in floatwin', function()
1852      before_each(function()
1853        --row must > 10
1854        screen:try_resize(40, 11)
1855        exec([[
1856          let g:list = [#{word: "one", info: "1info"}, #{word: "two", info: "2info"}, #{word: "looooooooooooooong"}]
1857          let g:bufnrs = []
1858          let g:reduce_info_height = 0
1859          funct Omni_test(findstart, base)
1860            if a:findstart
1861              return col(".") - 1
1862            endif
1863            return g:list
1864          endfunc
1865          set omnifunc=Omni_test
1866          set completeopt=menu,popup
1867          funct Set_info()
1868            let comp_info = complete_info()
1869            if get(comp_info, 'preview_bufnr', 0) > 0
1870              call add(g:bufnrs, comp_info['preview_bufnr'])
1871            endif
1872            if comp_info['selected'] == 2
1873              call nvim__complete_set(comp_info['selected'], {"info": "3info"})
1874            endif
1875          endfunc
1876          funct TsHl()
1877            let comp_info = complete_info(['selected'])
1878            if comp_info['selected'] == 0
1879              let windata = nvim__complete_set(comp_info['selected'], {"info": "```lua\nfunction test()\n  print('foo')\nend\n```"})
1880              call v:lua.vim.treesitter.start(windata['bufnr'], 'markdown')
1881              if g:reduce_info_height > 0
1882                let h = v:lua.vim.api.nvim_win_text_height(windata['winid'], {}).all
1883                if h > 3
1884                  call v:lua.vim.api.nvim_win_set_height(windata['winid'], h - 3)
1885                endif
1886              endif
1887            endif
1888          endfunc
1889          augroup Group
1890            au!
1891            autocmd CompleteChanged * :call Set_info()
1892          augroup END
1893          funct TestTs()
1894            autocmd! Group
1895            autocmd CompleteChanged * call TsHl()
1896          endfunc
1897          funct Append_multipe()
1898            call extend(g:list, [#{word: "for .. ipairs", info: "```lua\nfor index, value in ipairs(t) do\n\t\nend\n```"}])
1899          endfunc
1900        ]])
1901      end)
1902
1903      it('pum popup preview', function()
1904        feed('Gi<C-x><C-o>')
1905        --floating preview in right
1906        if multigrid then
1907          screen:expect({
1908            grid = [[
1909            ## grid 1
1910              [2:----------------------------------------]|*10
1911              [3:----------------------------------------]|
1912            ## grid 2
1913              one^                                     |
1914              {1:~                                       }|*9
1915            ## grid 3
1916              {5:-- }{6:match 1 of 3}                         |
1917            ## grid 4
1918              {n:1info}|
1919            ## grid 5
1920              {12:one                }|
1921              {n:two                }|
1922              {n:looooooooooooooong }|
1923            ]],
1924            win_pos = { [2] = { height = 10, startcol = 0, startrow = 0, width = 40, win = 1000 } },
1925            float_pos = {
1926              [5] = { -1, 'NW', 2, 1, 0, false, 100, 2, 1, 0 },
1927              [4] = { 1001, 'NW', 1, 1, 19, true, 50, 1, 1, 19 },
1928            },
1929          })
1930        else
1931          screen:expect([[
1932            one^                                     |
1933            {12:one                }{n:1info}{1:                }|
1934            {n:two                }{1:                     }|
1935            {n:looooooooooooooong }{1:                     }|
1936            {1:~                                       }|*6
1937            {5:-- }{6:match 1 of 3}                         |
1938          ]])
1939        end
1940
1941        -- delete one character make the pum width smaller than before
1942        -- info window position should be adjusted when popupmenu width changed
1943        feed('<BS>')
1944        if multigrid then
1945          screen:expect({
1946            grid = [[
1947            ## grid 1
1948              [2:----------------------------------------]|*10
1949              [3:----------------------------------------]|
1950            ## grid 2
1951              on^                                      |
1952              {1:~                                       }|*9
1953            ## grid 3
1954              {5:-- }{6:match 1 of 3}                         |
1955            ## grid 4
1956              {n:1info}|
1957            ## grid 5
1958              {12:one            }|
1959            ]],
1960            win_pos = { [2] = { height = 10, startcol = 0, startrow = 0, width = 40, win = 1000 } },
1961            float_pos = {
1962              [5] = { -1, 'NW', 2, 1, 0, false, 100, 2, 1, 0 },
1963              [4] = { 1001, 'NW', 1, 1, 15, true, 50, 1, 1, 15 },
1964            },
1965          })
1966        else
1967          screen:expect([[
1968            on^                                      |
1969            {12:one            }{n:1info}{1:                    }|
1970            {1:~                                       }|*8
1971            {5:-- }{6:match 1 of 3}                         |
1972          ]])
1973        end
1974
1975        -- when back to original the preview float should be closed.
1976        feed('<C-P>')
1977        if multigrid then
1978          screen:expect({
1979            grid = [[
1980            ## grid 1
1981              [2:----------------------------------------]|*10
1982              [3:----------------------------------------]|
1983            ## grid 2
1984              on^                                      |
1985              {1:~                                       }|*9
1986            ## grid 3
1987              {5:-- }{19:Back at original}                     |
1988            ## grid 4 (hidden)
1989              {n:1info}|
1990            ## grid 5
1991              {n:one            }|
1992            ]],
1993            win_pos = { [2] = { height = 10, startcol = 0, startrow = 0, width = 40, win = 1000 } },
1994            float_pos = { [5] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
1995            win_viewport = {
1996              [2] = {
1997                win = 1000,
1998                topline = 0,
1999                botline = 2,
2000                curline = 0,
2001                curcol = 2,
2002                linecount = 1,
2003                sum_scroll_delta = 0,
2004              },
2005              [4] = {
2006                win = 1001,
2007                topline = 0,
2008                botline = 1,
2009                curline = 0,
2010                curcol = 0,
2011                linecount = 1,
2012                sum_scroll_delta = 0,
2013              },
2014            },
2015            win_viewport_margins = {
2016              [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
2017              [4] = { bottom = 0, left = 0, right = 0, top = 0, win = 1001 },
2018            },
2019          })
2020        else
2021          screen:expect([[
2022            on^                                      |
2023            {n:one            }{1:                         }|
2024            {1:~                                       }|*8
2025            {5:-- }{19:Back at original}                     |
2026          ]])
2027        end
2028        feed('<C-E><ESC>')
2029      end)
2030
2031      it('nvim__set_complete', function()
2032        feed('S<C-X><C-O><C-N><C-N>')
2033        if multigrid then
2034          screen:expect({
2035            grid = [[
2036            ## grid 1
2037              [2:----------------------------------------]|*10
2038              [3:----------------------------------------]|
2039            ## grid 2
2040              looooooooooooooong^                      |
2041              {1:~                                       }|*9
2042            ## grid 3
2043              {5:-- }{6:match 3 of 3}                         |
2044            ## grid 4
2045              {n:3info}|
2046            ## grid 5
2047              {n:one                }|
2048              {n:two                }|
2049              {12:looooooooooooooong }|
2050            ]],
2051            win_pos = { [2] = { height = 10, startcol = 0, startrow = 0, width = 40, win = 1000 } },
2052            float_pos = {
2053              [5] = { -1, 'NW', 2, 1, 0, false, 100, 2, 1, 0 },
2054              [4] = { 1001, 'NW', 1, 1, 19, true, 50, 1, 1, 19 },
2055            },
2056          })
2057        else
2058          screen:expect([[
2059            looooooooooooooong^                      |
2060            {n:one                3info}{1:                }|
2061            {n:two                }{1:                     }|
2062            {12:looooooooooooooong }{1:                     }|
2063            {1:~                                       }|*6
2064            {5:-- }{6:match 3 of 3}                         |
2065          ]])
2066        end
2067        feed('<C-E><ESC>')
2068      end)
2069
2070      it('popup preview placed to left', function()
2071        insert(('test'):rep(5))
2072        feed('i<C-x><C-o>')
2073        if multigrid then
2074          screen:expect({
2075            grid = [[
2076            ## grid 1
2077              [2:----------------------------------------]|*10
2078              [3:----------------------------------------]|
2079            ## grid 2
2080              testtesttesttesttesone^t                 |
2081              {1:~                                       }|*9
2082            ## grid 3
2083              {5:-- }{6:match 1 of 3}                         |
2084            ## grid 4
2085              {n:1info}|
2086            ## grid 5
2087              {12: one                }|
2088              {n: two                }|
2089              {n: looooooooooooooong }|
2090            ]],
2091            win_pos = { [2] = { height = 10, startcol = 0, startrow = 0, width = 40, win = 1000 } },
2092            float_pos = {
2093              [5] = { -1, 'NW', 2, 1, 18, false, 100, 2, 1, 18 },
2094              [4] = { 1001, 'NW', 1, 1, 13, true, 50, 1, 1, 13 },
2095            },
2096          })
2097        else
2098          screen:expect([[
2099            testtesttesttesttesone^t                 |
2100            {1:~            }{n:1info}{12: one                }{1:  }|
2101            {1:~                 }{n: two                }{1:  }|
2102            {1:~                 }{n: looooooooooooooong }{1:  }|
2103            {1:~                                       }|*6
2104            {5:-- }{6:match 1 of 3}                         |
2105          ]])
2106        end
2107        feed('<C-E><Esc>')
2108      end)
2109
2110      it('works when scroll with treesitter highlight', function()
2111        command('call TestTs()')
2112        feed('S<C-x><C-o>')
2113        if multigrid then
2114          screen:expect({
2115            grid = [[
2116            ## grid 1
2117              [2:----------------------------------------]|*10
2118              [3:----------------------------------------]|
2119            ## grid 2
2120              one^                                     |
2121              {1:~                                       }|*9
2122            ## grid 3
2123              {5:-- }{6:match 1 of 3}                         |
2124            ## grid 4
2125              {mn:```}{102:lua}{n:         }|
2126              {102:function}{mn: }{103:test}{104:()}|
2127              {mn:  }{104:print(}{105:'foo'}{104:)}{n: }|
2128              {102:end}{n:            }|
2129              {mn:```}{n:            }|
2130            ## grid 5
2131              {12:one                }|
2132              {n:two                }|
2133              {n:looooooooooooooong }|
2134            ]],
2135            win_pos = { [2] = { height = 10, startcol = 0, startrow = 0, width = 40, win = 1000 } },
2136            float_pos = {
2137              [5] = { -1, 'NW', 2, 1, 0, false, 100, 2, 1, 0 },
2138              [4] = { 1001, 'NW', 1, 1, 19, true, 50, 1, 1, 19 },
2139            },
2140          })
2141        else
2142          screen:expect([[
2143            one^                                     |
2144            {12:one                }{mn:```}{102:lua}{n:         }{1:      }|
2145            {n:two                }{102:function}{mn: }{103:test}{104:()}{1:      }|
2146            {n:looooooooooooooong }{mn:  }{104:print(}{105:'foo'}{104:)}{n: }{1:      }|
2147            {1:~                  }{102:end}{n:            }{1:      }|
2148            {1:~                  }{mn:```}{n:            }{1:      }|
2149            {1:~                                       }|*4
2150            {5:-- }{6:match 1 of 3}                         |
2151          ]])
2152        end
2153      end)
2154
2155      it('info window aligns with pum when above cursor', function()
2156        command('let g:reduce_info_height=1 | call TestTs()')
2157        feed('<C-E><ESC>18o<Esc>i<C-x><C-O>')
2158        if multigrid then
2159          screen:expect({
2160            grid = [[
2161            ## grid 1
2162              [2:----------------------------------------]|*10
2163              [3:----------------------------------------]|
2164            ## grid 2
2165                                                      |*9
2166              one^                                     |
2167            ## grid 3
2168              {5:-- }{6:match 1 of 3}                         |
2169            ## grid 4
2170              {mn:```}{102:lua}{n:         }|
2171              {102:function}{mn: }{103:test}{104:()}|
2172            ## grid 5
2173              {12:one                }|
2174              {n:two                }|
2175              {n:looooooooooooooong }|
2176            ]],
2177            win_pos = {
2178              [2] = { height = 10, startcol = 0, startrow = 0, width = 40, win = 1000 },
2179            },
2180            float_pos = {
2181              [5] = { -1, 'SW', 2, 9, 0, false, 100, 2, 6, 0 },
2182              [4] = { 1001, 'NW', 1, 6, 19, true, 50, 1, 6, 19 },
2183            },
2184          })
2185        else
2186          screen:expect([[
2187                                                    |*6
2188            {12:one                }{mn:```}{102:lua}{n:         }      |
2189            {n:two                }{102:function}{mn: }{103:test}{104:()}      |
2190            {n:looooooooooooooong }                     |
2191            one^                                     |
2192            {5:-- }{6:match 1 of 3}                         |
2193          ]])
2194        end
2195      end)
2196
2197      it('avoid modified original info text', function()
2198        command('call Append_multipe()')
2199        feed('S<C-x><C-o><C-P><C-P>')
2200        if multigrid then
2201          screen:expect({
2202            grid = [[
2203            ## grid 1
2204              [2:----------------------------------------]|*10
2205              [3:----------------------------------------]|
2206            ## grid 2
2207              for .. ipairs^                           |
2208              {1:~                                       }|*9
2209            ## grid 3
2210              {5:-- }{6:match 1 of 4}                         |
2211            ## grid 4
2212              {n:one                }|
2213              {n:two                }|
2214              {n:looooooooooooooong }|
2215              {12:for .. ipairs      }|
2216            ## grid 5
2217              {n:```lua              }|
2218              {n:for index, value in }|
2219              {n:ipairs(t) do        }|
2220              {n:                    }|
2221              {n:end                 }|
2222              {n:```                 }|
2223            ]],
2224            win_pos = { [2] = { height = 10, startcol = 0, startrow = 0, width = 40, win = 1000 } },
2225            float_pos = {
2226              [5] = { 1001, 'NW', 1, 1, 19, true, 50, 1, 1, 19 },
2227              [4] = { -1, 'NW', 2, 1, 0, false, 100, 2, 1, 0 },
2228            },
2229          })
2230        else
2231          screen:expect([[
2232            for .. ipairs^                           |
2233            {n:one                ```lua              }{1: }|
2234            {n:two                for index, value in }{1: }|
2235            {n:looooooooooooooong ipairs(t) do        }{1: }|
2236            {12:for .. ipairs      }{n:                    }{1: }|
2237            {1:~                  }{n:end                 }{1: }|
2238            {1:~                  }{n:```                 }{1: }|
2239            {1:~                                       }|*3
2240            {5:-- }{6:match 1 of 4}                         |
2241          ]])
2242        end
2243
2244        feed('<C-N><C-N><C-N><C-N><C-N>')
2245        if not multigrid then
2246          screen:expect_unchanged()
2247        end
2248        feed('<C-E><ESC>')
2249      end)
2250
2251      it('popup info window reuses bufnr', function()
2252        feed('S<C-x><C-o><C-N>')
2253        eq(1, n.eval([[len(uniq(copy(g:bufnrs))) == 1]]))
2254      end)
2255
2256      it('handles tabs and "linebreak" in info width calculation', function()
2257        screen:try_resize(50, 11)
2258        command([[
2259          set linebreak
2260          set cot+=menuone
2261          let g:list = [#{word: 'class', info: "\tClassName() = default;"}]
2262        ]])
2263        feed('S<C-x><C-o>')
2264        local info = fn.complete_info()
2265        eq(30, api.nvim_win_get_width(info.preview_winid))
2266        feed('<C-N><C-P>')
2267        info = fn.complete_info()
2268        eq(30, api.nvim_win_get_width(info.preview_winid))
2269        feed('<ESC>')
2270        exec([[
2271          setlocal tabstop=1
2272          autocmd ModeChanged *:i ++once call complete(1, [#{word: 'a'}])
2273                \| call nvim__complete_set(0, #{info: "\tfloob\tfloob"})
2274        ]])
2275        feed('i')
2276        info = fn.complete_info()
2277        eq(21, api.nvim_win_get_width(info.preview_winid))
2278        if not multigrid then
2279          screen:expect([[
2280            a^s                                                |
2281            {12:a              }{n:        floob   floob}{1:              }|
2282            {1:~                                                 }|*8
2283            {5:-- INSERT --}                                      |
2284          ]])
2285        end
2286      end)
2287
2288      it('hide info window when insufficient space', function()
2289        screen:try_resize(12, 11)
2290        feed('S<C-x><C-o>')
2291        local info = fn.complete_info()
2292        eq(true, api.nvim_win_get_config(info.preview_winid).hide)
2293      end)
2294
2295      it('enables wrap to avoid info text truncation', function()
2296        screen:try_resize(50, 11)
2297        command([[
2298          set nowrap
2299          set cot+=menuone
2300          let g:list = [#{word: 'class', info: repeat('+', 60)}]
2301        ]])
2302        feed('S<C-x><C-o>')
2303        local info = fn.complete_info()
2304        eq(2, api.nvim_win_get_config(info.preview_winid).height)
2305      end)
2306    end)
2307
2308    it('with vsplits', function()
2309      screen:try_resize(32, 8)
2310      insert('aaa aab aac\n')
2311      feed(':vsplit<cr>')
2312      if multigrid then
2313        screen:expect([[
2314        ## grid 1
2315          [4:--------------------]│[2:-----------]|*6
2316          {3:[No Name] [+]        }{2:<Name] [+] }|
2317          [3:--------------------------------]|
2318        ## grid 2
2319          aaa aab aac|
2320                     |
2321          {1:~          }|*4
2322        ## grid 3
2323          :vsplit                         |
2324        ## grid 4
2325          aaa aab aac         |
2326          ^                    |
2327          {1:~                   }|*4
2328        ]])
2329      else
2330        screen:expect([[
2331          aaa aab aac         │aaa aab aac|
2332          ^                    │           |
2333          {1:~                   }│{1:~          }|*4
2334          {3:[No Name] [+]        }{2:<Name] [+] }|
2335          :vsplit                         |
2336        ]])
2337      end
2338
2339      feed('ibbb a<c-x><c-n>')
2340      if multigrid then
2341        screen:expect {
2342          grid = [[
2343        ## grid 1
2344          [4:--------------------]│[2:-----------]|*6
2345          {3:[No Name] [+]        }{2:<Name] [+] }|
2346          [3:--------------------------------]|
2347        ## grid 2
2348          aaa aab aac|
2349          bbb aaa    |
2350          {1:~          }|*4
2351        ## grid 3
2352          {5:-- }{6:match 1 of 3}                 |
2353        ## grid 4
2354          aaa aab aac         |
2355          bbb aaa^             |
2356          {1:~                   }|*4
2357        ## grid 5
2358          {12: aaa            }|
2359          {n: aab            }|
2360          {n: aac            }|
2361        ]],
2362          float_pos = { [5] = { -1, 'NW', 4, 2, 3, false, 100, 1, 2, 3 } },
2363        }
2364      else
2365        screen:expect([[
2366          aaa aab aac         │aaa aab aac|
2367          bbb aaa^             │bbb aaa    |
2368          {1:~  }{12: aaa            }{1: }│{1:~          }|
2369          {1:~  }{n: aab            }{1: }│{1:~          }|
2370          {1:~  }{n: aac            }{1: }│{1:~          }|
2371          {1:~                   }│{1:~          }|
2372          {3:[No Name] [+]        }{2:<Name] [+] }|
2373          {5:-- }{6:match 1 of 3}                 |
2374        ]])
2375      end
2376
2377      feed('<esc><c-w><c-w>oc a<c-x><c-n>')
2378      if multigrid then
2379        screen:expect {
2380          grid = [[
2381        ## grid 1
2382          [4:-----------]│[2:--------------------]|*6
2383          {2:<Name] [+]  }{3:[No Name] [+]       }|
2384          [3:--------------------------------]|
2385        ## grid 2
2386          aaa aab aac         |
2387          bbb aaa             |
2388          c aaa^               |
2389          {1:~                   }|*3
2390        ## grid 3
2391          {5:-- }{6:match 1 of 3}                 |
2392        ## grid 4
2393          aaa aab aac|
2394          bbb aaa    |
2395          c aaa      |
2396          {1:~          }|*3
2397        ## grid 5
2398          {12: aaa            }|
2399          {n: aab            }|
2400          {n: aac            }|
2401        ]],
2402          float_pos = { [5] = { -1, 'NW', 2, 3, 1, false, 100, 1, 3, 13 } },
2403        }
2404      else
2405        screen:expect([[
2406          aaa aab aac│aaa aab aac         |
2407          bbb aaa    │bbb aaa             |
2408          c aaa      │c aaa^               |
2409          {1:~          }│{1:~}{12: aaa            }{1:   }|
2410          {1:~          }│{1:~}{n: aab            }{1:   }|
2411          {1:~          }│{1:~}{n: aac            }{1:   }|
2412          {2:<Name] [+]  }{3:[No Name] [+]       }|
2413          {5:-- }{6:match 1 of 3}                 |
2414        ]])
2415      end
2416
2417      feed('bcdef ccc a<c-x><c-n>')
2418      if multigrid then
2419        screen:expect {
2420          grid = [[
2421        ## grid 1
2422          [4:-----------]│[2:--------------------]|*6
2423          {2:<Name] [+]  }{3:[No Name] [+]       }|
2424          [3:--------------------------------]|
2425        ## grid 2
2426          aaa aab aac         |
2427          bbb aaa             |
2428          c aaabcdef ccc aaa^  |
2429          {1:~                   }|*3
2430        ## grid 3
2431          {5:-- }{6:match 1 of 4}                 |
2432        ## grid 4
2433          aaa aab aac|
2434          bbb aaa    |
2435          c aaabcdef |
2436          ccc aaa    |
2437          {1:~          }|*2
2438        ## grid 5
2439          {12: aaa             }|
2440          {n: aab             }|
2441          {n: aac             }|
2442          {n: aaabcdef        }|
2443        ]],
2444          float_pos = { [5] = { -1, 'NW', 2, 3, 3, false, 100, 1, 3, 15 } },
2445        }
2446      else
2447        screen:expect([[
2448          aaa aab aac│aaa aab aac         |
2449          bbb aaa    │bbb aaa             |
2450          c aaabcdef │c aaabcdef ccc aaa^  |
2451          ccc aaa    │{1:~  }{12: aaa             }|
2452          {1:~          }│{1:~  }{n: aab             }|
2453          {1:~          }│{1:~  }{n: aac             }|
2454          {2:<Name] [+]  }{3:[No}{n: aaabcdef        }|
2455          {5:-- }{6:match 1 of 4}                 |
2456        ]])
2457      end
2458
2459      feed('\n<c-x><c-n>')
2460      if multigrid then
2461        screen:expect {
2462          grid = [[
2463        ## grid 1
2464          [4:-----------]│[2:--------------------]|*6
2465          {2:<Name] [+]  }{3:[No Name] [+]       }|
2466          [3:--------------------------------]|
2467        ## grid 2
2468          aaa aab aac         |
2469          bbb aaa             |
2470          c aaabcdef ccc aaa  |
2471          aaa^                 |
2472          {1:~                   }|*2
2473        ## grid 3
2474          {5:-- }{6:match 1 of 6}                 |
2475        ## grid 4
2476          aaa aab aac|
2477          bbb aaa    |
2478          c aaabcdef |
2479          ccc aaa    |
2480          aaa        |
2481          {1:~          }|
2482        ## grid 5
2483          {12: aaa            }{c: }|
2484          {n: aab            }{12: }|
2485          {n: aac            }{12: }|
2486        ]],
2487          float_pos = { [5] = { -1, 'NW', 2, 4, -1, false, 100, 1, 4, 11 } },
2488        }
2489      else
2490        screen:expect([[
2491          aaa aab aac│aaa aab aac         |
2492          bbb aaa    │bbb aaa             |
2493          c aaabcdef │c aaabcdef ccc aaa  |
2494          ccc aaa    │aaa^                 |
2495          aaa        {12: aaa            }{c: }{1:    }|
2496          {1:~          }{n: aab            }{12: }{1:    }|
2497          {2:<Name] [+] }{n: aac            }{12: }{3:    }|
2498          {5:-- }{6:match 1 of 6}                 |
2499        ]])
2500      end
2501    end)
2502
2503    it('with split and scroll', function()
2504      screen:try_resize(60, 14)
2505      command('split')
2506      command('set completeopt+=noinsert')
2507      command('set mouse=a')
2508      insert([[
2509          Lorem ipsum dolor sit amet, consectetur
2510          adipisicing elit, sed do eiusmod tempor
2511          incididunt ut labore et dolore magna aliqua.
2512          Ut enim ad minim veniam, quis nostrud
2513          exercitation ullamco laboris nisi ut aliquip ex
2514          ea commodo consequat. Duis aute irure dolor in
2515          reprehenderit in voluptate velit esse cillum
2516          dolore eu fugiat nulla pariatur. Excepteur sint
2517          occaecat cupidatat non proident, sunt in culpa
2518          qui officia deserunt mollit anim id est
2519          laborum.
2520        .
2521      ]])
2522
2523      if multigrid then
2524        screen:expect([[
2525          ## grid 1
2526            [4:------------------------------------------------------------]|*6
2527            {3:[No Name] [+]                                               }|
2528            [2:------------------------------------------------------------]|*5
2529            {2:[No Name] [+]                                               }|
2530            [3:------------------------------------------------------------]|
2531          ## grid 2
2532              Lorem ipsum dolor sit amet, consectetur                   |
2533              adipisicing elit, sed do eiusmod tempor                   |
2534              incididunt ut labore et dolore magna aliqua.              |
2535              Ut enim ad minim veniam, quis nostrud                     |
2536              exercitation ullamco laboris nisi ut aliquip ex           |
2537          ## grid 3
2538                                                                        |
2539          ## grid 4
2540              dolore eu fugiat nulla pariatur. Excepteur sint           |
2541              occaecat cupidatat non proident, sunt in culpa            |
2542              qui officia deserunt mollit anim id est                   |
2543              laborum.                                                  |
2544            .                                                           |
2545            ^                                                            |
2546        ]])
2547      else
2548        screen:expect([[
2549            dolore eu fugiat nulla pariatur. Excepteur sint           |
2550            occaecat cupidatat non proident, sunt in culpa            |
2551            qui officia deserunt mollit anim id est                   |
2552            laborum.                                                  |
2553          .                                                           |
2554          ^                                                            |
2555          {3:[No Name] [+]                                               }|
2556            Lorem ipsum dolor sit amet, consectetur                   |
2557            adipisicing elit, sed do eiusmod tempor                   |
2558            incididunt ut labore et dolore magna aliqua.              |
2559            Ut enim ad minim veniam, quis nostrud                     |
2560            exercitation ullamco laboris nisi ut aliquip ex           |
2561          {2:[No Name] [+]                                               }|
2562                                                                      |
2563        ]])
2564      end
2565
2566      feed('ggOEst <c-x><c-p>')
2567      if multigrid then
2568        screen:expect({
2569          grid = [[
2570          ## grid 1
2571            [4:------------------------------------------------------------]|*6
2572            {3:[No Name] [+]                                               }|
2573            [2:------------------------------------------------------------]|*5
2574            {2:[No Name] [+]                                               }|
2575            [3:------------------------------------------------------------]|
2576          ## grid 2
2577            Est                                                         |
2578              Lorem ipsum dolor sit amet, consectetur                   |
2579              adipisicing elit, sed do eiusmod tempor                   |
2580              incididunt ut labore et dolore magna aliqua.              |
2581              Ut enim ad minim veniam, quis nostrud                     |
2582          ## grid 3
2583            {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
2584          ## grid 4
2585            Est ^                                                        |
2586              Lorem ipsum dolor sit amet, consectetur                   |
2587              adipisicing elit, sed do eiusmod tempor                   |
2588              incididunt ut labore et dolore magna aliqua.              |
2589              Ut enim ad minim veniam, quis nostrud                     |
2590              exercitation ullamco laboris nisi ut aliquip ex           |
2591          ## grid 5
2592            {n: sunt           }{12: }|
2593            {n: in             }{12: }|
2594            {n: culpa          }{12: }|
2595            {n: qui            }{12: }|
2596            {n: officia        }{12: }|
2597            {n: deserunt       }{12: }|
2598            {n: mollit         }{12: }|
2599            {n: anim           }{12: }|
2600            {n: id             }{12: }|
2601            {n: est            }{12: }|
2602            {n: laborum        }{c: }|
2603            {12: Est            }{c: }|
2604          ]],
2605          float_pos = { [5] = { -1, 'NW', 4, 1, 3, false, 100, 1, 1, 3 } },
2606        })
2607      else
2608        screen:expect([[
2609          Est ^                                                        |
2610            L{n: sunt           }{12: }sit amet, consectetur                   |
2611            a{n: in             }{12: }sed do eiusmod tempor                   |
2612            i{n: culpa          }{12: }re et dolore magna aliqua.              |
2613            U{n: qui            }{12: }eniam, quis nostrud                     |
2614            e{n: officia        }{12: }co laboris nisi ut aliquip ex           |
2615          {3:[No}{n: deserunt       }{12: }{3:                                        }|
2616          Est{n: mollit         }{12: }                                        |
2617            L{n: anim           }{12: }sit amet, consectetur                   |
2618            a{n: id             }{12: }sed do eiusmod tempor                   |
2619            i{n: est            }{12: }re et dolore magna aliqua.              |
2620            U{n: laborum        }{c: }eniam, quis nostrud                     |
2621          {2:[No}{12: Est            }{c: }{2:                                        }|
2622          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
2623        ]])
2624      end
2625
2626      if send_mouse_grid then
2627        api.nvim_input_mouse('wheel', 'down', '', 2, 9, 33)
2628      else
2629        api.nvim_input_mouse('wheel', 'down', '', 0, 9, 40)
2630      end
2631      if multigrid then
2632        screen:expect({
2633          grid = [[
2634          ## grid 1
2635            [4:------------------------------------------------------------]|*6
2636            {3:[No Name] [+]                                               }|
2637            [2:------------------------------------------------------------]|*5
2638            {2:[No Name] [+]                                               }|
2639            [3:------------------------------------------------------------]|
2640          ## grid 2
2641              incididunt ut labore et dolore magna aliqua.              |
2642              Ut enim ad minim veniam, quis nostrud                     |
2643              exercitation ullamco laboris nisi ut aliquip ex           |
2644              ea commodo consequat. Duis aute irure dolor in            |
2645              reprehenderit in voluptate velit esse cillum              |
2646          ## grid 3
2647            {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
2648          ## grid 4
2649            Est ^                                                        |
2650              Lorem ipsum dolor sit amet, consectetur                   |
2651              adipisicing elit, sed do eiusmod tempor                   |
2652              incididunt ut labore et dolore magna aliqua.              |
2653              Ut enim ad minim veniam, quis nostrud                     |
2654              exercitation ullamco laboris nisi ut aliquip ex           |
2655          ## grid 5
2656            {n: sunt           }{12: }|
2657            {n: in             }{12: }|
2658            {n: culpa          }{12: }|
2659            {n: qui            }{12: }|
2660            {n: officia        }{12: }|
2661            {n: deserunt       }{12: }|
2662            {n: mollit         }{12: }|
2663            {n: anim           }{12: }|
2664            {n: id             }{12: }|
2665            {n: est            }{12: }|
2666            {n: laborum        }{c: }|
2667            {12: Est            }{c: }|
2668          ]],
2669          float_pos = { [5] = { -1, 'NW', 4, 1, 3, false, 100, 1, 1, 3 } },
2670        })
2671      else
2672        screen:expect([[
2673          Est ^                                                        |
2674            L{n: sunt           }{12: }sit amet, consectetur                   |
2675            a{n: in             }{12: }sed do eiusmod tempor                   |
2676            i{n: culpa          }{12: }re et dolore magna aliqua.              |
2677            U{n: qui            }{12: }eniam, quis nostrud                     |
2678            e{n: officia        }{12: }co laboris nisi ut aliquip ex           |
2679          {3:[No}{n: deserunt       }{12: }{3:                                        }|
2680            i{n: mollit         }{12: }re et dolore magna aliqua.              |
2681            U{n: anim           }{12: }eniam, quis nostrud                     |
2682            e{n: id             }{12: }co laboris nisi ut aliquip ex           |
2683            e{n: est            }{12: }at. Duis aute irure dolor in            |
2684            r{n: laborum        }{c: }oluptate velit esse cillum              |
2685          {2:[No}{12: Est            }{c: }{2:                                        }|
2686          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
2687        ]])
2688      end
2689
2690      feed('e')
2691      if multigrid then
2692        screen:expect({
2693          grid = [[
2694          ## grid 1
2695            [4:------------------------------------------------------------]|*6
2696            {3:[No Name] [+]                                               }|
2697            [2:------------------------------------------------------------]|*5
2698            {2:[No Name] [+]                                               }|
2699            [3:------------------------------------------------------------]|
2700          ## grid 2
2701              incididunt ut labore et dolore magna aliqua.              |
2702              Ut enim ad minim veniam, quis nostrud                     |
2703              exercitation ullamco laboris nisi ut aliquip ex           |
2704              ea commodo consequat. Duis aute irure dolor in            |
2705              reprehenderit in voluptate velit esse cillum              |
2706          ## grid 3
2707            {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
2708          ## grid 4
2709            Est e^                                                       |
2710              Lorem ipsum dolor sit amet, consectetur                   |
2711              adipisicing elit, sed do eiusmod tempor                   |
2712              incididunt ut labore et dolore magna aliqua.              |
2713              Ut enim ad minim veniam, quis nostrud                     |
2714              exercitation ullamco laboris nisi ut aliquip ex           |
2715          ## grid 5
2716            {n: elit           }|
2717            {n: eiusmod        }|
2718            {n: et             }|
2719            {n: enim           }|
2720            {n: exercitation   }|
2721            {n: ex             }|
2722            {n: ea             }|
2723            {n: esse           }|
2724            {n: eu             }|
2725            {12: est            }|
2726          ]],
2727          float_pos = { [5] = { -1, 'NW', 4, 1, 3, false, 100, 1, 1, 3 } },
2728        })
2729      else
2730        screen:expect([[
2731          Est e^                                                       |
2732            L{n: elit           } sit amet, consectetur                   |
2733            a{n: eiusmod        } sed do eiusmod tempor                   |
2734            i{n: et             }ore et dolore magna aliqua.              |
2735            U{n: enim           }veniam, quis nostrud                     |
2736            e{n: exercitation   }mco laboris nisi ut aliquip ex           |
2737          {3:[No}{n: ex             }{3:                                         }|
2738            i{n: ea             }ore et dolore magna aliqua.              |
2739            U{n: esse           }veniam, quis nostrud                     |
2740            e{n: eu             }mco laboris nisi ut aliquip ex           |
2741            e{12: est            }uat. Duis aute irure dolor in            |
2742            reprehenderit in voluptate velit esse cillum              |
2743          {2:[No Name] [+]                                               }|
2744          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
2745        ]])
2746      end
2747
2748      if send_mouse_grid then
2749        api.nvim_input_mouse('wheel', 'up', '', 2, 9, 33)
2750      else
2751        api.nvim_input_mouse('wheel', 'up', '', 0, 9, 40)
2752      end
2753      if multigrid then
2754        screen:expect({
2755          grid = [[
2756          ## grid 1
2757            [4:------------------------------------------------------------]|*6
2758            {3:[No Name] [+]                                               }|
2759            [2:------------------------------------------------------------]|*5
2760            {2:[No Name] [+]                                               }|
2761            [3:------------------------------------------------------------]|
2762          ## grid 2
2763            Est e                                                       |
2764              Lorem ipsum dolor sit amet, consectetur                   |
2765              adipisicing elit, sed do eiusmod tempor                   |
2766              incididunt ut labore et dolore magna aliqua.              |
2767              Ut enim ad minim veniam, quis nostrud                     |
2768          ## grid 3
2769            {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
2770          ## grid 4
2771            Est e^                                                       |
2772              Lorem ipsum dolor sit amet, consectetur                   |
2773              adipisicing elit, sed do eiusmod tempor                   |
2774              incididunt ut labore et dolore magna aliqua.              |
2775              Ut enim ad minim veniam, quis nostrud                     |
2776              exercitation ullamco laboris nisi ut aliquip ex           |
2777          ## grid 5
2778            {n: elit           }|
2779            {n: eiusmod        }|
2780            {n: et             }|
2781            {n: enim           }|
2782            {n: exercitation   }|
2783            {n: ex             }|
2784            {n: ea             }|
2785            {n: esse           }|
2786            {n: eu             }|
2787            {12: est            }|
2788          ]],
2789          float_pos = { [5] = { -1, 'NW', 4, 1, 3, false, 100, 1, 1, 3 } },
2790        })
2791      else
2792        screen:expect([[
2793          Est e^                                                       |
2794            L{n: elit           } sit amet, consectetur                   |
2795            a{n: eiusmod        } sed do eiusmod tempor                   |
2796            i{n: et             }ore et dolore magna aliqua.              |
2797            U{n: enim           }veniam, quis nostrud                     |
2798            e{n: exercitation   }mco laboris nisi ut aliquip ex           |
2799          {3:[No}{n: ex             }{3:                                         }|
2800          Est{n: ea             }                                         |
2801            L{n: esse           } sit amet, consectetur                   |
2802            a{n: eu             } sed do eiusmod tempor                   |
2803            i{12: est            }ore et dolore magna aliqua.              |
2804            Ut enim ad minim veniam, quis nostrud                     |
2805          {2:[No Name] [+]                                               }|
2806          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
2807        ]])
2808      end
2809
2810      feed('s')
2811      if multigrid then
2812        screen:expect({
2813          grid = [[
2814          ## grid 1
2815            [4:------------------------------------------------------------]|*6
2816            {3:[No Name] [+]                                               }|
2817            [2:------------------------------------------------------------]|*5
2818            {2:[No Name] [+]                                               }|
2819            [3:------------------------------------------------------------]|
2820          ## grid 2
2821            Est es                                                      |
2822              Lorem ipsum dolor sit amet, consectetur                   |
2823              adipisicing elit, sed do eiusmod tempor                   |
2824              incididunt ut labore et dolore magna aliqua.              |
2825              Ut enim ad minim veniam, quis nostrud                     |
2826          ## grid 3
2827            {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
2828          ## grid 4
2829            Est es^                                                      |
2830              Lorem ipsum dolor sit amet, consectetur                   |
2831              adipisicing elit, sed do eiusmod tempor                   |
2832              incididunt ut labore et dolore magna aliqua.              |
2833              Ut enim ad minim veniam, quis nostrud                     |
2834              exercitation ullamco laboris nisi ut aliquip ex           |
2835          ## grid 5
2836            {n: esse           }|
2837            {12: est            }|
2838          ]],
2839          float_pos = { [5] = { -1, 'NW', 4, 1, 3, false, 100, 1, 1, 3 } },
2840        })
2841      else
2842        screen:expect([[
2843          Est es^                                                      |
2844            L{n: esse           } sit amet, consectetur                   |
2845            a{12: est            } sed do eiusmod tempor                   |
2846            incididunt ut labore et dolore magna aliqua.              |
2847            Ut enim ad minim veniam, quis nostrud                     |
2848            exercitation ullamco laboris nisi ut aliquip ex           |
2849          {3:[No Name] [+]                                               }|
2850          Est es                                                      |
2851            Lorem ipsum dolor sit amet, consectetur                   |
2852            adipisicing elit, sed do eiusmod tempor                   |
2853            incididunt ut labore et dolore magna aliqua.              |
2854            Ut enim ad minim veniam, quis nostrud                     |
2855          {2:[No Name] [+]                                               }|
2856          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
2857        ]])
2858      end
2859
2860      if send_mouse_grid then
2861        api.nvim_input_mouse('wheel', 'down', '', 2, 9, 33)
2862      else
2863        api.nvim_input_mouse('wheel', 'down', '', 0, 9, 40)
2864      end
2865      if multigrid then
2866        screen:expect({
2867          grid = [[
2868          ## grid 1
2869            [4:------------------------------------------------------------]|*6
2870            {3:[No Name] [+]                                               }|
2871            [2:------------------------------------------------------------]|*5
2872            {2:[No Name] [+]                                               }|
2873            [3:------------------------------------------------------------]|
2874          ## grid 2
2875              incididunt ut labore et dolore magna aliqua.              |
2876              Ut enim ad minim veniam, quis nostrud                     |
2877              exercitation ullamco laboris nisi ut aliquip ex           |
2878              ea commodo consequat. Duis aute irure dolor in            |
2879              reprehenderit in voluptate velit esse cillum              |
2880          ## grid 3
2881            {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
2882          ## grid 4
2883            Est es^                                                      |
2884              Lorem ipsum dolor sit amet, consectetur                   |
2885              adipisicing elit, sed do eiusmod tempor                   |
2886              incididunt ut labore et dolore magna aliqua.              |
2887              Ut enim ad minim veniam, quis nostrud                     |
2888              exercitation ullamco laboris nisi ut aliquip ex           |
2889          ## grid 5
2890            {n: esse           }|
2891            {12: est            }|
2892          ]],
2893          float_pos = { [5] = { -1, 'NW', 4, 1, 3, false, 100, 1, 1, 3 } },
2894        })
2895      else
2896        screen:expect([[
2897          Est es^                                                      |
2898            L{n: esse           } sit amet, consectetur                   |
2899            a{12: est            } sed do eiusmod tempor                   |
2900            incididunt ut labore et dolore magna aliqua.              |
2901            Ut enim ad minim veniam, quis nostrud                     |
2902            exercitation ullamco laboris nisi ut aliquip ex           |
2903          {3:[No Name] [+]                                               }|
2904            incididunt ut labore et dolore magna aliqua.              |
2905            Ut enim ad minim veniam, quis nostrud                     |
2906            exercitation ullamco laboris nisi ut aliquip ex           |
2907            ea commodo consequat. Duis aute irure dolor in            |
2908            reprehenderit in voluptate velit esse cillum              |
2909          {2:[No Name] [+]                                               }|
2910          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
2911        ]])
2912      end
2913
2914      feed('<bs>')
2915      if multigrid then
2916        screen:expect({
2917          grid = [[
2918          ## grid 1
2919            [4:------------------------------------------------------------]|*6
2920            {3:[No Name] [+]                                               }|
2921            [2:------------------------------------------------------------]|*5
2922            {2:[No Name] [+]                                               }|
2923            [3:------------------------------------------------------------]|
2924          ## grid 2
2925              incididunt ut labore et dolore magna aliqua.              |
2926              Ut enim ad minim veniam, quis nostrud                     |
2927              exercitation ullamco laboris nisi ut aliquip ex           |
2928              ea commodo consequat. Duis aute irure dolor in            |
2929              reprehenderit in voluptate velit esse cillum              |
2930          ## grid 3
2931            {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
2932          ## grid 4
2933            Est e^                                                       |
2934              Lorem ipsum dolor sit amet, consectetur                   |
2935              adipisicing elit, sed do eiusmod tempor                   |
2936              incididunt ut labore et dolore magna aliqua.              |
2937              Ut enim ad minim veniam, quis nostrud                     |
2938              exercitation ullamco laboris nisi ut aliquip ex           |
2939          ## grid 5
2940            {n: elit           }|
2941            {n: eiusmod        }|
2942            {n: et             }|
2943            {n: enim           }|
2944            {n: exercitation   }|
2945            {n: ex             }|
2946            {n: ea             }|
2947            {n: esse           }|
2948            {n: eu             }|
2949            {12: est            }|
2950          ]],
2951          float_pos = { [5] = { -1, 'NW', 4, 1, 3, false, 100, 1, 1, 3 } },
2952        })
2953      else
2954        screen:expect([[
2955          Est e^                                                       |
2956            L{n: elit           } sit amet, consectetur                   |
2957            a{n: eiusmod        } sed do eiusmod tempor                   |
2958            i{n: et             }ore et dolore magna aliqua.              |
2959            U{n: enim           }veniam, quis nostrud                     |
2960            e{n: exercitation   }mco laboris nisi ut aliquip ex           |
2961          {3:[No}{n: ex             }{3:                                         }|
2962            i{n: ea             }ore et dolore magna aliqua.              |
2963            U{n: esse           }veniam, quis nostrud                     |
2964            e{n: eu             }mco laboris nisi ut aliquip ex           |
2965            e{12: est            }uat. Duis aute irure dolor in            |
2966            reprehenderit in voluptate velit esse cillum              |
2967          {2:[No Name] [+]                                               }|
2968          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 65}            |
2969        ]])
2970      end
2971
2972      feed('<c-p>')
2973      if multigrid then
2974        screen:expect({
2975          grid = [[
2976          ## grid 1
2977            [4:------------------------------------------------------------]|*6
2978            {3:[No Name] [+]                                               }|
2979            [2:------------------------------------------------------------]|*5
2980            {2:[No Name] [+]                                               }|
2981            [3:------------------------------------------------------------]|
2982          ## grid 2
2983              incididunt ut labore et dolore magna aliqua.              |
2984              Ut enim ad minim veniam, quis nostrud                     |
2985              exercitation ullamco laboris nisi ut aliquip ex           |
2986              ea commodo consequat. Duis aute irure dolor in            |
2987              reprehenderit in voluptate velit esse cillum              |
2988          ## grid 3
2989            {5:-- Keyword Local completion (^N^P) }{6:match 22 of 65}           |
2990          ## grid 4
2991            Est eu^                                                      |
2992              Lorem ipsum dolor sit amet, consectetur                   |
2993              adipisicing elit, sed do eiusmod tempor                   |
2994              incididunt ut labore et dolore magna aliqua.              |
2995              Ut enim ad minim veniam, quis nostrud                     |
2996              exercitation ullamco laboris nisi ut aliquip ex           |
2997          ## grid 5
2998            {n: elit           }|
2999            {n: eiusmod        }|
3000            {n: et             }|
3001            {n: enim           }|
3002            {n: exercitation   }|
3003            {n: ex             }|
3004            {n: ea             }|
3005            {n: esse           }|
3006            {12: eu             }|
3007            {n: est            }|
3008          ]],
3009          float_pos = { [5] = { -1, 'NW', 4, 1, 3, false, 100, 1, 1, 3 } },
3010        })
3011      else
3012        screen:expect([[
3013          Est eu^                                                      |
3014            L{n: elit           } sit amet, consectetur                   |
3015            a{n: eiusmod        } sed do eiusmod tempor                   |
3016            i{n: et             }ore et dolore magna aliqua.              |
3017            U{n: enim           }veniam, quis nostrud                     |
3018            e{n: exercitation   }mco laboris nisi ut aliquip ex           |
3019          {3:[No}{n: ex             }{3:                                         }|
3020            i{n: ea             }ore et dolore magna aliqua.              |
3021            U{n: esse           }veniam, quis nostrud                     |
3022            e{12: eu             }mco laboris nisi ut aliquip ex           |
3023            e{n: est            }uat. Duis aute irure dolor in            |
3024            reprehenderit in voluptate velit esse cillum              |
3025          {2:[No Name] [+]                                               }|
3026          {5:-- Keyword Local completion (^N^P) }{6:match 22 of 65}           |
3027        ]])
3028      end
3029
3030      if send_mouse_grid then
3031        api.nvim_input_mouse('wheel', 'down', '', 2, 9, 33)
3032      else
3033        api.nvim_input_mouse('wheel', 'down', '', 0, 9, 40)
3034      end
3035      if multigrid then
3036        screen:expect({
3037          grid = [[
3038          ## grid 1
3039            [4:------------------------------------------------------------]|*6
3040            {3:[No Name] [+]                                               }|
3041            [2:------------------------------------------------------------]|*5
3042            {2:[No Name] [+]                                               }|
3043            [3:------------------------------------------------------------]|
3044          ## grid 2
3045              ea commodo consequat. Duis aute irure dolor in            |
3046              reprehenderit in voluptate velit esse cillum              |
3047              dolore eu fugiat nulla pariatur. Excepteur sint           |
3048              occaecat cupidatat non proident, sunt in culpa            |
3049              qui officia deserunt mollit anim id est                   |
3050          ## grid 3
3051            {5:-- Keyword Local completion (^N^P) }{6:match 22 of 65}           |
3052          ## grid 4
3053            Est eu^                                                      |
3054              Lorem ipsum dolor sit amet, consectetur                   |
3055              adipisicing elit, sed do eiusmod tempor                   |
3056              incididunt ut labore et dolore magna aliqua.              |
3057              Ut enim ad minim veniam, quis nostrud                     |
3058              exercitation ullamco laboris nisi ut aliquip ex           |
3059          ## grid 5
3060            {n: elit           }|
3061            {n: eiusmod        }|
3062            {n: et             }|
3063            {n: enim           }|
3064            {n: exercitation   }|
3065            {n: ex             }|
3066            {n: ea             }|
3067            {n: esse           }|
3068            {12: eu             }|
3069            {n: est            }|
3070          ]],
3071          float_pos = { [5] = { -1, 'NW', 4, 1, 3, false, 100, 1, 1, 3 } },
3072        })
3073      else
3074        screen:expect([[
3075          Est eu^                                                      |
3076            L{n: elit           } sit amet, consectetur                   |
3077            a{n: eiusmod        } sed do eiusmod tempor                   |
3078            i{n: et             }ore et dolore magna aliqua.              |
3079            U{n: enim           }veniam, quis nostrud                     |
3080            e{n: exercitation   }mco laboris nisi ut aliquip ex           |
3081          {3:[No}{n: ex             }{3:                                         }|
3082            e{n: ea             }uat. Duis aute irure dolor in            |
3083            r{n: esse           }voluptate velit esse cillum              |
3084            d{12: eu             }nulla pariatur. Excepteur sint           |
3085            o{n: est            }t non proident, sunt in culpa            |
3086            qui officia deserunt mollit anim id est                   |
3087          {2:[No Name] [+]                                               }|
3088          {5:-- Keyword Local completion (^N^P) }{6:match 22 of 65}           |
3089        ]])
3090      end
3091
3092      fn.complete(4, { 'ea', 'eeeeeeeeeeeeeeeeee', 'ei', 'eo', 'eu', 'ey', 'eå', 'eä', 'eö' })
3093      if multigrid then
3094        screen:expect({
3095          grid = [[
3096          ## grid 1
3097            [4:------------------------------------------------------------]|*6
3098            {3:[No Name] [+]                                               }|
3099            [2:------------------------------------------------------------]|*5
3100            {2:[No Name] [+]                                               }|
3101            [3:------------------------------------------------------------]|
3102          ## grid 2
3103              ea commodo consequat. Duis aute irure dolor in            |
3104              reprehenderit in voluptate velit esse cillum              |
3105              dolore eu fugiat nulla pariatur. Excepteur sint           |
3106              occaecat cupidatat non proident, sunt in culpa            |
3107              qui officia deserunt mollit anim id est                   |
3108          ## grid 3
3109            {5:-- INSERT --}                                                |
3110          ## grid 4
3111            Est eu^                                                      |
3112              Lorem ipsum dolor sit amet, consectetur                   |
3113              adipisicing elit, sed do eiusmod tempor                   |
3114              incididunt ut labore et dolore magna aliqua.              |
3115              Ut enim ad minim veniam, quis nostrud                     |
3116              exercitation ullamco laboris nisi ut aliquip ex           |
3117          ## grid 5
3118            {12: ea                 }|
3119            {n: eeeeeeeeeeeeeeeeee }|
3120            {n: ei                 }|
3121            {n: eo                 }|
3122            {n: eu                 }|
3123            {n: ey                 }|
3124            {n: eå                 }|
3125            {n: eä                 }|
3126            {n: eö                 }|
3127          ]],
3128          float_pos = { [5] = { -1, 'NW', 4, 1, 2, false, 100, 1, 1, 2 } },
3129        })
3130      else
3131        screen:expect([[
3132          Est eu^                                                      |
3133            {12: ea                 }t amet, consectetur                   |
3134            {n: eeeeeeeeeeeeeeeeee }d do eiusmod tempor                   |
3135            {n: ei                 } et dolore magna aliqua.              |
3136            {n: eo                 }iam, quis nostrud                     |
3137            {n: eu                 } laboris nisi ut aliquip ex           |
3138          {3:[N}{n: ey                 }{3:                                      }|
3139            {n: eå                 }. Duis aute irure dolor in            |
3140            {n: eä                 }uptate velit esse cillum              |
3141            {n: eö                 }la pariatur. Excepteur sint           |
3142            occaecat cupidatat non proident, sunt in culpa            |
3143            qui officia deserunt mollit anim id est                   |
3144          {2:[No Name] [+]                                               }|
3145          {5:-- INSERT --}                                                |
3146        ]])
3147      end
3148
3149      fn.complete(4, { 'ea', 'eee', 'ei', 'eo', 'eu', 'ey', 'eå', 'eä', 'eö' })
3150      if multigrid then
3151        screen:expect({
3152          grid = [[
3153          ## grid 1
3154            [4:------------------------------------------------------------]|*6
3155            {3:[No Name] [+]                                               }|
3156            [2:------------------------------------------------------------]|*5
3157            {2:[No Name] [+]                                               }|
3158            [3:------------------------------------------------------------]|
3159          ## grid 2
3160              ea commodo consequat. Duis aute irure dolor in            |
3161              reprehenderit in voluptate velit esse cillum              |
3162              dolore eu fugiat nulla pariatur. Excepteur sint           |
3163              occaecat cupidatat non proident, sunt in culpa            |
3164              qui officia deserunt mollit anim id est                   |
3165          ## grid 3
3166            {5:-- INSERT --}                                                |
3167          ## grid 4
3168            Est eu^                                                      |
3169              Lorem ipsum dolor sit amet, consectetur                   |
3170              adipisicing elit, sed do eiusmod tempor                   |
3171              incididunt ut labore et dolore magna aliqua.              |
3172              Ut enim ad minim veniam, quis nostrud                     |
3173              exercitation ullamco laboris nisi ut aliquip ex           |
3174          ## grid 5
3175            {12: ea             }|
3176            {n: eee            }|
3177            {n: ei             }|
3178            {n: eo             }|
3179            {n: eu             }|
3180            {n: ey             }|
3181            {n: eå             }|
3182            {n: eä             }|
3183            {n: eö             }|
3184          ]],
3185          float_pos = { [5] = { -1, 'NW', 4, 1, 2, false, 100, 1, 1, 2 } },
3186        })
3187      else
3188        screen:expect([[
3189          Est eu^                                                      |
3190            {12: ea             }r sit amet, consectetur                   |
3191            {n: eee            }, sed do eiusmod tempor                   |
3192            {n: ei             }bore et dolore magna aliqua.              |
3193            {n: eo             } veniam, quis nostrud                     |
3194            {n: eu             }amco laboris nisi ut aliquip ex           |
3195          {3:[N}{n: ey             }{3:                                          }|
3196            {n: eå             }quat. Duis aute irure dolor in            |
3197            {n: eä             } voluptate velit esse cillum              |
3198            {n: eö             } nulla pariatur. Excepteur sint           |
3199            occaecat cupidatat non proident, sunt in culpa            |
3200            qui officia deserunt mollit anim id est                   |
3201          {2:[No Name] [+]                                               }|
3202          {5:-- INSERT --}                                                |
3203        ]])
3204      end
3205
3206      feed('<c-n>')
3207      if multigrid then
3208        screen:expect({
3209          grid = [[
3210          ## grid 1
3211            [4:------------------------------------------------------------]|*6
3212            {3:[No Name] [+]                                               }|
3213            [2:------------------------------------------------------------]|*5
3214            {2:[No Name] [+]                                               }|
3215            [3:------------------------------------------------------------]|
3216          ## grid 2
3217              ea commodo consequat. Duis aute irure dolor in            |
3218              reprehenderit in voluptate velit esse cillum              |
3219              dolore eu fugiat nulla pariatur. Excepteur sint           |
3220              occaecat cupidatat non proident, sunt in culpa            |
3221              qui officia deserunt mollit anim id est                   |
3222          ## grid 3
3223            {5:-- INSERT --}                                                |
3224          ## grid 4
3225            Esteee^                                                      |
3226              Lorem ipsum dolor sit amet, consectetur                   |
3227              adipisicing elit, sed do eiusmod tempor                   |
3228              incididunt ut labore et dolore magna aliqua.              |
3229              Ut enim ad minim veniam, quis nostrud                     |
3230              exercitation ullamco laboris nisi ut aliquip ex           |
3231          ## grid 5
3232            {n: ea             }|
3233            {12: eee            }|
3234            {n: ei             }|
3235            {n: eo             }|
3236            {n: eu             }|
3237            {n: ey             }|
3238            {n: eå             }|
3239            {n: eä             }|
3240            {n: eö             }|
3241          ]],
3242          float_pos = { [5] = { -1, 'NW', 4, 1, 2, false, 100, 1, 1, 2 } },
3243        })
3244      else
3245        screen:expect([[
3246          Esteee^                                                      |
3247            {n: ea             }r sit amet, consectetur                   |
3248            {12: eee            }, sed do eiusmod tempor                   |
3249            {n: ei             }bore et dolore magna aliqua.              |
3250            {n: eo             } veniam, quis nostrud                     |
3251            {n: eu             }amco laboris nisi ut aliquip ex           |
3252          {3:[N}{n: ey             }{3:                                          }|
3253            {n: eå             }quat. Duis aute irure dolor in            |
3254            {n: eä             } voluptate velit esse cillum              |
3255            {n: eö             } nulla pariatur. Excepteur sint           |
3256            occaecat cupidatat non proident, sunt in culpa            |
3257            qui officia deserunt mollit anim id est                   |
3258          {2:[No Name] [+]                                               }|
3259          {5:-- INSERT --}                                                |
3260        ]])
3261      end
3262
3263      fn.complete(6, { 'foo', 'bar' })
3264      if multigrid then
3265        screen:expect({
3266          grid = [[
3267          ## grid 1
3268            [4:------------------------------------------------------------]|*6
3269            {3:[No Name] [+]                                               }|
3270            [2:------------------------------------------------------------]|*5
3271            {2:[No Name] [+]                                               }|
3272            [3:------------------------------------------------------------]|
3273          ## grid 2
3274              ea commodo consequat. Duis aute irure dolor in            |
3275              reprehenderit in voluptate velit esse cillum              |
3276              dolore eu fugiat nulla pariatur. Excepteur sint           |
3277              occaecat cupidatat non proident, sunt in culpa            |
3278              qui officia deserunt mollit anim id est                   |
3279          ## grid 3
3280            {5:-- INSERT --}                                                |
3281          ## grid 4
3282            Esteee^                                                      |
3283              Lorem ipsum dolor sit amet, consectetur                   |
3284              adipisicing elit, sed do eiusmod tempor                   |
3285              incididunt ut labore et dolore magna aliqua.              |
3286              Ut enim ad minim veniam, quis nostrud                     |
3287              exercitation ullamco laboris nisi ut aliquip ex           |
3288          ## grid 5
3289            {12: foo            }|
3290            {n: bar            }|
3291          ]],
3292          float_pos = { [5] = { -1, 'NW', 4, 1, 4, false, 100, 1, 1, 4 } },
3293        })
3294      else
3295        screen:expect([[
3296          Esteee^                                                      |
3297            Lo{12: foo            }sit amet, consectetur                   |
3298            ad{n: bar            }sed do eiusmod tempor                   |
3299            incididunt ut labore et dolore magna aliqua.              |
3300            Ut enim ad minim veniam, quis nostrud                     |
3301            exercitation ullamco laboris nisi ut aliquip ex           |
3302          {3:[No Name] [+]                                               }|
3303            ea commodo consequat. Duis aute irure dolor in            |
3304            reprehenderit in voluptate velit esse cillum              |
3305            dolore eu fugiat nulla pariatur. Excepteur sint           |
3306            occaecat cupidatat non proident, sunt in culpa            |
3307            qui officia deserunt mollit anim id est                   |
3308          {2:[No Name] [+]                                               }|
3309          {5:-- INSERT --}                                                |
3310        ]])
3311      end
3312
3313      feed('<c-y>')
3314      if multigrid then
3315        screen:expect([[
3316          ## grid 1
3317            [4:------------------------------------------------------------]|*6
3318            {3:[No Name] [+]                                               }|
3319            [2:------------------------------------------------------------]|*5
3320            {2:[No Name] [+]                                               }|
3321            [3:------------------------------------------------------------]|
3322          ## grid 2
3323              ea commodo consequat. Duis aute irure dolor in            |
3324              reprehenderit in voluptate velit esse cillum              |
3325              dolore eu fugiat nulla pariatur. Excepteur sint           |
3326              occaecat cupidatat non proident, sunt in culpa            |
3327              qui officia deserunt mollit anim id est                   |
3328          ## grid 3
3329            {5:-- INSERT --}                                                |
3330          ## grid 4
3331            Esteefoo^                                                    |
3332              Lorem ipsum dolor sit amet, consectetur                   |
3333              adipisicing elit, sed do eiusmod tempor                   |
3334              incididunt ut labore et dolore magna aliqua.              |
3335              Ut enim ad minim veniam, quis nostrud                     |
3336              exercitation ullamco laboris nisi ut aliquip ex           |
3337          ]])
3338      else
3339        screen:expect([[
3340          Esteefoo^                                                    |
3341            Lorem ipsum dolor sit amet, consectetur                   |
3342            adipisicing elit, sed do eiusmod tempor                   |
3343            incididunt ut labore et dolore magna aliqua.              |
3344            Ut enim ad minim veniam, quis nostrud                     |
3345            exercitation ullamco laboris nisi ut aliquip ex           |
3346          {3:[No Name] [+]                                               }|
3347            ea commodo consequat. Duis aute irure dolor in            |
3348            reprehenderit in voluptate velit esse cillum              |
3349            dolore eu fugiat nulla pariatur. Excepteur sint           |
3350            occaecat cupidatat non proident, sunt in culpa            |
3351            qui officia deserunt mollit anim id est                   |
3352          {2:[No Name] [+]                                               }|
3353          {5:-- INSERT --}                                                |
3354        ]])
3355      end
3356    end)
3357
3358    it('can be moved due to wrap or resize', function()
3359      feed('isome long prefix before the ')
3360      command('set completeopt+=noinsert,noselect')
3361      command('set linebreak')
3362      fn.complete(29, { 'word', 'choice', 'text', 'thing' })
3363      if multigrid then
3364        screen:expect({
3365          grid = [[
3366          ## grid 1
3367            [2:--------------------------------]|*19
3368            [3:--------------------------------]|
3369          ## grid 2
3370            some long prefix before the ^    |
3371            {1:~                               }|*18
3372          ## grid 3
3373            {5:-- INSERT --}                    |
3374          ## grid 4
3375            {n: word            }|
3376            {n: choice          }|
3377            {n: text            }|
3378            {n: thing           }|
3379          ]],
3380          float_pos = { [4] = { -1, 'NW', 2, 1, 15, false, 100, 1, 1, 15 } },
3381        })
3382      else
3383        screen:expect([[
3384          some long prefix before the ^    |
3385          {1:~              }{n: word            }|
3386          {1:~              }{n: choice          }|
3387          {1:~              }{n: text            }|
3388          {1:~              }{n: thing           }|
3389          {1:~                               }|*14
3390          {5:-- INSERT --}                    |
3391        ]])
3392      end
3393
3394      feed('<c-p>')
3395      if multigrid then
3396        screen:expect({
3397          grid = [[
3398          ## grid 1
3399            [2:--------------------------------]|*19
3400            [3:--------------------------------]|
3401          ## grid 2
3402            some long prefix before the     |
3403            thing^                           |
3404            {1:~                               }|*17
3405          ## grid 3
3406            {5:-- INSERT --}                    |
3407          ## grid 4
3408            {n:word           }|
3409            {n:choice         }|
3410            {n:text           }|
3411            {12:thing          }|
3412          ]],
3413          float_pos = { [4] = { -1, 'NW', 2, 2, 0, false, 100, 1, 2, 0 } },
3414        })
3415      else
3416        screen:expect([[
3417          some long prefix before the     |
3418          thing^                           |
3419          {n:word           }{1:                 }|
3420          {n:choice         }{1:                 }|
3421          {n:text           }{1:                 }|
3422          {12:thing          }{1:                 }|
3423          {1:~                               }|*13
3424          {5:-- INSERT --}                    |
3425        ]])
3426      end
3427
3428      feed('<c-p>')
3429      if multigrid then
3430        screen:expect({
3431          grid = [[
3432          ## grid 1
3433            [2:--------------------------------]|*19
3434            [3:--------------------------------]|
3435          ## grid 2
3436            some long prefix before the text|
3437            {1:^~                               }|
3438            {1:~                               }|*17
3439          ## grid 3
3440            {5:-- INSERT --}                    |
3441          ## grid 4
3442            {n: word            }|
3443            {n: choice          }|
3444            {12: text            }|
3445            {n: thing           }|
3446          ]],
3447          float_pos = { [4] = { -1, 'NW', 2, 1, 15, false, 100, 1, 1, 15 } },
3448        })
3449      else
3450        screen:expect([[
3451          some long prefix before the text|
3452          {1:^~              }{n: word            }|
3453          {1:~              }{n: choice          }|
3454          {1:~              }{12: text            }|
3455          {1:~              }{n: thing           }|
3456          {1:~                               }|*14
3457          {5:-- INSERT --}                    |
3458        ]])
3459      end
3460
3461      screen:try_resize(30, 8)
3462      if multigrid then
3463        screen:expect({
3464          grid = [[
3465          ## grid 1
3466            [2:------------------------------]|*7
3467            [3:------------------------------]|
3468          ## grid 2
3469            some long prefix before the   |
3470            text^                          |
3471            {1:~                             }|*5
3472          ## grid 3
3473            {5:-- INSERT --}                  |
3474          ## grid 4
3475            {n:word           }|
3476            {n:choice         }|
3477            {12:text           }|
3478            {n:thing          }|
3479          ]],
3480          float_pos = { [4] = { -1, 'NW', 2, 2, 0, false, 100, 1, 2, 0 } },
3481        })
3482      else
3483        screen:expect([[
3484          some long prefix before the   |
3485          text^                          |
3486          {n:word           }{1:               }|
3487          {n:choice         }{1:               }|
3488          {12:text           }{1:               }|
3489          {n:thing          }{1:               }|
3490          {1:~                             }|
3491          {5:-- INSERT --}                  |
3492        ]])
3493      end
3494
3495      screen:try_resize(50, 8)
3496      if multigrid then
3497        screen:expect({
3498          grid = [[
3499          ## grid 1
3500            [2:--------------------------------------------------]|*7
3501            [3:--------------------------------------------------]|
3502          ## grid 2
3503            some long prefix before the text^                  |
3504            {1:~                                                 }|*6
3505          ## grid 3
3506            {5:-- INSERT --}                                      |
3507          ## grid 4
3508            {n: word           }|
3509            {n: choice         }|
3510            {12: text           }|
3511            {n: thing          }|
3512          ]],
3513          float_pos = { [4] = { -1, 'NW', 2, 1, 27, false, 100, 1, 1, 27 } },
3514        })
3515      else
3516        screen:expect([[
3517          some long prefix before the text^                  |
3518          {1:~                          }{n: word           }{1:       }|
3519          {1:~                          }{n: choice         }{1:       }|
3520          {1:~                          }{12: text           }{1:       }|
3521          {1:~                          }{n: thing          }{1:       }|
3522          {1:~                                                 }|*2
3523          {5:-- INSERT --}                                      |
3524        ]])
3525      end
3526
3527      screen:try_resize(25, 10)
3528      if multigrid then
3529        screen:expect({
3530          grid = [[
3531          ## grid 1
3532            [2:-------------------------]|*9
3533            [3:-------------------------]|
3534          ## grid 2
3535            some long prefix before  |
3536            the text^                 |
3537            {1:~                        }|*7
3538          ## grid 3
3539            {5:-- INSERT --}             |
3540          ## grid 4
3541            {n: word           }|
3542            {n: choice         }|
3543            {12: text           }|
3544            {n: thing          }|
3545          ]],
3546          float_pos = { [4] = { -1, 'NW', 2, 2, 3, false, 100, 1, 2, 3 } },
3547        })
3548      else
3549        screen:expect([[
3550          some long prefix before  |
3551          the text^                 |
3552          {1:~  }{n: word           }{1:      }|
3553          {1:~  }{n: choice         }{1:      }|
3554          {1:~  }{12: text           }{1:      }|
3555          {1:~  }{n: thing          }{1:      }|
3556          {1:~                        }|*3
3557          {5:-- INSERT --}             |
3558        ]])
3559      end
3560
3561      screen:try_resize(12, 5)
3562      if multigrid then
3563        screen:expect({
3564          grid = [[
3565          ## grid 1
3566            [2:------------]|*4
3567            [3:------------]|
3568          ## grid 2
3569            some long   |
3570            prefix      |
3571            before the  |
3572            text^        |
3573          ## grid 3
3574            {5:-- INSERT --}|
3575          ## grid 4
3576            {n: word           }|
3577            {n: choice         }|
3578            {12: text           }|
3579            {n: thing          }|
3580          ]],
3581          float_pos = { [4] = { -1, 'NW', 2, 2, 3, false, 100, 1, 2, 3 } },
3582        })
3583      else
3584        screen:expect([[
3585          some long   |
3586          prefix      |
3587          bef{n: word  }  |
3588          tex{n: }^        |
3589          {5:-- INSERT --}|
3590        ]])
3591      end
3592
3593      -- can't draw the pum, but check we don't crash
3594      screen:try_resize(12, 2)
3595      if multigrid then
3596        screen:expect({
3597          grid = [[
3598          ## grid 1
3599            [2:------------]|
3600            [3:------------]|
3601          ## grid 2
3602            {1:<<<}t^        |
3603          ## grid 3
3604            {5:-- INSERT --}|
3605          ## grid 4
3606            {n: word           }|
3607            {n: choice         }|
3608            {12: text           }|
3609            {n: thing          }|
3610          ]],
3611          float_pos = { [4] = { -1, 'NW', 2, 2, 3, false, 100, 1, 2, 3 } },
3612        })
3613      else
3614        screen:expect([[
3615          {1:<<<}t^        |
3616          {5:-- INSERT --}|
3617        ]])
3618      end
3619
3620      -- but state is preserved, pum reappears
3621      screen:try_resize(20, 8)
3622      if multigrid then
3623        screen:expect({
3624          grid = [[
3625          ## grid 1
3626            [2:--------------------]|*7
3627            [3:--------------------]|
3628          ## grid 2
3629            some long prefix    |
3630            before the text^     |
3631            {1:~                   }|*5
3632          ## grid 3
3633            {5:-- INSERT --}        |
3634          ## grid 4
3635            {n: word            }|
3636            {n: choice          }|
3637            {12: text            }|
3638            {n: thing           }|
3639          ]],
3640          float_pos = { [4] = { -1, 'NW', 2, 2, 3, false, 100, 1, 2, 3 } },
3641        })
3642      else
3643        screen:expect([[
3644          some long prefix    |
3645          before the text^     |
3646          {1:~  }{n: word            }|
3647          {1:~  }{n: choice          }|
3648          {1:~  }{12: text            }|
3649          {1:~  }{n: thing           }|
3650          {1:~                   }|
3651          {5:-- INSERT --}        |
3652        ]])
3653      end
3654    end)
3655
3656    it('with VimResized autocmd', function()
3657      feed('isome long prefix before the ')
3658      command('set completeopt+=noinsert,noselect pumwidth=12')
3659      command('autocmd VimResized * redraw!')
3660      command('set linebreak')
3661      fn.complete(29, { 'word', 'choice', 'text', 'thing' })
3662      if multigrid then
3663        screen:expect({
3664          grid = [[
3665          ## grid 1
3666            [2:--------------------------------]|*19
3667            [3:--------------------------------]|
3668          ## grid 2
3669            some long prefix before the ^    |
3670            {1:~                               }|*18
3671          ## grid 3
3672            {5:-- INSERT --}                    |
3673          ## grid 4
3674            {n: word         }|
3675            {n: choice       }|
3676            {n: text         }|
3677            {n: thing        }|
3678          ]],
3679          float_pos = { [4] = { -1, 'NW', 2, 1, 18, false, 100, 1, 1, 18 } },
3680        })
3681      else
3682        screen:expect([[
3683          some long prefix before the ^    |
3684          {1:~                 }{n: word         }|
3685          {1:~                 }{n: choice       }|
3686          {1:~                 }{n: text         }|
3687          {1:~                 }{n: thing        }|
3688          {1:~                               }|*14
3689          {5:-- INSERT --}                    |
3690        ]])
3691      end
3692
3693      screen:try_resize(16, 10)
3694      if multigrid then
3695        screen:expect({
3696          grid = [[
3697          ## grid 1
3698            [2:----------------]|*9
3699            [3:----------------]|
3700          ## grid 2
3701            some long       |
3702            prefix before   |
3703            the ^            |
3704            {1:~               }|*6
3705          ## grid 3
3706            {5:-- INSERT --}    |
3707          ## grid 4
3708            {n: word        }|
3709            {n: choice      }|
3710            {n: text        }|
3711            {n: thing       }|
3712          ]],
3713          float_pos = { [4] = { -1, 'NW', 2, 3, 3, false, 100, 1, 3, 3 } },
3714        })
3715      else
3716        screen:expect([[
3717          some long       |
3718          prefix before   |
3719          the ^            |
3720          {1:~  }{n: word        }|
3721          {1:~  }{n: choice      }|
3722          {1:~  }{n: text        }|
3723          {1:~  }{n: thing       }|
3724          {1:~               }|*2
3725          {5:-- INSERT --}    |
3726        ]])
3727      end
3728    end)
3729
3730    it('with rightleft window', function()
3731      command('set rl wildoptions+=pum')
3732      feed('isome rightleft ')
3733      if multigrid then
3734        screen:expect([[
3735          ## grid 1
3736            [2:--------------------------------]|*19
3737            [3:--------------------------------]|
3738          ## grid 2
3739                            ^  tfelthgir emos|
3740            {1:                               ~}|*18
3741          ## grid 3
3742            {5:-- INSERT --}                    |
3743        ]])
3744      else
3745        screen:expect([[
3746                          ^  tfelthgir emos|
3747          {1:                               ~}|*18
3748          {5:-- INSERT --}                    |
3749        ]])
3750      end
3751
3752      command('set completeopt+=noinsert,noselect')
3753      fn.complete(16, { 'word', 'choice', 'text', 'thing' })
3754      if multigrid then
3755        screen:expect({
3756          grid = [[
3757          ## grid 1
3758            [2:--------------------------------]|*19
3759            [3:--------------------------------]|
3760          ## grid 2
3761                            ^  tfelthgir emos|
3762            {1:                               ~}|*18
3763          ## grid 3
3764            {5:-- INSERT --}                    |
3765          ## grid 4
3766            {n:           drow }|
3767            {n:         eciohc }|
3768            {n:           txet }|
3769            {n:          gniht }|
3770          ]],
3771          float_pos = { [4] = { -1, 'NW', 2, 1, 2, false, 100, 1, 1, 2 } },
3772        })
3773      else
3774        screen:expect([[
3775                          ^  tfelthgir emos|
3776          {1:  }{n:           drow }{1:             ~}|
3777          {1:  }{n:         eciohc }{1:             ~}|
3778          {1:  }{n:           txet }{1:             ~}|
3779          {1:  }{n:          gniht }{1:             ~}|
3780          {1:                               ~}|*14
3781          {5:-- INSERT --}                    |
3782        ]])
3783      end
3784
3785      feed('<c-n>')
3786      if multigrid then
3787        screen:expect({
3788          grid = [[
3789          ## grid 1
3790            [2:--------------------------------]|*19
3791            [3:--------------------------------]|
3792          ## grid 2
3793                        ^ drow tfelthgir emos|
3794            {1:                               ~}|*18
3795          ## grid 3
3796            {5:-- INSERT --}                    |
3797          ## grid 4
3798            {12:           drow }|
3799            {n:         eciohc }|
3800            {n:           txet }|
3801            {n:          gniht }|
3802          ]],
3803          float_pos = { [4] = { -1, 'NW', 2, 1, 2, false, 100, 1, 1, 2 } },
3804        })
3805      else
3806        screen:expect([[
3807                      ^ drow tfelthgir emos|
3808          {1:  }{12:           drow }{1:             ~}|
3809          {1:  }{n:         eciohc }{1:             ~}|
3810          {1:  }{n:           txet }{1:             ~}|
3811          {1:  }{n:          gniht }{1:             ~}|
3812          {1:                               ~}|*14
3813          {5:-- INSERT --}                    |
3814        ]])
3815      end
3816
3817      feed('<c-y>')
3818      if multigrid then
3819        screen:expect([[
3820          ## grid 1
3821            [2:--------------------------------]|*19
3822            [3:--------------------------------]|
3823          ## grid 2
3824                        ^ drow tfelthgir emos|
3825            {1:                               ~}|*18
3826          ## grid 3
3827            {5:-- INSERT --}                    |
3828        ]])
3829      else
3830        screen:expect([[
3831                      ^ drow tfelthgir emos|
3832          {1:                               ~}|*18
3833          {5:-- INSERT --}                    |
3834        ]])
3835      end
3836
3837      -- oldtest: Test_wildmenu_pum_rightleft()
3838      feed('<esc>:sign ')
3839      if multigrid then
3840        screen:expect([[
3841          ## grid 1
3842            [2:--------------------------------]|*19
3843            [3:--------------------------------]|
3844          ## grid 2
3845                         drow tfelthgir emos|
3846            {1:                               ~}|*18
3847          ## grid 3
3848            :sign ^                          |
3849        ]])
3850      else
3851        screen:expect([[
3852                       drow tfelthgir emos|
3853          {1:                               ~}|*18
3854          :sign ^                          |
3855        ]])
3856      end
3857      -- Not rightleft on the cmdline.
3858      feed('<Tab>')
3859      if multigrid then
3860        screen:expect({
3861          grid = [[
3862          ## grid 1
3863            [2:--------------------------------]|*19
3864            [3:--------------------------------]|
3865          ## grid 2
3866                         drow tfelthgir emos|
3867            {1:                               ~}|*18
3868          ## grid 3
3869            :sign define^                    |
3870          ## grid 4
3871            {12: define         }|
3872            {n: jump           }|
3873            {n: list           }|
3874            {n: place          }|
3875            {n: undefine       }|
3876            {n: unplace        }|
3877          ]],
3878          float_pos = { [4] = { -1, 'SW', 1, 19, 5, false, 250, 2, 13, 5 } },
3879        })
3880      else
3881        screen:expect([[
3882                       drow tfelthgir emos|
3883          {1:                               ~}|*12
3884          {1:     }{12: define         }{1:          ~}|
3885          {1:     }{n: jump           }{1:          ~}|
3886          {1:     }{n: list           }{1:          ~}|
3887          {1:     }{n: place          }{1:          ~}|
3888          {1:     }{n: undefine       }{1:          ~}|
3889          {1:     }{n: unplace        }{1:          ~}|
3890          :sign define^                    |
3891        ]])
3892      end
3893
3894      -- Behavior is the same when using 'keymap'.
3895      feed('<Esc>')
3896      command('set keymap=dvorak')
3897      -- ";gul" -> "sign" when using Dvorak keymap.
3898      feed(':<C-^>;gul <Tab>')
3899      screen:expect_unchanged(true)
3900      feed('<Esc>')
3901      command('set keymap&')
3902    end)
3903
3904    it('with rightleft vsplits', function()
3905      screen:try_resize(40, 6)
3906      command('set rightleft')
3907      command('rightbelow vsplit')
3908      command('set completeopt+=noinsert,noselect')
3909      command('set pumheight=2')
3910      feed('isome rightleft ')
3911      fn.complete(16, { 'word', 'choice', 'text', 'thing' })
3912      if multigrid then
3913        screen:expect {
3914          grid = [[
3915        ## grid 1
3916          [2:-------------------]│[4:--------------------]|*4
3917          {2:[No Name] [+]       }{3:[No Name] [+]       }|
3918          [3:----------------------------------------]|
3919        ## grid 2
3920               tfelthgir emos|
3921          {1:                  ~}|*3
3922        ## grid 3
3923          {5:-- INSERT --}                            |
3924        ## grid 4
3925              ^  tfelthgir emos|
3926          {1:                   ~}|*3
3927        ## grid 5
3928          {c: }{n:           drow }|
3929          {12: }{n:         eciohc }|
3930        ]],
3931          float_pos = { [5] = { -1, 'NW', 4, 1, -11, false, 100, 1, 1, 9 } },
3932        }
3933      else
3934        screen:expect([[
3935               tfelthgir emos│    ^  tfelthgir emos|
3936          {1:         }{c: }{n:           drow }{1:             ~}|
3937          {1:         }{12: }{n:         eciohc }{1:             ~}|
3938          {1:                  ~}│{1:                   ~}|
3939          {2:[No Name] [+]       }{3:[No Name] [+]       }|
3940          {5:-- INSERT --}                            |
3941        ]])
3942      end
3943      feed('<C-E><CR>')
3944      fn.complete(1, { 'word', 'choice', 'text', 'thing' })
3945      if multigrid then
3946        screen:expect {
3947          grid = [[
3948        ## grid 1
3949          [2:-------------------]│[4:--------------------]|*4
3950          {2:[No Name] [+]       }{3:[No Name] [+]       }|
3951          [3:----------------------------------------]|
3952        ## grid 2
3953               tfelthgir emos|
3954                             |
3955          {1:                  ~}|*2
3956        ## grid 3
3957          {5:-- INSERT --}                            |
3958        ## grid 4
3959                tfelthgir emos|
3960                             ^ |
3961          {1:                   ~}|*2
3962        ## grid 5
3963          {c: }{n:           drow}|
3964          {12: }{n:         eciohc}|
3965        ]],
3966          float_pos = { [5] = { -1, 'NW', 4, 2, 4, false, 100, 1, 2, 24 } },
3967        }
3968      else
3969        screen:expect([[
3970               tfelthgir emos│      tfelthgir emos|
3971                             │                   ^ |
3972          {1:                  ~}│{1:    }{c: }{n:           drow}|
3973          {1:                  ~}│{1:    }{12: }{n:         eciohc}|
3974          {2:[No Name] [+]       }{3:[No Name] [+]       }|
3975          {5:-- INSERT --}                            |
3976        ]])
3977      end
3978      feed('<C-E>')
3979      async_meths.nvim_call_function('input', { '', '', 'sign' })
3980      if multigrid then
3981        screen:expect([[
3982        ## grid 1
3983          [2:-------------------]│[4:--------------------]|*4
3984          {2:[No Name] [+]       }{3:[No Name] [+]       }|
3985          [3:----------------------------------------]|
3986        ## grid 2
3987               tfelthgir emos|
3988                             |
3989          {1:                  ~}|*2
3990        ## grid 3
3991          ^                                        |
3992        ## grid 4
3993                tfelthgir emos|
3994                              |
3995          {1:                   ~}|*2
3996        ]])
3997      else
3998        screen:expect([[
3999               tfelthgir emos│      tfelthgir emos|
4000                             │                    |
4001          {1:                  ~}│{1:                   ~}|*2
4002          {2:[No Name] [+]       }{3:[No Name] [+]       }|
4003          ^                                        |
4004        ]])
4005      end
4006      command('set wildoptions+=pum')
4007      feed('<Tab>')
4008      if multigrid then
4009        screen:expect {
4010          grid = [[
4011        ## grid 1
4012          [2:-------------------]│[4:--------------------]|*4
4013          {2:[No Name] [+]       }{3:[No Name] [+]       }|
4014          [3:----------------------------------------]|
4015        ## grid 2
4016               tfelthgir emos|
4017                             |
4018          {1:                  ~}|*2
4019        ## grid 3
4020          define^                                  |
4021        ## grid 4
4022                tfelthgir emos|
4023                              |
4024          {1:                   ~}|*2
4025        ## grid 5
4026          {12:define         }{c: }|
4027          {n:jump           }{12: }|
4028        ]],
4029          float_pos = { [5] = { -1, 'SW', 1, 5, 0, false, 250, 2, 3, 0 } },
4030        }
4031      else
4032        screen:expect([[
4033               tfelthgir emos│      tfelthgir emos|
4034                             │                    |
4035          {1:                  ~}│{1:                   ~}|
4036          {12:define         }{c: }{1:  ~}│{1:                   ~}|
4037          {n:jump           }{12: }{2:    }{3:[No Name] [+]       }|
4038          define^                                  |
4039        ]])
4040      end
4041    end)
4042
4043    it('with multiline messages', function()
4044      screen:try_resize(40, 8)
4045      feed('ixx<cr>')
4046      command('imap <f2> <cmd>echoerr "very"\\|echoerr "much"\\|echoerr "error"<cr>')
4047      fn.complete(1, { 'word', 'choice', 'text', 'thing' })
4048      if multigrid then
4049        screen:expect({
4050          grid = [[
4051        ## grid 1
4052          [2:----------------------------------------]|*7
4053          [3:----------------------------------------]|
4054        ## grid 2
4055          xx                                      |
4056          word^                                    |
4057          {1:~                                       }|*5
4058        ## grid 3
4059          {5:-- INSERT --}                            |
4060        ## grid 4
4061          {12:word           }|
4062          {n:choice         }|
4063          {n:text           }|
4064          {n:thing          }|
4065        ]],
4066          float_pos = { [4] = { -1, 'NW', 2, 2, 0, false, 100, 1, 2, 0 } },
4067        })
4068      else
4069        screen:expect([[
4070          xx                                      |
4071          word^                                    |
4072          {12:word           }{1:                         }|
4073          {n:choice         }{1:                         }|
4074          {n:text           }{1:                         }|
4075          {n:thing          }{1:                         }|
4076          {1:~                                       }|
4077          {5:-- INSERT --}                            |
4078        ]])
4079      end
4080
4081      feed('<f2>')
4082      if multigrid then
4083        screen:expect({
4084          grid = [[
4085        ## grid 1
4086          [2:----------------------------------------]|*4
4087          [3:----------------------------------------]|*4
4088        ## grid 2
4089          xx                                      |
4090          word                                    |
4091          {1:~                                       }|*5
4092        ## grid 3
4093          {9:very}                                    |
4094          {9:much}                                    |
4095          {9:error}                                   |
4096          {6:Press ENTER or type command to continue}^ |
4097        ## grid 4
4098          {12:word           }|
4099          {n:choice         }|
4100          {n:text           }|
4101          {n:thing          }|
4102        ]],
4103          float_pos = { [4] = { -1, 'NW', 2, 2, 0, false, 100, 1, 2, 0 } },
4104        })
4105      else
4106        screen:expect([[
4107          xx                                      |
4108          word                                    |
4109          {12:word           }{1:                         }|
4110          {3:                                        }|
4111          {9:very}                                    |
4112          {9:much}                                    |
4113          {9:error}                                   |
4114          {6:Press ENTER or type command to continue}^ |
4115        ]])
4116      end
4117
4118      feed('<cr>')
4119      if multigrid then
4120        screen:expect({
4121          grid = [[
4122        ## grid 1
4123          [2:----------------------------------------]|*7
4124          [3:----------------------------------------]|
4125        ## grid 2
4126          xx                                      |
4127          word^                                    |
4128          {1:~                                       }|*5
4129        ## grid 3
4130          {5:-- INSERT --}                            |
4131        ## grid 4
4132          {12:word           }|
4133          {n:choice         }|
4134          {n:text           }|
4135          {n:thing          }|
4136        ]],
4137          float_pos = { [4] = { -1, 'NW', 2, 2, 0, false, 100, 1, 2, 0 } },
4138        })
4139      else
4140        screen:expect([[
4141          xx                                      |
4142          word^                                    |
4143          {12:word           }{1:                         }|
4144          {n:choice         }{1:                         }|
4145          {n:text           }{1:                         }|
4146          {n:thing          }{1:                         }|
4147          {1:~                                       }|
4148          {5:-- INSERT --}                            |
4149        ]])
4150      end
4151
4152      feed('<c-n>')
4153      if multigrid then
4154        screen:expect({
4155          grid = [[
4156        ## grid 1
4157          [2:----------------------------------------]|*7
4158          [3:----------------------------------------]|
4159        ## grid 2
4160          xx                                      |
4161          choice^                                  |
4162          {1:~                                       }|*5
4163        ## grid 3
4164          {5:-- INSERT --}                            |
4165        ## grid 4
4166          {n:word           }|
4167          {12:choice         }|
4168          {n:text           }|
4169          {n:thing          }|
4170        ]],
4171          float_pos = { [4] = { -1, 'NW', 2, 2, 0, false, 100, 1, 2, 0 } },
4172        })
4173      else
4174        screen:expect([[
4175          xx                                      |
4176          choice^                                  |
4177          {n:word           }{1:                         }|
4178          {12:choice         }{1:                         }|
4179          {n:text           }{1:                         }|
4180          {n:thing          }{1:                         }|
4181          {1:~                                       }|
4182          {5:-- INSERT --}                            |
4183        ]])
4184      end
4185
4186      command('split')
4187      feed('<c-u>')
4188      fn.complete(1, { 'word', 'choice', 'text', 'thing' })
4189      if multigrid then
4190        screen:expect({
4191          grid = [[
4192        ## grid 1
4193          [5:----------------------------------------]|*3
4194          {3:[No Name] [+]                           }|
4195          [2:----------------------------------------]|*2
4196          {2:[No Name] [+]                           }|
4197          [3:----------------------------------------]|
4198        ## grid 2
4199          xx                                      |
4200          word                                    |
4201        ## grid 3
4202          {5:-- INSERT --}                            |
4203        ## grid 4
4204          {12:word           }|
4205          {n:choice         }|
4206          {n:text           }|
4207          {n:thing          }|
4208        ## grid 5
4209          xx                                      |
4210          word^                                    |
4211          {1:~                                       }|
4212        ]],
4213          float_pos = { [4] = { -1, 'NW', 5, 2, 0, false, 100, 1, 2, 0 } },
4214        })
4215      else
4216        screen:expect([[
4217          xx                                      |
4218          word^                                    |
4219          {12:word           }{1:                         }|
4220          {n:choice         }{3:                         }|
4221          {n:text           }                         |
4222          {n:thing          }                         |
4223          {2:[No Name] [+]                           }|
4224          {5:-- INSERT --}                            |
4225        ]])
4226      end
4227
4228      api.nvim_input_mouse('wheel', 'down', '', 0, 6, 15)
4229      if multigrid then
4230        screen:expect({
4231          grid = [[
4232        ## grid 1
4233          [5:----------------------------------------]|*3
4234          {3:[No Name] [+]                           }|
4235          [2:----------------------------------------]|*2
4236          {2:[No Name] [+]                           }|
4237          [3:----------------------------------------]|
4238        ## grid 2
4239          word                                    |
4240          {1:~                                       }|
4241        ## grid 3
4242          {5:-- INSERT --}                            |
4243        ## grid 4
4244          {12:word           }|
4245          {n:choice         }|
4246          {n:text           }|
4247          {n:thing          }|
4248        ## grid 5
4249          xx                                      |
4250          word^                                    |
4251          {1:~                                       }|
4252        ]],
4253          float_pos = { [4] = { -1, 'NW', 5, 2, 0, false, 100, 1, 2, 0 } },
4254        })
4255      else
4256        screen:expect([[
4257          xx                                      |
4258          word^                                    |
4259          {12:word           }{1:                         }|
4260          {n:choice         }{3:                         }|
4261          {n:text           }                         |
4262          {n:thing          }{1:                         }|
4263          {2:[No Name] [+]                           }|
4264          {5:-- INSERT --}                            |
4265        ]])
4266      end
4267    end)
4268
4269    if not multigrid then
4270      it('with kind, menu and abbr attributes', function()
4271        screen:try_resize(40, 8)
4272        feed('ixx ')
4273        fn.complete(4, {
4274          { word = 'wordey', kind = 'x', menu = 'extrainfo' },
4275          'thing',
4276          { word = 'secret', abbr = 'sneaky', menu = 'bar' },
4277        })
4278        screen:expect([[
4279          xx wordey^                               |
4280          {1:~ }{12: wordey x extrainfo }{1:                  }|
4281          {1:~ }{n: thing              }{1:                  }|
4282          {1:~ }{n: sneaky   bar       }{1:                  }|
4283          {1:~                                       }|*3
4284          {5:-- INSERT --}                            |
4285        ]])
4286
4287        feed('<c-p>')
4288        screen:expect([[
4289          xx ^                                     |
4290          {1:~ }{n: wordey x extrainfo }{1:                  }|
4291          {1:~ }{n: thing              }{1:                  }|
4292          {1:~ }{n: sneaky   bar       }{1:                  }|
4293          {1:~                                       }|*3
4294          {5:-- INSERT --}                            |
4295        ]])
4296
4297        feed('<c-p>')
4298        screen:expect([[
4299          xx secret^                               |
4300          {1:~ }{n: wordey x extrainfo }{1:                  }|
4301          {1:~ }{n: thing              }{1:                  }|
4302          {1:~ }{12: sneaky   bar       }{1:                  }|
4303          {1:~                                       }|*3
4304          {5:-- INSERT --}                            |
4305        ]])
4306
4307        feed('<esc>')
4308        screen:expect([[
4309          xx secre^t                               |
4310          {1:~                                       }|*6
4311                                                  |
4312        ]])
4313      end)
4314
4315      it('wildoptions=pum', function()
4316        screen:try_resize(32, 10)
4317        command('set wildmenu')
4318        command('set wildoptions=pum')
4319        command('set shellslash')
4320        command('cd test/functional/fixtures/wildpum')
4321
4322        feed(':sign ')
4323        screen:expect([[
4324                                          |
4325          {1:~                               }|*8
4326          :sign ^                          |
4327        ]])
4328
4329        feed('<Tab>')
4330        screen:expect([[
4331                                          |
4332          {1:~                               }|*2
4333          {1:~    }{12: define         }{1:           }|
4334          {1:~    }{n: jump           }{1:           }|
4335          {1:~    }{n: list           }{1:           }|
4336          {1:~    }{n: place          }{1:           }|
4337          {1:~    }{n: undefine       }{1:           }|
4338          {1:~    }{n: unplace        }{1:           }|
4339          :sign define^                    |
4340        ]])
4341
4342        feed('<Right><Right>')
4343        screen:expect([[
4344                                          |
4345          {1:~                               }|*2
4346          {1:~    }{n: define         }{1:           }|
4347          {1:~    }{n: jump           }{1:           }|
4348          {1:~    }{12: list           }{1:           }|
4349          {1:~    }{n: place          }{1:           }|
4350          {1:~    }{n: undefine       }{1:           }|
4351          {1:~    }{n: unplace        }{1:           }|
4352          :sign list^                      |
4353        ]])
4354
4355        feed('<C-N>')
4356        screen:expect([[
4357                                          |
4358          {1:~                               }|*2
4359          {1:~    }{n: define         }{1:           }|
4360          {1:~    }{n: jump           }{1:           }|
4361          {1:~    }{n: list           }{1:           }|
4362          {1:~    }{12: place          }{1:           }|
4363          {1:~    }{n: undefine       }{1:           }|
4364          {1:~    }{n: unplace        }{1:           }|
4365          :sign place^                     |
4366        ]])
4367
4368        feed('<C-P>')
4369        screen:expect([[
4370                                          |
4371          {1:~                               }|*2
4372          {1:~    }{n: define         }{1:           }|
4373          {1:~    }{n: jump           }{1:           }|
4374          {1:~    }{12: list           }{1:           }|
4375          {1:~    }{n: place          }{1:           }|
4376          {1:~    }{n: undefine       }{1:           }|
4377          {1:~    }{n: unplace        }{1:           }|
4378          :sign list^                      |
4379        ]])
4380
4381        feed('<Left>')
4382        screen:expect([[
4383                                          |
4384          {1:~                               }|*2
4385          {1:~    }{n: define         }{1:           }|
4386          {1:~    }{12: jump           }{1:           }|
4387          {1:~    }{n: list           }{1:           }|
4388          {1:~    }{n: place          }{1:           }|
4389          {1:~    }{n: undefine       }{1:           }|
4390          {1:~    }{n: unplace        }{1:           }|
4391          :sign jump^                      |
4392        ]])
4393
4394        -- pressing <C-E> should end completion and go back to the original match
4395        feed('<C-E>')
4396        screen:expect([[
4397                                          |
4398          {1:~                               }|*8
4399          :sign ^                          |
4400        ]])
4401
4402        -- pressing <C-Y> should select the current match and end completion
4403        feed('<Tab><C-P><C-P><C-Y>')
4404        screen:expect([[
4405                                          |
4406          {1:~                               }|*8
4407          :sign unplace^                   |
4408        ]])
4409
4410        -- showing popup menu in different columns in the cmdline
4411        feed('<C-U>sign define <Tab>')
4412        screen:expect([[
4413                                          |
4414          {1:~                               }|
4415          {1:~           }{12: culhl=         }{1:    }|
4416          {1:~           }{n: icon=          }{1:    }|
4417          {1:~           }{n: linehl=        }{1:    }|
4418          {1:~           }{n: numhl=         }{1:    }|
4419          {1:~           }{n: priority=      }{1:    }|
4420          {1:~           }{n: text=          }{1:    }|
4421          {1:~           }{n: texthl=        }{1:    }|
4422          :sign define culhl=^             |
4423        ]])
4424
4425        feed('<Space><Tab>')
4426        screen:expect([[
4427                                          |
4428          {1:~                               }|
4429          {1:~              }{12: culhl=          }|
4430          {1:~              }{n: icon=           }|
4431          {1:~              }{n: linehl=         }|
4432          {1:~              }{n: numhl=          }|
4433          {1:~              }{n: priority=       }|
4434          {1:~              }{n: text=           }|
4435          {1:~              }{n: texthl=         }|
4436          :sign define culhl= culhl=^      |
4437        ]])
4438
4439        feed('<C-U>e Xnamedi<Tab><Tab>')
4440        screen:expect([[
4441                                          |
4442          {1:~                               }|*6
4443          {1:~          }{12: XdirA/         }{1:     }|
4444          {1:~          }{n: XfileA         }{1:     }|
4445          :e Xnamedir/XdirA/^              |
4446        ]])
4447
4448        -- Pressing <Down> on a directory name should go into that directory
4449        feed('<Down>')
4450        screen:expect([[
4451                                          |
4452          {1:~                               }|*6
4453          {1:~              }{12: XdirB/          }|
4454          {1:~              }{n: XfileB          }|
4455          :e Xnamedir/XdirA/XdirB/^        |
4456        ]])
4457
4458        -- Pressing <Up> on a directory name should go to the parent directory
4459        feed('<Up>')
4460        screen:expect([[
4461                                          |
4462          {1:~                               }|*6
4463          {1:~          }{12: XdirA/         }{1:     }|
4464          {1:~          }{n: XfileA         }{1:     }|
4465          :e Xnamedir/XdirA/^              |
4466        ]])
4467
4468        -- Pressing <C-A> when the popup menu is displayed should list all the
4469        -- matches and remove the popup menu
4470        feed(':<C-U>sign <Tab><C-A>')
4471        screen:expect([[
4472                                          |
4473          {1:~                               }|*6
4474          {3:                                }|
4475          :sign define jump list place und|
4476          efine unplace^                   |
4477        ]])
4478
4479        -- Pressing <Left> after that should move the cursor
4480        feed('<Left>')
4481        screen:expect([[
4482                                          |
4483          {1:~                               }|*6
4484          {3:                                }|
4485          :sign define jump list place und|
4486          efine unplac^e                   |
4487        ]])
4488        feed('<End>')
4489
4490        -- Pressing <C-D> when the popup menu is displayed should remove the popup
4491        -- menu
4492        feed('<C-U>sign <Tab><C-D>')
4493        screen:expect([[
4494                                          |
4495          {1:~                               }|*5
4496          {3:                                }|
4497          :sign define                    |
4498          define                          |
4499          :sign define^                    |
4500        ]])
4501
4502        -- Pressing <S-Tab> should open the popup menu with the last entry selected
4503        feed('<C-U><CR>:sign <S-Tab><C-P>')
4504        screen:expect([[
4505                                          |
4506          {1:~                               }|*2
4507          {1:~    }{n: define         }{1:           }|
4508          {1:~    }{n: jump           }{1:           }|
4509          {1:~    }{n: list           }{1:           }|
4510          {1:~    }{n: place          }{1:           }|
4511          {1:~    }{12: undefine       }{1:           }|
4512          {1:~    }{n: unplace        }{1:           }|
4513          :sign undefine^                  |
4514        ]])
4515
4516        -- Pressing <Esc> should close the popup menu and cancel the cmd line
4517        feed('<C-U><CR>:sign <Tab><Esc>')
4518        screen:expect([[
4519          ^                                |
4520          {1:~                               }|*8
4521                                          |
4522        ]])
4523
4524        -- Typing a character when the popup is open, should close the popup
4525        feed(':sign <Tab>x')
4526        screen:expect([[
4527                                          |
4528          {1:~                               }|*8
4529          :sign definex^                   |
4530        ]])
4531
4532        -- When the popup is open, entering cmdwin should close the popup.
4533        feed('<C-U>sign <Tab><C-F>')
4534        t.retry(nil, 2000, function()
4535          eq(':', n.fn.getcmdwintype())
4536        end)
4537        eq(0, n.fn.pumvisible())
4538        feed(':q<CR>')
4539
4540        -- After the last popup menu item, <C-N> should show the original string
4541        feed(':sign u<Tab><C-N><C-N>')
4542        screen:expect([[
4543                                          |
4544          {1:~                               }|*6
4545          {1:~    }{n: undefine       }{1:           }|
4546          {1:~    }{n: unplace        }{1:           }|
4547          :sign u^                         |
4548        ]])
4549
4550        -- Use the popup menu for the command name
4551        feed('<C-U>bu<Tab>')
4552        screen:expect([[
4553                                          |
4554          {1:~                               }|*4
4555          {12: bufdo          }{1:                }|
4556          {n: buffer         }{1:                }|
4557          {n: buffers        }{1:                }|
4558          {n: bunload        }{1:                }|
4559          :bufdo^                          |
4560        ]])
4561
4562        -- Pressing <BS> should remove the popup menu and erase the last character
4563        feed('<C-E><C-U>sign <Tab><BS>')
4564        screen:expect([[
4565                                          |
4566          {1:~                               }|*8
4567          :sign defin^                     |
4568        ]])
4569
4570        -- Pressing <C-W> should remove the popup menu and erase the previous word
4571        feed('<C-E><C-U>sign <Tab><C-W>')
4572        screen:expect([[
4573                                          |
4574          {1:~                               }|*8
4575          :sign ^                          |
4576        ]])
4577
4578        -- Pressing <C-U> should remove the popup menu and erase the entire line
4579        feed('<C-E><C-U>sign <Tab><C-U>')
4580        screen:expect([[
4581                                          |
4582          {1:~                               }|*8
4583          :^                               |
4584        ]])
4585
4586        -- Using <C-E> to cancel the popup menu and then pressing <Up> should recall
4587        -- the cmdline from history
4588        feed('sign xyz<Esc>:sign <Tab><C-E><Up>')
4589        screen:expect([[
4590                                          |
4591          {1:~                               }|*8
4592          :sign xyz^                       |
4593        ]])
4594
4595        feed('<esc>')
4596
4597        -- Check that when "longest" produces no result, "list" works
4598        command('set wildmode=longest,list')
4599        feed(':cn<Tab>')
4600        screen:expect([[
4601                                          |
4602          {1:~                               }|*3
4603          {3:                                }|
4604          :cn                             |
4605          cnewer       cnoreabbrev        |
4606          cnext        cnoremap           |
4607          cnfile       cnoremenu          |
4608          :cn^                             |
4609        ]])
4610        feed('<Tab>')
4611        screen:expect_unchanged()
4612        feed('s')
4613        screen:expect([[
4614                                          |
4615          {1:~                               }|*3
4616          {3:                                }|
4617          :cn                             |
4618          cnewer       cnoreabbrev        |
4619          cnext        cnoremap           |
4620          cnfile       cnoremenu          |
4621          :cns^                            |
4622        ]])
4623
4624        feed('<esc>')
4625        command('set wildmode=full')
4626
4627        -- Tests a directory name contained full-width characters.
4628        feed(':e あいう/<Tab>')
4629        screen:expect([[
4630                                          |
4631          {1:~                               }|*5
4632          {1:~        }{12: 123            }{1:       }|
4633          {1:~        }{n: abc            }{1:       }|
4634          {1:~        }{n: xyz            }{1:       }|
4635          :e あいう/123^                   |
4636        ]])
4637        feed('<Esc>')
4638
4639        -- Pressing <PageDown> should scroll the menu downward
4640        feed(':sign <Tab><PageDown>')
4641        screen:expect([[
4642                                          |
4643          {1:~                               }|*2
4644          {1:~    }{n: define         }{1:           }|
4645          {1:~    }{n: jump           }{1:           }|
4646          {1:~    }{n: list           }{1:           }|
4647          {1:~    }{n: place          }{1:           }|
4648          {1:~    }{12: undefine       }{1:           }|
4649          {1:~    }{n: unplace        }{1:           }|
4650          :sign undefine^                  |
4651        ]])
4652        feed('<PageDown>')
4653        screen:expect([[
4654                                          |
4655          {1:~                               }|*2
4656          {1:~    }{n: define         }{1:           }|
4657          {1:~    }{n: jump           }{1:           }|
4658          {1:~    }{n: list           }{1:           }|
4659          {1:~    }{n: place          }{1:           }|
4660          {1:~    }{n: undefine       }{1:           }|
4661          {1:~    }{12: unplace        }{1:           }|
4662          :sign unplace^                   |
4663        ]])
4664        feed('<PageDown>')
4665        screen:expect([[
4666                                          |
4667          {1:~                               }|*2
4668          {1:~    }{n: define         }{1:           }|
4669          {1:~    }{n: jump           }{1:           }|
4670          {1:~    }{n: list           }{1:           }|
4671          {1:~    }{n: place          }{1:           }|
4672          {1:~    }{n: undefine       }{1:           }|
4673          {1:~    }{n: unplace        }{1:           }|
4674          :sign ^                          |
4675        ]])
4676        feed('<PageDown>')
4677        screen:expect([[
4678                                          |
4679          {1:~                               }|*2
4680          {1:~    }{12: define         }{1:           }|
4681          {1:~    }{n: jump           }{1:           }|
4682          {1:~    }{n: list           }{1:           }|
4683          {1:~    }{n: place          }{1:           }|
4684          {1:~    }{n: undefine       }{1:           }|
4685          {1:~    }{n: unplace        }{1:           }|
4686          :sign define^                    |
4687        ]])
4688        feed('<C-U>sign <Tab><Right><Right><PageDown>')
4689        screen:expect([[
4690                                          |
4691          {1:~                               }|*2
4692          {1:~    }{n: define         }{1:           }|
4693          {1:~    }{n: jump           }{1:           }|
4694          {1:~    }{n: list           }{1:           }|
4695          {1:~    }{n: place          }{1:           }|
4696          {1:~    }{n: undefine       }{1:           }|
4697          {1:~    }{12: unplace        }{1:           }|
4698          :sign unplace^                   |
4699        ]])
4700
4701        -- Pressing <PageUp> should scroll the menu upward
4702        feed('<C-U>sign <Tab><PageUp>')
4703        screen:expect([[
4704                                          |
4705          {1:~                               }|*2
4706          {1:~    }{n: define         }{1:           }|
4707          {1:~    }{n: jump           }{1:           }|
4708          {1:~    }{n: list           }{1:           }|
4709          {1:~    }{n: place          }{1:           }|
4710          {1:~    }{n: undefine       }{1:           }|
4711          {1:~    }{n: unplace        }{1:           }|
4712          :sign ^                          |
4713        ]])
4714        feed('<PageUp>')
4715        screen:expect([[
4716                                          |
4717          {1:~                               }|*2
4718          {1:~    }{n: define         }{1:           }|
4719          {1:~    }{n: jump           }{1:           }|
4720          {1:~    }{n: list           }{1:           }|
4721          {1:~    }{n: place          }{1:           }|
4722          {1:~    }{n: undefine       }{1:           }|
4723          {1:~    }{12: unplace        }{1:           }|
4724          :sign unplace^                   |
4725        ]])
4726        feed('<PageUp>')
4727        screen:expect([[
4728                                          |
4729          {1:~                               }|*2
4730          {1:~    }{n: define         }{1:           }|
4731          {1:~    }{12: jump           }{1:           }|
4732          {1:~    }{n: list           }{1:           }|
4733          {1:~    }{n: place          }{1:           }|
4734          {1:~    }{n: undefine       }{1:           }|
4735          {1:~    }{n: unplace        }{1:           }|
4736          :sign jump^                      |
4737        ]])
4738        feed('<PageUp>')
4739        screen:expect([[
4740                                          |
4741          {1:~                               }|*2
4742          {1:~    }{12: define         }{1:           }|
4743          {1:~    }{n: jump           }{1:           }|
4744          {1:~    }{n: list           }{1:           }|
4745          {1:~    }{n: place          }{1:           }|
4746          {1:~    }{n: undefine       }{1:           }|
4747          {1:~    }{n: unplace        }{1:           }|
4748          :sign define^                    |
4749        ]])
4750
4751        -- pressing <C-E> to end completion should work in middle of the line too
4752        feed('<Esc>:set wildchazz<Left><Left><Tab>')
4753        screen:expect([[
4754                                          |
4755          {1:~                               }|*6
4756          {1:~   }{12: wildchar       }{1:            }|
4757          {1:~   }{n: wildcharm      }{1:            }|
4758          :set wildchar^zz                 |
4759        ]])
4760        feed('<C-E>')
4761        screen:expect([[
4762                                          |
4763          {1:~                               }|*8
4764          :set wildcha^zz                  |
4765        ]])
4766
4767        -- pressing <C-Y> should select the current match and end completion
4768        feed('<Esc>:set wildchazz<Left><Left><Tab><C-Y>')
4769        screen:expect([[
4770                                          |
4771          {1:~                               }|*8
4772          :set wildchar^zz                 |
4773        ]])
4774
4775        feed('<Esc>')
4776
4777        -- "longest:list" shows list whether it finds a candidate or not
4778        command('set wildmode=longest:list,full wildoptions=')
4779        feed(':cn<Tab>')
4780        screen:expect([[
4781                                          |
4782          {1:~                               }|*3
4783          {3:                                }|
4784          :cn                             |
4785          cnewer       cnoreabbrev        |
4786          cnext        cnoremap           |
4787          cnfile       cnoremenu          |
4788          :cn^                             |
4789        ]])
4790        feed('<Tab>')
4791        screen:expect([[
4792                                          |
4793          {1:~                               }|*2
4794          {3:                                }|
4795          :cn                             |
4796          cnewer       cnoreabbrev        |
4797          cnext        cnoremap           |
4798          cnfile       cnoremenu          |
4799          {113:cnewer}{3:  cnext  cnfile  >        }|
4800          :cnewer^                         |
4801        ]])
4802        feed('<Esc>:sign u<Tab>')
4803        screen:expect([[
4804                                          |
4805          {1:~                               }|*5
4806          {3:                                }|
4807          :sign un                        |
4808          undefine  unplace               |
4809          :sign un^                        |
4810        ]])
4811
4812        -- "longest:full" shows wildmenu whether it finds a candidate or not;
4813        -- item not selected
4814        feed('<Esc>')
4815        command('set wildmode=longest:full,full')
4816        feed(':sign u<Tab>')
4817        screen:expect([[
4818                                          |
4819          {1:~                               }|*7
4820          {3:undefine  unplace               }|
4821          :sign un^                        |
4822        ]])
4823        feed('<Tab>')
4824        screen:expect([[
4825                                          |
4826          {1:~                               }|*7
4827          {113:undefine}{3:  unplace               }|
4828          :sign undefine^                  |
4829        ]])
4830
4831        feed('<Esc>:cn<Tab>')
4832        screen:expect([[
4833                                          |
4834          {1:~                               }|*7
4835          {3:cnewer  cnext  cnfile  >        }|
4836          :cn^                             |
4837        ]])
4838        feed('<Tab>')
4839        screen:expect([[
4840                                          |
4841          {1:~                               }|*7
4842          {113:cnewer}{3:  cnext  cnfile  >        }|
4843          :cnewer^                         |
4844        ]])
4845
4846        -- If "longest,full" finds a candidate, wildmenu is not shown
4847        feed('<Esc>')
4848        command('set wildmode=longest,full')
4849        feed(':sign u<Tab>')
4850        screen:expect([[
4851                                          |
4852          {1:~                               }|*8
4853          :sign un^                        |
4854        ]])
4855        -- Subsequent wildchar shows wildmenu
4856        feed('<Tab>')
4857        screen:expect([[
4858                                          |
4859          {1:~                               }|*7
4860          {113:undefine}{3:  unplace               }|
4861          :sign undefine^                  |
4862        ]])
4863
4864        -- 'longest' does not find candidate, and displays menu without selecting item
4865        feed('<Esc>')
4866        command('set wildmode=longest,noselect')
4867        feed(':cn<Tab>')
4868        screen:expect([[
4869                                          |
4870          {1:~                               }|*7
4871          {3:cnewer  cnext  cnfile  >        }|
4872          :cn^                             |
4873        ]])
4874
4875        command('set wildmode& wildoptions=pum')
4876
4877        feed('<C-U><Esc>')
4878
4879        -- check positioning with multibyte char in pattern
4880        command('e långfile1')
4881        command('sp långfile2')
4882        feed(':b lå<tab>')
4883        screen:expect([[
4884                                          |
4885          {1:~                               }|*3
4886          {3:långfile2                       }|
4887                                          |
4888          {1:~                               }|
4889          {1:~ }{12: långfile1      }{1:              }|
4890          {2:lå}{n: långfile2      }{2:              }|
4891          :b långfile1^                    |
4892        ]])
4893
4894        -- check doesn't crash on screen resize
4895        screen:try_resize(20, 6)
4896        screen:expect([[
4897                              |
4898          {1:~                   }|
4899          {3:långfile2           }|
4900            {12: långfile1      }  |
4901          {2:lå}{n: långfile2      }{2:  }|
4902          :b långfile1^        |
4903        ]])
4904
4905        screen:try_resize(50, 15)
4906        screen:expect([[
4907                                                            |
4908          {1:~                                                 }|
4909          {3:långfile2                                         }|
4910                                                            |
4911          {1:~                                                 }|*8
4912          {1:~ }{12: långfile1      }{1:                                }|
4913          {2:lå}{n: långfile2      }{2:                                }|
4914          :b långfile1^                                      |
4915        ]])
4916
4917        -- position is calculated correctly with "longest"
4918        feed('<esc>')
4919        command('set wildmode=longest:full,full')
4920        feed(':b lå<tab>')
4921        screen:expect([[
4922                                                            |
4923          {1:~                                                 }|
4924          {3:långfile2                                         }|
4925                                                            |
4926          {1:~                                                 }|*8
4927          {1:~ }{n: långfile1      }{1:                                }|
4928          {2:lå}{n: långfile2      }{2:                                }|
4929          :b långfile^                                       |
4930        ]])
4931
4932        feed('<esc>')
4933        command('%bwipe')
4934        command('set wildmode=full')
4935
4936        -- special case: when patterns ends with "/", show menu items aligned
4937        -- after the "/"
4938        feed(':e compdir/<tab>')
4939        screen:expect([[
4940                                                            |
4941          {1:~                                                 }|*11
4942          {1:~         }{12: file1          }{1:                        }|
4943          {1:~         }{n: file2          }{1:                        }|
4944          :e compdir/file1^                                  |
4945        ]])
4946
4947        -- position is correct when expanding environment variable #20348
4948        command('cd ..')
4949        fn.setenv('XNDIR', 'wildpum/Xnamedir')
4950        feed('<C-U>e $XNDIR/<Tab>')
4951        screen:expect([[
4952                                                            |
4953          {1:~                                                 }|*11
4954          {1:~                  }{12: XdirA/         }{1:               }|
4955          {1:~                  }{n: XfileA         }{1:               }|
4956          :e wildpum/Xnamedir/XdirA/^                        |
4957        ]])
4958      end)
4959    end
4960
4961    it('wildoptions=pum with scrolled messages', function()
4962      screen:try_resize(40, 10)
4963      command('set wildmenu')
4964      command('set wildoptions=pum')
4965
4966      feed(':echoerr "fail"|echoerr "error"<cr>')
4967      if multigrid then
4968        screen:expect([[
4969          ## grid 1
4970            [2:----------------------------------------]|*7
4971            [3:----------------------------------------]|*3
4972          ## grid 2
4973                                                    |
4974            {1:~                                       }|*8
4975          ## grid 3
4976            {9:fail}                                    |
4977            {9:error}                                   |
4978            {6:Press ENTER or type command to continue}^ |
4979        ]])
4980      else
4981        screen:expect([[
4982                                                  |
4983          {1:~                                       }|*5
4984          {3:                                        }|
4985          {9:fail}                                    |
4986          {9:error}                                   |
4987          {6:Press ENTER or type command to continue}^ |
4988        ]])
4989      end
4990
4991      feed(':sign <tab>')
4992      if multigrid then
4993        screen:expect({
4994          grid = [[
4995          ## grid 1
4996            [2:----------------------------------------]|*7
4997            [3:----------------------------------------]|*3
4998          ## grid 2
4999                                                    |
5000            {1:~                                       }|*8
5001          ## grid 3
5002            {9:fail}                                    |
5003            {9:error}                                   |
5004            :sign define^                            |
5005          ## grid 4
5006            {12: define         }|
5007            {n: jump           }|
5008            {n: list           }|
5009            {n: place          }|
5010            {n: undefine       }|
5011            {n: unplace        }|
5012          ]],
5013          float_pos = { [4] = { -1, 'SW', 1, 9, 5, false, 250, 2, 3, 5 } },
5014        })
5015      else
5016        screen:expect([[
5017                                                  |
5018          {1:~                                       }|*2
5019          {1:~    }{12: define         }{1:                   }|
5020          {1:~    }{n: jump           }{1:                   }|
5021          {1:~    }{n: list           }{1:                   }|
5022          {3:     }{n: place          }{3:                   }|
5023          {9:fail} {n: undefine       }                   |
5024          {9:error}{n: unplace        }                   |
5025          :sign define^                            |
5026        ]])
5027      end
5028
5029      feed('d')
5030      if multigrid then
5031        screen:expect([[
5032          ## grid 1
5033            [2:----------------------------------------]|*7
5034            [3:----------------------------------------]|*3
5035          ## grid 2
5036                                                    |
5037            {1:~                                       }|*8
5038          ## grid 3
5039            {9:fail}                                    |
5040            {9:error}                                   |
5041            :sign defined^                           |
5042        ]])
5043      else
5044        screen:expect([[
5045                                                  |
5046          {1:~                                       }|*5
5047          {3:                                        }|
5048          {9:fail}                                    |
5049          {9:error}                                   |
5050          :sign defined^                           |
5051        ]])
5052      end
5053    end)
5054
5055    if not multigrid then
5056      it('wildoptions=pum and wildmode=longest,full #11622', function()
5057        screen:try_resize(30, 8)
5058        command('set wildmenu')
5059        command('set wildoptions=pum')
5060        command('set wildmode=longest,full')
5061
5062        -- With 'wildmode' set to 'longest,full', completing a match should display
5063        -- the longest match, the wildmenu should not be displayed.
5064        feed(':sign u<Tab>')
5065        screen:expect([[
5066                                        |
5067          {1:~                             }|*6
5068          :sign un^                      |
5069        ]])
5070        eq(0, fn.wildmenumode())
5071
5072        -- pressing <Tab> should display the wildmenu
5073        feed('<Tab>')
5074        local s1 = [[
5075                                        |
5076          {1:~                             }|*4
5077          {1:~    }{12: undefine       }{1:         }|
5078          {1:~    }{n: unplace        }{1:         }|
5079          :sign undefine^                |
5080        ]]
5081        screen:expect(s1)
5082        eq(1, fn.wildmenumode())
5083
5084        -- pressing <Tab> second time should select the next entry in the menu
5085        feed('<Tab>')
5086        local s2 = [[
5087                                        |
5088          {1:~                             }|*4
5089          {1:~    }{n: undefine       }{1:         }|
5090          {1:~    }{12: unplace        }{1:         }|
5091          :sign unplace^                 |
5092        ]]
5093        screen:expect(s2)
5094        eq(1, fn.wildmenumode())
5095
5096        -- If "longest" finds no candidate in "longest,full", "full" is used
5097        feed('<Esc>')
5098        command('set wildmode=longest,full')
5099        command('set wildoptions=pum')
5100        feed(':sign un<Tab>')
5101        screen:expect(s1)
5102        feed('<Tab>')
5103        screen:expect(s2)
5104
5105        -- Similarly for "longest,noselect:full"
5106        feed('<Esc>')
5107        command('set wildmode=longest,noselect:full')
5108        feed(':sign un<Tab>')
5109        screen:expect([[
5110                                        |
5111          {1:~                             }|*4
5112          {1:~    }{n: undefine       }{1:         }|
5113          {1:~    }{n: unplace        }{1:         }|
5114          :sign un^                      |
5115        ]])
5116        feed('<Tab>')
5117        screen:expect(s1)
5118        feed('<Tab>')
5119        screen:expect(s2)
5120      end)
5121
5122      it('wildoptions=pum with a wrapped line in buffer vim-patch:8.2.4655', function()
5123        screen:try_resize(32, 10)
5124        api.nvim_buf_set_lines(0, 0, -1, true, { ('a'):rep(100) })
5125        command('set wildoptions+=pum')
5126        feed('$')
5127        feed(':sign <Tab>')
5128        screen:expect([[
5129          aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|*3
5130          aaaa {12: define         }           |
5131          {1:~    }{n: jump           }{1:           }|
5132          {1:~    }{n: list           }{1:           }|
5133          {1:~    }{n: place          }{1:           }|
5134          {1:~    }{n: undefine       }{1:           }|
5135          {1:~    }{n: unplace        }{1:           }|
5136          :sign define^                    |
5137        ]])
5138      end)
5139
5140      -- oldtest: Test_wildmenu_pum_odd_wildchar()
5141      it('wildoptions=pum with odd wildchar', function()
5142        screen:try_resize(30, 10)
5143        -- Test odd wildchar interactions with pum. Make sure they behave properly
5144        -- and don't lead to memory corruption due to improperly cleaned up memory.
5145        exec([[
5146          set wildoptions=pum
5147          set wildchar=<C-E>
5148        ]])
5149
5150        feed(':sign <C-E>')
5151        screen:expect([[
5152                                        |
5153          {1:~                             }|*2
5154          {1:~    }{12: define         }{1:         }|
5155          {1:~    }{n: jump           }{1:         }|
5156          {1:~    }{n: list           }{1:         }|
5157          {1:~    }{n: place          }{1:         }|
5158          {1:~    }{n: undefine       }{1:         }|
5159          {1:~    }{n: unplace        }{1:         }|
5160          :sign define^                  |
5161        ]])
5162
5163        -- <C-E> being a wildchar takes priority over its original functionality
5164        feed('<C-E>')
5165        screen:expect([[
5166                                        |
5167          {1:~                             }|*2
5168          {1:~    }{n: define         }{1:         }|
5169          {1:~    }{12: jump           }{1:         }|
5170          {1:~    }{n: list           }{1:         }|
5171          {1:~    }{n: place          }{1:         }|
5172          {1:~    }{n: undefine       }{1:         }|
5173          {1:~    }{n: unplace        }{1:         }|
5174          :sign jump^                    |
5175        ]])
5176
5177        feed('<Esc>')
5178        screen:expect([[
5179          ^                              |
5180          {1:~                             }|*8
5181                                        |
5182        ]])
5183
5184        -- Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
5185        -- command-line, and we need to make sure to clean up properly.
5186        command('set wildchar=<Esc>')
5187        feed(':sign <Esc>')
5188        screen:expect([[
5189                                        |
5190          {1:~                             }|*2
5191          {1:~    }{12: define         }{1:         }|
5192          {1:~    }{n: jump           }{1:         }|
5193          {1:~    }{n: list           }{1:         }|
5194          {1:~    }{n: place          }{1:         }|
5195          {1:~    }{n: undefine       }{1:         }|
5196          {1:~    }{n: unplace        }{1:         }|
5197          :sign define^                  |
5198        ]])
5199
5200        feed('<Esc>')
5201        screen:expect([[
5202          ^                              |
5203          {1:~                             }|*8
5204                                        |
5205        ]])
5206
5207        -- <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
5208        -- and we again need to make sure we clean up properly.
5209        command([[set wildchar=<C-\>]])
5210        feed([[:sign <C-\><C-\>]])
5211        screen:expect([[
5212                                        |
5213          {1:~                             }|*2
5214          {1:~    }{12: define         }{1:         }|
5215          {1:~    }{n: jump           }{1:         }|
5216          {1:~    }{n: list           }{1:         }|
5217          {1:~    }{n: place          }{1:         }|
5218          {1:~    }{n: undefine       }{1:         }|
5219          {1:~    }{n: unplace        }{1:         }|
5220          :sign define^                  |
5221        ]])
5222
5223        feed('<C-N>')
5224        screen:expect([[
5225          ^                              |
5226          {1:~                             }|*8
5227                                        |
5228        ]])
5229      end)
5230
5231      -- oldtest: Test_wildmenu_pum_hl_match()
5232      it('highlighting matched text in cmdline pum', function()
5233        exec([[
5234          set wildoptions=pum,fuzzy
5235          hi PmenuMatchSel  guifg=Blue guibg=Grey
5236          hi PmenuMatch     guifg=Blue guibg=Plum1
5237        ]])
5238
5239        feed(':sign plc<Tab>')
5240        screen:expect([[
5241                                          |
5242          {1:~                               }|*16
5243          {1:~    }{12: }{ms:pl}{12:a}{ms:c}{12:e          }{1:           }|
5244          {1:~    }{n: un}{mn:pl}{n:a}{mn:c}{n:e        }{1:           }|
5245          :sign place^                     |
5246        ]])
5247        feed('<Tab>')
5248        screen:expect([[
5249                                          |
5250          {1:~                               }|*16
5251          {1:~    }{n: }{mn:pl}{n:a}{mn:c}{n:e          }{1:           }|
5252          {1:~    }{12: un}{ms:pl}{12:a}{ms:c}{12:e        }{1:           }|
5253          :sign unplace^                   |
5254        ]])
5255        feed('<Tab>')
5256        screen:expect([[
5257                                          |
5258          {1:~                               }|*16
5259          {1:~    }{n: }{mn:pl}{n:a}{mn:c}{n:e          }{1:           }|
5260          {1:~    }{n: un}{mn:pl}{n:a}{mn:c}{n:e        }{1:           }|
5261          :sign plc^                       |
5262        ]])
5263        feed('<Esc>')
5264        command('set wildoptions-=fuzzy')
5265        feed(':sign un<Tab>')
5266        screen:expect([[
5267                                          |
5268          {1:~                               }|*16
5269          {1:~    }{12: }{ms:un}{12:define       }{1:           }|
5270          {1:~    }{n: }{mn:un}{n:place        }{1:           }|
5271          :sign undefine^                  |
5272        ]])
5273        feed('<Tab>')
5274        screen:expect([[
5275                                          |
5276          {1:~                               }|*16
5277          {1:~    }{n: }{mn:un}{n:define       }{1:           }|
5278          {1:~    }{12: }{ms:un}{12:place        }{1:           }|
5279          :sign unplace^                   |
5280        ]])
5281        feed('<Tab>')
5282        screen:expect([[
5283                                          |
5284          {1:~                               }|*16
5285          {1:~    }{n: }{mn:un}{n:define       }{1:           }|
5286          {1:~    }{n: }{mn:un}{n:place        }{1:           }|
5287          :sign un^                        |
5288        ]])
5289      end)
5290
5291      -- oldtest: Test_wildmenu_pum_hl_nonfirst()
5292      it('highlight matched text in the middle in cmdline pum', function()
5293        exec([[
5294          set wildoptions=pum wildchar=<tab> wildmode=noselect,full
5295          hi PmenuMatchSel  guifg=Blue guibg=Grey
5296          hi PmenuMatch     guifg=Blue guibg=Plum1
5297          func T(a, c, p)
5298            return ["oneA", "o neBneB", "aoneC"]
5299          endfunc
5300          command -nargs=1 -complete=customlist,T MyCmd
5301        ]])
5302
5303        feed(':MyCmd ne<tab>')
5304        screen:expect([[
5305                                          |
5306          {1:~                               }|*15
5307          {1:~     }{n: o}{mn:ne}{n:A           }{1:          }|
5308          {1:~     }{n: o }{mn:ne}{n:BneB       }{1:          }|
5309          {1:~     }{n: ao}{mn:ne}{n:C          }{1:          }|
5310          :MyCmd ne^                       |
5311        ]])
5312      end)
5313
5314      -- oldtest: Test_pum_scroll_noselect()
5315      it('cmdline pum does not retain scroll position with "noselect"', function()
5316        screen:try_resize(32, 10)
5317        exec([[
5318          command! -nargs=* -complete=customlist,TestFn TestCmd echo
5319          func TestFn(a, b, c)
5320            return map(range(1, 50), 'printf("a%d", v:val)')
5321          endfunc
5322          set wildmode=noselect,full
5323          set wildoptions=pum
5324          set wildmenu
5325          set noruler
5326        ]])
5327
5328        feed(':TestCmd <tab>' .. ('<c-n>'):rep(20))
5329        screen:expect([[
5330                  {n: a15            }{12: }       |
5331          {1:~       }{n: a16            }{12: }{1:       }|
5332          {1:~       }{n: a17            }{12: }{1:       }|
5333          {1:~       }{n: a18            }{c: }{1:       }|
5334          {1:~       }{n: a19            }{12: }{1:       }|
5335          {1:~       }{12: a20             }{1:       }|
5336          {1:~       }{n: a21            }{12: }{1:       }|
5337          {1:~       }{n: a22            }{12: }{1:       }|
5338          {1:~       }{n: a23            }{12: }{1:       }|
5339          :TestCmd a20^                    |
5340        ]])
5341
5342        feed('<esc>:TestCmd <tab>')
5343        screen:expect([[
5344                  {n: a1             }{c: }       |
5345          {1:~       }{n: a2             }{12: }{1:       }|
5346          {1:~       }{n: a3             }{12: }{1:       }|
5347          {1:~       }{n: a4             }{12: }{1:       }|
5348          {1:~       }{n: a5             }{12: }{1:       }|
5349          {1:~       }{n: a6             }{12: }{1:       }|
5350          {1:~       }{n: a7             }{12: }{1:       }|
5351          {1:~       }{n: a8             }{12: }{1:       }|
5352          {1:~       }{n: a9             }{12: }{1:       }|
5353          :TestCmd ^                       |
5354        ]])
5355      end)
5356
5357      it(
5358        'cascading highlights for matched text (PmenuMatch, PmenuMatchSel) in cmdline pum',
5359        function()
5360          exec([[
5361            set wildoptions=pum,fuzzy
5362            hi Pmenu          guifg=White guibg=Grey gui=underline,italic
5363            hi PmenuSel       guifg=Red gui=strikethrough
5364            hi PmenuMatch     guifg=Yellow guibg=Pink gui=bold
5365            hi PmenuMatchSel  guifg=Black guibg=White
5366          ]])
5367
5368          feed(':sign plc<Tab>')
5369          screen:expect([[
5370                                            |
5371            {1:~                               }|*16
5372            {1:~    }{106: }{107:pl}{106:a}{107:c}{106:e          }{1:           }|
5373            {1:~    }{108: un}{109:pl}{108:a}{109:c}{108:e        }{1:           }|
5374            :sign place^                     |
5375          ]])
5376        end
5377      )
5378    end
5379
5380    -- oldtest: Test_customlist_dict_completion_info_popup()
5381    it('cmdline pum with info popup from customlist', function()
5382      screen:try_resize(55, 12)
5383      exec([[
5384        func DictComp(A, L, P)
5385          return [
5386                \ {'word': 'apple',  'kind': 'f', 'menu': 'fruit',     'info': 'A red fruit',    'abbr': '🍎'},
5387                \ {'word': 'banana', 'kind': 'f', 'menu': 'fruit',     'info': 'A yellow fruit', 'abbr': '🍌'},
5388                \ {'word': 'carrot', 'kind': 'v', 'menu': 'vegetable', 'info': 'An orange vegetable'},
5389                \ 'plain',
5390                \ ]
5391        endfunc
5392        command -nargs=1 -complete=customlist,DictComp DictCmd echo <q-args>
5393        set wildmenu wildoptions=pum completeopt=menu,popup
5394      ]])
5395
5396      feed(':DictCmd <Tab>')
5397      if multigrid then
5398        screen:expect({
5399          grid = [[
5400        ## grid 1
5401          [2:-------------------------------------------------------]|*11
5402          [3:-------------------------------------------------------]|
5403        ## grid 2
5404                                                                 |
5405          {1:~                                                      }|*10
5406        ## grid 3
5407          :DictCmd apple^                                         |
5408        ## grid 4
5409          {n:A red fruit}|
5410        ## grid 5
5411          {12: 🍎     f fruit     }|
5412          {n: 🍌     f fruit     }|
5413          {n: carrot v vegetable }|
5414          {n: plain              }|
5415        ]],
5416          float_pos = {
5417            [5] = { -1, 'SW', 1, 11, 8, false, 250, 3, 7, 8 },
5418            [4] = { 1001, 'NW', 1, 7, 28, true, 50, 1, 7, 28 },
5419          },
5420        })
5421      else
5422        screen:expect([[
5423                                                                 |
5424          {1:~                                                      }|*6
5425          {1:~       }{12: 🍎     f fruit     }{n:A red fruit}{1:                }|
5426          {1:~       }{n: 🍌     f fruit     }{1:                           }|
5427          {1:~       }{n: carrot v vegetable }{1:                           }|
5428          {1:~       }{n: plain              }{1:                           }|
5429          :DictCmd apple^                                         |
5430        ]])
5431      end
5432
5433      feed('<Tab>')
5434      if multigrid then
5435        screen:expect({
5436          grid = [[
5437        ## grid 1
5438          [2:-------------------------------------------------------]|*11
5439          [3:-------------------------------------------------------]|
5440        ## grid 2
5441                                                                 |
5442          {1:~                                                      }|*10
5443        ## grid 3
5444          :DictCmd banana^                                        |
5445        ## grid 4
5446          {n:A yellow fruit}|
5447        ## grid 5
5448          {n: 🍎     f fruit     }|
5449          {12: 🍌     f fruit     }|
5450          {n: carrot v vegetable }|
5451          {n: plain              }|
5452        ]],
5453          float_pos = {
5454            [5] = { -1, 'SW', 1, 11, 8, false, 250, 3, 7, 8 },
5455            [4] = { 1001, 'NW', 1, 7, 28, true, 50, 1, 7, 28 },
5456          },
5457        })
5458      else
5459        screen:expect([[
5460                                                                 |
5461          {1:~                                                      }|*6
5462          {1:~       }{n: 🍎     f fruit     A yellow fruit}{1:             }|
5463          {1:~       }{12: 🍌     f fruit     }{1:                           }|
5464          {1:~       }{n: carrot v vegetable }{1:                           }|
5465          {1:~       }{n: plain              }{1:                           }|
5466          :DictCmd banana^                                        |
5467        ]])
5468      end
5469
5470      feed('<Tab>')
5471      if multigrid then
5472        screen:expect({
5473          grid = [[
5474        ## grid 1
5475          [2:-------------------------------------------------------]|*11
5476          [3:-------------------------------------------------------]|
5477        ## grid 2
5478                                                                 |
5479          {1:~                                                      }|*10
5480        ## grid 3
5481          :DictCmd carrot^                                        |
5482        ## grid 4
5483          {n:An orange vegetable}|
5484        ## grid 5
5485          {n: 🍎     f fruit     }|
5486          {n: 🍌     f fruit     }|
5487          {12: carrot v vegetable }|
5488          {n: plain              }|
5489        ]],
5490          float_pos = {
5491            [5] = { -1, 'SW', 1, 11, 8, false, 250, 3, 7, 8 },
5492            [4] = { 1001, 'NW', 1, 7, 28, true, 50, 1, 7, 28 },
5493          },
5494        })
5495      else
5496        screen:expect([[
5497                                                                 |
5498          {1:~                                                      }|*6
5499          {1:~       }{n: 🍎     f fruit     An orange vegetable}{1:        }|
5500          {1:~       }{n: 🍌     f fruit     }{1:                           }|
5501          {1:~       }{12: carrot v vegetable }{1:                           }|
5502          {1:~       }{n: plain              }{1:                           }|
5503          :DictCmd carrot^                                        |
5504        ]])
5505      end
5506
5507      feed('<Tab>')
5508      if multigrid then
5509        screen:expect({
5510          grid = [[
5511        ## grid 1
5512          [2:-------------------------------------------------------]|*11
5513          [3:-------------------------------------------------------]|
5514        ## grid 2
5515                                                                 |
5516          {1:~                                                      }|*10
5517        ## grid 3
5518          :DictCmd plain^                                         |
5519        ## grid 4 (hidden)
5520          {n:An orange vegetable}|
5521        ## grid 5
5522          {n: 🍎     f fruit     }|
5523          {n: 🍌     f fruit     }|
5524          {n: carrot v vegetable }|
5525          {12: plain              }|
5526        ]],
5527          float_pos = {
5528            [5] = { -1, 'SW', 1, 11, 8, false, 250, 2, 7, 8 },
5529          },
5530        })
5531      else
5532        screen:expect([[
5533                                                                 |
5534          {1:~                                                      }|*6
5535          {1:~       }{n: 🍎     f fruit     }{1:                           }|
5536          {1:~       }{n: 🍌     f fruit     }{1:                           }|
5537          {1:~       }{n: carrot v vegetable }{1:                           }|
5538          {1:~       }{12: plain              }{1:                           }|
5539          :DictCmd plain^                                         |
5540        ]])
5541      end
5542
5543      feed('<Tab>')
5544      if multigrid then
5545        screen:expect({
5546          grid = [[
5547        ## grid 1
5548          [2:-------------------------------------------------------]|*11
5549          [3:-------------------------------------------------------]|
5550        ## grid 2
5551                                                                 |
5552          {1:~                                                      }|*10
5553        ## grid 3
5554          :DictCmd ^                                              |
5555        ## grid 4 (hidden)
5556          {n:An orange vegetable}|
5557        ## grid 5
5558          {n: 🍎     f fruit     }|
5559          {n: 🍌     f fruit     }|
5560          {n: carrot v vegetable }|
5561          {n: plain              }|
5562        ]],
5563          float_pos = {
5564            [5] = { -1, 'SW', 1, 11, 8, false, 250, 2, 7, 8 },
5565          },
5566        })
5567      else
5568        screen:expect([[
5569                                                                 |
5570          {1:~                                                      }|*6
5571          {1:~       }{n: 🍎     f fruit     }{1:                           }|
5572          {1:~       }{n: 🍌     f fruit     }{1:                           }|
5573          {1:~       }{n: carrot v vegetable }{1:                           }|
5574          {1:~       }{n: plain              }{1:                           }|
5575          :DictCmd ^                                              |
5576        ]])
5577      end
5578
5579      feed('<Esc>')
5580
5581      -- Tests for Insert mode i_CTRL-X_CTRL-V
5582      feed('iDictCmd <C-X><C-V>')
5583      if multigrid then
5584        screen:expect({
5585          grid = [[
5586        ## grid 1
5587          [2:-------------------------------------------------------]|*11
5588          [3:-------------------------------------------------------]|
5589        ## grid 2
5590          DictCmd apple^                                          |
5591          {1:~                                                      }|*10
5592        ## grid 3
5593          {5:-- Command-line completion (^V^N^P) }{6:match 1 of 4}       |
5594        ## grid 5
5595          {12: 🍎     f fruit     }|
5596          {n: 🍌     f fruit     }|
5597          {n: carrot v vegetable }|
5598          {n: plain              }|
5599        ## grid 6
5600          {n:A red fruit}|
5601        ]],
5602          float_pos = {
5603            [5] = { -1, 'NW', 2, 1, 7, false, 100, 2, 1, 7 },
5604            [6] = { 1002, 'NW', 1, 1, 27, true, 50, 1, 1, 27 },
5605          },
5606        })
5607      else
5608        screen:expect([[
5609          DictCmd apple^                                          |
5610          {1:~      }{12: 🍎     f fruit     }{n:A red fruit}{1:                 }|
5611          {1:~      }{n: 🍌     f fruit     }{1:                            }|
5612          {1:~      }{n: carrot v vegetable }{1:                            }|
5613          {1:~      }{n: plain              }{1:                            }|
5614          {1:~                                                      }|*6
5615          {5:-- Command-line completion (^V^N^P) }{6:match 1 of 4}       |
5616        ]])
5617      end
5618
5619      feed('<C-N>')
5620      if multigrid then
5621        screen:expect({
5622          grid = [[
5623        ## grid 1
5624          [2:-------------------------------------------------------]|*11
5625          [3:-------------------------------------------------------]|
5626        ## grid 2
5627          DictCmd banana^                                         |
5628          {1:~                                                      }|*10
5629        ## grid 3
5630          {5:-- Command-line completion (^V^N^P) }{6:match 2 of 4}       |
5631        ## grid 5
5632          {n: 🍎     f fruit     }|
5633          {12: 🍌     f fruit     }|
5634          {n: carrot v vegetable }|
5635          {n: plain              }|
5636        ## grid 6
5637          {n:A yellow fruit}|
5638        ]],
5639          float_pos = {
5640            [5] = { -1, 'NW', 2, 1, 7, false, 100, 2, 1, 7 },
5641            [6] = { 1002, 'NW', 1, 1, 27, true, 50, 1, 1, 27 },
5642          },
5643        })
5644      else
5645        screen:expect([[
5646          DictCmd banana^                                         |
5647          {1:~      }{n: 🍎     f fruit     A yellow fruit}{1:              }|
5648          {1:~      }{12: 🍌     f fruit     }{1:                            }|
5649          {1:~      }{n: carrot v vegetable }{1:                            }|
5650          {1:~      }{n: plain              }{1:                            }|
5651          {1:~                                                      }|*6
5652          {5:-- Command-line completion (^V^N^P) }{6:match 2 of 4}       |
5653        ]])
5654      end
5655
5656      feed('<C-N>')
5657      if multigrid then
5658        screen:expect({
5659          grid = [[
5660        ## grid 1
5661          [2:-------------------------------------------------------]|*11
5662          [3:-------------------------------------------------------]|
5663        ## grid 2
5664          DictCmd carrot^                                         |
5665          {1:~                                                      }|*10
5666        ## grid 3
5667          {5:-- Command-line completion (^V^N^P) }{6:match 3 of 4}       |
5668        ## grid 5
5669          {n: 🍎     f fruit     }|
5670          {n: 🍌     f fruit     }|
5671          {12: carrot v vegetable }|
5672          {n: plain              }|
5673        ## grid 6
5674          {n:An orange vegetable}|
5675        ]],
5676          float_pos = {
5677            [5] = { -1, 'NW', 2, 1, 7, false, 100, 2, 1, 7 },
5678            [6] = { 1002, 'NW', 1, 1, 27, true, 50, 1, 1, 27 },
5679          },
5680        })
5681      else
5682        screen:expect([[
5683          DictCmd carrot^                                         |
5684          {1:~      }{n: 🍎     f fruit     An orange vegetable}{1:         }|
5685          {1:~      }{n: 🍌     f fruit     }{1:                            }|
5686          {1:~      }{12: carrot v vegetable }{1:                            }|
5687          {1:~      }{n: plain              }{1:                            }|
5688          {1:~                                                      }|*6
5689          {5:-- Command-line completion (^V^N^P) }{6:match 3 of 4}       |
5690        ]])
5691      end
5692
5693      feed('<C-N>')
5694      if multigrid then
5695        screen:expect({
5696          grid = [[
5697        ## grid 1
5698          [2:-------------------------------------------------------]|*11
5699          [3:-------------------------------------------------------]|
5700        ## grid 2
5701          DictCmd plain^                                          |
5702          {1:~                                                      }|*10
5703        ## grid 3
5704          {5:-- Command-line completion (^V^N^P) }{6:match 4 of 4}       |
5705        ## grid 5
5706          {n: 🍎     f fruit     }|
5707          {n: 🍌     f fruit     }|
5708          {n: carrot v vegetable }|
5709          {12: plain              }|
5710        ## grid 6 (hidden)
5711          {n:An orange vegetable}|
5712        ]],
5713          float_pos = {
5714            [5] = { -1, 'NW', 2, 1, 7, false, 100, 1, 1, 7 },
5715          },
5716        })
5717      else
5718        screen:expect([[
5719          DictCmd plain^                                          |
5720          {1:~      }{n: 🍎     f fruit     }{1:                            }|
5721          {1:~      }{n: 🍌     f fruit     }{1:                            }|
5722          {1:~      }{n: carrot v vegetable }{1:                            }|
5723          {1:~      }{12: plain              }{1:                            }|
5724          {1:~                                                      }|*6
5725          {5:-- Command-line completion (^V^N^P) }{6:match 4 of 4}       |
5726        ]])
5727      end
5728
5729      feed('<C-N>')
5730      if multigrid then
5731        screen:expect({
5732          grid = [[
5733        ## grid 1
5734          [2:-------------------------------------------------------]|*11
5735          [3:-------------------------------------------------------]|
5736        ## grid 2
5737          DictCmd ^                                               |
5738          {1:~                                                      }|*10
5739        ## grid 3
5740          {5:-- Command-line completion (^V^N^P) }{19:Back at original}   |
5741        ## grid 5
5742          {n: 🍎     f fruit     }|
5743          {n: 🍌     f fruit     }|
5744          {n: carrot v vegetable }|
5745          {n: plain              }|
5746        ## grid 6 (hidden)
5747          {n:An orange vegetable}|
5748        ]],
5749          float_pos = {
5750            [5] = { -1, 'NW', 2, 1, 7, false, 100, 1, 1, 7 },
5751          },
5752        })
5753      else
5754        screen:expect([[
5755          DictCmd ^                                               |
5756          {1:~      }{n: 🍎     f fruit     }{1:                            }|
5757          {1:~      }{n: 🍌     f fruit     }{1:                            }|
5758          {1:~      }{n: carrot v vegetable }{1:                            }|
5759          {1:~      }{n: plain              }{1:                            }|
5760          {1:~                                                      }|*6
5761          {5:-- Command-line completion (^V^N^P) }{19:Back at original}   |
5762        ]])
5763      end
5764
5765      -- Starting another i_CTRL-X_CTRL-V completion should not leak memory
5766      feed('<C-U>')
5767      poke_eventloop() -- Allow pum_check_clear() to remove the info popup.
5768      feed('sign un<C-X><C-V>')
5769      if multigrid then
5770        screen:expect({
5771          grid = [[
5772        ## grid 1
5773          [2:-------------------------------------------------------]|*11
5774          [3:-------------------------------------------------------]|
5775        ## grid 2
5776          sign undefine^                                          |
5777          {1:~                                                      }|*10
5778        ## grid 3
5779          {5:-- Command-line completion (^V^N^P) }{6:match 1 of 2}       |
5780        ## grid 5
5781          {12: undefine       }|
5782          {n: unplace        }|
5783        ]],
5784          float_pos = {
5785            [5] = { -1, 'NW', 2, 1, 4, false, 100, 1, 1, 4 },
5786          },
5787        })
5788      else
5789        screen:expect([[
5790          sign undefine^                                          |
5791          {1:~   }{12: undefine       }{1:                                   }|
5792          {1:~   }{n: unplace        }{1:                                   }|
5793          {1:~                                                      }|*8
5794          {5:-- Command-line completion (^V^N^P) }{6:match 1 of 2}       |
5795        ]])
5796      end
5797    end)
5798
5799    -- oldtest: Test_wildmenu_pum_info_mouse_scroll()
5800    it('scrolling cmdline pum info popup', function()
5801      screen:try_resize(55, 12)
5802      exec([[
5803        func DictComp(A, L, P)
5804          let info = join(map(range(1, 30), '"info line " .. v:val'), "\n")
5805          return [
5806                \ {'word': 'apple',  'kind': 'f', 'menu': 'fruit', 'info': info},
5807                \ {'word': 'banana', 'kind': 'f', 'menu': 'fruit', 'info': info},
5808                \ ]
5809        endfunc
5810        command -nargs=1 -complete=customlist,DictComp DictCmd echo <q-args>
5811        set wildmenu wildoptions=pum completeopt=menu,popup mouse=a
5812      ]])
5813
5814      feed(':DictCmd <Tab>')
5815      if multigrid then
5816        screen:expect({
5817          grid = [[
5818        ## grid 1
5819          [2:-------------------------------------------------------]|*11
5820          [3:-------------------------------------------------------]|
5821        ## grid 2
5822                                                                 |
5823          {1:~                                                      }|*10
5824        ## grid 3
5825          :DictCmd apple^                                         |
5826        ## grid 4
5827          {n:info line 1 }|
5828          {n:info line 2 }|
5829          {n:info line 3 }|
5830          {n:info line 4 }|
5831          {n:info line 5 }|
5832          {n:info line 6 }|
5833          {n:info line 7 }|
5834          {n:info line 8 }|
5835          {n:info line 9 }|
5836          {n:info line 10}|
5837          {n:info line 11}|
5838          {n:info line 12}|
5839        ## grid 5
5840          {12: apple  f fruit }|
5841          {n: banana f fruit }|
5842        ]],
5843          float_pos = {
5844            [5] = { -1, 'SW', 1, 11, 8, false, 250, 3, 9, 8 },
5845            [4] = { 1001, 'NW', 1, 9, 24, true, 50, 1, 0, 24 },
5846          },
5847        })
5848      else
5849        screen:expect([[
5850                                  {n:info line 1 }                   |
5851          {1:~                       }{n:info line 2 }{1:                   }|
5852          {1:~                       }{n:info line 3 }{1:                   }|
5853          {1:~                       }{n:info line 4 }{1:                   }|
5854          {1:~                       }{n:info line 5 }{1:                   }|
5855          {1:~                       }{n:info line 6 }{1:                   }|
5856          {1:~                       }{n:info line 7 }{1:                   }|
5857          {1:~                       }{n:info line 8 }{1:                   }|
5858          {1:~                       }{n:info line 9 }{1:                   }|
5859          {1:~       }{12: apple  f fruit }{n:info line 10}{1:                   }|
5860          {1:~       }{n: banana f fruit info line 11}{1:                   }|
5861          :DictCmd apple^                                         |
5862        ]])
5863      end
5864
5865      if send_mouse_grid then
5866        api.nvim_input_mouse('wheel', 'down', '', 4, 0, 0)
5867        api.nvim_input_mouse('wheel', 'down', '', 4, 0, 0)
5868        api.nvim_input_mouse('wheel', 'down', '', 4, 0, 0)
5869      else
5870        api.nvim_input_mouse('wheel', 'down', '', 0, 0, 24)
5871        api.nvim_input_mouse('wheel', 'down', '', 0, 0, 24)
5872        api.nvim_input_mouse('wheel', 'down', '', 0, 0, 24)
5873      end
5874      if multigrid then
5875        screen:expect({
5876          grid = [[
5877        ## grid 1
5878          [2:-------------------------------------------------------]|*11
5879          [3:-------------------------------------------------------]|
5880        ## grid 2
5881                                                                 |
5882          {1:~                                                      }|*10
5883        ## grid 3
5884          :DictCmd apple^                                         |
5885        ## grid 4
5886          {n:info line 10}|
5887          {n:info line 11}|
5888          {n:info line 12}|
5889          {n:info line 13}|
5890          {n:info line 14}|
5891          {n:info line 15}|
5892          {n:info line 16}|
5893          {n:info line 17}|
5894          {n:info line 18}|
5895          {n:info line 19}|
5896          {n:info line 20}|
5897          {n:info line 21}|
5898        ## grid 5
5899          {12: apple  f fruit }|
5900          {n: banana f fruit }|
5901        ]],
5902          float_pos = {
5903            [5] = { -1, 'SW', 1, 11, 8, false, 250, 3, 9, 8 },
5904            [4] = { 1001, 'NW', 1, 9, 24, true, 50, 1, 0, 24 },
5905          },
5906        })
5907      else
5908        screen:expect([[
5909                                  {n:info line 10}                   |
5910          {1:~                       }{n:info line 11}{1:                   }|
5911          {1:~                       }{n:info line 12}{1:                   }|
5912          {1:~                       }{n:info line 13}{1:                   }|
5913          {1:~                       }{n:info line 14}{1:                   }|
5914          {1:~                       }{n:info line 15}{1:                   }|
5915          {1:~                       }{n:info line 16}{1:                   }|
5916          {1:~                       }{n:info line 17}{1:                   }|
5917          {1:~                       }{n:info line 18}{1:                   }|
5918          {1:~       }{12: apple  f fruit }{n:info line 19}{1:                   }|
5919          {1:~       }{n: banana f fruit info line 20}{1:                   }|
5920          :DictCmd apple^                                         |
5921        ]])
5922      end
5923
5924      if send_mouse_grid then
5925        api.nvim_input_mouse('wheel', 'up', '', 4, 0, 0)
5926        api.nvim_input_mouse('wheel', 'up', '', 4, 0, 0)
5927      else
5928        api.nvim_input_mouse('wheel', 'up', '', 0, 0, 24)
5929        api.nvim_input_mouse('wheel', 'up', '', 0, 0, 24)
5930      end
5931      if multigrid then
5932        screen:expect({
5933          grid = [[
5934        ## grid 1
5935          [2:-------------------------------------------------------]|*11
5936          [3:-------------------------------------------------------]|
5937        ## grid 2
5938                                                                 |
5939          {1:~                                                      }|*10
5940        ## grid 3
5941          :DictCmd apple^                                         |
5942        ## grid 4
5943          {n:info line 4 }|
5944          {n:info line 5 }|
5945          {n:info line 6 }|
5946          {n:info line 7 }|
5947          {n:info line 8 }|
5948          {n:info line 9 }|
5949          {n:info line 10}|
5950          {n:info line 11}|
5951          {n:info line 12}|
5952          {n:info line 13}|
5953          {n:info line 14}|
5954          {n:info line 15}|
5955        ## grid 5
5956          {12: apple  f fruit }|
5957          {n: banana f fruit }|
5958        ]],
5959          float_pos = {
5960            [5] = { -1, 'SW', 1, 11, 8, false, 250, 3, 9, 8 },
5961            [4] = { 1001, 'NW', 1, 9, 24, true, 50, 1, 0, 24 },
5962          },
5963        })
5964      else
5965        screen:expect([[
5966                                  {n:info line 4 }                   |
5967          {1:~                       }{n:info line 5 }{1:                   }|
5968          {1:~                       }{n:info line 6 }{1:                   }|
5969          {1:~                       }{n:info line 7 }{1:                   }|
5970          {1:~                       }{n:info line 8 }{1:                   }|
5971          {1:~                       }{n:info line 9 }{1:                   }|
5972          {1:~                       }{n:info line 10}{1:                   }|
5973          {1:~                       }{n:info line 11}{1:                   }|
5974          {1:~                       }{n:info line 12}{1:                   }|
5975          {1:~       }{12: apple  f fruit }{n:info line 13}{1:                   }|
5976          {1:~       }{n: banana f fruit info line 14}{1:                   }|
5977          :DictCmd apple^                                         |
5978        ]])
5979      end
5980
5981      feed('<Esc>')
5982    end)
5983
5984    -- oldtest: Test_cmdline_complete_findfunc_dict()
5985    it("'findfunc' can return extra info for cmdline completion", function()
5986      screen:try_resize(55, 12)
5987      exec([[
5988        set wildmenu wildoptions=pum completeopt=menu,popup
5989        func FindComplete(cmdarg, cmdcomplete)
5990          return [
5991                \ 'Xplain',
5992                \ {'word': 'Xfile1', 'kind': 'F', 'menu': 'file', 'info': '1st file'},
5993                \ {'word': 'Xfile2', 'kind': 'F', 'menu': 'file', 'info': '2nd file'},
5994                \ {'word': 'Xdir1',  'kind': 'D', 'menu': 'dir',  'info': '1st dir'},
5995                \ {'word': 'Xdir2',  'kind': 'D', 'menu': 'dir',  'info': '2nd dir'},
5996                \ ]
5997        endfunc
5998        set findfunc=FindComplete
5999      ]])
6000
6001      feed(':find <Tab>')
6002      if multigrid then
6003        screen:expect({
6004          grid = [[
6005        ## grid 1
6006          [2:-------------------------------------------------------]|*11
6007          [3:-------------------------------------------------------]|
6008        ## grid 2
6009                                                                 |
6010          {1:~                                                      }|*10
6011        ## grid 3
6012          :find Xplain^                                           |
6013        ## grid 4
6014          {12: Xplain         }|
6015          {n: Xfile1 F file  }|
6016          {n: Xfile2 F file  }|
6017          {n: Xdir1  D dir   }|
6018          {n: Xdir2  D dir   }|
6019        ]],
6020          float_pos = {
6021            [4] = { -1, 'SW', 1, 11, 5, false, 250, 2, 6, 5 },
6022          },
6023        })
6024      else
6025        screen:expect([[
6026                                                                 |
6027          {1:~                                                      }|*5
6028          {1:~    }{12: Xplain         }{1:                                  }|
6029          {1:~    }{n: Xfile1 F file  }{1:                                  }|
6030          {1:~    }{n: Xfile2 F file  }{1:                                  }|
6031          {1:~    }{n: Xdir1  D dir   }{1:                                  }|
6032          {1:~    }{n: Xdir2  D dir   }{1:                                  }|
6033          :find Xplain^                                           |
6034        ]])
6035      end
6036
6037      feed('<PageDown>')
6038      if multigrid then
6039        screen:expect({
6040          grid = [[
6041        ## grid 1
6042          [2:-------------------------------------------------------]|*11
6043          [3:-------------------------------------------------------]|
6044        ## grid 2
6045                                                                 |
6046          {1:~                                                      }|*10
6047        ## grid 3
6048          :find Xdir1^                                            |
6049        ## grid 4
6050          {n: Xplain         }|
6051          {n: Xfile1 F file  }|
6052          {n: Xfile2 F file  }|
6053          {12: Xdir1  D dir   }|
6054          {n: Xdir2  D dir   }|
6055        ## grid 5
6056          {n:1st dir}|
6057        ]],
6058          float_pos = {
6059            [4] = { -1, 'SW', 1, 11, 5, false, 250, 3, 6, 5 },
6060            [5] = { 1001, 'NW', 1, 6, 21, true, 50, 1, 6, 21 },
6061          },
6062        })
6063      else
6064        screen:expect([[
6065                                                                 |
6066          {1:~                                                      }|*5
6067          {1:~    }{n: Xplain         1st dir}{1:                           }|
6068          {1:~    }{n: Xfile1 F file  }{1:                                  }|
6069          {1:~    }{n: Xfile2 F file  }{1:                                  }|
6070          {1:~    }{12: Xdir1  D dir   }{1:                                  }|
6071          {1:~    }{n: Xdir2  D dir   }{1:                                  }|
6072          :find Xdir1^                                            |
6073        ]])
6074      end
6075    end)
6076
6077    it("'pumheight'", function()
6078      screen:try_resize(32, 8)
6079      feed('isome long prefix before the ')
6080      command('set completeopt+=noinsert,noselect')
6081      command('set linebreak')
6082      command('set pumheight=2')
6083      fn.complete(29, { 'word', 'choice', 'text', 'thing' })
6084      if multigrid then
6085        screen:expect {
6086          grid = [[
6087        ## grid 1
6088          [2:--------------------------------]|*7
6089          [3:--------------------------------]|
6090        ## grid 2
6091          some long prefix before the ^    |
6092          {1:~                               }|*6
6093        ## grid 3
6094          {5:-- INSERT --}                    |
6095        ## grid 4
6096          {n: word            }{c: }|
6097          {n: choice          }{12: }|
6098        ]],
6099          float_pos = { [4] = { -1, 'NW', 2, 1, 14, false, 100, 1, 1, 14 } },
6100        }
6101      else
6102        screen:expect([[
6103          some long prefix before the ^    |
6104          {1:~             }{n: word            }{c: }|
6105          {1:~             }{n: choice          }{12: }|
6106          {1:~                               }|*4
6107          {5:-- INSERT --}                    |
6108        ]])
6109      end
6110    end)
6111
6112    it("'pumwidth'", function()
6113      screen:try_resize(32, 8)
6114      feed('isome long prefix before the ')
6115      command('set completeopt+=noinsert,noselect')
6116      command('set linebreak')
6117      command('set pumwidth=8')
6118      fn.complete(29, { 'word', 'choice', 'text', 'thing' })
6119      if multigrid then
6120        screen:expect {
6121          grid = [[
6122        ## grid 1
6123          [2:--------------------------------]|*7
6124          [3:--------------------------------]|
6125        ## grid 2
6126          some long prefix before the ^    |
6127          {1:~                               }|*6
6128        ## grid 3
6129          {5:-- INSERT --}                    |
6130        ## grid 4
6131          {n: word     }|
6132          {n: choice   }|
6133          {n: text     }|
6134          {n: thing    }|
6135        ]],
6136          float_pos = { [4] = { -1, 'NW', 2, 1, 22, false, 100, 1, 1, 22 } },
6137        }
6138      else
6139        screen:expect([[
6140          some long prefix before the ^    |
6141          {1:~                     }{n: word     }|
6142          {1:~                     }{n: choice   }|
6143          {1:~                     }{n: text     }|
6144          {1:~                     }{n: thing    }|
6145          {1:~                               }|*2
6146          {5:-- INSERT --}                    |
6147        ]])
6148      end
6149    end)
6150
6151    -- oldtest: Test_pum_maxwidth()
6152    it("'pummaxwidth'", function()
6153      screen:try_resize(60, 8)
6154      api.nvim_buf_set_lines(0, 0, -1, true, {
6155        '123456789_123456789_123456789_a',
6156        '123456789_123456789_123456789_b',
6157        '            123',
6158      })
6159      feed('G"zyy')
6160      feed('A<C-X><C-N>')
6161      if multigrid then
6162        screen:expect({
6163          grid = [[
6164        ## grid 1
6165          [2:------------------------------------------------------------]|*7
6166          [3:------------------------------------------------------------]|
6167        ## grid 2
6168          123456789_123456789_123456789_a                             |
6169          123456789_123456789_123456789_b                             |
6170                      123456789_123456789_123456789_a^                 |
6171          {1:~                                                           }|*4
6172        ## grid 3
6173          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 2}             |
6174        ## grid 4
6175          {12: 123456789_123456789_123456789_a }|
6176          {n: 123456789_123456789_123456789_b }|
6177        ]],
6178          float_pos = { [4] = { -1, 'NW', 2, 3, 11, false, 100, 1, 3, 11 } },
6179        })
6180      else
6181        screen:expect([[
6182          123456789_123456789_123456789_a                             |
6183          123456789_123456789_123456789_b                             |
6184                      123456789_123456789_123456789_a^                 |
6185          {1:~          }{12: 123456789_123456789_123456789_a }{1:                }|
6186          {1:~          }{n: 123456789_123456789_123456789_b }{1:                }|
6187          {1:~                                                           }|*2
6188          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 2}             |
6189        ]])
6190      end
6191      feed('<Esc>3Gdd"zp')
6192
6193      command('set pummaxwidth=10')
6194      feed('GA<C-X><C-N>')
6195      if multigrid then
6196        screen:expect({
6197          grid = [[
6198        ## grid 1
6199          [2:------------------------------------------------------------]|*7
6200          [3:------------------------------------------------------------]|
6201        ## grid 2
6202          123456789_123456789_123456789_a                             |
6203          123456789_123456789_123456789_b                             |
6204                      123456789_123456789_123456789_a^                 |
6205          {1:~                                                           }|*4
6206        ## grid 3
6207          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 2}             |
6208        ## grid 4
6209          {12: 123456789>}|
6210          {n: 123456789>}|
6211        ]],
6212          float_pos = { [4] = { -1, 'NW', 2, 3, 11, false, 100, 1, 3, 11 } },
6213        })
6214      else
6215        screen:expect([[
6216          123456789_123456789_123456789_a                             |
6217          123456789_123456789_123456789_b                             |
6218                      123456789_123456789_123456789_a^                 |
6219          {1:~          }{12: 123456789>}{1:                                      }|
6220          {1:~          }{n: 123456789>}{1:                                      }|
6221          {1:~                                                           }|*2
6222          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 2}             |
6223        ]])
6224      end
6225      feed('<Esc>3Gdd"zp')
6226
6227      command('set pummaxwidth=20')
6228      feed('GA<C-X><C-N>')
6229      if multigrid then
6230        screen:expect({
6231          grid = [[
6232        ## grid 1
6233          [2:------------------------------------------------------------]|*7
6234          [3:------------------------------------------------------------]|
6235        ## grid 2
6236          123456789_123456789_123456789_a                             |
6237          123456789_123456789_123456789_b                             |
6238                      123456789_123456789_123456789_a^                 |
6239          {1:~                                                           }|*4
6240        ## grid 3
6241          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 2}             |
6242        ## grid 4
6243          {12: 123456789_123456789>}|
6244          {n: 123456789_123456789>}|
6245        ]],
6246          float_pos = { [4] = { -1, 'NW', 2, 3, 11, false, 100, 1, 3, 11 } },
6247        })
6248      else
6249        screen:expect([[
6250          123456789_123456789_123456789_a                             |
6251          123456789_123456789_123456789_b                             |
6252                      123456789_123456789_123456789_a^                 |
6253          {1:~          }{12: 123456789_123456789>}{1:                            }|
6254          {1:~          }{n: 123456789_123456789>}{1:                            }|
6255          {1:~                                                           }|*2
6256          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 2}             |
6257        ]])
6258      end
6259      feed('<Esc>3Gdd"zp')
6260
6261      command('set pumwidth=20 pummaxwidth=8')
6262      feed('GA<C-X><C-N>')
6263      if multigrid then
6264        screen:expect({
6265          grid = [[
6266        ## grid 1
6267          [2:------------------------------------------------------------]|*7
6268          [3:------------------------------------------------------------]|
6269        ## grid 2
6270          123456789_123456789_123456789_a                             |
6271          123456789_123456789_123456789_b                             |
6272                      123456789_123456789_123456789_a^                 |
6273          {1:~                                                           }|*4
6274        ## grid 3
6275          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 2}             |
6276        ## grid 4
6277          {12: 1234567>}|
6278          {n: 1234567>}|
6279        ]],
6280          float_pos = { [4] = { -1, 'NW', 2, 3, 11, false, 100, 1, 3, 11 } },
6281        })
6282      else
6283        screen:expect([[
6284          123456789_123456789_123456789_a                             |
6285          123456789_123456789_123456789_b                             |
6286                      123456789_123456789_123456789_a^                 |
6287          {1:~          }{12: 1234567>}{1:                                        }|
6288          {1:~          }{n: 1234567>}{1:                                        }|
6289          {1:~                                                           }|*2
6290          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 2}             |
6291        ]])
6292      end
6293      feed('<Esc>3Gdd"zp')
6294
6295      screen:try_resize(32, 10)
6296      feed('GA<C-X><C-N>')
6297      if multigrid then
6298        screen:expect({
6299          grid = [[
6300        ## grid 1
6301          [2:--------------------------------]|*9
6302          [3:--------------------------------]|
6303        ## grid 2
6304          123456789_123456789_123456789_a |
6305          123456789_123456789_123456789_b |
6306                      123456789_123456789_|
6307          123456789_a^                     |
6308          {1:~                               }|*5
6309        ## grid 3
6310          {5:-- }{6:match 1 of 2}                 |
6311        ## grid 4
6312          {12: 1234567>}|
6313          {n: 1234567>}|
6314        ]],
6315          float_pos = { [4] = { -1, 'NW', 2, 4, 11, false, 100, 1, 4, 11 } },
6316        })
6317      else
6318        screen:expect([[
6319          123456789_123456789_123456789_a |
6320          123456789_123456789_123456789_b |
6321                      123456789_123456789_|
6322          123456789_a^                     |
6323          {1:~          }{12: 1234567>}{1:            }|
6324          {1:~          }{n: 1234567>}{1:            }|
6325          {1:~                               }|*3
6326          {5:-- }{6:match 1 of 2}                 |
6327        ]])
6328      end
6329      feed('<Esc>3Gdd"zp')
6330    end)
6331
6332    -- oldtest: Test_pum_maxwidth_multibyte()
6333    it("'pummaxwidth' with multibyte", function()
6334      screen:try_resize(60, 8)
6335      exec([[
6336        hi StrikeFake guifg=DarkRed
6337        let g:change = 0
6338        func Omni_test(findstart, base)
6339          if a:findstart
6340            return col(".")
6341          endif
6342          if g:change == 0
6343            return [
6344              \ #{word: "123456789_123456789_123456789_"},
6345              \ #{word: "一二三四五六七八九十"},
6346              \ #{word: "abcdefghij"},
6347              \ #{word: "上下左右"},
6348              \ ]
6349          elseif g:change == 1
6350            return [
6351              \ #{word: "foo", menu: "fooMenu", kind: "fooKind"},
6352              \ #{word: "bar", menu: "barMenu", kind: "barKind"},
6353              \ #{word: "baz", menu: "bazMenu", kind: "bazKind"},
6354              \ ]
6355          elseif g:change == 2
6356            return [
6357              \ #{word: "foo", menu: "fooMenu", kind: "fooKind"},
6358              \ #{word: "bar", menu: "fooMenu", kind: "一二三四"},
6359              \ #{word: "一二三四五", kind: "multi"},
6360              \ ]
6361            return [#{word: "bar", menu: "fooMenu", kind: "一二三"}]
6362          elseif g:change == 3
6363            return [#{word: "bar", menu: "fooMenu", kind: "一二三"}]
6364          else
6365            return [
6366              \ #{word: "一二三四五六七八九十", abbr_hlgroup: "StrikeFake"},
6367              \ #{word: "123456789_123456789_123456789_", abbr_hlgroup: "StrikeFake"},
6368              \ ]
6369          endif
6370        endfunc
6371        set omnifunc=Omni_test
6372        set cot+=menuone
6373      ]])
6374
6375      feed('S<C-X><C-O>')
6376      if multigrid then
6377        screen:expect({
6378          grid = [[
6379        ## grid 1
6380          [2:------------------------------------------------------------]|*7
6381          [3:------------------------------------------------------------]|
6382        ## grid 2
6383          123456789_123456789_123456789_^                              |
6384          {1:~                                                           }|*6
6385        ## grid 3
6386          {5:-- Omni completion (^O^N^P) }{6:match 1 of 4}                    |
6387        ## grid 4
6388          {12:123456789_123456789_123456789_ }|
6389          {n:一二三四五六七八九十           }|
6390          {n:abcdefghij                     }|
6391          {n:上下左右                       }|
6392        ]],
6393          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
6394        })
6395      else
6396        screen:expect([[
6397          123456789_123456789_123456789_^                              |
6398          {12:123456789_123456789_123456789_ }{1:                             }|
6399          {n:一二三四五六七八九十           }{1:                             }|
6400          {n:abcdefghij                     }{1:                             }|
6401          {n:上下左右                       }{1:                             }|
6402          {1:~                                                           }|*2
6403          {5:-- Omni completion (^O^N^P) }{6:match 1 of 4}                    |
6404        ]])
6405      end
6406      feed('<Esc>')
6407
6408      command('set pummaxwidth=10')
6409      feed('S<C-X><C-O>')
6410      if multigrid then
6411        screen:expect({
6412          grid = [[
6413        ## grid 1
6414          [2:------------------------------------------------------------]|*7
6415          [3:------------------------------------------------------------]|
6416        ## grid 2
6417          123456789_123456789_123456789_^                              |
6418          {1:~                                                           }|*6
6419        ## grid 3
6420          {5:-- Omni completion (^O^N^P) }{6:match 1 of 4}                    |
6421        ## grid 4
6422          {12:123456789>}|
6423          {n:一二三四 >}|
6424          {n:abcdefghij}|
6425          {n:上下左右  }|
6426        ]],
6427          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
6428        })
6429      else
6430        screen:expect([[
6431          123456789_123456789_123456789_^                              |
6432          {12:123456789>}{1:                                                  }|
6433          {n:一二三四 >}{1:                                                  }|
6434          {n:abcdefghij}{1:                                                  }|
6435          {n:上下左右  }{1:                                                  }|
6436          {1:~                                                           }|*2
6437          {5:-- Omni completion (^O^N^P) }{6:match 1 of 4}                    |
6438        ]])
6439      end
6440      feed('<Esc>')
6441
6442      command('set rightleft')
6443      feed('S<C-X><C-O>')
6444      if multigrid then
6445        screen:expect({
6446          grid = [[
6447        ## grid 1
6448          [2:------------------------------------------------------------]|*7
6449          [3:------------------------------------------------------------]|
6450        ## grid 2
6451                                       ^ _987654321_987654321_987654321|
6452          {1:                                                           ~}|*6
6453        ## grid 3
6454          {5:-- Omni completion (^O^N^P) }{6:match 1 of 4}                    |
6455        ## grid 4
6456          {12:<987654321}|
6457          {n:< 四三二一}|
6458          {n:jihgfedcba}|
6459          {n:  右左下上}|
6460        ]],
6461          float_pos = { [4] = { -1, 'NW', 2, 1, 50, false, 100, 1, 1, 50 } },
6462        })
6463      else
6464        screen:expect([[
6465                                       ^ _987654321_987654321_987654321|
6466          {1:                                                  }{12:<987654321}|
6467          {1:                                                  }{n:< 四三二一}|
6468          {1:                                                  }{n:jihgfedcba}|
6469          {1:                                                  }{n:  右左下上}|
6470          {1:                                                           ~}|*2
6471          {5:-- Omni completion (^O^N^P) }{6:match 1 of 4}                    |
6472        ]])
6473      end
6474      feed('<Esc>')
6475      command('set norightleft')
6476
6477      command('set pummaxwidth=2')
6478      feed('S<C-X><C-O>')
6479      if multigrid then
6480        screen:expect({
6481          grid = [[
6482        ## grid 1
6483          [2:------------------------------------------------------------]|*7
6484          [3:------------------------------------------------------------]|
6485        ## grid 2
6486          123456789_123456789_123456789_^                              |
6487          {1:~                                                           }|*6
6488        ## grid 3
6489          {5:-- Omni completion (^O^N^P) }{6:match 1 of 4}                    |
6490        ## grid 4
6491          {12:1>}|
6492          {n: >}|
6493          {n:a>}|
6494          {n: >}|
6495        ]],
6496          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
6497        })
6498      else
6499        screen:expect([[
6500          123456789_123456789_123456789_^                              |
6501          {12:1>}{1:                                                          }|
6502          {n: >}{1:                                                          }|
6503          {n:a>}{1:                                                          }|
6504          {n: >}{1:                                                          }|
6505          {1:~                                                           }|*2
6506          {5:-- Omni completion (^O^N^P) }{6:match 1 of 4}                    |
6507        ]])
6508      end
6509      feed('<Esc>')
6510
6511      screen:try_resize(32, 20)
6512      command('set pummaxwidth=14')
6513      command('let g:change=1')
6514      feed('S<C-X><C-O>')
6515      if multigrid then
6516        screen:expect({
6517          grid = [[
6518        ## grid 1
6519          [2:--------------------------------]|*19
6520          [3:--------------------------------]|
6521        ## grid 2
6522          foo^                             |
6523          {1:~                               }|*18
6524        ## grid 3
6525          {5:-- }{6:match 1 of 3}                 |
6526        ## grid 4
6527          {12:foo fooKind f>}|
6528          {n:bar barKind b>}|
6529          {n:baz bazKind b>}|
6530        ]],
6531          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
6532        })
6533      else
6534        screen:expect([[
6535          foo^                             |
6536          {12:foo fooKind f>}{1:                  }|
6537          {n:bar barKind b>}{1:                  }|
6538          {n:baz bazKind b>}{1:                  }|
6539          {1:~                               }|*15
6540          {5:-- }{6:match 1 of 3}                 |
6541        ]])
6542      end
6543      feed('<Esc>')
6544
6545      -- Unicode Character U+2026 but one cell
6546      command('set fcs+=trunc:…')
6547      feed('S<C-X><C-O>')
6548      if multigrid then
6549        screen:expect({
6550          grid = [[
6551        ## grid 1
6552          [2:--------------------------------]|*19
6553          [3:--------------------------------]|
6554        ## grid 2
6555          foo^                             |
6556          {1:~                               }|*18
6557        ## grid 3
6558          {5:-- }{6:match 1 of 3}                 |
6559        ## grid 4
6560          {12:foo fooKind f…}|
6561          {n:bar barKind b…}|
6562          {n:baz bazKind b…}|
6563        ]],
6564          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
6565        })
6566      else
6567        screen:expect([[
6568          foo^                             |
6569          {12:foo fooKind f…}{1:                  }|
6570          {n:bar barKind b…}{1:                  }|
6571          {n:baz bazKind b…}{1:                  }|
6572          {1:~                               }|*15
6573          {5:-- }{6:match 1 of 3}                 |
6574        ]])
6575      end
6576      feed('<Esc>')
6577
6578      command('let g:change=2')
6579      feed('S<C-X><C-O>')
6580      if multigrid then
6581        screen:expect({
6582          grid = [[
6583        ## grid 1
6584          [2:--------------------------------]|*19
6585          [3:--------------------------------]|
6586        ## grid 2
6587          foo^                             |
6588          {1:~                               }|*18
6589        ## grid 3
6590          {5:-- }{6:match 1 of 3}                 |
6591        ## grid 4
6592          {12:foo        fo…}|
6593          {n:bar        一…}|
6594          {n:一二三四五 mu…}|
6595        ]],
6596          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
6597        })
6598      else
6599        screen:expect([[
6600          foo^                             |
6601          {12:foo        fo…}{1:                  }|
6602          {n:bar        一…}{1:                  }|
6603          {n:一二三四五 mu…}{1:                  }|
6604          {1:~                               }|*15
6605          {5:-- }{6:match 1 of 3}                 |
6606        ]])
6607      end
6608      feed('<Esc>')
6609
6610      command('set fcs&')
6611      feed('S<C-X><C-O>')
6612      if multigrid then
6613        screen:expect({
6614          grid = [[
6615        ## grid 1
6616          [2:--------------------------------]|*19
6617          [3:--------------------------------]|
6618        ## grid 2
6619          foo^                             |
6620          {1:~                               }|*18
6621        ## grid 3
6622          {5:-- }{6:match 1 of 3}                 |
6623        ## grid 4
6624          {12:foo        fo>}|
6625          {n:bar        一>}|
6626          {n:一二三四五 mu>}|
6627        ]],
6628          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
6629        })
6630      else
6631        screen:expect([[
6632          foo^                             |
6633          {12:foo        fo>}{1:                  }|
6634          {n:bar        一>}{1:                  }|
6635          {n:一二三四五 mu>}{1:                  }|
6636          {1:~                               }|*15
6637          {5:-- }{6:match 1 of 3}                 |
6638        ]])
6639      end
6640      feed('<Esc>')
6641
6642      command('set fcs=trunc:_')
6643      command('let g:change=1')
6644      feed('S<C-X><C-O>')
6645      if multigrid then
6646        screen:expect({
6647          grid = [[
6648        ## grid 1
6649          [2:--------------------------------]|*19
6650          [3:--------------------------------]|
6651        ## grid 2
6652          foo^                             |
6653          {1:~                               }|*18
6654        ## grid 3
6655          {5:-- }{6:match 1 of 3}                 |
6656        ## grid 4
6657          {12:foo fooKind f_}|
6658          {n:bar barKind b_}|
6659          {n:baz bazKind b_}|
6660        ]],
6661          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
6662        })
6663      else
6664        screen:expect([[
6665          foo^                             |
6666          {12:foo fooKind f_}{1:                  }|
6667          {n:bar barKind b_}{1:                  }|
6668          {n:baz bazKind b_}{1:                  }|
6669          {1:~                               }|*15
6670          {5:-- }{6:match 1 of 3}                 |
6671        ]])
6672      end
6673      feed('<Esc>')
6674      command('set fcs&')
6675
6676      command('set rightleft')
6677      feed('S<C-X><C-O>')
6678      if multigrid then
6679        screen:expect({
6680          grid = [[
6681        ## grid 1
6682          [2:--------------------------------]|*19
6683          [3:--------------------------------]|
6684        ## grid 2
6685                                      ^ oof|
6686          {1:                               ~}|*18
6687        ## grid 3
6688          {5:-- }{6:match 1 of 3}                 |
6689        ## grid 4
6690          {12:<f dniKoof oof}|
6691          {n:<b dniKrab rab}|
6692          {n:<b dniKzab zab}|
6693        ]],
6694          float_pos = { [4] = { -1, 'NW', 2, 1, 18, false, 100, 1, 1, 18 } },
6695        })
6696      else
6697        screen:expect([[
6698                                      ^ oof|
6699          {1:                  }{12:<f dniKoof oof}|
6700          {1:                  }{n:<b dniKrab rab}|
6701          {1:                  }{n:<b dniKzab zab}|
6702          {1:                               ~}|*15
6703          {5:-- }{6:match 1 of 3}                 |
6704        ]])
6705      end
6706      feed('<Esc>')
6707
6708      command('let g:change=2')
6709      feed('S<C-X><C-O>')
6710      if multigrid then
6711        screen:expect({
6712          grid = [[
6713        ## grid 1
6714          [2:--------------------------------]|*19
6715          [3:--------------------------------]|
6716        ## grid 2
6717                                      ^ oof|
6718          {1:                               ~}|*18
6719        ## grid 3
6720          {5:-- }{6:match 1 of 3}                 |
6721        ## grid 4
6722          {12:<of        oof}|
6723          {n:<一        rab}|
6724          {n:<um 五四三二一}|
6725        ]],
6726          float_pos = { [4] = { -1, 'NW', 2, 1, 18, false, 100, 1, 1, 18 } },
6727        })
6728      else
6729        screen:expect([[
6730                                      ^ oof|
6731          {1:                  }{12:<of        oof}|
6732          {1:                  }{n:<一        rab}|
6733          {1:                  }{n:<um 五四三二一}|
6734          {1:                               ~}|*15
6735          {5:-- }{6:match 1 of 3}                 |
6736        ]])
6737      end
6738      feed('<Esc>')
6739
6740      command('set fcs+=truncrl:…')
6741      feed('S<C-X><C-O>')
6742      if multigrid then
6743        screen:expect({
6744          grid = [[
6745        ## grid 1
6746          [2:--------------------------------]|*19
6747          [3:--------------------------------]|
6748        ## grid 2
6749                                      ^ oof|
6750          {1:                               ~}|*18
6751        ## grid 3
6752          {5:-- }{6:match 1 of 3}                 |
6753        ## grid 4
6754          {12:…of        oof}|
6755          {n:…一        rab}|
6756          {n:…um 五四三二一}|
6757        ]],
6758          float_pos = { [4] = { -1, 'NW', 2, 1, 18, false, 100, 1, 1, 18 } },
6759        })
6760      else
6761        screen:expect([[
6762                                      ^ oof|
6763          {1:                  }{12:…of        oof}|
6764          {1:                  }{n:…一        rab}|
6765          {1:                  }{n:…um 五四三二一}|
6766          {1:                               ~}|*15
6767          {5:-- }{6:match 1 of 3}                 |
6768        ]])
6769      end
6770      feed('<Esc>')
6771
6772      command('set fcs&')
6773      command('let g:change=3')
6774      feed('S<C-X><C-O>')
6775      if multigrid then
6776        screen:expect({
6777          grid = [[
6778        ## grid 1
6779          [2:--------------------------------]|*19
6780          [3:--------------------------------]|
6781        ## grid 2
6782                                      ^ rab|
6783          {1:                               ~}|*18
6784        ## grid 3
6785          {5:-- The only match}               |
6786        ## grid 4
6787          {12:<of 三二一 rab}|
6788        ]],
6789          float_pos = { [4] = { -1, 'NW', 2, 1, 18, false, 100, 1, 1, 18 } },
6790        })
6791      else
6792        screen:expect([[
6793                                      ^ rab|
6794          {1:                  }{12:<of 三二一 rab}|
6795          {1:                               ~}|*17
6796          {5:-- The only match}               |
6797        ]])
6798      end
6799      feed('<Esc>')
6800      command('set norightleft')
6801
6802      command('set pummaxwidth=4')
6803      command('let g:change=2')
6804      feed('S<C-X><C-O>')
6805      if multigrid then
6806        screen:expect({
6807          grid = [[
6808        ## grid 1
6809          [2:--------------------------------]|*19
6810          [3:--------------------------------]|
6811        ## grid 2
6812          foo^                             |
6813          {1:~                               }|*18
6814        ## grid 3
6815          {5:-- }{6:match 1 of 3}                 |
6816        ## grid 4
6817          {12:foo>}|
6818          {n:bar>}|
6819          {n:一 >}|
6820        ]],
6821          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
6822        })
6823      else
6824        screen:expect([[
6825          foo^                             |
6826          {12:foo>}{1:                            }|
6827          {n:bar>}{1:                            }|
6828          {n:一 >}{1:                            }|
6829          {1:~                               }|*15
6830          {5:-- }{6:match 1 of 3}                 |
6831        ]])
6832      end
6833      feed('<Esc>')
6834
6835      command('set rightleft')
6836      feed('S<C-X><C-O>')
6837      if multigrid then
6838        screen:expect({
6839          grid = [[
6840        ## grid 1
6841          [2:--------------------------------]|*19
6842          [3:--------------------------------]|
6843        ## grid 2
6844                                      ^ oof|
6845          {1:                               ~}|*18
6846        ## grid 3
6847          {5:-- }{6:match 1 of 3}                 |
6848        ## grid 4
6849          {12:<oof}|
6850          {n:<rab}|
6851          {n:< 一}|
6852        ]],
6853          float_pos = { [4] = { -1, 'NW', 2, 1, 28, false, 100, 1, 1, 28 } },
6854        })
6855      else
6856        screen:expect([[
6857                                      ^ oof|
6858          {1:                            }{12:<oof}|
6859          {1:                            }{n:<rab}|
6860          {1:                            }{n:< 一}|
6861          {1:                               ~}|*15
6862          {5:-- }{6:match 1 of 3}                 |
6863        ]])
6864      end
6865      feed('<Esc>')
6866      command('set norightleft')
6867
6868      command('set pummaxwidth=16')
6869      feed('S<C-X><C-O>')
6870      if multigrid then
6871        screen:expect({
6872          grid = [[
6873        ## grid 1
6874          [2:--------------------------------]|*19
6875          [3:--------------------------------]|
6876        ## grid 2
6877          foo^                             |
6878          {1:~                               }|*18
6879        ## grid 3
6880          {5:-- }{6:match 1 of 3}                 |
6881        ## grid 4
6882          {12:foo        fooK>}|
6883          {n:bar        一二>}|
6884          {n:一二三四五 multi}|
6885        ]],
6886          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
6887        })
6888      else
6889        screen:expect([[
6890          foo^                             |
6891          {12:foo        fooK>}{1:                }|
6892          {n:bar        一二>}{1:                }|
6893          {n:一二三四五 multi}{1:                }|
6894          {1:~                               }|*15
6895          {5:-- }{6:match 1 of 3}                 |
6896        ]])
6897      end
6898      feed('<Esc>')
6899
6900      command('set rightleft')
6901      feed('S<C-X><C-O>')
6902      if multigrid then
6903        screen:expect({
6904          grid = [[
6905        ## grid 1
6906          [2:--------------------------------]|*19
6907          [3:--------------------------------]|
6908        ## grid 2
6909                                      ^ oof|
6910          {1:                               ~}|*18
6911        ## grid 3
6912          {5:-- }{6:match 1 of 3}                 |
6913        ## grid 4
6914          {12:<Koof        oof}|
6915          {n:<二一        rab}|
6916          {n:itlum 五四三二一}|
6917        ]],
6918          float_pos = { [4] = { -1, 'NW', 2, 1, 16, false, 100, 1, 1, 16 } },
6919        })
6920      else
6921        screen:expect([[
6922                                      ^ oof|
6923          {1:                }{12:<Koof        oof}|
6924          {1:                }{n:<二一        rab}|
6925          {1:                }{n:itlum 五四三二一}|
6926          {1:                               ~}|*15
6927          {5:-- }{6:match 1 of 3}                 |
6928        ]])
6929      end
6930      feed('<Esc>')
6931      command('set norightleft')
6932
6933      command('let g:change=4')
6934      feed('S<C-X><C-O>')
6935      if multigrid then
6936        screen:expect({
6937          grid = [[
6938        ## grid 1
6939          [2:--------------------------------]|*19
6940          [3:--------------------------------]|
6941        ## grid 2
6942          一二三四五六七八九十^            |
6943          {1:~                               }|*18
6944        ## grid 3
6945          {5:-- }{6:match 1 of 2}                 |
6946        ## grid 4
6947          {ds:一二三四五六七 }{12:>}|
6948          {dn:123456789_12345}{n:>}|
6949        ]],
6950          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
6951        })
6952      else
6953        screen:expect([[
6954          一二三四五六七八九十^            |
6955          {ds:一二三四五六七 }{12:>}{1:                }|
6956          {dn:123456789_12345}{n:>}{1:                }|
6957          {1:~                               }|*16
6958          {5:-- }{6:match 1 of 2}                 |
6959        ]])
6960      end
6961      feed('<Esc>')
6962    end)
6963
6964    -- oldtest: Test_pum_position_when_wrap()
6965    it('with cursor on a wrapped line', function()
6966      exec([[
6967        func Omni_test(findstart, base)
6968          if a:findstart
6969            return col(".")
6970          endif
6971          return ['foo', 'bar', 'foobar']
6972        endfunc
6973        set omnifunc=Omni_test
6974        set wrap
6975        set cot+=noinsert
6976      ]])
6977      screen:try_resize(25, 15)
6978
6979      insert(('abcde '):rep(20))
6980
6981      feed('5|')
6982      feed('a<C-X><C-O>')
6983      if multigrid then
6984        screen:expect({
6985          float_pos = { [4] = { -1, 'NW', 2, 3, 4, false, 100, 1, 3, 4 } },
6986        })
6987      else
6988        screen:expect([[
6989          abcde^ abcde abcde abcde a|
6990          bcde abcde abcde abcde ab|
6991          cde abcde abcde abcde abc|
6992          de a{12: foo            } abcd|
6993          e ab{n: bar            }     |
6994          {1:~   }{n: foobar         }{1:     }|
6995          {1:~                        }|*8
6996          {5:-- }{6:match 1 of 3}          |
6997        ]])
6998      end
6999      feed('<Esc>')
7000
7001      feed('30|')
7002      feed('a<C-X><C-O>')
7003      if multigrid then
7004        screen:expect({
7005          float_pos = { [4] = { -1, 'NW', 2, 4, 4, false, 100, 1, 4, 4 } },
7006        })
7007      else
7008        screen:expect([[
7009          abcde abcde abcde abcde a|
7010          bcde ^abcde abcde abcde ab|
7011          cde abcde abcde abcde abc|
7012          de abcde abcde abcde abcd|
7013          e ab{12: foo            }     |
7014          {1:~   }{n: bar            }{1:     }|
7015          {1:~   }{n: foobar         }{1:     }|
7016          {1:~                        }|*7
7017          {5:-- }{6:match 1 of 3}          |
7018        ]])
7019      end
7020      feed('<Esc>')
7021
7022      feed('55|')
7023      feed('a<C-X><C-O>')
7024      if multigrid then
7025        screen:expect({
7026          float_pos = { [4] = { -1, 'NW', 2, 5, 4, false, 100, 1, 5, 4 } },
7027        })
7028      else
7029        screen:expect([[
7030          abcde abcde abcde abcde a|
7031          bcde abcde abcde abcde ab|
7032          cde a^bcde abcde abcde abc|
7033          de abcde abcde abcde abcd|
7034          e abcde abcde abcde      |
7035          {1:~   }{12: foo            }{1:     }|
7036          {1:~   }{n: bar            }{1:     }|
7037          {1:~   }{n: foobar         }{1:     }|
7038          {1:~                        }|*6
7039          {5:-- }{6:match 1 of 3}          |
7040        ]])
7041      end
7042      feed('<Esc>')
7043
7044      feed('85|')
7045      feed('a<C-X><C-O>')
7046      if multigrid then
7047        screen:expect({
7048          float_pos = { [4] = { -1, 'NW', 2, 5, 9, false, 100, 1, 5, 9 } },
7049        })
7050      else
7051        screen:expect([[
7052          abcde abcde abcde abcde a|
7053          bcde abcde abcde abcde ab|
7054          cde abcde abcde abcde abc|
7055          de abcde a^bcde abcde abcd|
7056          e abcde abcde abcde      |
7057          {1:~        }{12: foo            }|
7058          {1:~        }{n: bar            }|
7059          {1:~        }{n: foobar         }|
7060          {1:~                        }|*6
7061          {5:-- }{6:match 1 of 3}          |
7062        ]])
7063      end
7064      feed('<C-E><Esc>')
7065
7066      feed('108|')
7067      feed('a<C-X><C-O>')
7068      if multigrid then
7069        screen:expect({
7070          float_pos = { [4] = { -1, 'NW', 2, 5, 7, false, 100, 1, 5, 7 } },
7071        })
7072      else
7073        screen:expect([[
7074          abcde abcde abcde abcde a|
7075          bcde abcde abcde abcde ab|
7076          cde abcde abcde abcde abc|
7077          de abcde abcde abcde abcd|
7078          e abcde ^abcde abcde      |
7079          {1:~      }{12: foo            }{1:  }|
7080          {1:~      }{n: bar            }{1:  }|
7081          {1:~      }{n: foobar         }{1:  }|
7082          {1:~                        }|*6
7083          {5:-- }{6:match 1 of 3}          |
7084        ]])
7085      end
7086      feed('<C-E><Esc>')
7087    end)
7088
7089    it('does not crash when displayed in last column with rightleft #12032', function()
7090      local col = 30
7091      local items = { 'word', 'choice', 'text', 'thing' }
7092      local max_len = 0
7093      for _, v in ipairs(items) do
7094        max_len = max_len < #v and #v or max_len
7095      end
7096      screen:try_resize(col, 8)
7097      command('set rightleft')
7098      command('call setline(1, repeat(" ", &columns - ' .. max_len .. '))')
7099      feed('$i')
7100      fn.complete(col - max_len, items)
7101      feed('<c-y>')
7102      assert_alive()
7103    end)
7104
7105    it('truncates double-width character correctly without scrollbar', function()
7106      screen:try_resize(32, 8)
7107      command('set completeopt+=menuone,noselect')
7108      feed('i' .. string.rep(' ', 13))
7109
7110      fn.complete(14, { '一二三四五六七八九十' })
7111      if multigrid then
7112        screen:expect({
7113          grid = [[
7114        ## grid 1
7115          [2:--------------------------------]|*7
7116          [3:--------------------------------]|
7117        ## grid 2
7118                       ^                   |
7119          {1:~                               }|*6
7120        ## grid 3
7121          {5:-- INSERT --}                    |
7122        ## grid 4
7123          {n: 一二三四五六七八九>}|
7124        ]],
7125          float_pos = { [4] = { -1, 'NW', 2, 1, 12, false, 100, 1, 1, 12 } },
7126        })
7127      else
7128        screen:expect([[
7129                       ^                   |
7130          {1:~           }{n: 一二三四五六七八九>}|
7131          {1:~                               }|*5
7132          {5:-- INSERT --}                    |
7133        ]])
7134      end
7135      feed('<C-E>')
7136
7137      fn.complete(14, { { word = '一二三', kind = '四五六', menu = '七八九十' } })
7138      if multigrid then
7139        screen:expect({
7140          grid = [[
7141        ## grid 1
7142          [2:--------------------------------]|*7
7143          [3:--------------------------------]|
7144        ## grid 2
7145                       ^                   |
7146          {1:~                               }|*6
7147        ## grid 3
7148          {5:-- INSERT --}                    |
7149        ## grid 4
7150          {n: 一二三 四五六 七八>}|
7151        ]],
7152          float_pos = { [4] = { -1, 'NW', 2, 1, 12, false, 100, 1, 1, 12 } },
7153        })
7154      else
7155        screen:expect([[
7156                       ^                   |
7157          {1:~           }{n: 一二三 四五六 七八>}|
7158          {1:~                               }|*5
7159          {5:-- INSERT --}                    |
7160        ]])
7161      end
7162      feed('<C-E>')
7163
7164      command('set rightleft')
7165      fn.complete(14, { '一二三四五六七八九十' })
7166      if multigrid then
7167        screen:expect({
7168          grid = [[
7169        ## grid 1
7170          [2:--------------------------------]|*7
7171          [3:--------------------------------]|
7172        ## grid 2
7173                            ^              |
7174          {1:                               ~}|*6
7175        ## grid 3
7176          {5:-- INSERT --}                    |
7177        ## grid 4
7178          {n:<九八七六五四三二一 }|
7179        ]],
7180          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
7181        })
7182      else
7183        screen:expect([[
7184                            ^              |
7185          {n:<九八七六五四三二一 }{1:           ~}|
7186          {1:                               ~}|*5
7187          {5:-- INSERT --}                    |
7188        ]])
7189      end
7190      feed('<C-E>')
7191
7192      fn.complete(14, { { word = '一二三', kind = '四五六', menu = '七八九十' } })
7193      if multigrid then
7194        screen:expect({
7195          grid = [[
7196        ## grid 1
7197          [2:--------------------------------]|*7
7198          [3:--------------------------------]|
7199        ## grid 2
7200                            ^              |
7201          {1:                               ~}|*6
7202        ## grid 3
7203          {5:-- INSERT --}                    |
7204        ## grid 4
7205          {n:<八七 六五四 三二一 }|
7206        ]],
7207          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
7208        })
7209      else
7210        screen:expect([[
7211                            ^              |
7212          {n:<八七 六五四 三二一 }{1:           ~}|
7213          {1:                               ~}|*5
7214          {5:-- INSERT --}                    |
7215        ]])
7216      end
7217      feed('<C-E>')
7218    end)
7219
7220    it('truncates double-width character correctly with scrollbar', function()
7221      screen:try_resize(32, 8)
7222      command('set completeopt+=noselect')
7223      command('set pumheight=4')
7224      feed('i' .. string.rep(' ', 12))
7225      local items1 = {}
7226      local items2 = {}
7227      for _ = 1, 8 do
7228        table.insert(items1, { word = '一二三四五六七八九十', equal = 1, dup = 1 })
7229      end
7230      for _ = 1, 2 do
7231        table.insert(
7232          items2,
7233          { word = 'abcdef', kind = 'ghijkl', menu = 'mnopqrst', equal = 1, dup = 1 }
7234        )
7235      end
7236      for _ = 3, 8 do
7237        table.insert(
7238          items2,
7239          { word = '一二三', kind = '四五六', menu = '七八九十', equal = 1, dup = 1 }
7240        )
7241      end
7242
7243      fn.complete(13, items1)
7244      if multigrid then
7245        screen:expect({
7246          grid = [[
7247        ## grid 1
7248          [2:--------------------------------]|*7
7249          [3:--------------------------------]|
7250        ## grid 2
7251                      ^                    |
7252          {1:~                               }|*6
7253        ## grid 3
7254          {5:-- INSERT --}                    |
7255        ## grid 4
7256          {n: 一二三四五六七八九>}{c: }|*2
7257          {n: 一二三四五六七八九>}{12: }|*2
7258        ]],
7259          float_pos = { [4] = { -1, 'NW', 2, 1, 11, false, 100, 1, 1, 11 } },
7260        })
7261      else
7262        screen:expect([[
7263                      ^                    |
7264          {1:~          }{n: 一二三四五六七八九>}{c: }|*2
7265          {1:~          }{n: 一二三四五六七八九>}{12: }|*2
7266          {1:~                               }|*2
7267          {5:-- INSERT --}                    |
7268        ]])
7269      end
7270      feed('<C-E>')
7271
7272      fn.complete(13, items2)
7273      if multigrid then
7274        screen:expect({
7275          grid = [[
7276        ## grid 1
7277          [2:--------------------------------]|*7
7278          [3:--------------------------------]|
7279        ## grid 2
7280                      ^                    |
7281          {1:~                               }|*6
7282        ## grid 3
7283          {5:-- INSERT --}                    |
7284        ## grid 4
7285          {n: abcdef ghijkl mnop>}{c: }|*2
7286          {n: 一二三 四五六 七八>}{12: }|*2
7287        ]],
7288          float_pos = { [4] = { -1, 'NW', 2, 1, 11, false, 100, 1, 1, 11 } },
7289        })
7290      else
7291        screen:expect([[
7292                      ^                    |
7293          {1:~          }{n: abcdef ghijkl mnop>}{c: }|*2
7294          {1:~          }{n: 一二三 四五六 七八>}{12: }|*2
7295          {1:~                               }|*2
7296          {5:-- INSERT --}                    |
7297        ]])
7298      end
7299      feed('<C-E>')
7300
7301      command('set rightleft')
7302      fn.complete(13, items1)
7303      if multigrid then
7304        screen:expect({
7305          grid = [[
7306        ## grid 1
7307          [2:--------------------------------]|*7
7308          [3:--------------------------------]|
7309        ## grid 2
7310                             ^             |
7311          {1:                               ~}|*6
7312        ## grid 3
7313          {5:-- INSERT --}                    |
7314        ## grid 4
7315          {c: }{n:<九八七六五四三二一 }|*2
7316          {12: }{n:<九八七六五四三二一 }|*2
7317        ]],
7318          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
7319        })
7320      else
7321        screen:expect([[
7322                             ^             |
7323          {c: }{n:<九八七六五四三二一 }{1:          ~}|*2
7324          {12: }{n:<九八七六五四三二一 }{1:          ~}|*2
7325          {1:                               ~}|*2
7326          {5:-- INSERT --}                    |
7327        ]])
7328      end
7329      feed('<C-E>')
7330
7331      fn.complete(13, items2)
7332      if multigrid then
7333        screen:expect({
7334          grid = [[
7335        ## grid 1
7336          [2:--------------------------------]|*7
7337          [3:--------------------------------]|
7338        ## grid 2
7339                             ^             |
7340          {1:                               ~}|*6
7341        ## grid 3
7342          {5:-- INSERT --}                    |
7343        ## grid 4
7344          {c: }{n:<ponm lkjihg fedcba }|*2
7345          {12: }{n:<八七 六五四 三二一 }|*2
7346        ]],
7347          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
7348        })
7349      else
7350        screen:expect([[
7351                             ^             |
7352          {c: }{n:<ponm lkjihg fedcba }{1:          ~}|*2
7353          {12: }{n:<八七 六五四 三二一 }{1:          ~}|*2
7354          {1:                               ~}|*2
7355          {5:-- INSERT --}                    |
7356        ]])
7357      end
7358      feed('<C-E>')
7359    end)
7360
7361    it('supports mousemodel=popup', function()
7362      screen:try_resize(32, 6)
7363      exec([[
7364        call setline(1, 'popup menu test')
7365        set mouse=a mousemodel=popup
7366
7367        " Delete the default MenuPopup event handler.
7368        autocmd! nvim.popupmenu
7369        aunmenu PopUp
7370        menu PopUp.foo :let g:menustr = 'foo'<CR>
7371        menu PopUp.bar :let g:menustr = 'bar'<CR>
7372        menu PopUp.baz :let g:menustr = 'baz'<CR>
7373      ]])
7374
7375      --- @param state string|test.functional.ui.screen.Expect
7376      --- @param str string
7377      --- @param repl string
7378      --- @return string|test.functional.ui.screen.Expect
7379      local function screen_replace(state, str, repl)
7380        if type(state) == 'string' then
7381          local new_state = state:gsub(vim.pesc(str), vim.pesc(repl))
7382          return new_state
7383        end
7384        local new_state = vim.deepcopy(state)
7385        local grid = assert(new_state.grid)
7386        grid = grid:gsub(vim.pesc(str), vim.pesc(repl))
7387        new_state.grid = grid
7388        return new_state
7389      end
7390
7391      local no_sel_screen ---@type string|test.function.ui.screen.Expect
7392      if send_mouse_grid then
7393        api.nvim_input_mouse('right', 'press', '', 2, 0, 4)
7394      else
7395        feed('<RightMouse><4,0>')
7396      end
7397      if multigrid then
7398        no_sel_screen = {
7399          grid = [[
7400        ## grid 1
7401          [2:--------------------------------]|*5
7402          [3:--------------------------------]|
7403        ## grid 2
7404          ^popup menu test                 |
7405          {1:~                               }|*4
7406        ## grid 3
7407                                          |
7408        ## grid 4
7409          {n: foo }|
7410          {n: bar }|
7411          {n: baz }|
7412        ]],
7413          float_pos = { [4] = { -1, 'NW', 2, 1, 3, false, 250, 2, 1, 3 } },
7414        }
7415      else
7416        no_sel_screen = [[
7417          ^popup menu test                 |
7418          {1:~  }{n: foo }{1:                        }|
7419          {1:~  }{n: bar }{1:                        }|
7420          {1:~  }{n: baz }{1:                        }|
7421          {1:~                               }|
7422                                          |
7423        ]]
7424      end
7425      screen:expect(no_sel_screen)
7426      feed('<Down>')
7427      screen:expect(screen_replace(no_sel_screen, '{n: foo }', '{12: foo }'))
7428      feed('<Down>')
7429      screen:expect(screen_replace(no_sel_screen, '{n: bar }', '{12: bar }'))
7430      feed('<CR>')
7431      local no_menu_screen ---@type string
7432      if multigrid then
7433        no_menu_screen = [[
7434        ## grid 1
7435          [2:--------------------------------]|*5
7436          [3:--------------------------------]|
7437        ## grid 2
7438          ^popup menu test                 |
7439          {1:~                               }|*4
7440        ## grid 3
7441          :let g:menustr = 'bar'          |
7442        ]]
7443      else
7444        no_menu_screen = [[
7445          ^popup menu test                 |
7446          {1:~                               }|*4
7447          :let g:menustr = 'bar'          |
7448        ]]
7449      end
7450      screen:expect(no_menu_screen)
7451      eq('bar', api.nvim_get_var('menustr'))
7452
7453      if send_mouse_grid then
7454        api.nvim_input_mouse('right', 'press', '', 2, 2, 20)
7455      else
7456        feed('<RightMouse><20,2>')
7457      end
7458      if multigrid then
7459        screen:expect({
7460          grid = [[
7461        ## grid 1
7462          [2:--------------------------------]|*5
7463          [3:--------------------------------]|
7464        ## grid 2
7465          ^popup menu test                 |
7466          {1:~                               }|*4
7467        ## grid 3
7468          :let g:menustr = 'bar'          |
7469        ## grid 4
7470          {n: foo }|
7471          {n: bar }|
7472          {n: baz }|
7473        ]],
7474          float_pos = { [4] = { -1, 'NW', 2, 3, 19, false, 250, 2, 3, 19 } },
7475        })
7476      else
7477        screen:expect([[
7478          ^popup menu test                 |
7479          {1:~                               }|*2
7480          {1:~                  }{n: foo }{1:        }|
7481          {1:~                  }{n: bar }{1:        }|
7482          :let g:menustr = 'b{n: baz }        |
7483        ]])
7484      end
7485      if send_mouse_grid then
7486        api.nvim_input_mouse('right', 'press', '', 2, 0, 18)
7487      else
7488        feed('<RightMouse><18,0>')
7489      end
7490      if multigrid then
7491        screen:expect({
7492          grid = [[
7493        ## grid 1
7494          [2:--------------------------------]|*5
7495          [3:--------------------------------]|
7496        ## grid 2
7497          ^popup menu test                 |
7498          {1:~                               }|*4
7499        ## grid 3
7500          :let g:menustr = 'bar'          |
7501        ## grid 4
7502          {n: foo }|
7503          {n: bar }|
7504          {n: baz }|
7505        ]],
7506          float_pos = { [4] = { -1, 'NW', 2, 1, 17, false, 250, 2, 1, 17 } },
7507        })
7508      else
7509        screen:expect([[
7510          ^popup menu test                 |
7511          {1:~                }{n: foo }{1:          }|
7512          {1:~                }{n: bar }{1:          }|
7513          {1:~                }{n: baz }{1:          }|
7514          {1:~                               }|
7515          :let g:menustr = 'bar'          |
7516        ]])
7517      end
7518      if send_mouse_grid then
7519        api.nvim_input_mouse('right', 'press', '', 4, 1, 3)
7520      else
7521        feed('<RightMouse><20,2>')
7522      end
7523      if multigrid then
7524        screen:expect({
7525          grid = [[
7526        ## grid 1
7527          [2:--------------------------------]|*5
7528          [3:--------------------------------]|
7529        ## grid 2
7530          ^popup menu test                 |
7531          {1:~                               }|*4
7532        ## grid 3
7533          :let g:menustr = 'bar'          |
7534        ## grid 4
7535          {n: foo }|
7536          {n: bar }|
7537          {n: baz }|
7538        ]],
7539          float_pos = { [4] = { -1, 'NW', 2, 3, 19, false, 250, 2, 3, 19 } },
7540        })
7541      else
7542        screen:expect([[
7543          ^popup menu test                 |
7544          {1:~                               }|*2
7545          {1:~                  }{n: foo }{1:        }|
7546          {1:~                  }{n: bar }{1:        }|
7547          :let g:menustr = 'b{n: baz }        |
7548        ]])
7549      end
7550      if send_mouse_grid then
7551        api.nvim_input_mouse('left', 'press', '', 4, 2, 2)
7552      else
7553        feed('<LeftMouse><21,5>')
7554      end
7555      no_menu_screen = no_menu_screen:gsub([['bar']], [['baz']])
7556      screen:expect(no_menu_screen)
7557      eq('baz', api.nvim_get_var('menustr'))
7558
7559      if send_mouse_grid then
7560        api.nvim_input_mouse('right', 'press', '', 2, 0, 4)
7561      else
7562        feed('<RightMouse><4,0>')
7563      end
7564      if multigrid then
7565        no_sel_screen = {
7566          grid = [[
7567        ## grid 1
7568          [2:--------------------------------]|*5
7569          [3:--------------------------------]|
7570        ## grid 2
7571          ^popup menu test                 |
7572          {1:~                               }|*4
7573        ## grid 3
7574          :let g:menustr = 'baz'          |
7575        ## grid 4
7576          {n: foo }|
7577          {n: bar }|
7578          {n: baz }|
7579        ]],
7580          float_pos = { [4] = { -1, 'NW', 2, 1, 3, false, 250, 2, 1, 3 } },
7581        }
7582      else
7583        no_sel_screen = [[
7584          ^popup menu test                 |
7585          {1:~  }{n: foo }{1:                        }|
7586          {1:~  }{n: bar }{1:                        }|
7587          {1:~  }{n: baz }{1:                        }|
7588          {1:~                               }|
7589          :let g:menustr = 'baz'          |
7590        ]]
7591      end
7592      screen:expect(no_sel_screen)
7593      if send_mouse_grid then
7594        api.nvim_input_mouse('right', 'drag', '', 2, 3, 6)
7595      else
7596        feed('<RightDrag><6,3>')
7597      end
7598      screen:expect(screen_replace(no_sel_screen, '{n: baz }', '{12: baz }'))
7599      if send_mouse_grid then
7600        api.nvim_input_mouse('right', 'release', '', 2, 1, 6)
7601      else
7602        feed('<RightRelease><6,1>')
7603      end
7604      no_menu_screen = no_menu_screen:gsub([['baz']], [['foo']])
7605      screen:expect(no_menu_screen)
7606      eq('foo', api.nvim_get_var('menustr'))
7607      no_sel_screen = screen_replace(no_sel_screen, [['baz']], [['foo']])
7608
7609      eq(false, screen.options.mousemoveevent)
7610
7611      if send_mouse_grid then
7612        api.nvim_input_mouse('right', 'press', '', 2, 0, 4)
7613      else
7614        feed('<RightMouse><4,0>')
7615      end
7616      screen:expect(no_sel_screen)
7617      eq(true, screen.options.mousemoveevent)
7618      if send_mouse_grid then
7619        api.nvim_input_mouse('wheel', 'up', '', 2, 0, 4)
7620      else
7621        feed('<ScrollWheelUp><4,0>')
7622      end
7623      screen:expect(screen_replace(no_sel_screen, '{n: foo }', '{12: foo }'))
7624      eq(true, screen.options.mousemoveevent)
7625      if send_mouse_grid then
7626        api.nvim_input_mouse('move', '', '', 4, 2, 3)
7627      else
7628        feed('<MouseMove><6,3>')
7629      end
7630      screen:expect(screen_replace(no_sel_screen, '{n: baz }', '{12: baz }'))
7631      eq(true, screen.options.mousemoveevent)
7632      if send_mouse_grid then
7633        api.nvim_input_mouse('wheel', 'down', '', 4, 2, 3)
7634      else
7635        feed('<ScrollWheelDown><6,3>')
7636      end
7637      screen:expect(screen_replace(no_sel_screen, '{n: bar }', '{12: bar }'))
7638      eq(true, screen.options.mousemoveevent)
7639      if send_mouse_grid then
7640        api.nvim_input_mouse('left', 'press', '', 4, 1, 3)
7641      else
7642        feed('<LeftMouse><6,2>')
7643      end
7644      no_menu_screen = no_menu_screen:gsub([['foo']], [['bar']])
7645      screen:expect(no_menu_screen)
7646      eq(false, screen.options.mousemoveevent)
7647      eq('bar', api.nvim_get_var('menustr'))
7648
7649      command('set laststatus=0 | botright split')
7650      if send_mouse_grid then
7651        api.nvim_input_mouse('right', 'press', '', 5, 1, 20)
7652      else
7653        feed('<RightMouse><20,4>')
7654      end
7655      if multigrid then
7656        screen:expect({
7657          grid = [[
7658        ## grid 1
7659          [2:--------------------------------]|*2
7660          {2:[No Name] [+]                   }|
7661          [5:--------------------------------]|*2
7662          [3:--------------------------------]|
7663        ## grid 2
7664          popup menu test                 |
7665          {1:~                               }|
7666        ## grid 3
7667          :let g:menustr = 'bar'          |
7668        ## grid 4
7669          {n: foo }|
7670          {n: bar }|
7671          {n: baz }|
7672        ## grid 5
7673          ^popup menu test                 |
7674          {1:~                               }|
7675        ]],
7676          float_pos = { [4] = { -1, 'SW', 5, 1, 19, false, 250, 2, 1, 19 } },
7677        })
7678      else
7679        screen:expect([[
7680          popup menu test                 |
7681          {1:~                  }{n: foo }{1:        }|
7682          {2:[No Name] [+]      }{n: bar }{2:        }|
7683          ^popup menu test    {n: baz }        |
7684          {1:~                               }|
7685          :let g:menustr = 'bar'          |
7686        ]])
7687      end
7688      if send_mouse_grid then
7689        api.nvim_input_mouse('left', 'press', '', 4, 2, 2)
7690      else
7691        feed('<LeftMouse><21,3>')
7692      end
7693      if multigrid then
7694        screen:expect([[
7695        ## grid 1
7696          [2:--------------------------------]|*2
7697          {2:[No Name] [+]                   }|
7698          [5:--------------------------------]|*2
7699          [3:--------------------------------]|
7700        ## grid 2
7701          popup menu test                 |
7702          {1:~                               }|
7703        ## grid 3
7704          :let g:menustr = 'baz'          |
7705        ## grid 5
7706          ^popup menu test                 |
7707          {1:~                               }|
7708        ]])
7709      else
7710        screen:expect([[
7711          popup menu test                 |
7712          {1:~                               }|
7713          {2:[No Name] [+]                   }|
7714          ^popup menu test                 |
7715          {1:~                               }|
7716          :let g:menustr = 'baz'          |
7717        ]])
7718      end
7719      eq('baz', api.nvim_get_var('menustr'))
7720
7721      command('set winwidth=1 | rightbelow vsplit')
7722      if send_mouse_grid then
7723        api.nvim_input_mouse('right', 'press', '', 6, 1, 14)
7724      else
7725        feed('<RightMouse><30,4>')
7726      end
7727      if multigrid then
7728        screen:expect({
7729          grid = [[
7730        ## grid 1
7731          [2:--------------------------------]|*2
7732          {2:[No Name] [+]                   }|
7733          [5:---------------]│[6:----------------]|*2
7734          [3:--------------------------------]|
7735        ## grid 2
7736          popup menu test                 |
7737          {1:~                               }|
7738        ## grid 3
7739          :let g:menustr = 'baz'          |
7740        ## grid 4
7741          {n: foo}|
7742          {n: bar}|
7743          {n: baz}|
7744        ## grid 5
7745          popup menu test|
7746          {1:~              }|
7747        ## grid 6
7748          ^popup menu test |
7749          {1:~               }|
7750        ]],
7751          float_pos = { [4] = { -1, 'SW', 6, 1, 12, false, 250, 2, 1, 28 } },
7752        })
7753      else
7754        screen:expect([[
7755          popup menu test                 |
7756          {1:~                           }{n: foo}|
7757          {2:[No Name] [+]               }{n: bar}|
7758          popup menu test│^popup menu t{n: baz}|
7759          {1:~              }│{1:~               }|
7760          :let g:menustr = 'baz'          |
7761        ]])
7762      end
7763      if send_mouse_grid then
7764        api.nvim_input_mouse('left', 'press', '', 4, 0, 2)
7765      else
7766        feed('<LeftMouse><31,1>')
7767      end
7768      if multigrid then
7769        screen:expect([[
7770        ## grid 1
7771          [2:--------------------------------]|*2
7772          {2:[No Name] [+]                   }|
7773          [5:---------------]│[6:----------------]|*2
7774          [3:--------------------------------]|
7775        ## grid 2
7776          popup menu test                 |
7777          {1:~                               }|
7778        ## grid 3
7779          :let g:menustr = 'foo'          |
7780        ## grid 5
7781          popup menu test|
7782          {1:~              }|
7783        ## grid 6
7784          ^popup menu test |
7785          {1:~               }|
7786        ]])
7787      else
7788        screen:expect([[
7789          popup menu test                 |
7790          {1:~                               }|
7791          {2:[No Name] [+]                   }|
7792          popup menu test│^popup menu test |
7793          {1:~              }│{1:~               }|
7794          :let g:menustr = 'foo'          |
7795        ]])
7796      end
7797      eq('foo', api.nvim_get_var('menustr'))
7798
7799      command('setlocal winbar=WINBAR')
7800      if send_mouse_grid then
7801        api.nvim_input_mouse('right', 'press', '', 6, 1, 14)
7802      else
7803        feed('<RightMouse><30,4>')
7804      end
7805      if multigrid then
7806        no_sel_screen = {
7807          grid = [[
7808        ## grid 1
7809          [2:--------------------------------]|*2
7810          {2:[No Name] [+]                   }|
7811          [5:---------------]│[6:----------------]|*2
7812          [3:--------------------------------]|
7813        ## grid 2
7814          popup menu test                 |
7815          {1:~                               }|
7816        ## grid 3
7817          :let g:menustr = 'foo'          |
7818        ## grid 4
7819          {n: foo}|
7820          {n: bar}|
7821          {n: baz}|
7822        ## grid 5
7823          popup menu test|
7824          {1:~              }|
7825        ## grid 6
7826          {5:WINBAR          }|
7827          ^popup menu test |
7828        ]],
7829          float_pos = { [4] = { -1, 'SW', 6, 1, 12, false, 250, 2, 1, 28 } },
7830        }
7831      else
7832        no_sel_screen = [[
7833          popup menu test                 |
7834          {1:~                           }{n: foo}|
7835          {2:[No Name] [+]               }{n: bar}|
7836          popup menu test│{5:WINBAR      }{n: baz}|
7837          {1:~              }│^popup menu test |
7838          :let g:menustr = 'foo'          |
7839        ]]
7840      end
7841      screen:expect(no_sel_screen)
7842      if send_mouse_grid then
7843        api.nvim_input_mouse('right', 'drag', '', 6, 0, 15)
7844      else
7845        feed('<RightDrag><31,3>')
7846      end
7847      screen:expect(screen_replace(no_sel_screen, '{n: baz}', '{12: baz}'))
7848      if send_mouse_grid then
7849        api.nvim_input_mouse('right', 'release', '', 6, 1, 15)
7850      else
7851        feed('<RightRelease><31,4>')
7852      end
7853      screen:expect(no_sel_screen)
7854      if send_mouse_grid then
7855        api.nvim_input_mouse('left', 'press', '', 4, 1, 2)
7856      else
7857        feed('<LeftMouse><31,2>')
7858      end
7859      if multigrid then
7860        screen:expect([[
7861        ## grid 1
7862          [2:--------------------------------]|*2
7863          {2:[No Name] [+]                   }|
7864          [5:---------------]│[6:----------------]|*2
7865          [3:--------------------------------]|
7866        ## grid 2
7867          popup menu test                 |
7868          {1:~                               }|
7869        ## grid 3
7870          :let g:menustr = 'bar'          |
7871        ## grid 5
7872          popup menu test|
7873          {1:~              }|
7874        ## grid 6
7875          {5:WINBAR          }|
7876          ^popup menu test |
7877        ]])
7878      else
7879        screen:expect([[
7880          popup menu test                 |
7881          {1:~                               }|
7882          {2:[No Name] [+]                   }|
7883          popup menu test│{5:WINBAR          }|
7884          {1:~              }│^popup menu test |
7885          :let g:menustr = 'bar'          |
7886        ]])
7887      end
7888      eq('bar', api.nvim_get_var('menustr'))
7889
7890      command([[let g:menustr = '']])
7891      screen:try_resize(32, 9)
7892      command('wincmd t | 4vsplit | wincmd l | topleft 1split')
7893      if multigrid then
7894        no_menu_screen = [[
7895        ## grid 1
7896          [8:--------------------------------]|
7897          {3:[No Name] [+]                   }|
7898          [7:----]│[2:---------------------------]|*2
7899          {2:<+]  [No Name] [+]              }|
7900          [5:---------------]│[6:----------------]|*3
7901          [3:--------------------------------]|
7902        ## grid 2
7903          popup menu test            |
7904          {1:~                          }|
7905        ## grid 3
7906                                          |
7907        ## grid 5
7908          popup menu test|
7909          {1:~              }|*2
7910        ## grid 6
7911          {5:WINBAR          }|
7912          popup menu test |
7913          {1:~               }|
7914        ## grid 7
7915          popu|
7916          p me|
7917        ## grid 8
7918          ^popup menu test                 |
7919        ]]
7920      else
7921        no_menu_screen = [[
7922          ^popup menu test                 |
7923          {3:[No Name] [+]                   }|
7924          popu│popup menu test            |
7925          p me│{1:~                          }|
7926          {2:<+]  [No Name] [+]              }|
7927          popup menu test│{5:WINBAR          }|
7928          {1:~              }│popup menu test |
7929          {1:~              }│{1:~               }|
7930                                          |
7931        ]]
7932      end
7933      screen:expect(no_menu_screen)
7934
7935      if multigrid then
7936        no_sel_screen = {
7937          grid = [[
7938        ## grid 1
7939          [8:--------------------------------]|
7940          {3:[No Name] [+]                   }|
7941          [7:----]│[2:---------------------------]|*2
7942          {2:<+]  [No Name] [+]              }|
7943          [5:---------------]│[6:----------------]|*3
7944          [3:--------------------------------]|
7945        ## grid 2
7946          popup menu test            |
7947          {1:~                          }|
7948        ## grid 3
7949                                          |
7950        ## grid 4
7951          {n: foo }|
7952          {n: bar }|
7953          {n: baz }|
7954        ## grid 5
7955          popup menu test|
7956          {1:~              }|*2
7957        ## grid 6
7958          {5:WINBAR          }|
7959          popup menu test |
7960          {1:~               }|
7961        ## grid 7
7962          popu|
7963          p me|
7964        ## grid 8
7965          ^popup menu test                 |
7966        ]],
7967          float_pos = { [4] = { -1, 'NW', 2, 1, 14, false, 250, 2, 3, 19 } },
7968        }
7969      else
7970        no_sel_screen = [[
7971          ^popup menu test                 |
7972          {3:[No Name] [+]                   }|
7973          popu│popup menu test            |
7974          p me│{1:~             }{n: foo }{1:        }|
7975          {2:<+]  [No Name] [+] }{n: bar }{2:        }|
7976          popup menu test│{5:WIN}{n: baz }{5:        }|
7977          {1:~              }│popup menu test |
7978          {1:~              }│{1:~               }|
7979                                          |
7980        ]]
7981      end
7982
7983      local pos = {
7984        { 0, 2, 20 },
7985        { 0, 3, 19 },
7986        { 0, 3, 18 },
7987        { 0, 4, 23 },
7988        { 0, 4, 24 },
7989        { 0, 5, 19 },
7990        { 0, 5, 18 },
7991      }
7992      if send_mouse_grid then
7993        for i = 1, 7 do
7994          local _, row, col = unpack(pos[i])
7995          pos[i] = { 2, row - 2, col - 5 }
7996        end
7997      end
7998
7999      api.nvim_input_mouse('right', 'press', '', unpack(pos[1]))
8000      screen:expect(no_sel_screen)
8001      api.nvim_input_mouse('right', 'drag', '', unpack(pos[2]))
8002      screen:expect(screen_replace(no_sel_screen, '{n: foo }', '{12: foo }'))
8003      api.nvim_input_mouse('right', 'drag', '', unpack(pos[3]))
8004      screen:expect(no_sel_screen)
8005      api.nvim_input_mouse('right', 'drag', '', unpack(pos[4]))
8006      screen:expect(screen_replace(no_sel_screen, '{n: bar }', '{12: bar }'))
8007      api.nvim_input_mouse('right', 'drag', '', unpack(pos[5]))
8008      screen:expect(no_sel_screen)
8009      api.nvim_input_mouse('right', 'drag', '', unpack(pos[6]))
8010      screen:expect(screen_replace(no_sel_screen, '{n: baz }', '{12: baz }'))
8011      api.nvim_input_mouse('right', 'release', '', unpack(pos[7]))
8012      screen:expect(no_sel_screen)
8013      api.nvim_input_mouse('left', 'press', '', unpack(pos[7]))
8014      screen:expect(no_menu_screen)
8015      eq('', api.nvim_get_var('menustr'))
8016
8017      if send_mouse_grid then
8018        for i = 2, 6, 2 do
8019          local _, row, col = unpack(pos[i])
8020          pos[i] = { 4, row - 1, col - 14 }
8021        end
8022      end
8023
8024      api.nvim_input_mouse('right', 'press', '', unpack(pos[1]))
8025      screen:expect(no_sel_screen)
8026      api.nvim_input_mouse('move', '', '', unpack(pos[2]))
8027      screen:expect(screen_replace(no_sel_screen, '{n: foo }', '{12: foo }'))
8028      api.nvim_input_mouse('move', '', '', unpack(pos[3]))
8029      screen:expect(no_sel_screen)
8030      api.nvim_input_mouse('move', '', '', unpack(pos[4]))
8031      screen:expect(screen_replace(no_sel_screen, '{n: bar }', '{12: bar }'))
8032      api.nvim_input_mouse('move', '', '', unpack(pos[5]))
8033      screen:expect(no_sel_screen)
8034      api.nvim_input_mouse('move', '', '', unpack(pos[6]))
8035      screen:expect(screen_replace(no_sel_screen, '{n: baz }', '{12: baz }'))
8036      api.nvim_input_mouse('left', 'press', '', unpack(pos[7]))
8037      screen:expect(no_menu_screen)
8038      eq('', api.nvim_get_var('menustr'))
8039
8040      command('set rightleft | wincmd p | set rightleft | wincmd p')
8041      if multigrid then
8042        no_menu_screen = [[
8043        ## grid 1
8044          [8:--------------------------------]|
8045          {3:[No Name] [+]                   }|
8046          [7:----]│[2:---------------------------]|*2
8047          {2:<+]  [No Name] [+]              }|
8048          [5:---------------]│[6:----------------]|*3
8049          [3:--------------------------------]|
8050        ## grid 2
8051                      tset unem pupop|
8052          {1:                          ~}|
8053        ## grid 3
8054                                          |
8055        ## grid 5
8056          popup menu test|
8057          {1:~              }|*2
8058        ## grid 6
8059          {5:WINBAR          }|
8060          popup menu test |
8061          {1:~               }|
8062        ## grid 7
8063          popu|
8064          p me|
8065        ## grid 8
8066                           tset unem pupo^p|
8067        ]]
8068      else
8069        no_menu_screen = [[
8070                           tset unem pupo^p|
8071          {3:[No Name] [+]                   }|
8072          popu│            tset unem pupop|
8073          p me│{1:                          ~}|
8074          {2:<+]  [No Name] [+]              }|
8075          popup menu test│{5:WINBAR          }|
8076          {1:~              }│popup menu test |
8077          {1:~              }│{1:~               }|
8078                                          |
8079        ]]
8080      end
8081      screen:expect(no_menu_screen)
8082
8083      if multigrid then
8084        no_sel_screen = {
8085          grid = [[
8086        ## grid 1
8087          [8:--------------------------------]|
8088          {3:[No Name] [+]                   }|
8089          [7:----]│[2:---------------------------]|*2
8090          {2:<+]  [No Name] [+]              }|
8091          [5:---------------]│[6:----------------]|*3
8092          [3:--------------------------------]|
8093        ## grid 2
8094                      tset unem pupop|
8095          {1:                          ~}|
8096        ## grid 3
8097                                          |
8098        ## grid 4
8099          {n: oof }|
8100          {n: rab }|
8101          {n: zab }|
8102        ## grid 5
8103          popup menu test|
8104          {1:~              }|*2
8105        ## grid 6
8106          {5:WINBAR          }|
8107          popup menu test |
8108          {1:~               }|
8109        ## grid 7
8110          popu|
8111          p me|
8112        ## grid 8
8113                           tset unem pupo^p|
8114        ]],
8115          float_pos = { [4] = { -1, 'NW', 2, 1, 12, false, 250, 2, 3, 17 } },
8116        }
8117      else
8118        no_sel_screen = [[
8119                           tset unem pupo^p|
8120          {3:[No Name] [+]                   }|
8121          popu│            tset unem pupop|
8122          p me│{1:            }{n: oof }{1:         ~}|
8123          {2:<+]  [No Name] [+}{n: rab }{2:          }|
8124          popup menu test│{5:W}{n: zab }{5:          }|
8125          {1:~              }│popup menu test |
8126          {1:~              }│{1:~               }|
8127                                          |
8128        ]]
8129      end
8130
8131      pos = {
8132        { 0, 2, 20 },
8133        { 0, 3, 21 },
8134        { 0, 3, 22 },
8135        { 0, 4, 17 },
8136        { 0, 4, 16 },
8137        { 0, 5, 21 },
8138        { 0, 5, 22 },
8139      }
8140      if send_mouse_grid then
8141        for i = 1, 7 do
8142          local _, row, col = unpack(pos[i])
8143          pos[i] = { 2, row - 2, col - 5 }
8144        end
8145      end
8146
8147      api.nvim_input_mouse('right', 'press', '', unpack(pos[1]))
8148      screen:expect(no_sel_screen)
8149      api.nvim_input_mouse('move', '', '', unpack(pos[2]))
8150      screen:expect(screen_replace(no_sel_screen, '{n: oof }', '{12: oof }'))
8151      api.nvim_input_mouse('move', '', '', unpack(pos[3]))
8152      screen:expect(no_sel_screen)
8153      api.nvim_input_mouse('move', '', '', unpack(pos[4]))
8154      screen:expect(screen_replace(no_sel_screen, '{n: rab }', '{12: rab }'))
8155      api.nvim_input_mouse('move', '', '', unpack(pos[5]))
8156      screen:expect(no_sel_screen)
8157      api.nvim_input_mouse('move', '', '', unpack(pos[6]))
8158      screen:expect(screen_replace(no_sel_screen, '{n: zab }', '{12: zab }'))
8159      api.nvim_input_mouse('left', 'press', '', unpack(pos[7]))
8160      screen:expect(no_menu_screen)
8161      eq('', api.nvim_get_var('menustr'))
8162
8163      if send_mouse_grid then
8164        for i = 2, 6, 2 do
8165          local _, row, col = unpack(pos[i])
8166          pos[i] = { 4, row - 1, col - 12 }
8167        end
8168      end
8169
8170      api.nvim_input_mouse('right', 'press', '', unpack(pos[1]))
8171      screen:expect(no_sel_screen)
8172      api.nvim_input_mouse('right', 'drag', '', unpack(pos[2]))
8173      screen:expect(screen_replace(no_sel_screen, '{n: oof }', '{12: oof }'))
8174      api.nvim_input_mouse('right', 'drag', '', unpack(pos[3]))
8175      screen:expect(no_sel_screen)
8176      api.nvim_input_mouse('right', 'drag', '', unpack(pos[4]))
8177      screen:expect(screen_replace(no_sel_screen, '{n: rab }', '{12: rab }'))
8178      api.nvim_input_mouse('right', 'drag', '', unpack(pos[5]))
8179      screen:expect(no_sel_screen)
8180      api.nvim_input_mouse('right', 'drag', '', unpack(pos[6]))
8181      screen:expect(screen_replace(no_sel_screen, '{n: zab }', '{12: zab }'))
8182      api.nvim_input_mouse('right', 'release', '', unpack(pos[7]))
8183      screen:expect(no_sel_screen)
8184      api.nvim_input_mouse('left', 'press', '', unpack(pos[7]))
8185      eq('', api.nvim_get_var('menustr'))
8186
8187      command('set norightleft')
8188    end)
8189
8190    if not multigrid then
8191      -- oldtest: Test_popup_command_dump()
8192      it(':popup command', function()
8193        exec([[
8194          " Delete the default MenuPopup event handler.
8195          autocmd! nvim.popupmenu
8196
8197          func ChangeMenu()
8198            aunmenu PopUp.&Paste
8199            nnoremenu 1.40 PopUp.&Paste :echomsg "pasted"<CR>
8200            echomsg 'changed'
8201            return "\<Ignore>"
8202          endfunc
8203
8204          let lines =<< trim END
8205            one two three four five
8206            and one two Xthree four five
8207            one more two three four five
8208          END
8209          call setline(1, lines)
8210
8211          aunmenu *
8212          source $VIMRUNTIME/menu.vim
8213        ]])
8214        feed('/X<CR>:popup PopUp<CR>')
8215        screen:expect([[
8216          one two three four five         |
8217          and one two {10:^X}three four five    |
8218          one more tw{n: Undo             }   |
8219          {1:~          }{n:                  }{1:   }|
8220          {1:~          }{n: Paste            }{1:   }|
8221          {1:~          }{n:                  }{1:   }|
8222          {1:~          }{n: Select Word      }{1:   }|
8223          {1:~          }{n: Select Sentence  }{1:   }|
8224          {1:~          }{n: Select Paragraph }{1:   }|
8225          {1:~          }{n: Select Line      }{1:   }|
8226          {1:~          }{n: Select Block     }{1:   }|
8227          {1:~          }{n: Select All       }{1:   }|
8228          {1:~                               }|*7
8229          :popup PopUp                    |
8230        ]])
8231
8232        -- go to the Paste entry in the menu
8233        feed('jj')
8234        screen:expect([[
8235          one two three four five         |
8236          and one two {10:^X}three four five    |
8237          one more tw{n: Undo             }   |
8238          {1:~          }{n:                  }{1:   }|
8239          {1:~          }{12: Paste            }{1:   }|
8240          {1:~          }{n:                  }{1:   }|
8241          {1:~          }{n: Select Word      }{1:   }|
8242          {1:~          }{n: Select Sentence  }{1:   }|
8243          {1:~          }{n: Select Paragraph }{1:   }|
8244          {1:~          }{n: Select Line      }{1:   }|
8245          {1:~          }{n: Select Block     }{1:   }|
8246          {1:~          }{n: Select All       }{1:   }|
8247          {1:~                               }|*7
8248          :popup PopUp                    |
8249        ]])
8250
8251        -- Select a word
8252        feed('j')
8253        screen:expect([[
8254          one two three four five         |
8255          and one two {10:^X}three four five    |
8256          one more tw{n: Undo             }   |
8257          {1:~          }{n:                  }{1:   }|
8258          {1:~          }{n: Paste            }{1:   }|
8259          {1:~          }{n:                  }{1:   }|
8260          {1:~          }{12: Select Word      }{1:   }|
8261          {1:~          }{n: Select Sentence  }{1:   }|
8262          {1:~          }{n: Select Paragraph }{1:   }|
8263          {1:~          }{n: Select Line      }{1:   }|
8264          {1:~          }{n: Select Block     }{1:   }|
8265          {1:~          }{n: Select All       }{1:   }|
8266          {1:~                               }|*7
8267          :popup PopUp                    |
8268        ]])
8269
8270        feed('<Esc>')
8271
8272        command('set rightleft')
8273        feed('/X<CR>:popup PopUp<CR>')
8274        screen:expect([[
8275                   evif ruof eerht owt eno|
8276              evif ruof eerht{10:^X} owt eno dna|
8277             {n:             odnU }wt erom eno|
8278          {1:   }{n:                  }{1:          ~}|
8279          {1:   }{n:            etsaP }{1:          ~}|
8280          {1:   }{n:                  }{1:          ~}|
8281          {1:   }{n:      droW tceleS }{1:          ~}|
8282          {1:   }{n:  ecnetneS tceleS }{1:          ~}|
8283          {1:   }{n: hpargaraP tceleS }{1:          ~}|
8284          {1:   }{n:      eniL tceleS }{1:          ~}|
8285          {1:   }{n:     kcolB tceleS }{1:          ~}|
8286          {1:   }{n:       llA tceleS }{1:          ~}|
8287          {1:                               ~}|*7
8288          :popup PopUp                    |
8289        ]])
8290        feed('<Esc>')
8291        command('set norightleft')
8292
8293        -- Set an <expr> mapping to change a menu entry while it's displayed.
8294        -- The text should not change but the command does.
8295        -- Also verify that "changed" shows up, which means the mapping triggered.
8296        command('nnoremap <expr> <F2> ChangeMenu()')
8297        feed('/X<CR>:popup PopUp<CR><F2>')
8298        screen:expect([[
8299          one two three four five         |
8300          and one two {10:^X}three four five    |
8301          one more tw{n: Undo             }   |
8302          {1:~          }{n:                  }{1:   }|
8303          {1:~          }{n: Paste            }{1:   }|
8304          {1:~          }{n:                  }{1:   }|
8305          {1:~          }{n: Select Word      }{1:   }|
8306          {1:~          }{n: Select Sentence  }{1:   }|
8307          {1:~          }{n: Select Paragraph }{1:   }|
8308          {1:~          }{n: Select Line      }{1:   }|
8309          {1:~          }{n: Select Block     }{1:   }|
8310          {1:~          }{n: Select All       }{1:   }|
8311          {1:~                               }|*7
8312          changed                         |
8313        ]])
8314
8315        -- Select the Paste entry, executes the changed menu item.
8316        feed('jj<CR>')
8317        screen:expect([[
8318          one two three four five         |
8319          and one two {10:^X}three four five    |
8320          one more two three four five    |
8321          {1:~                               }|*16
8322          pasted                          |
8323        ]])
8324
8325        -- Add a window toolbar to the window and check the :popup menu position.
8326        command('setlocal winbar=TEST')
8327        feed('/X<CR>:popup PopUp<CR>')
8328        screen:expect([[
8329          {5:TEST                            }|
8330          one two three four five         |
8331          and one two {10:^X}three four five    |
8332          one more tw{n: Undo             }   |
8333          {1:~          }{n:                  }{1:   }|
8334          {1:~          }{n: Paste            }{1:   }|
8335          {1:~          }{n:                  }{1:   }|
8336          {1:~          }{n: Select Word      }{1:   }|
8337          {1:~          }{n: Select Sentence  }{1:   }|
8338          {1:~          }{n: Select Paragraph }{1:   }|
8339          {1:~          }{n: Select Line      }{1:   }|
8340          {1:~          }{n: Select Block     }{1:   }|
8341          {1:~          }{n: Select All       }{1:   }|
8342          {1:~                               }|*6
8343          :popup PopUp                    |
8344        ]])
8345
8346        feed('<Esc>')
8347      end)
8348    end
8349
8350    -- oldtest: Test_mouse_popup_position()
8351    it('position of right-click menu when clicking near edge', function()
8352      screen:try_resize(50, 20)
8353      exec([[
8354        set mousemodel=popup_setpos
8355        " Delete the default MenuPopup event handler.
8356        autocmd! nvim.popupmenu
8357        aunmenu *
8358        source $VIMRUNTIME/menu.vim
8359        call setline(1, join(range(20)))
8360      ]])
8361
8362      if send_mouse_grid then
8363        api.nvim_input_mouse('right', 'press', '', 2, 0, 45 - 1)
8364      else
8365        api.nvim_input_mouse('right', 'press', '', 0, 0, 45 - 1)
8366      end
8367      if multigrid then
8368        screen:expect({
8369          grid = [[
8370          ## grid 1
8371            [2:--------------------------------------------------]|*19
8372            [3:--------------------------------------------------]|
8373          ## grid 2
8374            0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ^18 19 |
8375            {1:~                                                 }|*18
8376          ## grid 3
8377                                                              |
8378          ## grid 4
8379            {n: Undo            }|
8380            {n:                 }|
8381            {n: Paste           }|
8382            {n:                 }|
8383            {n: Select Word     }|
8384            {n: Select Sentence }|
8385            {n: Select Paragraph}|
8386            {n: Select Line     }|
8387            {n: Select Block    }|
8388            {n: Select All      }|
8389          ]],
8390          float_pos = { [4] = { -1, 'NW', 2, 1, 33, false, 250, 2, 1, 33 } },
8391        })
8392      else
8393        screen:expect([[
8394          0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ^18 19 |
8395          {1:~                                }{n: Undo            }|
8396          {1:~                                }{n:                 }|
8397          {1:~                                }{n: Paste           }|
8398          {1:~                                }{n:                 }|
8399          {1:~                                }{n: Select Word     }|
8400          {1:~                                }{n: Select Sentence }|
8401          {1:~                                }{n: Select Paragraph}|
8402          {1:~                                }{n: Select Line     }|
8403          {1:~                                }{n: Select Block    }|
8404          {1:~                                }{n: Select All      }|
8405          {1:~                                                 }|*8
8406                                                            |
8407        ]])
8408      end
8409      feed('<Esc>')
8410
8411      command('set rightleft')
8412      if send_mouse_grid then
8413        api.nvim_input_mouse('right', 'press', '', 2, 0, 50 - 45)
8414      else
8415        api.nvim_input_mouse('right', 'press', '', 0, 0, 50 - 45)
8416      end
8417      if multigrid then
8418        screen:expect({
8419          grid = [[
8420          ## grid 1
8421            [2:--------------------------------------------------]|*19
8422            [3:--------------------------------------------------]|
8423          ## grid 2
8424             91 8^1 71 61 51 41 31 21 11 01 9 8 7 6 5 4 3 2 1 0|
8425            {1:                                                 ~}|*18
8426          ## grid 3
8427                                                              |
8428          ## grid 4
8429            {n:            odnU }|
8430            {n:                 }|
8431            {n:           etsaP }|
8432            {n:                 }|
8433            {n:     droW tceleS }|
8434            {n: ecnetneS tceleS }|
8435            {n:hpargaraP tceleS }|
8436            {n:     eniL tceleS }|
8437            {n:    kcolB tceleS }|
8438            {n:      llA tceleS }|
8439          ]],
8440          float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 250, 2, 1, 0 } },
8441        })
8442      else
8443        screen:expect([[
8444           91 8^1 71 61 51 41 31 21 11 01 9 8 7 6 5 4 3 2 1 0|
8445          {n:            odnU }{1:                                ~}|
8446          {n:                 }{1:                                ~}|
8447          {n:           etsaP }{1:                                ~}|
8448          {n:                 }{1:                                ~}|
8449          {n:     droW tceleS }{1:                                ~}|
8450          {n: ecnetneS tceleS }{1:                                ~}|
8451          {n:hpargaraP tceleS }{1:                                ~}|
8452          {n:     eniL tceleS }{1:                                ~}|
8453          {n:    kcolB tceleS }{1:                                ~}|
8454          {n:      llA tceleS }{1:                                ~}|
8455          {1:                                                 ~}|*8
8456                                                            |
8457        ]])
8458      end
8459      feed('<Esc>')
8460      command('set norightleft')
8461    end)
8462
8463    if not multigrid then
8464      describe('"kind" and "menu"', function()
8465        before_each(function()
8466          screen:try_resize(30, 8)
8467          exec([[
8468            func CompleteFunc( findstart, base )
8469              if a:findstart
8470                return 0
8471              endif
8472              return {
8473                    \ 'words': [
8474                    \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', },
8475                    \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
8476                    \ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', },
8477                    \]}
8478            endfunc
8479            set completeopt=menu
8480            set completefunc=CompleteFunc
8481          ]])
8482        end)
8483
8484        -- oldtest: Test_pum_highlights_default()
8485        it('default highlight groups', function()
8486          feed('iaw<C-X><C-u>')
8487          screen:expect([[
8488            aword1^                        |
8489            {12:aword1 W extra text 1 }{1:        }|
8490            {n:aword2 W extra text 2 }{1:        }|
8491            {n:aword3 W extra text 3 }{1:        }|
8492            {1:~                             }|*3
8493            {5:-- }{6:match 1 of 3}               |
8494          ]])
8495        end)
8496
8497        -- oldtest: Test_pum_highlights_custom()
8498        it('custom highlight groups', function()
8499          exec([[
8500            hi PmenuKind      guifg=Red guibg=Plum1
8501            hi PmenuKindSel   guifg=Red guibg=Grey
8502            hi PmenuExtra     guifg=White guibg=Plum1
8503            hi PmenuExtraSel  guifg=Black guibg=Grey
8504          ]])
8505          feed('iaw<C-X><C-u>')
8506          screen:expect([[
8507            aword1^                        |
8508            {12:aword1 }{ks:W }{xs:extra text 1 }{1:        }|
8509            {n:aword2 }{kn:W }{xn:extra text 2 }{1:        }|
8510            {n:aword3 }{kn:W }{xn:extra text 3 }{1:        }|
8511            {1:~                             }|*3
8512            {5:-- }{6:match 1 of 3}               |
8513          ]])
8514        end)
8515      end)
8516
8517      -- oldtest: Test_pum_highlights_match()
8518      it('can highlight matched text', function()
8519        exec([[
8520          func Omni_test(findstart, base)
8521            if a:findstart
8522              return col(".")
8523            endif
8524            return {
8525                  \ 'words': [
8526                  \ { 'word': 'foo', 'kind': 'fookind' },
8527                  \ { 'word': 'foofoo', 'kind': 'fookind' },
8528                  \ { 'word': 'foobar', 'kind': 'fookind' },
8529                  \ { 'word': 'fooBaz', 'kind': 'fookind' },
8530                  \ { 'word': 'foobala', 'kind': 'fookind' },
8531                  \ { 'word': '你好' },
8532                  \ { 'word': '你好吗' },
8533                  \ { 'word': '你不好吗' },
8534                  \ { 'word': '你可好吗' },
8535                  \]}
8536          endfunc
8537
8538          func Comp()
8539            let col = col('.')
8540            if getline('.') == 'f'
8541              let col -= 1
8542            endif
8543            call complete(col, [
8544                  \ #{word: "foo", icase: 1},
8545                  \ #{word: "Foobar", icase: 1},
8546                  \ #{word: "fooBaz", icase: 1},
8547                  \])
8548            return ''
8549          endfunc
8550
8551          set omnifunc=Omni_test
8552          set completeopt=menu,noinsert,fuzzy
8553          hi PmenuMatchSel  guifg=Blue guibg=Grey
8554          hi PmenuMatch     guifg=Blue guibg=Plum1
8555        ]])
8556        feed('i<C-X><C-O>')
8557        local pum_start = [[
8558          ^                                |
8559          {12:foo      fookind }{1:               }|
8560          {n:foofoo   fookind }{1:               }|
8561          {n:foobar   fookind }{1:               }|
8562          {n:fooBaz   fookind }{1:               }|
8563          {n:foobala  fookind }{1:               }|
8564          {n:你好             }{1:               }|
8565          {n:你好吗           }{1:               }|
8566          {n:你不好吗         }{1:               }|
8567          {n:你可好吗         }{1:               }|
8568          {1:~                               }|*9
8569          {5:-- }{6:match 1 of 9}                 |
8570        ]]
8571        screen:expect(pum_start)
8572        feed('fo')
8573        screen:expect([[
8574          fo^                              |
8575          {ms:fo}{12:o     fookind }{1:                }|
8576          {mn:fo}{n:ofoo  fookind }{1:                }|
8577          {mn:fo}{n:obar  fookind }{1:                }|
8578          {mn:fo}{n:oBaz  fookind }{1:                }|
8579          {mn:fo}{n:obala fookind }{1:                }|
8580          {1:~                               }|*13
8581          {5:-- }{6:match 1 of 9}                 |
8582        ]])
8583        feed('<Esc>S<C-X><C-O>')
8584        screen:expect(pum_start)
8585        feed('你')
8586        screen:expect([[
8587          你^                              |
8588          {ms:你}{12:好           }{1:                 }|
8589          {mn:你}{n:好吗         }{1:                 }|
8590          {mn:你}{n:不好吗       }{1:                 }|
8591          {mn:你}{n:可好吗       }{1:                 }|
8592          {1:~                               }|*14
8593          {5:-- }{6:match 1 of 9}                 |
8594        ]])
8595        feed('吗')
8596        screen:expect([[
8597          你吗^                            |
8598          {ms:你}{12:好}{ms:吗}{12:         }{1:                 }|
8599          {mn:你}{n:不好}{mn:吗}{n:       }{1:                 }|
8600          {mn:你}{n:可好}{mn:吗}{n:       }{1:                 }|
8601          {1:~                               }|*15
8602          {5:-- }{6:match 1 of 9}                 |
8603        ]])
8604        feed('<C-E><Esc>')
8605
8606        command('set rightleft')
8607        feed('S<C-X><C-O>')
8608        local pum_start_rl = [[
8609                                         ^ |
8610          {1:               }{12: dnikoof      oof}|
8611          {1:               }{n: dnikoof   oofoof}|
8612          {1:               }{n: dnikoof   raboof}|
8613          {1:               }{n: dnikoof   zaBoof}|
8614          {1:               }{n: dnikoof  alaboof}|
8615          {1:               }{n:             好你}|
8616          {1:               }{n:           吗好你}|
8617          {1:               }{n:         吗好不你}|
8618          {1:               }{n:         吗好可你}|
8619          {1:                               ~}|*9
8620          {5:-- }{6:match 1 of 9}                 |
8621        ]]
8622        screen:expect(pum_start_rl)
8623        feed('fo')
8624        screen:expect([[
8625                                       ^ of|
8626          {1:                }{12: dnikoof     o}{ms:of}|
8627          {1:                }{n: dnikoof  oofo}{mn:of}|
8628          {1:                }{n: dnikoof  rabo}{mn:of}|
8629          {1:                }{n: dnikoof  zaBo}{mn:of}|
8630          {1:                }{n: dnikoof alabo}{mn:of}|
8631          {1:                               ~}|*13
8632          {5:-- }{6:match 1 of 9}                 |
8633        ]])
8634        feed('<Esc>S<C-X><C-O>')
8635        screen:expect(pum_start_rl)
8636        feed('你')
8637        screen:expect([[
8638                                       ^ 你|
8639          {1:                 }{12:           好}{ms:你}|
8640          {1:                 }{n:         吗好}{mn:你}|
8641          {1:                 }{n:       吗好不}{mn:你}|
8642          {1:                 }{n:       吗好可}{mn:你}|
8643          {1:                               ~}|*14
8644          {5:-- }{6:match 1 of 9}                 |
8645        ]])
8646        feed('吗')
8647        screen:expect([[
8648                                     ^ 吗你|
8649          {1:                 }{12:         }{ms:吗}{12:好}{ms:你}|
8650          {1:                 }{n:       }{mn:吗}{n:好不}{mn:你}|
8651          {1:                 }{n:       }{mn:吗}{n:好可}{mn:你}|
8652          {1:                               ~}|*15
8653          {5:-- }{6:match 1 of 9}                 |
8654        ]])
8655        feed('<C-E><Esc>')
8656        command('set norightleft')
8657
8658        command('set completeopt-=fuzzy')
8659        feed('S<C-X><C-O>')
8660        screen:expect(pum_start)
8661        feed('fo')
8662        screen:expect([[
8663          fo^                              |
8664          {ms:fo}{12:o     fookind }{1:                }|
8665          {mn:fo}{n:ofoo  fookind }{1:                }|
8666          {mn:fo}{n:obar  fookind }{1:                }|
8667          {mn:fo}{n:oBaz  fookind }{1:                }|
8668          {mn:fo}{n:obala fookind }{1:                }|
8669          {1:~                               }|*13
8670          {5:-- }{6:match 1 of 9}                 |
8671        ]])
8672        feed('<C-E><Esc>')
8673
8674        command('set rightleft')
8675        feed('S<C-X><C-O>')
8676        screen:expect(pum_start_rl)
8677        feed('fo')
8678        screen:expect([[
8679                                       ^ of|
8680          {1:                }{12: dnikoof     o}{ms:of}|
8681          {1:                }{n: dnikoof  oofo}{mn:of}|
8682          {1:                }{n: dnikoof  rabo}{mn:of}|
8683          {1:                }{n: dnikoof  zaBo}{mn:of}|
8684          {1:                }{n: dnikoof alabo}{mn:of}|
8685          {1:                               ~}|*13
8686          {5:-- }{6:match 1 of 9}                 |
8687        ]])
8688        feed('<C-E><Esc>')
8689        command('set norightleft')
8690
8691        feed('S<C-R>=Comp()<CR>f')
8692        screen:expect([[
8693          f^                               |
8694          {ms:f}{12:oo            }{1:                 }|
8695          {mn:F}{n:oobar         }{1:                 }|
8696          {mn:f}{n:ooBaz         }{1:                 }|
8697          {1:~                               }|*15
8698          {5:-- INSERT --}                    |
8699        ]])
8700        feed('o<BS><C-R>=Comp()<CR>')
8701        screen:expect_unchanged(true)
8702        feed('<C-E><Esc>')
8703
8704        command('hi PmenuMatchSel guibg=NONE')
8705        command('hi PmenuMatch guibg=NONE')
8706        command('set cot=menu,noinsert,fuzzy')
8707        feed('S<C-X><C-O>')
8708        screen:expect(pum_start)
8709        feed('fb')
8710        screen:expect([[
8711          fb^                              |
8712          {ms:f}{12:oo}{ms:B}{12:az  fookind }{1:                }|
8713          {mn:f}{n:oo}{mn:b}{n:ar  fookind }{1:                }|
8714          {mn:f}{n:oo}{mn:b}{n:ala fookind }{1:                }|
8715          {1:~                               }|*15
8716          {5:-- }{6:match 1 of 9}                 |
8717        ]])
8718
8719        feed('<C-E><Esc>')
8720      end)
8721
8722      -- oldtest: Test_pum_completefuzzycollect()
8723      it('fuzzy completion', function()
8724        exec([[
8725          set pumwidth=13
8726          set completeopt=menu,menuone,fuzzy
8727        ]])
8728
8729        feed('S hello helio hero h<C-X><C-P>')
8730        screen:expect([[
8731           hello helio hero hello^         |
8732          {1:~                }{n: hero         }{1: }|
8733          {1:~                }{n: helio        }{1: }|
8734          {1:~                }{12: hello        }{1: }|
8735          {1:~                               }|*15
8736          {5:-- }{6:match 1 of 3}                 |
8737        ]])
8738
8739        feed('<Esc>S hello helio hero h<C-X><C-P><C-P>')
8740        screen:expect([[
8741           hello helio hero helio^         |
8742          {1:~                }{n: hero         }{1: }|
8743          {1:~                }{12: helio        }{1: }|
8744          {1:~                }{n: hello        }{1: }|
8745          {1:~                               }|*15
8746          {5:-- }{6:match 2 of 3}                 |
8747        ]])
8748
8749        feed('<Esc>S/non_existing_folder<C-X><C-F>')
8750        screen:expect([[
8751          /non_existing_folder^            |
8752          {1:~                               }|*18
8753          {5:-- }{9:Pattern not found}            |
8754        ]])
8755        feed('<C-E><Esc>')
8756      end)
8757
8758      -- oldtest: Test_pum_highlights_match_with_abbr()
8759      it('can highlight matched text with abbr', function()
8760        exec([[
8761          func Omni_test(findstart, base)
8762            if a:findstart
8763              return col(".")
8764            endif
8765            return {
8766                  \ 'words': [
8767                  \ { 'word': 'foobar', 'abbr': "foobar\t\t!" },
8768                  \ { 'word': 'foobaz', 'abbr': "foobaz\t\t!" },
8769                  \]}
8770          endfunc
8771
8772          set omnifunc=Omni_test
8773          set completeopt=menuone,noinsert
8774          hi PmenuMatchSel  guifg=Blue guibg=Grey
8775          hi PmenuMatch     guifg=Blue guibg=Plum1
8776        ]])
8777        feed('i<C-X><C-O>')
8778        screen:expect([[
8779          ^                                |
8780          {12:foobar    !    }{1:                 }|
8781          {n:foobaz    !    }{1:                 }|
8782          {1:~                               }|*16
8783          {5:-- }{6:match 1 of 2}                 |
8784        ]])
8785        feed('foo')
8786        screen:expect([[
8787          foo^                             |
8788          {ms:foo}{12:bar    !    }{1:                 }|
8789          {mn:foo}{n:baz    !    }{1:                 }|
8790          {1:~                               }|*16
8791          {5:-- }{6:match 1 of 2}                 |
8792        ]])
8793
8794        feed('<C-E><Esc>')
8795      end)
8796
8797      -- oldtest: Test_pum_user_abbr_hlgroup()
8798      it('custom abbr_hlgroup override', function()
8799        exec([[
8800          let s:var = 0
8801          func CompleteFunc(findstart, base)
8802            if a:findstart
8803              return 0
8804            endif
8805            if s:var == 1
8806              return {
8807                    \ 'words': [
8808                    \ { 'word': 'aword1', 'abbr_hlgroup': 'StrikeFake' },
8809                    \ { 'word': '你好', 'abbr_hlgroup': 'StrikeFake' },
8810                    \]}
8811            endif
8812            return {
8813                  \ 'words': [
8814                  \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' },
8815                  \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
8816                  \ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' },
8817                  \]}
8818          endfunc
8819          func ChangeVar()
8820            let s:var = 1
8821          endfunc
8822          set completeopt=menu
8823          set completefunc=CompleteFunc
8824
8825          hi StrikeFake guifg=DarkRed
8826          func HlMatch()
8827            hi PmenuMatchSel  guifg=Blue guibg=Grey gui=underline
8828            hi PmenuMatch     guifg=Blue guibg=Plum1 gui=underline
8829          endfunc
8830        ]])
8831
8832        feed('Saw<C-X><C-U>')
8833        screen:expect([[
8834          aword1^                          |
8835          {ds:aword1}{12: W extra text 1 }{1:          }|
8836          {n:aword2 W extra text 2 }{1:          }|
8837          {dn:你好}{n:   W extra text 3 }{1:          }|
8838          {1:~                               }|*15
8839          {5:-- }{6:match 1 of 3}                 |
8840        ]])
8841        feed('<C-E><Esc>')
8842
8843        command('call HlMatch()')
8844
8845        feed('Saw<C-X><C-U>')
8846        screen:expect([[
8847          aword1^                          |
8848          {uds:aw}{ds:ord1}{12: W extra text 1 }{1:          }|
8849          {umn:aw}{n:ord2 W extra text 2 }{1:          }|
8850          {dn:你好}{n:   W extra text 3 }{1:          }|
8851          {1:~                               }|*15
8852          {5:-- }{6:match 1 of 3}                 |
8853        ]])
8854        feed('<C-N>')
8855        screen:expect([[
8856          aword2^                          |
8857          {udn:aw}{dn:ord1}{n: W extra text 1 }{1:          }|
8858          {ums:aw}{12:ord2 W extra text 2 }{1:          }|
8859          {dn:你好}{n:   W extra text 3 }{1:          }|
8860          {1:~                               }|*15
8861          {5:-- }{6:match 2 of 3}                 |
8862        ]])
8863        feed('<C-E><Esc>')
8864
8865        command('call ChangeVar()')
8866        feed('S<C-X><C-U>')
8867        screen:expect([[
8868          aword1^                          |
8869          {ds:aword1}{12:         }{1:                 }|
8870          {dn:你好}{n:           }{1:                 }|
8871          {1:~                               }|*16
8872          {5:-- }{6:match 1 of 2}                 |
8873        ]])
8874        feed('<C-E><Esc>')
8875      end)
8876
8877      -- oldtest: Test_pum_user_kind_hlgroup()
8878      it('custom kind_hlgroup override', function()
8879        exec([[
8880          func CompleteFunc( findstart, base )
8881            if a:findstart
8882              return 0
8883            endif
8884            return {
8885                  \ 'words': [
8886                  \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'variable', 'kind_hlgroup': 'KindVar', 'abbr_hlgroup': 'StrikeFake' },
8887                  \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'function', 'kind_hlgroup': 'KindFunc' },
8888                  \ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'class', 'kind_hlgroup': 'KindClass'  },
8889                  \]}
8890          endfunc
8891          set completeopt=menu
8892          set completefunc=CompleteFunc
8893
8894          hi StrikeFake guifg=DarkRed
8895          hi KindVar guifg=DarkYellow
8896          hi KindFunc guifg=DarkBlue
8897          hi KindClass guifg=DarkGreen
8898        ]])
8899
8900        feed('S<C-X><C-U>')
8901        screen:expect([[
8902          aword1^                          |
8903          {ds:aword1}{12: }{110:variable}{12: extra text 1 }{1:   }|
8904          {n:aword2 }{111:function}{n: extra text 2 }{1:   }|
8905          {n:你好   }{112:class}{n:    extra text 3 }{1:   }|
8906          {1:~                               }|*15
8907          {5:-- }{6:match 1 of 3}                 |
8908        ]])
8909        feed('<C-E><Esc>')
8910      end)
8911
8912      -- oldtest: Test_pum_completeitemalign()
8913      it('completeitemalign option', function()
8914        screen:try_resize(30, 15)
8915        exec([[
8916          func Omni_test(findstart, base)
8917            if a:findstart
8918              return col(".")
8919            endif
8920            return {
8921                  \ 'words': [
8922                  \ { 'word': 'foo', 'kind': 'S', 'menu': 'menu' },
8923                  \ { 'word': 'bar', 'kind': 'T', 'menu': 'menu' },
8924                  \ { 'word': '你好', 'kind': 'C', 'menu': '中文' },
8925                  \]}
8926          endfunc
8927
8928          func Omni_long(findstart, base)
8929            if a:findstart
8930              return col(".")
8931            endif
8932            return {
8933                  \ 'words': [
8934                  \ { 'word': 'loooong_foo', 'kind': 'S', 'menu': 'menu' },
8935                  \ { 'word': 'loooong_bar', 'kind': 'T', 'menu': 'menu' },
8936                  \]}
8937          endfunc
8938          set omnifunc=Omni_test
8939        ]])
8940        -- T1
8941        command('set cia=abbr,kind,menu')
8942        feed('S<C-X><C-O>')
8943        screen:expect([[
8944          foo^                           |
8945          {12:foo  S menu    }{1:               }|
8946          {n:bar  T menu    }{1:               }|
8947          {n:你好 C 中文    }{1:               }|
8948          {1:~                             }|*10
8949          {5:-- }{6:match 1 of 3}               |
8950        ]])
8951        feed('<C-E><ESC>')
8952        -- T2
8953        command('set cia=abbr,menu,kind')
8954        feed('S<C-X><C-O>')
8955        screen:expect([[
8956          foo^                           |
8957          {12:foo  menu S    }{1:               }|
8958          {n:bar  menu T    }{1:               }|
8959          {n:你好 中文 C    }{1:               }|
8960          {1:~                             }|*10
8961          {5:-- }{6:match 1 of 3}               |
8962        ]])
8963        feed('<C-E><ESC>')
8964        -- T3
8965        command('set cia=kind,abbr,menu')
8966        feed('S<C-X><C-O>')
8967        screen:expect([[
8968          foo^                           |
8969          {12:S foo  menu    }{1:               }|
8970          {n:T bar  menu    }{1:               }|
8971          {n:C 你好 中文    }{1:               }|
8972          {1:~                             }|*10
8973          {5:-- }{6:match 1 of 3}               |
8974        ]])
8975        feed('<C-E><ESC>')
8976        -- T4
8977        command('set cia=kind,menu,abbr')
8978        feed('S<C-X><C-O>')
8979        screen:expect([[
8980          foo^                           |
8981          {12:S menu foo     }{1:               }|
8982          {n:T menu bar     }{1:               }|
8983          {n:C 中文 你好    }{1:               }|
8984          {1:~                             }|*10
8985          {5:-- }{6:match 1 of 3}               |
8986        ]])
8987        feed('<C-E><ESC>')
8988        -- T5
8989        command('set cia=menu,abbr,kind')
8990        feed('S<C-X><C-O>')
8991        screen:expect([[
8992          foo^                           |
8993          {12:menu foo  S    }{1:               }|
8994          {n:menu bar  T    }{1:               }|
8995          {n:中文 你好 C    }{1:               }|
8996          {1:~                             }|*10
8997          {5:-- }{6:match 1 of 3}               |
8998        ]])
8999        feed('<C-E><ESC>')
9000        -- T6
9001        command('set cia=menu,kind,abbr')
9002        feed('S<C-X><C-O>')
9003        screen:expect([[
9004          foo^                           |
9005          {12:menu S foo     }{1:               }|
9006          {n:menu T bar     }{1:               }|
9007          {n:中文 C 你好    }{1:               }|
9008          {1:~                             }|*10
9009          {5:-- }{6:match 1 of 3}               |
9010        ]])
9011        feed('<C-E><ESC>')
9012        -- T7
9013        command('set cia&')
9014        feed('S<C-X><C-O>')
9015        screen:expect([[
9016          foo^                           |
9017          {12:foo  S menu    }{1:               }|
9018          {n:bar  T menu    }{1:               }|
9019          {n:你好 C 中文    }{1:               }|
9020          {1:~                             }|*10
9021          {5:-- }{6:match 1 of 3}               |
9022        ]])
9023        feed('<C-E><ESC>')
9024
9025        -- Test_pum_completeitemalign_07
9026        command('set cia=menu,kind,abbr columns=12 cmdheight=2 omnifunc=Omni_long')
9027        feed('S<C-X><C-O>')
9028        screen:expect([[
9029          loooong_foo^ |
9030          {12:menu S looo>}|
9031          {n:menu T looo>}|
9032          {1:~           }|*10
9033                      |
9034          {5:--}          |
9035        ]])
9036        feed('<C-E><ESC>')
9037      end)
9038
9039      -- oldtest: Test_pum_matchins_highlight()
9040      it('with ComplMatchIns highlight', function()
9041        exec([[
9042          let g:change = 0
9043          func Omni_test(findstart, base)
9044            if a:findstart
9045              return col(".")
9046            endif
9047            if g:change == 0
9048              return [#{word: "foo"}, #{word: "bar"}, #{word: "你好"}]
9049            endif
9050            return [#{word: "foo", info: "info"}, #{word: "bar"}, #{word: "你好"}]
9051          endfunc
9052          set completeopt-=popup completeopt+=preview
9053          set omnifunc=Omni_test
9054          hi ComplMatchIns guifg=red
9055        ]])
9056
9057        feed('Sαβγ <C-X><C-O>')
9058        screen:expect([[
9059          αβγ {19:foo}^                         |
9060          {1:~  }{12: foo            }{1:             }|
9061          {1:~  }{n: bar            }{1:             }|
9062          {1:~  }{n: 你好           }{1:             }|
9063          {1:~                               }|*15
9064          {5:-- }{6:match 1 of 3}                 |
9065        ]])
9066        feed('<C-E><Esc>')
9067
9068        feed('Sαβγ <C-X><C-O><C-N>')
9069        screen:expect([[
9070          αβγ {19:bar}^                         |
9071          {1:~  }{n: foo            }{1:             }|
9072          {1:~  }{12: bar            }{1:             }|
9073          {1:~  }{n: 你好           }{1:             }|
9074          {1:~                               }|*15
9075          {5:-- }{6:match 2 of 3}                 |
9076        ]])
9077        feed('<C-E><Esc>')
9078
9079        feed('Sαβγ <C-X><C-O><C-N><C-N>')
9080        screen:expect([[
9081          αβγ {19:你好}^                        |
9082          {1:~  }{n: foo            }{1:             }|
9083          {1:~  }{n: bar            }{1:             }|
9084          {1:~  }{12: 你好           }{1:             }|
9085          {1:~                               }|*15
9086          {5:-- }{6:match 3 of 3}                 |
9087        ]])
9088        feed('<C-E><Esc>')
9089
9090        -- restore after accept
9091        feed('Sαβγ <C-X><C-O><C-Y>')
9092        screen:expect([[
9093          αβγ foo^                         |
9094          {1:~                               }|*18
9095          {5:-- INSERT --}                    |
9096        ]])
9097        feed('<Esc>')
9098
9099        -- restore after cancel completion
9100        feed('Sαβγ <C-X><C-O><Space>')
9101        screen:expect([[
9102          αβγ foo ^                        |
9103          {1:~                               }|*18
9104          {5:-- INSERT --}                    |
9105        ]])
9106        feed('<Esc>')
9107
9108        -- text after the inserted text shouldn't be highlighted
9109        feed('0ea <C-X><C-O>')
9110        screen:expect([[
9111          αβγ {19:foo}^ foo                     |
9112          {1:~  }{12: foo            }{1:             }|
9113          {1:~  }{n: bar            }{1:             }|
9114          {1:~  }{n: 你好           }{1:             }|
9115          {1:~                               }|*15
9116          {5:-- }{6:match 1 of 3}                 |
9117        ]])
9118        feed('<C-P>')
9119        screen:expect([[
9120          αβγ ^ foo                        |
9121          {1:~  }{n: foo            }{1:             }|
9122          {1:~  }{n: bar            }{1:             }|
9123          {1:~  }{n: 你好           }{1:             }|
9124          {1:~                               }|*15
9125          {5:-- }{19:Back at original}             |
9126        ]])
9127        feed('<C-P>')
9128        screen:expect([[
9129          αβγ {19:你好}^ foo                    |
9130          {1:~  }{n: foo            }{1:             }|
9131          {1:~  }{n: bar            }{1:             }|
9132          {1:~  }{12: 你好           }{1:             }|
9133          {1:~                               }|*15
9134          {5:-- }{6:match 3 of 3}                 |
9135        ]])
9136        feed('<C-Y>')
9137        screen:expect([[
9138          αβγ 你好^ foo                    |
9139          {1:~                               }|*18
9140          {5:-- INSERT --}                    |
9141        ]])
9142        feed('<Esc>')
9143
9144        feed(':let g:change=1<CR>S<C-X><C-O>')
9145        screen:expect([[
9146          info                            |
9147          {1:~                               }|*2
9148          {2:[Scratch] [Preview][-]          }|
9149          {19:foo}^                             |
9150          {12:foo            }{1:                 }|
9151          {n:bar            }{1:                 }|
9152          {n:你好           }{1:                 }|
9153          {1:~                               }|*10
9154          {3:[No Name] [+]                   }|
9155          {5:-- }{6:match 1 of 3}                 |
9156        ]])
9157        feed('<Esc>')
9158      end)
9159
9160      -- oldtest: Test_pum_matchins_highlight_combine()
9161      it('with ComplMatchIns, Normal and CursorLine highlights', function()
9162        exec([[
9163          func Omni_test(findstart, base)
9164            if a:findstart
9165              return col(".")
9166            endif
9167            return [#{word: "foo"}, #{word: "bar"}, #{word: "你好"}]
9168          endfunc
9169          set completeopt-=popup completeopt+=preview
9170          " Avoid unwanted results in case local workspace has a "tags" file.
9171          set complete-=t
9172          set omnifunc=Omni_test
9173          hi Normal guibg=blue
9174          hi CursorLine guibg=green guifg=white
9175          set cursorline
9176          call setline(1, 'aaa bbb')
9177        ]])
9178
9179        -- when ComplMatchIns is not set, CursorLine applies normally
9180        feed('0ea <C-X><C-O>')
9181        screen:expect([[
9182          {101:aaa foo^ bbb                     }|
9183          {1:~  }{12: foo            }{1:             }|
9184          {1:~  }{n: bar            }{1:             }|
9185          {1:~  }{n: 你好           }{1:             }|
9186          {1:~                               }|*15
9187          {5:-- }{6:match 1 of 3}                 |
9188        ]])
9189        feed('<C-E>')
9190        screen:expect([[
9191          {101:aaa ^ bbb                        }|
9192          {1:~                               }|*18
9193          {5:-- INSERT --}                    |
9194        ]])
9195        feed('<BS><Esc>')
9196
9197        -- when ComplMatchIns is set, it is applied over CursorLine
9198        command('hi ComplMatchIns guifg=Yellow')
9199        feed('0ea <C-X><C-O>')
9200        screen:expect([[
9201          {101:aaa }{100:foo}{101:^ bbb                     }|
9202          {1:~  }{12: foo            }{1:             }|
9203          {1:~  }{n: bar            }{1:             }|
9204          {1:~  }{n: 你好           }{1:             }|
9205          {1:~                               }|*15
9206          {5:-- }{6:match 1 of 3}                 |
9207        ]])
9208        feed('<C-P>')
9209        screen:expect([[
9210          {101:aaa ^ bbb                        }|
9211          {1:~  }{n: foo            }{1:             }|
9212          {1:~  }{n: bar            }{1:             }|
9213          {1:~  }{n: 你好           }{1:             }|
9214          {1:~                               }|*15
9215          {5:-- }{19:Back at original}             |
9216        ]])
9217        feed('<C-P>')
9218        screen:expect([[
9219          {101:aaa }{100:你好}{101:^ bbb                    }|
9220          {1:~  }{n: foo            }{1:             }|
9221          {1:~  }{n: bar            }{1:             }|
9222          {1:~  }{12: 你好           }{1:             }|
9223          {1:~                               }|*15
9224          {5:-- }{6:match 3 of 3}                 |
9225        ]])
9226        feed('<C-E>')
9227        screen:expect([[
9228          {101:aaa ^ bbb                        }|
9229          {1:~                               }|*18
9230          {5:-- INSERT --}                    |
9231        ]])
9232        feed('<Esc>')
9233
9234        -- Does not highlight the compl leader
9235        command('set completeopt+=menuone,noselect')
9236        feed('S<C-X><C-O>')
9237        local pum_start = [[
9238          {101:^                                }|
9239          {n:foo            }{1:                 }|
9240          {n:bar            }{1:                 }|
9241          {n:你好           }{1:                 }|
9242          {1:~                               }|*15
9243          {5:-- }{19:Back at original}             |
9244        ]]
9245        screen:expect(pum_start)
9246        feed('f<C-N>')
9247        screen:expect([[
9248          {101:f}{100:oo}{101:^                             }|
9249          {12:foo            }{1:                 }|
9250          {1:~                               }|*17
9251          {5:-- }{6:match 1 of 3}                 |
9252        ]])
9253        feed('<C-E><ESC>')
9254
9255        command('set completeopt+=fuzzy')
9256        feed('S<C-X><C-O>')
9257        screen:expect(pum_start)
9258        feed('f<C-N>')
9259        screen:expect([[
9260          {101:foo^                             }|
9261          {12:foo            }{1:                 }|
9262          {1:~                               }|*17
9263          {5:-- }{6:match 1 of 3}                 |
9264        ]])
9265        feed('<C-E><Esc>')
9266
9267        command('set completeopt-=fuzzy')
9268        feed('Sf<C-N>')
9269        screen:expect([[
9270          {101:f^                               }|
9271          {1:~                               }|*18
9272          {5:-- }{9:Pattern not found}            |
9273        ]])
9274        feed('<C-E><Esc>')
9275      end)
9276
9277      -- oldtest: Test_pum_complete_with_special_characters()
9278      it('multi-line completion', function()
9279        exec([[
9280          func Omni_test(findstart, base)
9281            if a:findstart
9282              return col(".")
9283            endif
9284            return [#{word: "func ()\n\t\nend", abbr: "function ()",}, #{word: "foobar"}, #{word: "你好\n\t\n我好"}]
9285          endfunc
9286          set omnifunc=Omni_test
9287          inoremap <F5> <Cmd>call complete(col('.'), [ "my\n\tmulti\nline", "my\n\t\tmulti\nline" ])<CR>
9288        ]])
9289
9290        feed('S<C-X><C-O>')
9291        screen:expect([[
9292          func ()                         |
9293                                          |
9294          end^                             |
9295          {12:function ()    }{1:                 }|
9296          {n:foobar         }{1:                 }|
9297          {n:你好^@  ^@我好 }{1:                 }|
9298          {1:~                               }|*13
9299          {5:-- }{6:match 1 of 3}                 |
9300        ]])
9301
9302        feed('<C-N>')
9303        screen:expect([[
9304          foobar^                          |
9305          {n:function ()    }{1:                 }|
9306          {12:foobar         }{1:                 }|
9307          {n:你好^@  ^@我好 }{1:                 }|
9308          {1:~                               }|*15
9309          {5:-- }{6:match 2 of 3}                 |
9310        ]])
9311        feed('<C-E><ESC>')
9312
9313        feed('Shello  hero<ESC>hhhhha<C-X><C-O>')
9314        screen:expect([[
9315          hello func ()                   |
9316                                          |
9317          end^ hero                        |
9318          {1:~    }{12: function ()    }{1:           }|
9319          {1:~    }{n: foobar         }{1:           }|
9320          {1:~    }{n: 你好^@  ^@我好 }{1:           }|
9321          {1:~                               }|*13
9322          {5:-- }{6:match 1 of 3}                 |
9323        ]])
9324
9325        feed('<C-N>')
9326        screen:expect([[
9327          hello foobar^ hero               |
9328          {1:~    }{n: function ()    }{1:           }|
9329          {1:~    }{12: foobar         }{1:           }|
9330          {1:~    }{n: 你好^@  ^@我好 }{1:           }|
9331          {1:~                               }|*15
9332          {5:-- }{6:match 2 of 3}                 |
9333        ]])
9334
9335        feed('<C-N>')
9336        screen:expect([[
9337          hello 你好                      |
9338                                          |
9339          我好^ hero                       |
9340          {1:~  }{n: function ()    }{1:             }|
9341          {1:~  }{n: foobar         }{1:             }|
9342          {1:~  }{12: 你好^@  ^@我好 }{1:             }|
9343          {1:~                               }|*13
9344          {5:-- }{6:match 3 of 3}                 |
9345        ]])
9346
9347        feed('<C-N>')
9348        screen:expect([[
9349          hello ^ hero                     |
9350          {1:~    }{n: function ()    }{1:           }|
9351          {1:~    }{n: foobar         }{1:           }|
9352          {1:~    }{n: 你好^@  ^@我好 }{1:           }|
9353          {1:~                               }|*15
9354          {5:-- }{19:Back at original}             |
9355        ]])
9356        feed('<C-E><ESC>')
9357
9358        command(':hi ComplMatchIns guifg=red')
9359        feed('S<C-X><C-O>')
9360        screen:expect([[
9361          {19:func ()}                         |
9362          {19:        }                        |
9363          {19:end}^                             |
9364          {12:function ()    }{1:                 }|
9365          {n:foobar         }{1:                 }|
9366          {n:你好^@  ^@我好 }{1:                 }|
9367          {1:~                               }|*13
9368          {5:-- }{6:match 1 of 3}                 |
9369        ]])
9370        feed('<C-E><ESC>')
9371
9372        feed('Shello  hero<ESC>hhhhha<C-X><C-O>')
9373        screen:expect([[
9374          hello {19:func ()}                   |
9375          {19:        }                        |
9376          {19:end^ }hero                        |
9377          {1:~    }{12: function ()    }{1:           }|
9378          {1:~    }{n: foobar         }{1:           }|
9379          {1:~    }{n: 你好^@  ^@我好 }{1:           }|
9380          {1:~                               }|*13
9381          {5:-- }{6:match 1 of 3}                 |
9382        ]])
9383        feed('<C-E><ESC>')
9384
9385        command('setlocal autoindent shiftwidth=2 tabstop=2')
9386        feed('Slocal a = <C-X><C-O>')
9387        screen:expect([[
9388          local a = {19:func ()}               |
9389          {19:  }                              |
9390          {19:end}^                             |
9391          {1:~ }{12: function ()    }{1:              }|
9392          {1:~ }{n: foobar         }{1:              }|
9393          {1:~ }{n: 你好^@  ^@我好 }{1:              }|
9394          {1:~                               }|*13
9395          {5:-- }{6:match 1 of 3}                 |
9396        ]])
9397
9398        feed('<C-Y>')
9399        screen:expect([[
9400          local a = {19:func ()}               |
9401          {19:  }                              |
9402          end^                             |
9403          {1:~                               }|*16
9404          {5:-- INSERT --}                    |
9405        ]])
9406
9407        feed('<ESC>kAlocal b = <C-X><C-O>')
9408        screen:expect([[
9409          local a = {19:func ()}               |
9410            local b = {19:func ()}             |
9411          {19:    }                            |
9412          {19:  end}^                           |
9413          end {12: function ()    }            |
9414          {1:~   }{n: foobar         }{1:            }|
9415          {1:~   }{n: 你好^@  ^@我好 }{1:            }|
9416          {1:~                               }|*12
9417          {5:-- }{6:match 1 of 3}                 |
9418        ]])
9419
9420        feed('<C-Y>')
9421        screen:expect([[
9422          local a = {19:func ()}               |
9423            local b = {19:func ()}             |
9424          {19:    }                            |
9425            end^                           |
9426          end                             |
9427          {1:~                               }|*14
9428          {5:-- INSERT --}                    |
9429        ]])
9430
9431        feed('<Esc>ggVGd')
9432        command('filetype indent on')
9433        command('setlocal noautoindent shiftwidth& tabstop&')
9434        command('setlocal ft=lua')
9435        feed('S<F5>')
9436        screen:expect([[
9437          {19:my}                              |
9438          {19:        multi}                   |
9439          {19:line}^                            |
9440          {12:my^@  multi^@line   }{1:            }|
9441          {n:my^@    multi^@line }{1:            }|
9442          {1:~                               }|*14
9443          {5:-- INSERT --}                    |
9444        ]])
9445      end)
9446
9447      -- oldtest: Test_pum_clear_when_switch_tab_or_win()
9448      it('is cleared when switching tab or win', function()
9449        screen:try_resize(55, 20)
9450        exec([[
9451          inoremap <F4> <Cmd>wincmd w<CR>
9452          inoremap <F5> <Cmd>tabnext<CR>
9453        ]])
9454
9455        command('tabe')
9456        feed('Aaa aaa <C-X><C-N>')
9457        screen:expect([[
9458          {24: [No Name] }{5: + [No Name] }{2:                              }{24:X}|
9459          aa aaa aa^                                              |
9460          {1:~     }{12: aa             }{1:                                 }|
9461          {1:~     }{n: aaa            }{1:                                 }|
9462          {1:~                                                      }|*15
9463          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 2}        |
9464        ]])
9465        feed('<F5>')
9466        screen:expect([[
9467          {5: [No Name] }{24: + [No Name] }{2:                              }{24:X}|
9468          ^                                                       |
9469          {1:~                                                      }|*17
9470          {5:-- INSERT --}                                           |
9471        ]])
9472        feed('<Esc>')
9473        command('tabclose!')
9474
9475        command('vnew win_b')
9476        feed('Abb bbb <C-X><C-N>')
9477        screen:expect([[
9478          bb bbb bb^                  │aa aaa aa                  |
9479          {1:~     }{12: bb             }{1:     }│{1:~                          }|
9480          {1:~     }{n: bbb            }{1:     }│{1:~                          }|
9481          {1:~                          }│{1:~                          }|*15
9482          {3:win_b [+]                   }{2:[No Name] [+]              }|
9483          {5:-- Keyword Local completion (^N^P) }{6:match 1 of 2}        |
9484        ]])
9485        feed('<F4>')
9486        screen:expect([[
9487          bb bbb bb                  │aa aaa a^a                  |
9488          {1:~                          }│{1:~                          }|*17
9489          {2:win_b [+]                   }{3:[No Name] [+]              }|
9490          {5:-- INSERT --}                                           |
9491        ]])
9492      end)
9493    end
9494
9495    describe("'pumborder'", function()
9496      before_each(function()
9497        screen:try_resize(30, 11)
9498        exec([[
9499          let g:list = [#{word: "one", info: "1info"}, #{word: "two", info: "2info"}, #{word: "three", info: "3info"}]
9500          funct Omni_test(findstart, base)
9501            if a:findstart
9502              return col(".") - 1
9503            endif
9504            return g:list
9505          endfunc
9506          hi link PmenuBorder FloatBorder
9507          set omnifunc=Omni_test
9508          set completeopt-=preview
9509          set pumborder=rounded
9510        ]])
9511      end)
9512
9513      it('can set border', function()
9514        feed('Gi<C-x><C-o>')
9515        if multigrid then
9516          screen:expect({
9517            grid = [[
9518            ## grid 1
9519              [2:------------------------------]|*10
9520              [3:------------------------------]|
9521            ## grid 2
9522              one^                           |
9523              {1:~                             }|*9
9524            ## grid 3
9525              {5:-- }{6:match 1 of 3}               |
9526            ## grid 4
9527              {n:1info}|
9528            ## grid 5
9529              ╭───────────────╮|
9530              │{12:one            }│|
9531              │{n:two            }│|
9532              │{n:three          }│|
9533              ╰───────────────╯|
9534            ]],
9535            win_pos = {
9536              [2] = { height = 10, startcol = 0, startrow = 0, width = 30, win = 1000 },
9537            },
9538            float_pos = {
9539              [5] = { -1, 'NW', 2, 1, 0, false, 100, 2, 1, 0 },
9540              [4] = { 1001, 'NW', 1, 1, 17, true, 50, 1, 1, 17 },
9541            },
9542          })
9543        else
9544          screen:expect([[
9545            one^                           |
9546            ╭───────────────╮{n:1info}{1:        }|
9547            │{12:one            }│{1:             }|
9548            │{n:two            }│{1:             }|
9549            │{n:three          }│{1:             }|
9550            ╰───────────────╯{1:             }|
9551            {1:~                             }|*4
9552            {5:-- }{6:match 1 of 3}               |
9553          ]])
9554        end
9555
9556        -- avoid out of screen
9557        feed(('a'):rep(25) .. '<C-x><C-o>')
9558        if multigrid then
9559          screen:expect({
9560            grid = [[
9561            ## grid 1
9562              [2:------------------------------]|*10
9563              [3:------------------------------]|
9564            ## grid 2
9565              oneaaaaaaaaaaaaaaaaaaaaaaaaaon|
9566              e^                             |
9567              {1:~                             }|*8
9568            ## grid 3
9569              {5:-- }{6:match 1 of 3}               |
9570            ## grid 4
9571              {n:1info}|
9572            ## grid 5
9573              ╭─────────────────╮|
9574              │{12: one             }│|
9575              │{n: two             }│|
9576              │{n: three           }│|
9577              ╰─────────────────╯|
9578            ]],
9579            win_pos = {
9580              [2] = { height = 10, startcol = 0, startrow = 0, width = 30, win = 1000 },
9581            },
9582            float_pos = {
9583              [5] = { -1, 'NW', 2, 2, 11, false, 100, 2, 2, 11 },
9584              [4] = { 1001, 'NW', 1, 2, 6, true, 50, 1, 2, 6 },
9585            },
9586          })
9587        else
9588          screen:expect([[
9589            oneaaaaaaaaaaaaaaaaaaaaaaaaaon|
9590            e^                             |
9591            {1:~     }{n:1info}╭─────────────────╮|
9592            {1:~          }│{12: one             }│|
9593            {1:~          }│{n: two             }│|
9594            {1:~          }│{n: three           }│|
9595            {1:~          }╰─────────────────╯|
9596            {1:~                             }|*3
9597            {5:-- }{6:match 1 of 3}               |
9598          ]])
9599        end
9600      end)
9601
9602      it('adjust to above when the below row + border out of win height', function()
9603        command('set completeopt+=menuone,noselect')
9604        feed('<ESC>Stwo' .. ('<CR>'):rep(6) .. 'tw<C-N>')
9605        if multigrid then
9606          screen:expect({
9607            grid = [[
9608            ## grid 1
9609              [2:------------------------------]|*10
9610              [3:------------------------------]|
9611            ## grid 2
9612              two                           |
9613                                            |*5
9614              tw^                            |
9615              {1:~                             }|*3
9616            ## grid 3
9617              {5:-- }{19:Back at original}           |
9618            ## grid 4
9619              ╭───────────────╮|
9620              │{n:two            }│|
9621              ╰───────────────╯|
9622            ]],
9623            win_pos = {
9624              [2] = {
9625                height = 10,
9626                startcol = 0,
9627                startrow = 0,
9628                width = 30,
9629                win = 1000,
9630              },
9631            },
9632            float_pos = {
9633              [4] = { -1, 'SW', 2, 4, 0, false, 100, 1, 3, 0 },
9634            },
9635            win_viewport = {
9636              [2] = {
9637                win = 1000,
9638                topline = 0,
9639                botline = 8,
9640                curline = 6,
9641                curcol = 2,
9642                linecount = 7,
9643                sum_scroll_delta = 0,
9644              },
9645            },
9646            win_viewport_margins = {
9647              [2] = {
9648                bottom = 0,
9649                left = 0,
9650                right = 0,
9651                top = 0,
9652                win = 1000,
9653              },
9654            },
9655          })
9656        else
9657          screen:expect([[
9658            two                           |
9659                                          |*2
9660            ╭───────────────╮             |
9661            │{n:two            }│             |
9662            ╰───────────────╯             |
9663            tw^                            |
9664            {1:~                             }|*3
9665            {5:-- }{19:Back at original}           |
9666          ]])
9667        end
9668      end)
9669
9670      it("'pumborder' on cmdline and scrollbar rendering", function()
9671        command('set wildoptions=pum')
9672        feed(':t<TAB>')
9673        if multigrid then
9674          screen:expect({
9675            grid = [[
9676            ## grid 1
9677              [2:------------------------------]|*10
9678              [3:------------------------------]|
9679            ## grid 2
9680                                            |
9681              {1:~                             }|*9
9682            ## grid 3
9683              :t^                            |
9684            ## grid 4
9685              ╭────────────────╮|
9686              │{12: t              }{c: }|
9687              │{n: tNext          }│|
9688              │{n: tab            }│|
9689              │{n: tabNext        }│|
9690              │{n: tabclose       }│|
9691              │{n: tabdo          }│|
9692              │{n: tabedit        }│|
9693              │{n: tabfind        }│|
9694              ╰────────────────╯|
9695            ]],
9696            win_pos = {
9697              [2] = { height = 10, startcol = 0, startrow = 0, width = 30, win = 1000 },
9698            },
9699            float_pos = {
9700              [4] = { -1, 'SW', 1, 8, 0, false, 250, 2, 0, 0 },
9701            },
9702          })
9703        else
9704          screen:expect([[
9705            ╭────────────────╮            |
9706            │{12: t              }{c: }{1:            }|
9707            │{n: tNext          }│{1:            }|
9708            │{n: tab            }│{1:            }|
9709            │{n: tabNext        }│{1:            }|
9710            │{n: tabclose       }│{1:            }|
9711            │{n: tabdo          }│{1:            }|
9712            │{n: tabedit        }│{1:            }|
9713            │{n: tabfind        }│{1:            }|
9714            ╰────────────────╯{1:            }|
9715            :t^                            |
9716          ]])
9717        end
9718
9719        feed(('<C-N>'):rep(20))
9720        if not multigrid then
9721          screen:expect([[
9722            ╭────────────────╮            |
9723            │{n: tabs           }│{1:            }|
9724            │{n: tag            }│{1:            }|
9725            │{n: tags           }│{1:            }|
9726            │{n: tcd            }{c: }{1:            }|
9727            │{12: tchdir         }│{1:            }|
9728            │{n: tcl            }│{1:            }|
9729            │{n: tcldo          }│{1:            }|
9730            │{n: tclfile        }│{1:            }|
9731            ╰────────────────╯{1:            }|
9732            :tchdir^                       |
9733          ]])
9734        end
9735        feed(('<C-P>'):rep(20))
9736        if not multigrid then
9737          screen:expect([[
9738            ╭────────────────╮            |
9739            │{12: t              }{c: }{1:            }|
9740            │{n: tNext          }│{1:            }|
9741            │{n: tab            }│{1:            }|
9742            │{n: tabNext        }│{1:            }|
9743            │{n: tabclose       }│{1:            }|
9744            │{n: tabdo          }│{1:            }|
9745            │{n: tabedit        }│{1:            }|
9746            │{n: tabfind        }│{1:            }|
9747            ╰────────────────╯{1:            }|
9748            :t^                            |
9749          ]])
9750        end
9751      end)
9752
9753      it('reduce pum height when height is not enough', function()
9754        command('set lines=7 laststatus=2')
9755        feed('S<C-x><C-o>')
9756        if multigrid then
9757          screen:expect({
9758            grid = [[
9759            ## grid 1
9760              [2:------------------------------]|*5
9761              {3:[No Name] [+]                 }|
9762              [3:------------------------------]|
9763            ## grid 2
9764              one^                           |
9765              {1:~                             }|*4
9766            ## grid 3
9767              {5:-- }{6:match 1 of 3}               |
9768            ## grid 4
9769              ╭───────────────╮|
9770              │{12:one            }{c: }|
9771              ╰───────────────╯|
9772            ]],
9773            win_pos = {
9774              [2] = { height = 5, startcol = 0, startrow = 0, width = 30, win = 1000 },
9775            },
9776            float_pos = {
9777              [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 },
9778            },
9779          })
9780        else
9781          screen:expect([[
9782            one^                           |
9783            ╭───────────────╮{1:             }|
9784            │{12:one            }{c: }{1:             }|
9785            ╰───────────────╯{1:             }|
9786            {1:~                             }|
9787            {3:[No Name] [+]                 }|
9788            {5:-- }{6:match 1 of 3}               |
9789          ]])
9790        end
9791      end)
9792      it('custom pumborder characters', function()
9793        command('set pumborder=+,+,=,+,+,-,+,+')
9794        feed('S<C-x><C-o>')
9795        if not multigrid then
9796          screen:expect([[
9797            one^                           |
9798            ++++++++++++++++={n:1info}{1:        }|
9799            +{12:one            }+{1:             }|
9800            +{n:two            }+{1:             }|
9801            +{n:three          }+{1:             }|
9802            +---------------+{1:             }|
9803            {1:~                             }|*4
9804            {5:-- }{6:match 1 of 3}               |
9805          ]])
9806        end
9807      end)
9808      it("'pumborder' with shadow", function()
9809        command('set pumborder=shadow')
9810        insert('line1\nline2line2line2line2\nline3\nline4line4line4\nline5line5')
9811        feed('ggO<C-x><C-o>')
9812        if multigrid then
9813          screen:expect({
9814            grid = [[
9815            ## grid 1
9816              [2:------------------------------]|*10
9817              [3:------------------------------]|
9818            ## grid 2
9819              one^                           |
9820              line1                         |
9821              line2line2line2line2          |
9822              line3                         |
9823              line4line4line4               |
9824              line5line5                    |
9825              {1:~                             }|*4
9826            ## grid 3
9827              {5:-- }{6:match 1 of 3}               |
9828            ## grid 4
9829              {n:1info}|
9830            ## grid 5
9831              {12:one            }{114: }|
9832              {n:two            }{115: }|
9833              {n:three          }{115: }|
9834              {114: }{115:               }|
9835            ]],
9836            win_pos = {
9837              [2] = {
9838                height = 10,
9839                startcol = 0,
9840                startrow = 0,
9841                width = 30,
9842                win = 1000,
9843              },
9844            },
9845            float_pos = {
9846              [5] = { -1, 'NW', 2, 1, 0, false, 100, 2, 1, 0 },
9847              [4] = { 1001, 'NW', 1, 1, 16, true, 50, 1, 1, 16 },
9848            },
9849          })
9850        else
9851          screen:expect([[
9852            one^                           |
9853            {12:one            }{116: }{n:1info}         |
9854            {n:two            }{117:l}ine2          |
9855            {n:three          }{117: }              |
9856            {116:l}{117:ine4line4line4 }              |
9857            line5line5                    |
9858            {1:~                             }|*4
9859            {5:-- }{6:match 1 of 3}               |
9860          ]])
9861        end
9862        command('set pumheight=2')
9863        feed('<C-x><C-O>')
9864        if multigrid then
9865          screen:expect({
9866            grid = [[
9867            ## grid 1
9868              [2:------------------------------]|*10
9869              [3:------------------------------]|
9870            ## grid 2
9871              oneone^                        |
9872              line1                         |
9873              line2line2line2line2          |
9874              line3                         |
9875              line4line4line4               |
9876              line5line5                    |
9877              {1:~                             }|*4
9878            ## grid 3
9879              {5:-- }{6:match 1 of 3}               |
9880            ## grid 4
9881              {n:1info}|
9882            ## grid 5
9883              {12: one            }{c: }{114: }|
9884              {n: two            }{12: }{115: }|
9885              {114: }{115:                 }|
9886            ]],
9887            win_pos = {
9888              [2] = {
9889                height = 10,
9890                startcol = 0,
9891                startrow = 0,
9892                width = 30,
9893                win = 1000,
9894              },
9895            },
9896            float_pos = {
9897              [5] = { -1, 'NW', 2, 1, 2, false, 100, 2, 1, 2 },
9898              [4] = { 1001, 'NW', 1, 1, 19, true, 50, 1, 1, 19 },
9899            },
9900          })
9901        else
9902          screen:expect([[
9903            oneone^                        |
9904            li{12: one            }{c: }{116: }{n:info}      |
9905            li{n: two            }{12: }{117:2}          |
9906            li{116:n}{117:e3               }          |
9907            line4line4line4               |
9908            line5line5                    |
9909            {1:~                             }|*4
9910            {5:-- }{6:match 1 of 3}               |
9911          ]])
9912        end
9913      end)
9914      it("'pumborder' with none #36207", function()
9915        command('set wildoptions=pum pumborder=none')
9916        feed(':<TAB>')
9917        if multigrid then
9918          screen:expect({
9919            grid = [[
9920            ## grid 1
9921              [2:------------------------------]|*10
9922              [3:------------------------------]|
9923            ## grid 2
9924                                            |
9925              {1:~                             }|*9
9926            ## grid 3
9927              :!^                            |
9928            ## grid 4
9929              {12: !              }{c: }|
9930              {n: #              }{12: }|
9931              {n: &              }{12: }|
9932              {n: <              }{12: }|
9933              {n: =              }{12: }|
9934              {n: >              }{12: }|
9935              {n: @              }{12: }|
9936              {n: Next           }{12: }|
9937              {n: abbreviate     }{12: }|
9938              {n: abclear        }{12: }|
9939            ]],
9940            win_pos = {
9941              [2] = {
9942                height = 10,
9943                startcol = 0,
9944                startrow = 0,
9945                width = 30,
9946                win = 1000,
9947              },
9948            },
9949            float_pos = {
9950              [4] = { -1, 'SW', 1, 10, 0, false, 250, 2, 0, 0 },
9951            },
9952          })
9953        else
9954          screen:expect([[
9955            {12: !              }{c: }             |
9956            {n: #              }{12: }{1:             }|
9957            {n: &              }{12: }{1:             }|
9958            {n: <              }{12: }{1:             }|
9959            {n: =              }{12: }{1:             }|
9960            {n: >              }{12: }{1:             }|
9961            {n: @              }{12: }{1:             }|
9962            {n: Next           }{12: }{1:             }|
9963            {n: abbreviate     }{12: }{1:             }|
9964            {n: abclear        }{12: }{1:             }|
9965            :!^                            |
9966          ]])
9967        end
9968        feed('<ESC>:set pumheight=2<CR>Gi<C-X><C-O>')
9969        if not multigrid then
9970          screen:expect([[
9971            one^                           |
9972            {12:one            }{c: }{n:1info}{1:         }|
9973            {n:two            }{12: }{1:              }|
9974            {1:~                             }|*7
9975            {5:-- }{6:match 1 of 3}               |
9976          ]])
9977        end
9978      end)
9979      it("no crash when 'pumborder' set #36337", function()
9980        command('set autocomplete pumborder=rounded complete=o cot=popup,menuone,noinsert')
9981        command('set columns=50 lines=20')
9982        exec_lua(function()
9983          local list1 = {
9984            { abbr = 'array: ', info = '', kind = 'Field', word = 'array: ' },
9985            { abbr = 'arrays: ', info = '', kind = 'Field', word = 'arrays: ' },
9986          }
9987          local list2 = {
9988            { abbr = 'match ', info = '', kind = 'Keyword', word = 'match ' },
9989            { abbr = 'throw ', info = '', kind = 'Keyword', word = 'throw ' },
9990            { abbr = 'array: ', info = '', kind = 'Field', word = 'array: ' },
9991            { abbr = 'arrays: ', info = '', kind = 'Field', word = 'arrays: ' },
9992          }
9993          _G.fake_omni = function(_, _)
9994            local line = vim.api.nvim_get_current_line()
9995            if line:find('%s%)$') then
9996              vim.schedule(function()
9997                vim.fn.complete(25, list1)
9998                vim.fn.complete(25, list2)
9999              end)
10000            end
10001            return -2
10002          end
10003          vim.opt.omnifunc = 'v:lua.fake_omni'
10004          vim.api.nvim_buf_set_lines(0, 0, -1, true, { '<?php', 'array_intersect_key($x)' })
10005          vim.cmd.normal('G$')
10006        end)
10007        feed('i, ')
10008        poke_eventloop()
10009        assert_alive()
10010        eq({ 4, 1 }, { #fn.complete_info({ 'items' }).items, fn.pumvisible() })
10011      end)
10012
10013      it("works with 'pummaxwidth'", function()
10014        exec([[
10015          set pummaxwidth=10
10016          set cot+=menuone
10017          let g:list = [#{word: repeat('fo', 10)}]
10018        ]])
10019        feed('S<C-x><C-o>')
10020        if multigrid then
10021          screen:expect({
10022            grid = [[
10023            ## grid 1
10024              [2:------------------------------]|*10
10025              [3:------------------------------]|
10026            ## grid 2
10027              fofofofofofofofofofo^          |
10028              {1:~                             }|*9
10029            ## grid 3
10030              {5:-- The only match}             |
10031            ## grid 4
10032              ╭──────────╮|
10033              │{12:fofofofof>}│|
10034              ╰──────────╯|
10035            ]],
10036            float_pos = {
10037              [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 },
10038            },
10039          })
10040        else
10041          screen:expect([[
10042            fofofofofofofofofofo^          |
10043            ╭──────────╮{1:                  }|
10044            │{12:fofofofof>}│{1:                  }|
10045            ╰──────────╯{1:                  }|
10046            {1:~                             }|*6
10047            {5:-- The only match}             |
10048          ]])
10049        end
10050      end)
10051      it('no crash with wide item and border #38840', function()
10052        exec([[
10053          set cot+=menuone
10054          let g:list = [#{word: repeat('a', &columns - 2)}]
10055        ]])
10056        feed('S<C-x><C-o>')
10057        assert_alive()
10058      end)
10059    end)
10060    it("'pumborder' on mouse-menu displays completely within screen", function()
10061      screen:try_resize(40, 12)
10062      command('set pumborder=rounded')
10063      -- Click near right edge to test boundary handling
10064      if send_mouse_grid then
10065        api.nvim_input_mouse('right', 'press', '', 2, 2, 35)
10066      else
10067        feed('<RightMouse><35,2>')
10068      end
10069      if multigrid then
10070        screen:expect({
10071          grid = [[
10072          ## grid 1
10073            [2:----------------------------------------]|*11
10074            [3:----------------------------------------]|
10075          ## grid 2
10076            ^                                        |
10077            {1:~                                       }|*10
10078          ## grid 3
10079                                                    |
10080          ## grid 4
10081            {n:╭─────────────────────╮}|
10082            {n:│ Inspect             │}|
10083            {n:│                     │}|
10084            {n:│ Paste               │}|
10085            {n:│ Select All          │}|
10086            {n:│                     │}|
10087            {n:│ How-to disable mouse│}|
10088            {n:╰─────────────────────╯}|
10089          ]],
10090          float_pos = {
10091            [4] = { -1, 'NW', 2, 3, 17, false, 250, 2, 3, 17 },
10092          },
10093        })
10094      else
10095        screen:expect([[
10096          ^                                        |
10097          {1:~                                       }|*2
10098          {1:~                }{n:╭─────────────────────╮}|
10099          {1:~                }{n:│ Inspect             │}|
10100          {1:~                }{n:│                     │}|
10101          {1:~                }{n:│ Paste               │}|
10102          {1:~                }{n:│ Select All          │}|
10103          {1:~                }{n:│                     │}|
10104          {1:~                }{n:│ How-to disable mouse│}|
10105          {1:~                }{n:╰─────────────────────╯}|
10106                                                  |
10107        ]])
10108      end
10109      if send_mouse_grid then
10110        api.nvim_input_mouse('move', '', '', 4, 1, 1)
10111      else
10112        feed('<MouseMove><25,4>')
10113      end
10114      if multigrid then
10115        screen:expect({
10116          grid = [[
10117          ## grid 1
10118            [2:----------------------------------------]|*11
10119            [3:----------------------------------------]|
10120          ## grid 2
10121            ^                                        |
10122            {1:~                                       }|*10
10123          ## grid 3
10124                                                    |
10125          ## grid 4
10126            {n:╭─────────────────────╮}|
10127            {n:│}{12: Inspect             }{n:│}|
10128            {n:│                     │}|
10129            {n:│ Paste               │}|
10130            {n:│ Select All          │}|
10131            {n:│                     │}|
10132            {n:│ How-to disable mouse│}|
10133            {n:╰─────────────────────╯}|
10134          ]],
10135          float_pos = {
10136            [4] = { -1, 'NW', 2, 3, 17, false, 250, 2, 3, 17 },
10137          },
10138        })
10139      else
10140        screen:expect([[
10141          ^                                        |
10142          {1:~                                       }|*2
10143          {1:~                }{n:╭─────────────────────╮}|
10144          {1:~                }{n:│}{12: Inspect             }{n:│}|
10145          {1:~                }{n:│                     │}|
10146          {1:~                }{n:│ Paste               │}|
10147          {1:~                }{n:│ Select All          │}|
10148          {1:~                }{n:│                     │}|
10149          {1:~                }{n:│ How-to disable mouse│}|
10150          {1:~                }{n:╰─────────────────────╯}|
10151                                                  |
10152        ]])
10153      end
10154      -- when right-clicking on the bottom menu, it should appear above the mouse_row
10155      if send_mouse_grid then
10156        api.nvim_input_mouse('right', 'press', '', 2, 8, 20)
10157      else
10158        feed('<RightMouse><20,8>')
10159      end
10160      if multigrid then
10161        screen:expect({
10162          grid = [[
10163          ## grid 1
10164            [2:----------------------------------------]|*11
10165            [3:----------------------------------------]|
10166          ## grid 2
10167            ^                                        |
10168            {1:~                                       }|*10
10169          ## grid 3
10170                                                    |
10171          ## grid 4
10172            {n:╭─────────────────────╮}|
10173            {n:│ Inspect             │}|
10174            {n:│                     │}|
10175            {n:│ Paste               │}|
10176            {n:│ Select All          │}|
10177            {n:│                     │}|
10178            {n:│ How-to disable mouse│}|
10179            {n:╰─────────────────────╯}|
10180          ]],
10181          float_pos = {
10182            [4] = { -1, 'SW', 2, 6, 17, false, 250, 2, 0, 17 },
10183          },
10184        })
10185      else
10186        screen:expect([[
10187          ^                 {n:╭─────────────────────╮}|
10188          {1:~                }{n:│ Inspect             │}|
10189          {1:~                }{n:│                     │}|
10190          {1:~                }{n:│ Paste               │}|
10191          {1:~                }{n:│ Select All          │}|
10192          {1:~                }{n:│                     │}|
10193          {1:~                }{n:│ How-to disable mouse│}|
10194          {1:~                }{n:╰─────────────────────╯}|
10195          {1:~                                       }|*3
10196                                                  |
10197        ]])
10198      end
10199    end)
10200  end
10201
10202  describe('with ext_multigrid and actual mouse grid', function()
10203    with_ext_multigrid(true, true)
10204  end)
10205
10206  describe('with ext_multigrid and mouse grid 0', function()
10207    with_ext_multigrid(true, false)
10208  end)
10209
10210  describe('without ext_multigrid', function()
10211    with_ext_multigrid(false, false)
10212  end)
10213end)