robin/laufey

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

robinmerge: 1dc9728daa1d8a2702

master
121.4 KiB3292 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 clear = n.clear
7local feed, command, insert = n.feed, n.command, n.insert
8local eq = t.eq
9local fn = n.fn
10local api = n.api
11local curwin = n.api.nvim_get_current_win
12local poke_eventloop = n.poke_eventloop
13
14describe('ext_multigrid', function()
15  local screen
16
17  before_each(function()
18    clear { args_rm = { '--headless' }, args = { '--cmd', 'set laststatus=2' } }
19    screen = Screen.new(53, 14, { ext_multigrid = true })
20    screen:set_default_attr_ids({
21      [1] = { bold = true, foreground = Screen.colors.Blue1 },
22      [2] = { foreground = Screen.colors.Magenta },
23      [3] = { foreground = Screen.colors.Brown, bold = true },
24      [4] = { foreground = Screen.colors.SlateBlue },
25      [5] = { bold = true, foreground = Screen.colors.SlateBlue },
26      [6] = { foreground = Screen.colors.Cyan4 },
27      [7] = { bold = true },
28      [8] = { underline = true, bold = true, foreground = Screen.colors.SlateBlue },
29      [9] = { foreground = Screen.colors.SlateBlue, underline = true },
30      [10] = { foreground = Screen.colors.Red },
31      [11] = { bold = true, reverse = true },
32      [12] = { reverse = true },
33      [13] = { foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey },
34      [14] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
35      [15] = { bold = true, foreground = Screen.colors.SeaGreen4 },
36      [16] = { background = Screen.colors.LightGrey, underline = true },
37      [17] = { background = Screen.colors.LightGrey, underline = true, bold = true, foreground = Screen.colors.Magenta },
38      [18] = { bold = true, foreground = Screen.colors.Magenta },
39      [19] = { foreground = Screen.colors.Brown },
40      [20] = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black },
41      [21] = { background = Screen.colors.LightMagenta },
42      [22] = { background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue },
43      [23] = { background = Screen.colors.Grey90 },
44      [24] = { background = Screen.colors.Grey },
45    })
46  end)
47
48  it('default initial screen', function()
49    screen:expect {
50      grid = [[
51    ## grid 1
52      [2:-----------------------------------------------------]|*12
53      {11:[No Name]                                            }|
54      [3:-----------------------------------------------------]|
55    ## grid 2
56      ^                                                     |
57      {1:~                                                    }|*11
58    ## grid 3
59                                                           |
60    ]],
61    }
62  end)
63
64  it('positions windows correctly', function()
65    command('vsplit')
66    screen:expect {
67      grid = [[
68    ## grid 1
69      [4:--------------------------]│[2:--------------------------]|*12
70      {11:[No Name]                  }{12:[No Name]                 }|
71      [3:-----------------------------------------------------]|
72    ## grid 2
73                                |
74      {1:~                         }|*11
75    ## grid 3
76                                                           |
77    ## grid 4
78      ^                          |
79      {1:~                         }|*11
80    ]],
81      condition = function()
82        eq({
83          [2] = { win = 1000, startrow = 0, startcol = 27, width = 26, height = 12 },
84          [4] = { win = 1001, startrow = 0, startcol = 0, width = 26, height = 12 },
85        }, screen.win_position)
86      end,
87    }
88    command('wincmd l')
89    command('split')
90    screen:expect {
91      grid = [[
92    ## grid 1
93      [4:--------------------------]│[5:--------------------------]|*6
94      [4:--------------------------]│{11:[No Name]                 }|
95      [4:--------------------------]│[2:--------------------------]|*5
96      {12:[No Name]                  [No Name]                 }|
97      [3:-----------------------------------------------------]|
98    ## grid 2
99                                |
100      {1:~                         }|*4
101    ## grid 3
102                                                           |
103    ## grid 4
104                                |
105      {1:~                         }|*11
106    ## grid 5
107      ^                          |
108      {1:~                         }|*5
109    ]],
110      condition = function()
111        eq({
112          [2] = { win = 1000, startrow = 7, startcol = 27, width = 26, height = 5 },
113          [4] = { win = 1001, startrow = 0, startcol = 0, width = 26, height = 12 },
114          [5] = { win = 1002, startrow = 0, startcol = 27, width = 26, height = 6 },
115        }, screen.win_position)
116      end,
117    }
118    command('wincmd h')
119    command('q')
120    screen:expect {
121      grid = [[
122    ## grid 1
123      [5:-----------------------------------------------------]|*6
124      {11:[No Name]                                            }|
125      [2:-----------------------------------------------------]|*5
126      {12:[No Name]                                            }|
127      [3:-----------------------------------------------------]|
128    ## grid 2
129                                                           |
130      {1:~                                                    }|*4
131    ## grid 3
132                                                           |
133    ## grid 5
134      ^                                                     |
135      {1:~                                                    }|*5
136    ]],
137      condition = function()
138        eq({
139          [2] = { win = 1000, startrow = 7, startcol = 0, width = 53, height = 5 },
140          [5] = { win = 1002, startrow = 0, startcol = 0, width = 53, height = 6 },
141        }, screen.win_position)
142      end,
143    }
144  end)
145
146  describe('split', function()
147    describe('horizontally', function()
148      it('allocates grids', function()
149        command('sp')
150        screen:expect([[
151        ## grid 1
152          [4:-----------------------------------------------------]|*6
153          {11:[No Name]                                            }|
154          [2:-----------------------------------------------------]|*5
155          {12:[No Name]                                            }|
156          [3:-----------------------------------------------------]|
157        ## grid 2
158                                                               |
159          {1:~                                                    }|*4
160        ## grid 3
161                                                               |
162        ## grid 4
163          ^                                                     |
164          {1:~                                                    }|*5
165        ]])
166      end)
167
168      it('resizes grids', function()
169        command('sp')
170        command('resize 8')
171        screen:expect([[
172        ## grid 1
173          [4:-----------------------------------------------------]|*8
174          {11:[No Name]                                            }|
175          [2:-----------------------------------------------------]|*3
176          {12:[No Name]                                            }|
177          [3:-----------------------------------------------------]|
178        ## grid 2
179                                                               |
180          {1:~                                                    }|*2
181        ## grid 3
182                                                               |
183        ## grid 4
184          ^                                                     |
185          {1:~                                                    }|*7
186        ]])
187      end)
188
189      it('splits vertically', function()
190        command('sp')
191        command('vsp')
192        command('vsp')
193        screen:expect {
194          grid = [[
195        ## grid 1
196          [6:--------------------]│[5:----------------]│[4:---------------]|*6
197          {11:[No Name]            }{12:[No Name]        [No Name]      }|
198          [2:-----------------------------------------------------]|*5
199          {12:[No Name]                                            }|
200          [3:-----------------------------------------------------]|
201        ## grid 2
202                                                               |
203          {1:~                                                    }|*4
204        ## grid 3
205                                                               |
206        ## grid 4
207                         |
208          {1:~              }|*5
209        ## grid 5
210                          |
211          {1:~               }|*5
212        ## grid 6
213          ^                    |
214          {1:~                   }|*5
215        ]],
216        }
217        insert('hello')
218        screen:expect {
219          grid = [[
220        ## grid 1
221          [6:--------------------]│[5:----------------]│[4:---------------]|*6
222          {11:[No Name] [+]        }{12:[No Name] [+]    [No Name] [+]  }|
223          [2:-----------------------------------------------------]|*5
224          {12:[No Name] [+]                                        }|
225          [3:-----------------------------------------------------]|
226        ## grid 2
227          hello                                                |
228          {1:~                                                    }|*4
229        ## grid 3
230                                                               |
231        ## grid 4
232          hello          |
233          {1:~              }|*5
234        ## grid 5
235          hello           |
236          {1:~               }|*5
237        ## grid 6
238          hell^o               |
239          {1:~                   }|*5
240        ]],
241        }
242      end)
243      it('closes splits', function()
244        command('sp')
245        screen:expect {
246          grid = [[
247        ## grid 1
248          [4:-----------------------------------------------------]|*6
249          {11:[No Name]                                            }|
250          [2:-----------------------------------------------------]|*5
251          {12:[No Name]                                            }|
252          [3:-----------------------------------------------------]|
253        ## grid 2
254                                                               |
255          {1:~                                                    }|*4
256        ## grid 3
257                                                               |
258        ## grid 4
259          ^                                                     |
260          {1:~                                                    }|*5
261        ]],
262        }
263        command('q')
264        screen:expect {
265          grid = [[
266        ## grid 1
267          [2:-----------------------------------------------------]|*12
268          {11:[No Name]                                            }|
269          [3:-----------------------------------------------------]|
270        ## grid 2
271          ^                                                     |
272          {1:~                                                    }|*11
273        ## grid 3
274                                                               |
275        ]],
276        }
277      end)
278    end)
279
280    describe('vertically', function()
281      it('allocates grids', function()
282        command('vsp')
283        screen:expect {
284          grid = [[
285        ## grid 1
286          [4:--------------------------]│[2:--------------------------]|*12
287          {11:[No Name]                  }{12:[No Name]                 }|
288          [3:-----------------------------------------------------]|
289        ## grid 2
290                                    |
291          {1:~                         }|*11
292        ## grid 3
293                                                               |
294        ## grid 4
295          ^                          |
296          {1:~                         }|*11
297        ]],
298        }
299      end)
300      it('resizes grids', function()
301        command('vsp')
302        command('vertical resize 10')
303        screen:expect {
304          grid = [[
305        ## grid 1
306          [4:----------]│[2:------------------------------------------]|*12
307          {11:[No Name]  }{12:[No Name]                                 }|
308          [3:-----------------------------------------------------]|
309        ## grid 2
310                                                    |
311          {1:~                                         }|*11
312        ## grid 3
313                                                               |
314        ## grid 4
315          ^          |
316          {1:~         }|*11
317        ]],
318        }
319      end)
320      it('splits horizontally', function()
321        command('vsp')
322        command('sp')
323        screen:expect {
324          grid = [[
325        ## grid 1
326          [5:--------------------------]│[2:--------------------------]|*6
327          {11:[No Name]                 }│[2:--------------------------]|
328          [4:--------------------------]│[2:--------------------------]|*5
329          {12:[No Name]                  [No Name]                 }|
330          [3:-----------------------------------------------------]|
331        ## grid 2
332                                    |
333          {1:~                         }|*11
334        ## grid 3
335                                                               |
336        ## grid 4
337                                    |
338          {1:~                         }|*4
339        ## grid 5
340          ^                          |
341          {1:~                         }|*5
342        ]],
343        }
344        insert('hello')
345        screen:expect {
346          grid = [[
347        ## grid 1
348          [5:--------------------------]│[2:--------------------------]|*6
349          {11:[No Name] [+]             }│[2:--------------------------]|
350          [4:--------------------------]│[2:--------------------------]|*5
351          {12:[No Name] [+]              [No Name] [+]             }|
352          [3:-----------------------------------------------------]|
353        ## grid 2
354          hello                     |
355          {1:~                         }|*11
356        ## grid 3
357                                                               |
358        ## grid 4
359          hello                     |
360          {1:~                         }|*4
361        ## grid 5
362          hell^o                     |
363          {1:~                         }|*5
364        ]],
365        }
366      end)
367      it('closes splits', function()
368        command('vsp')
369        screen:expect {
370          grid = [[
371        ## grid 1
372          [4:--------------------------]│[2:--------------------------]|*12
373          {11:[No Name]                  }{12:[No Name]                 }|
374          [3:-----------------------------------------------------]|
375        ## grid 2
376                                    |
377          {1:~                         }|*11
378        ## grid 3
379                                                               |
380        ## grid 4
381          ^                          |
382          {1:~                         }|*11
383        ]],
384        }
385        command('q')
386        screen:expect {
387          grid = [[
388        ## grid 1
389          [2:-----------------------------------------------------]|*12
390          {11:[No Name]                                            }|
391          [3:-----------------------------------------------------]|
392        ## grid 2
393          ^                                                     |
394          {1:~                                                    }|*11
395        ## grid 3
396                                                               |
397        ]],
398        }
399      end)
400    end)
401  end)
402
403  describe('on resize', function()
404    it('rebuilds all grids', function()
405      screen:try_resize(25, 6)
406      screen:expect {
407        grid = [[
408      ## grid 1
409        [2:-------------------------]|*4
410        {11:[No Name]                }|
411        [3:-------------------------]|
412      ## grid 2
413        ^                         |
414        {1:~                        }|*3
415      ## grid 3
416                                 |
417      ]],
418      }
419    end)
420
421    it('has minimum width/height values', function()
422      screen:try_resize(1, 1)
423      screen:expect {
424        grid = [[
425      ## grid 1
426        [2:------------]|
427        {11:[No Name]   }|
428        [3:------------]|
429      ## grid 2
430        ^            |
431      ## grid 3
432                    |
433      ]],
434      }
435
436      feed('<esc>:ls')
437      screen:expect {
438        grid = [[
439      ## grid 1
440        [2:------------]|
441        {11:[No Name]   }|
442        [3:------------]|
443      ## grid 2
444                    |
445      ## grid 3
446        :ls^         |
447      ]],
448      }
449    end)
450  end)
451
452  describe('grid of smaller inner size', function()
453    before_each(function()
454      screen:try_resize_grid(2, 20, 5)
455    end)
456
457    it('is rendered correctly', function()
458      screen:expect {
459        grid = [[
460      ## grid 1
461        [2:-----------------------------------------------------]|*12
462        {11:[No Name]                                            }|
463        [3:-----------------------------------------------------]|
464      ## grid 2
465        ^                    |
466        {1:~                   }|*4
467      ## grid 3
468                                                             |
469      ]],
470      }
471      screen:try_resize_grid(2, 8, 5)
472      screen:expect {
473        grid = [[
474      ## grid 1
475        [2:-----------------------------------------------------]|*12
476        {11:[No Name]                                            }|
477        [3:-----------------------------------------------------]|
478      ## grid 2
479        ^        |
480        {1:~       }|*4
481      ## grid 3
482                                                             |
483      ]],
484      }
485    end)
486
487    it("cursor draws correctly with double-width char and 'showbreak'", function()
488      insert(('a'):rep(19) .. '哦bbbb')
489      command('setlocal showbreak=++')
490      screen:expect {
491        grid = [[
492      ## grid 1
493        [2:-----------------------------------------------------]|*12
494        {11:[No Name] [+]                                        }|
495        [3:-----------------------------------------------------]|
496      ## grid 2
497        aaaaaaaaaaaaaaaaaaa{1:>}|
498        {1:++}哦bbb^b            |
499        {1:~                   }|*3
500      ## grid 3
501                                                             |
502      ]],
503      }
504    end)
505  end)
506
507  describe('grid of bigger inner size', function()
508    before_each(function()
509      screen:try_resize_grid(2, 60, 20)
510    end)
511
512    it('is rendered correctly', function()
513      screen:expect {
514        grid = [[
515      ## grid 1
516        [2:-----------------------------------------------------]|*12
517        {11:[No Name]                                            }|
518        [3:-----------------------------------------------------]|
519      ## grid 2
520        ^                                                            |
521        {1:~                                                           }|*19
522      ## grid 3
523                                                             |
524      ]],
525      }
526      screen:try_resize_grid(2, 80, 20)
527      screen:expect {
528        grid = [[
529      ## grid 1
530        [2:-----------------------------------------------------]|*12
531        {11:[No Name]                                            }|
532        [3:-----------------------------------------------------]|
533      ## grid 2
534        ^                                                                                |
535        {1:~                                                                               }|*19
536      ## grid 3
537                                                             |
538      ]],
539      }
540    end)
541
542    it('winwidth() winheight() getwininfo() return inner width and height #19743', function()
543      eq(60, fn.winwidth(0))
544      eq(20, fn.winheight(0))
545      local win_info = fn.getwininfo(curwin())[1]
546      eq(60, win_info.width)
547      eq(20, win_info.height)
548    end)
549
550    it("'scroll' option works properly", function()
551      eq(10, api.nvim_get_option_value('scroll', { win = 0 }))
552      api.nvim_set_option_value('scroll', 15, { win = 0 })
553      eq(15, api.nvim_get_option_value('scroll', { win = 0 }))
554    end)
555
556    it('gets written till grid width', function()
557      insert(('a'):rep(60) .. '\n')
558      screen:expect {
559        grid = [[
560      ## grid 1
561        [2:-----------------------------------------------------]|*12
562        {11:[No Name] [+]                                        }|
563        [3:-----------------------------------------------------]|
564      ## grid 2
565        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
566        ^                                                            |
567        {1:~                                                           }|*18
568      ## grid 3
569                                                             |
570      ]],
571      }
572    end)
573
574    it('g$ works correctly with double-width chars and no wrapping', function()
575      command('set nowrap')
576      insert(('a'):rep(58) .. ('哦'):rep(3))
577      feed('0')
578      screen:expect {
579        grid = [[
580      ## grid 1
581        [2:-----------------------------------------------------]|*12
582        {11:[No Name] [+]                                        }|
583        [3:-----------------------------------------------------]|
584      ## grid 2
585        ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa哦|
586        {1:~                                                           }|*19
587      ## grid 3
588                                                             |
589      ]],
590      }
591      feed('g$')
592      screen:expect {
593        grid = [[
594      ## grid 1
595        [2:-----------------------------------------------------]|*12
596        {11:[No Name] [+]                                        }|
597        [3:-----------------------------------------------------]|
598      ## grid 2
599        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa^哦|
600        {1:~                                                           }|*19
601      ## grid 3
602                                                             |
603      ]],
604      }
605    end)
606
607    it('wraps with grid width', function()
608      insert(('b'):rep(160) .. '\n')
609      screen:expect {
610        grid = [[
611      ## grid 1
612        [2:-----------------------------------------------------]|*12
613        {11:[No Name] [+]                                        }|
614        [3:-----------------------------------------------------]|
615      ## grid 2
616        bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|*2
617        bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb                    |
618        ^                                                            |
619        {1:~                                                           }|*16
620      ## grid 3
621                                                             |
622      ]],
623      }
624      feed('2gk')
625      command('setlocal cursorline cursorlineopt=screenline')
626      screen:expect {
627        grid = [[
628      ## grid 1
629        [2:-----------------------------------------------------]|*12
630        {11:[No Name] [+]                                        }|
631        [3:-----------------------------------------------------]|
632      ## grid 2
633        bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
634        {23:^bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb}|
635        bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb                    |
636                                                                    |
637        {1:~                                                           }|*16
638      ## grid 3
639                                                             |
640      ]],
641      }
642      command('setlocal breakindent breakindentopt=shift:8')
643      feed('g$')
644      screen:expect {
645        grid = [[
646      ## grid 1
647        [2:-----------------------------------------------------]|*12
648        {11:[No Name] [+]                                        }|
649        [3:-----------------------------------------------------]|
650      ## grid 2
651        bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
652                {23:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb^b}|
653                bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb    |
654                                                                    |
655        {1:~                                                           }|*16
656      ## grid 3
657                                                             |
658      ]],
659      }
660    end)
661
662    it('displays messages with default grid width', function()
663      command('echomsg "this is a very very very very very very very very' .. ' long message"')
664      screen:expect {
665        grid = [[
666      ## grid 1
667        [2:-----------------------------------------------------]|*12
668        {11:[No Name]                                            }|
669        [3:-----------------------------------------------------]|
670      ## grid 2
671        ^                                                            |
672        {1:~                                                           }|*19
673      ## grid 3
674        this is a very very very...ry very very long message |
675      ]],
676      }
677    end)
678
679    it('creates folds with grid width', function()
680      insert('this is a fold\nthis is inside fold\nthis is outside fold')
681      feed('kzfgg')
682      screen:expect {
683        grid = [[
684      ## grid 1
685        [2:-----------------------------------------------------]|*12
686        {11:[No Name] [+]                                        }|
687        [3:-----------------------------------------------------]|
688      ## grid 2
689        {13:^+--  2 lines: this is a fold································}|
690        this is outside fold                                        |
691        {1:~                                                           }|*18
692      ## grid 3
693                                                             |
694      ]],
695      }
696    end)
697
698    it('anchored float window "bufpos"', function()
699      insert(('c'):rep(1111))
700      screen:expect {
701        grid = [[
702      ## grid 1
703        [2:-----------------------------------------------------]|*12
704        {11:[No Name] [+]                                        }|
705        [3:-----------------------------------------------------]|
706      ## grid 2
707        cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|*18
708        cccccccccccccccccccccccccccccc^c                             |
709        {1:~                                                           }|
710      ## grid 3
711                                                             |
712      ]],
713      }
714      local float_buf = api.nvim_create_buf(false, false)
715      api.nvim_open_win(float_buf, false, {
716        relative = 'win',
717        win = curwin(),
718        bufpos = { 0, 1018 },
719        anchor = 'SE',
720        width = 5,
721        height = 5,
722      })
723      screen:expect {
724        grid = [[
725      ## grid 1
726        [2:-----------------------------------------------------]|*12
727        {11:[No Name] [+]                                        }|
728        [3:-----------------------------------------------------]|
729      ## grid 2
730        cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc|*18
731        cccccccccccccccccccccccccccccc^c                             |
732        {1:~                                                           }|
733      ## grid 3
734                                                             |
735      ## grid 4
736        {21:     }|
737        {22:~    }|*4
738      ]],
739        float_pos = {
740          [4] = { 1001, 'SE', 2, 16, 58, true, 50, 1, 8, 48 },
741        },
742      }
743    end)
744
745    it('completion popup position', function()
746      insert(('\n'):rep(14) .. ('foo bar '):rep(7))
747      feed('A<C-X><C-N>')
748      screen:expect {
749        grid = [[
750      ## grid 1
751        [2:-----------------------------------------------------]|*12
752        {11:[No Name] [+]                                        }|
753        [3:-----------------------------------------------------]|
754      ## grid 2
755                                                                    |*14
756        foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo^ |
757        {1:~                                                           }|*5
758      ## grid 3
759        {7:-- Keyword Local completion (^N^P) }{15:match 1 of 2}      |
760      ## grid 4
761        {24: foo             }|
762        {21: bar             }|
763      ]],
764        float_pos = {
765          [4] = { -1, 'NW', 2, 15, 43, false, 100, 1, 15, 43 },
766        },
767      }
768      feed('<C-E><Esc>')
769
770      command('setlocal rightleft')
771      feed('o<C-X><C-N>')
772      screen:expect {
773        grid = [[
774      ## grid 1
775        [2:-----------------------------------------------------]|*12
776        {11:[No Name] [+]                                        }|
777        [3:-----------------------------------------------------]|
778      ## grid 2
779                                                                    |*14
780             rab oof rab oof rab oof rab oof rab oof rab oof rab oof|
781                                                                ^ oof|
782        {1:                                                           ~}|*4
783      ## grid 3
784        {7:-- Keyword Local completion (^N^P) }{15:match 1 of 2}      |
785      ## grid 4
786        {24:            oof}|
787        {21:            rab}|
788      ]],
789        float_pos = {
790          [4] = { -1, 'NW', 2, 16, 45, false, 100, 1, 16, 45 },
791        },
792      }
793      feed('<C-E><Esc>')
794
795      command('set wildoptions+=pum')
796      feed(':sign un<Tab>')
797      screen:expect {
798        grid = [[
799      ## grid 1
800        [2:-----------------------------------------------------]|*12
801        {11:[No Name] [+]                                        }|
802        [3:-----------------------------------------------------]|
803      ## grid 2
804                                                                    |*14
805             rab oof rab oof rab oof rab oof rab oof rab oof rab oof|
806                                                                    |
807        {1:                                                           ~}|*4
808      ## grid 3
809        :sign undefine^                                       |
810      ## grid 4
811        {24: undefine       }|
812        {21: unplace        }|
813      ]],
814        float_pos = {
815          [4] = { -1, 'SW', 1, 13, 5, false, 250, 2, 11, 5 },
816        },
817      }
818    end)
819
820    it('half-page scrolling stops at end of buffer', function()
821      command('set number')
822      insert(('foobar\n'):rep(100))
823      feed('7<C-Y>')
824      screen:expect({
825        grid = [[
826        ## grid 1
827          [2:-----------------------------------------------------]|*12
828          {11:[No Name] [+]                                        }|
829          [3:-----------------------------------------------------]|
830        ## grid 2
831          {19: 75 }foobar                                                  |
832          {19: 76 }foobar                                                  |
833          {19: 77 }foobar                                                  |
834          {19: 78 }foobar                                                  |
835          {19: 79 }foobar                                                  |
836          {19: 80 }foobar                                                  |
837          {19: 81 }foobar                                                  |
838          {19: 82 }foobar                                                  |
839          {19: 83 }foobar                                                  |
840          {19: 84 }foobar                                                  |
841          {19: 85 }foobar                                                  |
842          {19: 86 }foobar                                                  |
843          {19: 87 }foobar                                                  |
844          {19: 88 }foobar                                                  |
845          {19: 89 }foobar                                                  |
846          {19: 90 }foobar                                                  |
847          {19: 91 }foobar                                                  |
848          {19: 92 }foobar                                                  |
849          {19: 93 }foobar                                                  |
850          {19: 94 }^foobar                                                  |
851        ## grid 3
852                                                               |
853        ]],
854      })
855      feed('<C-D>')
856      screen:expect({
857        grid = [[
858        ## grid 1
859          [2:-----------------------------------------------------]|*12
860          {11:[No Name] [+]                                        }|
861          [3:-----------------------------------------------------]|
862        ## grid 2
863          {19: 82 }foobar                                                  |
864          {19: 83 }foobar                                                  |
865          {19: 84 }foobar                                                  |
866          {19: 85 }foobar                                                  |
867          {19: 86 }foobar                                                  |
868          {19: 87 }foobar                                                  |
869          {19: 88 }foobar                                                  |
870          {19: 89 }foobar                                                  |
871          {19: 90 }foobar                                                  |
872          {19: 91 }foobar                                                  |
873          {19: 92 }foobar                                                  |
874          {19: 93 }foobar                                                  |
875          {19: 94 }foobar                                                  |
876          {19: 95 }foobar                                                  |
877          {19: 96 }foobar                                                  |
878          {19: 97 }foobar                                                  |
879          {19: 98 }foobar                                                  |
880          {19: 99 }foobar                                                  |
881          {19:100 }foobar                                                  |
882          {19:101 }^                                                        |
883        ## grid 3
884                                                               |
885        ]],
886      })
887    end)
888  end)
889
890  it('multiline messages scroll over windows', function()
891    command('sp')
892    command('vsp')
893    screen:expect {
894      grid = [[
895    ## grid 1
896      [5:--------------------------]│[4:--------------------------]|*6
897      {11:[No Name]                  }{12:[No Name]                 }|
898      [2:-----------------------------------------------------]|*5
899      {12:[No Name]                                            }|
900      [3:-----------------------------------------------------]|
901    ## grid 2
902                                                           |
903      {1:~                                                    }|*4
904    ## grid 3
905                                                           |
906    ## grid 4
907                                |
908      {1:~                         }|*5
909    ## grid 5
910      ^                          |
911      {1:~                         }|*5
912    ]],
913    }
914
915    feed(":echoerr 'very' | echoerr 'much' | echoerr 'fail'<cr>")
916    screen:expect {
917      grid = [[
918    ## grid 1
919      [5:--------------------------]│[4:--------------------------]|*6
920      {11:[No Name]                  }{12:[No Name]                 }|
921      [2:-----------------------------------------------------]|*3
922      [3:-----------------------------------------------------]|*4
923    ## grid 2
924                                                           |
925      {1:~                                                    }|*4
926    ## grid 3
927      {14:very}                                                 |
928      {14:much}                                                 |
929      {14:fail}                                                 |
930      {15:Press ENTER or type command to continue}^              |
931    ## grid 4
932                                |
933      {1:~                         }|*5
934    ## grid 5
935                                |
936      {1:~                         }|*5
937    ]],
938    }
939
940    feed('<cr>')
941    screen:expect {
942      grid = [[
943    ## grid 1
944      [5:--------------------------]│[4:--------------------------]|*6
945      {11:[No Name]                  }{12:[No Name]                 }|
946      [2:-----------------------------------------------------]|*5
947      {12:[No Name]                                            }|
948      [3:-----------------------------------------------------]|
949    ## grid 2
950                                                           |
951      {1:~                                                    }|*4
952    ## grid 3
953                                                           |
954    ## grid 4
955                                |
956      {1:~                         }|*5
957    ## grid 5
958      ^                          |
959      {1:~                         }|*5
960    ]],
961    }
962
963    command([[
964      func! ErrMsg()
965        for i in range(11)
966          echoerr "error ".i
967        endfor
968      endfunc]])
969    feed(':call ErrMsg()<cr>')
970    screen:expect {
971      grid = [[
972    ## grid 1
973      [3:-----------------------------------------------------]|*14
974    ## grid 2
975                                                           |
976      {1:~                                                    }|*4
977    ## grid 3
978      {14:Error in function ErrMsg:}                            |
979      {19:line    2:}                                           |
980      {14:error 0}                                              |
981      {14:error 1}                                              |
982      {14:error 2}                                              |
983      {14:error 3}                                              |
984      {14:error 4}                                              |
985      {14:error 5}                                              |
986      {14:error 6}                                              |
987      {14:error 7}                                              |
988      {14:error 8}                                              |
989      {14:error 9}                                              |
990      {14:error 10}                                             |
991      {15:Press ENTER or type command to continue}^              |
992    ## grid 4
993                                |
994      {1:~                         }|*5
995    ## grid 5
996                                |
997      {1:~                         }|*5
998    ]],
999    }
1000
1001    feed('<c-c>')
1002    screen:expect {
1003      grid = [[
1004    ## grid 1
1005      [5:--------------------------]│[4:--------------------------]|*6
1006      {11:[No Name]                  }{12:[No Name]                 }|
1007      [2:-----------------------------------------------------]|*5
1008      {12:[No Name]                                            }|
1009      [3:-----------------------------------------------------]|
1010    ## grid 2
1011                                                           |
1012      {1:~                                                    }|*4
1013    ## grid 3
1014                                                           |
1015    ## grid 4
1016                                |
1017      {1:~                         }|*5
1018    ## grid 5
1019      ^                          |
1020      {1:~                         }|*5
1021    ]],
1022    }
1023  end)
1024
1025  it('handles switch tabs', function()
1026    command('vsp')
1027    screen:expect {
1028      grid = [[
1029    ## grid 1
1030      [4:--------------------------]│[2:--------------------------]|*12
1031      {11:[No Name]                  }{12:[No Name]                 }|
1032      [3:-----------------------------------------------------]|
1033    ## grid 2
1034                                |
1035      {1:~                         }|*11
1036    ## grid 3
1037                                                           |
1038    ## grid 4
1039      ^                          |
1040      {1:~                         }|*11
1041    ]],
1042    }
1043
1044    command('tabnew')
1045    -- note the old grids aren't resized yet
1046    screen:expect {
1047      grid = [[
1048    ## grid 1
1049      {16: }{17:2}{16: [No Name] }{7: [No Name] }{12:                            }{16:X}|
1050      [5:-----------------------------------------------------]|*11
1051      {11:[No Name]                                            }|
1052      [3:-----------------------------------------------------]|
1053    ## grid 2 (hidden)
1054                                |
1055      {1:~                         }|*11
1056    ## grid 3
1057                                                           |
1058    ## grid 4 (hidden)
1059                                |
1060      {1:~                         }|*11
1061    ## grid 5
1062      ^                                                     |
1063      {1:~                                                    }|*10
1064    ]],
1065    }
1066
1067    command('sp')
1068    screen:expect {
1069      grid = [[
1070    ## grid 1
1071      {16: }{17:2}{16: [No Name] }{7: }{18:2}{7: [No Name] }{12:                          }{16:X}|
1072      [6:-----------------------------------------------------]|*5
1073      {11:[No Name]                                            }|
1074      [5:-----------------------------------------------------]|*5
1075      {12:[No Name]                                            }|
1076      [3:-----------------------------------------------------]|
1077    ## grid 2 (hidden)
1078                                |
1079      {1:~                         }|*11
1080    ## grid 3
1081                                                           |
1082    ## grid 4 (hidden)
1083                                |
1084      {1:~                         }|*11
1085    ## grid 5
1086                                                           |
1087      {1:~                                                    }|*4
1088    ## grid 6
1089      ^                                                     |
1090      {1:~                                                    }|*4
1091    ]],
1092    }
1093
1094    command('tabnext')
1095    screen:expect {
1096      grid = [[
1097    ## grid 1
1098      {7: }{18:2}{7: [No Name] }{16: }{17:2}{16: [No Name] }{12:                          }{16:X}|
1099      [4:--------------------------]│[2:--------------------------]|*11
1100      {11:[No Name]                  }{12:[No Name]                 }|
1101      [3:-----------------------------------------------------]|
1102    ## grid 2
1103                                |
1104      {1:~                         }|*10
1105    ## grid 3
1106                                                           |
1107    ## grid 4
1108      ^                          |
1109      {1:~                         }|*10
1110    ## grid 5 (hidden)
1111                                                           |
1112      {1:~                                                    }|*4
1113    ## grid 6 (hidden)
1114                                                           |
1115      {1:~                                                    }|*4
1116    ]],
1117    }
1118
1119    command('tabnext')
1120    screen:expect {
1121      grid = [[
1122    ## grid 1
1123      {16: }{17:2}{16: [No Name] }{7: }{18:2}{7: [No Name] }{12:                          }{16:X}|
1124      [6:-----------------------------------------------------]|*5
1125      {11:[No Name]                                            }|
1126      [5:-----------------------------------------------------]|*5
1127      {12:[No Name]                                            }|
1128      [3:-----------------------------------------------------]|
1129    ## grid 2 (hidden)
1130                                |
1131      {1:~                         }|*10
1132    ## grid 3
1133                                                           |
1134    ## grid 4 (hidden)
1135                                |
1136      {1:~                         }|*10
1137    ## grid 5
1138                                                           |
1139      {1:~                                                    }|*4
1140    ## grid 6
1141      ^                                                     |
1142      {1:~                                                    }|*4
1143    ]],
1144    }
1145
1146    command('tabnext')
1147    command('$tabnew')
1148    screen:expect {
1149      grid = [[
1150    ## grid 1
1151      {16: }{17:2}{16: [No Name]  }{17:2}{16: [No Name] }{7: [No Name] }{12:               }{16:X}|
1152      [7:-----------------------------------------------------]|*11
1153      {11:[No Name]                                            }|
1154      [3:-----------------------------------------------------]|
1155    ## grid 2 (hidden)
1156                                |
1157      {1:~                         }|*10
1158    ## grid 3
1159                                                           |
1160    ## grid 4 (hidden)
1161                                |
1162      {1:~                         }|*10
1163    ## grid 5 (hidden)
1164                                                           |
1165      {1:~                                                    }|*4
1166    ## grid 6 (hidden)
1167                                                           |
1168      {1:~                                                    }|*4
1169    ## grid 7
1170      ^                                                     |
1171      {1:~                                                    }|*10
1172    ]],
1173    }
1174
1175    command('tabclose')
1176    command('tabclose')
1177    screen:expect {
1178      grid = [[
1179    ## grid 1
1180      [4:--------------------------]│[2:--------------------------]|*12
1181      {11:[No Name]                  }{12:[No Name]                 }|
1182      [3:-----------------------------------------------------]|
1183    ## grid 2
1184                                |
1185      {1:~                         }|*11
1186    ## grid 3
1187                                                           |
1188    ## grid 4
1189      ^                          |
1190      {1:~                         }|*11
1191    ]],
1192    }
1193  end)
1194
1195  it('supports mouse', function()
1196    command('autocmd! nvim.popupmenu') -- Delete the default MenuPopup event handler.
1197    insert('some text\nto be clicked')
1198    screen:expect {
1199      grid = [[
1200    ## grid 1
1201      [2:-----------------------------------------------------]|*12
1202      {11:[No Name] [+]                                        }|
1203      [3:-----------------------------------------------------]|
1204    ## grid 2
1205      some text                                            |
1206      to be clicke^d                                        |
1207      {1:~                                                    }|*10
1208    ## grid 3
1209                                                           |
1210    ]],
1211    }
1212
1213    api.nvim_input_mouse('left', 'press', '', 2, 0, 5)
1214    screen:expect {
1215      grid = [[
1216    ## grid 1
1217      [2:-----------------------------------------------------]|*12
1218      {11:[No Name] [+]                                        }|
1219      [3:-----------------------------------------------------]|
1220    ## grid 2
1221      some ^text                                            |
1222      to be clicked                                        |
1223      {1:~                                                    }|*10
1224    ## grid 3
1225                                                           |
1226    ]],
1227    }
1228
1229    feed(':new<cr>')
1230    insert('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmo')
1231
1232    screen:expect {
1233      grid = [[
1234    ## grid 1
1235      [4:-----------------------------------------------------]|*6
1236      {11:[No Name] [+]                                        }|
1237      [2:-----------------------------------------------------]|*5
1238      {12:[No Name] [+]                                        }|
1239      [3:-----------------------------------------------------]|
1240    ## grid 2
1241      some text                                            |
1242      to be clicked                                        |
1243      {1:~                                                    }|*3
1244    ## grid 3
1245                                                           |
1246    ## grid 4
1247      Lorem ipsum dolor sit amet, consectetur adipiscing el|
1248      it, sed do eiusm^o                                    |
1249      {1:~                                                    }|*4
1250    ]],
1251    }
1252
1253    api.nvim_input_mouse('left', 'press', '', 2, 1, 6)
1254    screen:expect {
1255      grid = [[
1256    ## grid 1
1257      [4:-----------------------------------------------------]|*6
1258      {12:[No Name] [+]                                        }|
1259      [2:-----------------------------------------------------]|*5
1260      {11:[No Name] [+]                                        }|
1261      [3:-----------------------------------------------------]|
1262    ## grid 2
1263      some text                                            |
1264      to be ^clicked                                        |
1265      {1:~                                                    }|*3
1266    ## grid 3
1267                                                           |
1268    ## grid 4
1269      Lorem ipsum dolor sit amet, consectetur adipiscing el|
1270      it, sed do eiusmo                                    |
1271      {1:~                                                    }|*4
1272    ]],
1273    }
1274
1275    api.nvim_input_mouse('left', 'press', '', 4, 1, 4)
1276    screen:expect {
1277      grid = [[
1278    ## grid 1
1279      [4:-----------------------------------------------------]|*6
1280      {11:[No Name] [+]                                        }|
1281      [2:-----------------------------------------------------]|*5
1282      {12:[No Name] [+]                                        }|
1283      [3:-----------------------------------------------------]|
1284    ## grid 2
1285      some text                                            |
1286      to be clicked                                        |
1287      {1:~                                                    }|*3
1288    ## grid 3
1289                                                           |
1290    ## grid 4
1291      Lorem ipsum dolor sit amet, consectetur adipiscing el|
1292      it, ^sed do eiusmo                                    |
1293      {1:~                                                    }|*4
1294    ]],
1295    }
1296
1297    screen:try_resize_grid(4, 80, 2)
1298    screen:expect {
1299      grid = [[
1300    ## grid 1
1301      [4:-----------------------------------------------------]|*6
1302      {11:[No Name] [+]                                        }|
1303      [2:-----------------------------------------------------]|*5
1304      {12:[No Name] [+]                                        }|
1305      [3:-----------------------------------------------------]|
1306    ## grid 2
1307      some text                                            |
1308      to be clicked                                        |
1309      {1:~                                                    }|*3
1310    ## grid 3
1311                                                           |
1312    ## grid 4
1313      Lorem ipsum dolor sit amet, consectetur adipiscing elit, ^sed do eiusmo          |
1314      {1:~                                                                               }|
1315    ]],
1316    }
1317
1318    api.nvim_input_mouse('left', 'press', '', 4, 0, 64)
1319    screen:expect {
1320      grid = [[
1321    ## grid 1
1322      [4:-----------------------------------------------------]|*6
1323      {11:[No Name] [+]                                        }|
1324      [2:-----------------------------------------------------]|*5
1325      {12:[No Name] [+]                                        }|
1326      [3:-----------------------------------------------------]|
1327    ## grid 2
1328      some text                                            |
1329      to be clicked                                        |
1330      {1:~                                                    }|*3
1331    ## grid 3
1332                                                           |
1333    ## grid 4
1334      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do ^eiusmo          |
1335      {1:~                                                                               }|
1336    ]],
1337    }
1338
1339    -- XXX: mouse_check_grid() doesn't work properly when clicking on grid 1
1340    api.nvim_input_mouse('left', 'press', '', 1, 6, 20)
1341    -- TODO(bfredl): "batching" input_mouse is formally not supported yet.
1342    -- Normally it should work fine in async context when nvim is not blocked,
1343    -- but add a poke_eventloop be sure.
1344    poke_eventloop()
1345    api.nvim_input_mouse('left', 'drag', '', 1, 4, 20)
1346    screen:expect {
1347      grid = [[
1348    ## grid 1
1349      [4:-----------------------------------------------------]|*4
1350      {11:[No Name] [+]                                        }|
1351      [2:-----------------------------------------------------]|*7
1352      {12:[No Name] [+]                                        }|
1353      [3:-----------------------------------------------------]|
1354    ## grid 2
1355      some text                                            |
1356      to be clicked                                        |
1357      {1:~                                                    }|*5
1358    ## grid 3
1359                                                           |
1360    ## grid 4
1361      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do ^eiusmo          |
1362      {1:~                                                                               }|
1363    ]],
1364    }
1365
1366    feed('<c-w><c-w><c-w>v')
1367    screen:expect {
1368      grid = [[
1369    ## grid 1
1370      [4:-----------------------------------------------------]|*4
1371      {12:[No Name] [+]                                        }|
1372      [5:--------------------------]│[2:--------------------------]|*7
1373      {11:[No Name] [+]              }{12:[No Name] [+]             }|
1374      [3:-----------------------------------------------------]|
1375    ## grid 2
1376      some text                 |
1377      to be clicked             |
1378      {1:~                         }|*5
1379    ## grid 3
1380                                                           |
1381    ## grid 4
1382      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmo          |
1383      {1:~                                                                               }|
1384    ## grid 5
1385      some text                 |
1386      to be ^clicked             |
1387      {1:~                         }|*5
1388    ]],
1389    }
1390
1391    api.nvim_input_mouse('left', 'press', '', 1, 8, 26)
1392    poke_eventloop()
1393    api.nvim_input_mouse('left', 'drag', '', 1, 6, 30)
1394    screen:expect {
1395      grid = [[
1396    ## grid 1
1397      [4:-----------------------------------------------------]|*4
1398      {12:[No Name] [+]                                        }|
1399      [5:------------------------------]│[2:----------------------]|*7
1400      {11:[No Name] [+]                  }{12:[No Name] [+]         }|
1401      [3:-----------------------------------------------------]|
1402    ## grid 2
1403      some text             |
1404      to be clicked         |
1405      {1:~                     }|*5
1406    ## grid 3
1407                                                           |
1408    ## grid 4
1409      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmo          |
1410      {1:~                                                                               }|
1411    ## grid 5
1412      some text                     |
1413      to be ^clicked                 |
1414      {1:~                             }|*5
1415    ]],
1416    }
1417
1418    command('aunmenu PopUp | vmenu PopUp.Copy y')
1419
1420    fn.setreg('"', '')
1421    api.nvim_input_mouse('left', 'press', '2', 2, 1, 6)
1422    screen:expect {
1423      grid = [[
1424    ## grid 1
1425      [4:-----------------------------------------------------]|*4
1426      {12:[No Name] [+]                                        }|
1427      [5:------------------------------]│[2:----------------------]|*7
1428      {12:[No Name] [+]                  }{11:[No Name] [+]         }|
1429      [3:-----------------------------------------------------]|
1430    ## grid 2
1431      some text             |
1432      to be {20:clicke^d}         |
1433      {1:~                     }|*5
1434    ## grid 3
1435      {7:-- VISUAL --}                                         |
1436    ## grid 4
1437      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmo          |
1438      {1:~                                                                               }|
1439    ## grid 5
1440      some text                     |
1441      to be {20:clicked}                 |
1442      {1:~                             }|*5
1443    ]],
1444    }
1445    api.nvim_input_mouse('right', 'press', '', 2, 1, 6)
1446    api.nvim_input_mouse('right', 'release', '', 2, 1, 6)
1447    screen:expect {
1448      grid = [[
1449    ## grid 1
1450      [4:-----------------------------------------------------]|*4
1451      {12:[No Name] [+]                                        }|
1452      [5:------------------------------]│[2:----------------------]|*7
1453      {12:[No Name] [+]                  }{11:[No Name] [+]         }|
1454      [3:-----------------------------------------------------]|
1455    ## grid 2
1456      some text             |
1457      to be {20:clicke^d}         |
1458      {1:~                     }|*5
1459    ## grid 3
1460      {7:-- VISUAL --}                                         |
1461    ## grid 4
1462      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmo          |
1463      {1:~                                                                               }|
1464    ## grid 5
1465      some text                     |
1466      to be {20:clicked}                 |
1467      {1:~                             }|*5
1468    ## grid 6
1469      {21: Copy }|
1470    ]],
1471      float_pos = {
1472        [6] = { -1, 'NW', 2, 2, 5, false, 250, 2, 7, 36 },
1473      },
1474    }
1475    feed('<Down><CR>')
1476    screen:expect {
1477      grid = [[
1478    ## grid 1
1479      [4:-----------------------------------------------------]|*4
1480      {12:[No Name] [+]                                        }|
1481      [5:------------------------------]│[2:----------------------]|*7
1482      {12:[No Name] [+]                  }{11:[No Name] [+]         }|
1483      [3:-----------------------------------------------------]|
1484    ## grid 2
1485      some text             |
1486      to be ^clicked         |
1487      {1:~                     }|*5
1488    ## grid 3
1489                                                           |
1490    ## grid 4
1491      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmo          |
1492      {1:~                                                                               }|
1493    ## grid 5
1494      some text                     |
1495      to be clicked                 |
1496      {1:~                             }|*5
1497    ]],
1498    }
1499    eq('clicked', fn.getreg('"'))
1500
1501    fn.setreg('"', '')
1502    api.nvim_input_mouse('left', 'press', '2', 4, 0, 64)
1503    screen:expect {
1504      grid = [[
1505    ## grid 1
1506      [4:-----------------------------------------------------]|*4
1507      {11:[No Name] [+]                                        }|
1508      [5:------------------------------]│[2:----------------------]|*7
1509      {12:[No Name] [+]                  [No Name] [+]         }|
1510      [3:-----------------------------------------------------]|
1511    ## grid 2
1512      some text             |
1513      to be clicked         |
1514      {1:~                     }|*5
1515    ## grid 3
1516      {7:-- VISUAL --}                                         |
1517    ## grid 4
1518      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do {20:eiusm^o}          |
1519      {1:~                                                                               }|
1520    ## grid 5
1521      some text                     |
1522      to be clicked                 |
1523      {1:~                             }|*5
1524    ]],
1525    }
1526    api.nvim_input_mouse('right', 'press', '', 4, 0, 64)
1527    api.nvim_input_mouse('right', 'release', '', 4, 0, 64)
1528    screen:expect {
1529      grid = [[
1530    ## grid 1
1531      [4:-----------------------------------------------------]|*4
1532      {11:[No Name] [+]                                        }|
1533      [5:------------------------------]│[2:----------------------]|*7
1534      {12:[No Name] [+]                  [No Name] [+]         }|
1535      [3:-----------------------------------------------------]|
1536    ## grid 2
1537      some text             |
1538      to be clicked         |
1539      {1:~                     }|*5
1540    ## grid 3
1541      {7:-- VISUAL --}                                         |
1542    ## grid 4
1543      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do {20:eiusm^o}          |
1544      {1:~                                                                               }|
1545    ## grid 5
1546      some text                     |
1547      to be clicked                 |
1548      {1:~                             }|*5
1549    ## grid 6
1550      {21: Copy }|
1551    ]],
1552      float_pos = {
1553        [6] = { -1, 'NW', 4, 1, 63, false, 250, 2, 1, 63 },
1554      },
1555    }
1556    feed('<Down><CR>')
1557    screen:expect {
1558      grid = [[
1559    ## grid 1
1560      [4:-----------------------------------------------------]|*4
1561      {11:[No Name] [+]                                        }|
1562      [5:------------------------------]│[2:----------------------]|*7
1563      {12:[No Name] [+]                  [No Name] [+]         }|
1564      [3:-----------------------------------------------------]|
1565    ## grid 2
1566      some text             |
1567      to be clicked         |
1568      {1:~                     }|*5
1569    ## grid 3
1570                                                           |
1571    ## grid 4
1572      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do ^eiusmo          |
1573      {1:~                                                                               }|
1574    ## grid 5
1575      some text                     |
1576      to be clicked                 |
1577      {1:~                             }|*5
1578    ]],
1579    }
1580    eq('eiusmo', fn.getreg('"'))
1581
1582    command('wincmd J')
1583    screen:try_resize_grid(4, 7, 10)
1584    screen:expect {
1585      grid = [[
1586    ## grid 1
1587      [5:------------------------------]│[2:----------------------]|*5
1588      {12:[No Name] [+]                  [No Name] [+]         }|
1589      [4:-----------------------------------------------------]|*6
1590      {11:[No Name] [+]                                        }|
1591      [3:-----------------------------------------------------]|
1592    ## grid 2
1593      some text             |
1594      to be clicked         |
1595      {1:~                     }|*3
1596    ## grid 3
1597                                                           |
1598    ## grid 4
1599      Lorem i|
1600      psum do|
1601      lor sit|
1602       amet, |
1603      consect|
1604      etur ad|
1605      ipiscin|
1606      g elit,|
1607       sed do|
1608       ^eiusmo|
1609    ## grid 5
1610      some text                     |
1611      to be clicked                 |
1612      {1:~                             }|*3
1613    ]],
1614    }
1615
1616    fn.setreg('"', '')
1617    api.nvim_input_mouse('left', 'press', '2', 4, 9, 1)
1618    screen:expect {
1619      grid = [[
1620    ## grid 1
1621      [5:------------------------------]│[2:----------------------]|*5
1622      {12:[No Name] [+]                  [No Name] [+]         }|
1623      [4:-----------------------------------------------------]|*6
1624      {11:[No Name] [+]                                        }|
1625      [3:-----------------------------------------------------]|
1626    ## grid 2
1627      some text             |
1628      to be clicked         |
1629      {1:~                     }|*3
1630    ## grid 3
1631      {7:-- VISUAL --}                                         |
1632    ## grid 4
1633      Lorem i|
1634      psum do|
1635      lor sit|
1636       amet, |
1637      consect|
1638      etur ad|
1639      ipiscin|
1640      g elit,|
1641       sed do|
1642       {20:eiusm^o}|
1643    ## grid 5
1644      some text                     |
1645      to be clicked                 |
1646      {1:~                             }|*3
1647    ]],
1648    }
1649    api.nvim_input_mouse('right', 'press', '', 4, 9, 1)
1650    api.nvim_input_mouse('right', 'release', '', 4, 9, 1)
1651    screen:expect {
1652      grid = [[
1653    ## grid 1
1654      [5:------------------------------]│[2:----------------------]|*5
1655      {12:[No Name] [+]                  [No Name] [+]         }|
1656      [4:-----------------------------------------------------]|*6
1657      {11:[No Name] [+]                                        }|
1658      [3:-----------------------------------------------------]|
1659    ## grid 2
1660      some text             |
1661      to be clicked         |
1662      {1:~                     }|*3
1663    ## grid 3
1664      {7:-- VISUAL --}                                         |
1665    ## grid 4
1666      Lorem i|
1667      psum do|
1668      lor sit|
1669       amet, |
1670      consect|
1671      etur ad|
1672      ipiscin|
1673      g elit,|
1674       sed do|
1675       {20:eiusm^o}|
1676    ## grid 5
1677      some text                     |
1678      to be clicked                 |
1679      {1:~                             }|*3
1680    ## grid 6
1681      {21: Copy }|
1682    ]],
1683      float_pos = {
1684        [6] = { -1, 'SW', 4, 9, 0, false, 250, 2, 14, 0 },
1685      },
1686    }
1687    feed('<Down><CR>')
1688    screen:expect {
1689      grid = [[
1690    ## grid 1
1691      [5:------------------------------]│[2:----------------------]|*5
1692      {12:[No Name] [+]                  [No Name] [+]         }|
1693      [4:-----------------------------------------------------]|*6
1694      {11:[No Name] [+]                                        }|
1695      [3:-----------------------------------------------------]|
1696    ## grid 2
1697      some text             |
1698      to be clicked         |
1699      {1:~                     }|*3
1700    ## grid 3
1701                                                           |
1702    ## grid 4
1703      Lorem i|
1704      psum do|
1705      lor sit|
1706       amet, |
1707      consect|
1708      etur ad|
1709      ipiscin|
1710      g elit,|
1711       sed do|
1712       ^eiusmo|
1713    ## grid 5
1714      some text                     |
1715      to be clicked                 |
1716      {1:~                             }|*3
1717    ]],
1718    }
1719    eq('eiusmo', fn.getreg('"'))
1720
1721    screen:try_resize_grid(4, 7, 11)
1722    screen:expect {
1723      grid = [[
1724    ## grid 1
1725      [5:------------------------------]│[2:----------------------]|*5
1726      {12:[No Name] [+]                  [No Name] [+]         }|
1727      [4:-----------------------------------------------------]|*6
1728      {11:[No Name] [+]                                        }|
1729      [3:-----------------------------------------------------]|
1730    ## grid 2
1731      some text             |
1732      to be clicked         |
1733      {1:~                     }|*3
1734    ## grid 3
1735                                                           |
1736    ## grid 4
1737      Lorem i|
1738      psum do|
1739      lor sit|
1740       amet, |
1741      consect|
1742      etur ad|
1743      ipiscin|
1744      g elit,|
1745       sed do|
1746       ^eiusmo|
1747      {1:~      }|
1748    ## grid 5
1749      some text                     |
1750      to be clicked                 |
1751      {1:~                             }|*3
1752    ]],
1753    }
1754
1755    fn.setreg('"', '')
1756    api.nvim_input_mouse('left', 'press', '2', 4, 9, 1)
1757    screen:expect {
1758      grid = [[
1759    ## grid 1
1760      [5:------------------------------]│[2:----------------------]|*5
1761      {12:[No Name] [+]                  [No Name] [+]         }|
1762      [4:-----------------------------------------------------]|*6
1763      {11:[No Name] [+]                                        }|
1764      [3:-----------------------------------------------------]|
1765    ## grid 2
1766      some text             |
1767      to be clicked         |
1768      {1:~                     }|*3
1769    ## grid 3
1770      {7:-- VISUAL --}                                         |
1771    ## grid 4
1772      Lorem i|
1773      psum do|
1774      lor sit|
1775       amet, |
1776      consect|
1777      etur ad|
1778      ipiscin|
1779      g elit,|
1780       sed do|
1781       {20:eiusm^o}|
1782      {1:~      }|
1783    ## grid 5
1784      some text                     |
1785      to be clicked                 |
1786      {1:~                             }|*3
1787    ]],
1788    }
1789    api.nvim_input_mouse('right', 'press', '', 4, 9, 1)
1790    api.nvim_input_mouse('right', 'release', '', 4, 9, 1)
1791    screen:expect {
1792      grid = [[
1793    ## grid 1
1794      [5:------------------------------]│[2:----------------------]|*5
1795      {12:[No Name] [+]                  [No Name] [+]         }|
1796      [4:-----------------------------------------------------]|*6
1797      {11:[No Name] [+]                                        }|
1798      [3:-----------------------------------------------------]|
1799    ## grid 2
1800      some text             |
1801      to be clicked         |
1802      {1:~                     }|*3
1803    ## grid 3
1804      {7:-- VISUAL --}                                         |
1805    ## grid 4
1806      Lorem i|
1807      psum do|
1808      lor sit|
1809       amet, |
1810      consect|
1811      etur ad|
1812      ipiscin|
1813      g elit,|
1814       sed do|
1815       {20:eiusm^o}|
1816      {1:~      }|
1817    ## grid 5
1818      some text                     |
1819      to be clicked                 |
1820      {1:~                             }|*3
1821    ## grid 6
1822      {21: Copy }|
1823    ]],
1824      float_pos = {
1825        [6] = { -1, 'NW', 4, 10, 0, false, 250, 2, 16, 0 },
1826      },
1827    }
1828    feed('<Down><CR>')
1829    screen:expect {
1830      grid = [[
1831    ## grid 1
1832      [5:------------------------------]│[2:----------------------]|*5
1833      {12:[No Name] [+]                  [No Name] [+]         }|
1834      [4:-----------------------------------------------------]|*6
1835      {11:[No Name] [+]                                        }|
1836      [3:-----------------------------------------------------]|
1837    ## grid 2
1838      some text             |
1839      to be clicked         |
1840      {1:~                     }|*3
1841    ## grid 3
1842                                                           |
1843    ## grid 4
1844      Lorem i|
1845      psum do|
1846      lor sit|
1847       amet, |
1848      consect|
1849      etur ad|
1850      ipiscin|
1851      g elit,|
1852       sed do|
1853       ^eiusmo|
1854      {1:~      }|
1855    ## grid 5
1856      some text                     |
1857      to be clicked                 |
1858      {1:~                             }|*3
1859    ]],
1860    }
1861    eq('eiusmo', fn.getreg('"'))
1862  end)
1863
1864  it('supports mouse drag with mouse=a', function()
1865    command('set mouse=a')
1866    command('vsplit')
1867    command('wincmd l')
1868    command('split')
1869    command('enew')
1870    feed('ifoo\nbar<esc>')
1871
1872    api.nvim_input_mouse('left', 'press', '', 5, 0, 0)
1873    poke_eventloop()
1874    api.nvim_input_mouse('left', 'drag', '', 5, 1, 2)
1875
1876    screen:expect {
1877      grid = [[
1878    ## grid 1
1879      [4:--------------------------]│[5:--------------------------]|*6
1880      [4:--------------------------]│{11:[No Name] [+]             }|
1881      [4:--------------------------]│[2:--------------------------]|*5
1882      {12:[No Name]                  [No Name]                 }|
1883      [3:-----------------------------------------------------]|
1884    ## grid 2
1885                                |
1886      {1:~                         }|*4
1887    ## grid 3
1888      {7:-- VISUAL --}                                         |
1889    ## grid 4
1890                                |
1891      {1:~                         }|*11
1892    ## grid 5
1893      {20:foo}                       |
1894      {20:ba^r}                       |
1895      {1:~                         }|*4
1896    ]],
1897    }
1898  end)
1899
1900  it('has viewport information', function()
1901    screen:try_resize(48, 8)
1902    screen:expect {
1903      grid = [[
1904    ## grid 1
1905      [2:------------------------------------------------]|*6
1906      {11:[No Name]                                       }|
1907      [3:------------------------------------------------]|
1908    ## grid 2
1909      ^                                                |
1910      {1:~                                               }|*5
1911    ## grid 3
1912                                                      |
1913    ]],
1914      win_viewport = {
1915        [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
1916      },
1917    }
1918    insert([[
1919      Lorem ipsum dolor sit amet, consectetur
1920      adipisicing elit, sed do eiusmod tempor
1921      incididunt ut labore et dolore magna aliqua.
1922      Ut enim ad minim veniam, quis nostrud
1923      exercitation ullamco laboris nisi ut aliquip ex
1924      ea commodo consequat. Duis aute irure dolor in
1925      reprehenderit in voluptate velit esse cillum
1926      dolore eu fugiat nulla pariatur. Excepteur sint
1927      occaecat cupidatat non proident, sunt in culpa
1928      qui officia deserunt mollit anim id est
1929      laborum.]])
1930
1931    screen:expect {
1932      grid = [[
1933    ## grid 1
1934      [2:------------------------------------------------]|*6
1935      {11:[No Name] [+]                                   }|
1936      [3:------------------------------------------------]|
1937    ## grid 2
1938      ea commodo consequat. Duis aute irure dolor in  |
1939      reprehenderit in voluptate velit esse cillum    |
1940      dolore eu fugiat nulla pariatur. Excepteur sint |
1941      occaecat cupidatat non proident, sunt in culpa  |
1942      qui officia deserunt mollit anim id est         |
1943      laborum^.                                        |
1944    ## grid 3
1945                                                      |
1946    ]],
1947      win_viewport = {
1948        [2] = { win = 1000, topline = 5, botline = 11, curline = 10, curcol = 7, linecount = 11, sum_scroll_delta = 5 },
1949      },
1950    }
1951
1952    feed('<c-u>')
1953    screen:expect {
1954      grid = [[
1955    ## grid 1
1956      [2:------------------------------------------------]|*6
1957      {11:[No Name] [+]                                   }|
1958      [3:------------------------------------------------]|
1959    ## grid 2
1960      incididunt ut labore et dolore magna aliqua.    |
1961      Ut enim ad minim veniam, quis nostrud           |
1962      exercitation ullamco laboris nisi ut aliquip ex |
1963      ea commodo consequat. Duis aute irure dolor in  |
1964      reprehenderit in voluptate velit esse cillum    |
1965      ^dolore eu fugiat nulla pariatur. Excepteur sint |
1966    ## grid 3
1967                                                      |
1968    ]],
1969      win_viewport = {
1970        [2] = { win = 1000, topline = 2, botline = 9, curline = 7, curcol = 0, linecount = 11, sum_scroll_delta = 2 },
1971      },
1972    }
1973
1974    command('split')
1975    screen:expect {
1976      grid = [[
1977    ## grid 1
1978      [4:------------------------------------------------]|*3
1979      {11:[No Name] [+]                                   }|
1980      [2:------------------------------------------------]|*2
1981      {12:[No Name] [+]                                   }|
1982      [3:------------------------------------------------]|
1983    ## grid 2
1984      reprehenderit in voluptate velit esse cillum    |
1985      dolore eu fugiat nulla pariatur. Excepteur sint |
1986    ## grid 3
1987                                                      |
1988    ## grid 4
1989      ea commodo consequat. Duis aute irure dolor in  |
1990      reprehenderit in voluptate velit esse cillum    |
1991      ^dolore eu fugiat nulla pariatur. Excepteur sint |
1992    ]],
1993      win_viewport = {
1994        [2] = { win = 1000, topline = 6, botline = 9, curline = 7, curcol = 0, linecount = 11, sum_scroll_delta = 6 },
1995        [4] = { win = 1001, topline = 5, botline = 9, curline = 7, curcol = 0, linecount = 11, sum_scroll_delta = 5 },
1996      },
1997    }
1998
1999    feed('b')
2000    screen:expect {
2001      grid = [[
2002    ## grid 1
2003      [4:------------------------------------------------]|*3
2004      {11:[No Name] [+]                                   }|
2005      [2:------------------------------------------------]|*2
2006      {12:[No Name] [+]                                   }|
2007      [3:------------------------------------------------]|
2008    ## grid 2
2009      reprehenderit in voluptate velit esse cillum    |
2010      dolore eu fugiat nulla pariatur. Excepteur sint |
2011    ## grid 3
2012                                                      |
2013    ## grid 4
2014      ea commodo consequat. Duis aute irure dolor in  |
2015      reprehenderit in voluptate velit esse ^cillum    |
2016      dolore eu fugiat nulla pariatur. Excepteur sint |
2017    ]],
2018      win_viewport = {
2019        [2] = { win = 1000, topline = 6, botline = 9, curline = 7, curcol = 0, linecount = 11, sum_scroll_delta = 6 },
2020        [4] = { win = 1001, topline = 5, botline = 9, curline = 6, curcol = 38, linecount = 11, sum_scroll_delta = 5 },
2021      },
2022    }
2023
2024    feed('2k')
2025    screen:expect {
2026      grid = [[
2027    ## grid 1
2028      [4:------------------------------------------------]|*3
2029      {11:[No Name] [+]                                   }|
2030      [2:------------------------------------------------]|*2
2031      {12:[No Name] [+]                                   }|
2032      [3:------------------------------------------------]|
2033    ## grid 2
2034      reprehenderit in voluptate velit esse cillum    |
2035      dolore eu fugiat nulla pariatur. Excepteur sint |
2036    ## grid 3
2037                                                      |
2038    ## grid 4
2039      exercitation ullamco laboris nisi ut a^liquip ex |
2040      ea commodo consequat. Duis aute irure dolor in  |
2041      reprehenderit in voluptate velit esse cillum    |
2042    ]],
2043      win_viewport = {
2044        [2] = { win = 1000, topline = 6, botline = 9, curline = 7, curcol = 0, linecount = 11, sum_scroll_delta = 6 },
2045        [4] = { win = 1001, topline = 4, botline = 8, curline = 4, curcol = 38, linecount = 11, sum_scroll_delta = 4 },
2046      },
2047    }
2048
2049    -- handles non-current window
2050    api.nvim_win_set_cursor(1000, { 1, 10 })
2051    screen:expect {
2052      grid = [[
2053    ## grid 1
2054      [4:------------------------------------------------]|*3
2055      {11:[No Name] [+]                                   }|
2056      [2:------------------------------------------------]|*2
2057      {12:[No Name] [+]                                   }|
2058      [3:------------------------------------------------]|
2059    ## grid 2
2060      Lorem ipsum dolor sit amet, consectetur         |
2061      adipisicing elit, sed do eiusmod tempor         |
2062    ## grid 3
2063                                                      |
2064    ## grid 4
2065      exercitation ullamco laboris nisi ut a^liquip ex |
2066      ea commodo consequat. Duis aute irure dolor in  |
2067      reprehenderit in voluptate velit esse cillum    |
2068    ]],
2069      win_viewport = {
2070        [2] = { win = 1000, topline = 0, botline = 3, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0 },
2071        [4] = { win = 1001, topline = 4, botline = 8, curline = 4, curcol = 38, linecount = 11, sum_scroll_delta = 4 },
2072      },
2073    }
2074
2075    -- sum_scroll_delta works with folds
2076    feed('zfj')
2077    screen:expect {
2078      grid = [[
2079    ## grid 1
2080      [4:------------------------------------------------]|*3
2081      {11:[No Name] [+]                                   }|
2082      [2:------------------------------------------------]|*2
2083      {12:[No Name] [+]                                   }|
2084      [3:------------------------------------------------]|
2085    ## grid 2
2086      Lorem ipsum dolor sit amet, consectetur         |
2087      adipisicing elit, sed do eiusmod tempor         |
2088    ## grid 3
2089                                                      |
2090    ## grid 4
2091      {13:^+--  2 lines: exercitation ullamco laboris nisi }|
2092      reprehenderit in voluptate velit esse cillum    |
2093      dolore eu fugiat nulla pariatur. Excepteur sint |
2094    ]],
2095      win_viewport = {
2096        [2] = { win = 1000, topline = 0, botline = 3, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0 },
2097        [4] = { win = 1001, topline = 4, botline = 9, curline = 4, curcol = 38, linecount = 11, sum_scroll_delta = 4 },
2098      },
2099    }
2100
2101    feed('<c-e>')
2102    screen:expect {
2103      grid = [[
2104    ## grid 1
2105      [4:------------------------------------------------]|*3
2106      {11:[No Name] [+]                                   }|
2107      [2:------------------------------------------------]|*2
2108      {12:[No Name] [+]                                   }|
2109      [3:------------------------------------------------]|
2110    ## grid 2
2111      Lorem ipsum dolor sit amet, consectetur         |
2112      adipisicing elit, sed do eiusmod tempor         |
2113    ## grid 3
2114                                                      |
2115    ## grid 4
2116      ^reprehenderit in voluptate velit esse cillum    |
2117      dolore eu fugiat nulla pariatur. Excepteur sint |
2118      occaecat cupidatat non proident, sunt in culpa  |
2119    ]],
2120      win_viewport = {
2121        [2] = { win = 1000, topline = 0, botline = 3, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0 },
2122        [4] = { win = 1001, topline = 6, botline = 10, curline = 6, curcol = 0, linecount = 11, sum_scroll_delta = 5 },
2123      },
2124    }
2125
2126    command('close | 21vsplit | setlocal number smoothscroll')
2127    screen:expect {
2128      grid = [[
2129    ## grid 1
2130      [5:---------------------]│[2:--------------------------]|*6
2131      {11:[No Name] [+]         }{12:[No Name] [+]             }|
2132      [3:------------------------------------------------]|
2133    ## grid 2
2134      Lorem ipsum dolor sit amet|
2135      , consectetur             |
2136      adipisicing elit, sed do e|
2137      iusmod tempor             |
2138      incididunt ut labore et do|
2139      lore magna aliqua.        |
2140    ## grid 3
2141                                                      |
2142    ## grid 5
2143      {19:  1 }Lorem ipsu^m dolor|
2144      {19:    } sit amet, consec|
2145      {19:    }tetur            |
2146      {19:  2 }adipisicing elit,|
2147      {19:    } sed do eiusmod t|
2148      {19:    }empor            |
2149    ]],
2150      win_viewport = {
2151        [2] = { win = 1000, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0 },
2152        [5] = { win = 1002, topline = 0, botline = 3, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0 },
2153      },
2154    }
2155
2156    feed('5<C-E>')
2157    screen:expect {
2158      grid = [[
2159    ## grid 1
2160      [5:---------------------]│[2:--------------------------]|*6
2161      {11:[No Name] [+]         }{12:[No Name] [+]             }|
2162      [3:------------------------------------------------]|
2163    ## grid 2
2164      Lorem ipsum dolor sit amet|
2165      , consectetur             |
2166      adipisicing elit, sed do e|
2167      iusmod tempor             |
2168      incididunt ut labore et do|
2169      lore magna aliqua.        |
2170    ## grid 3
2171                                                      |
2172    ## grid 5
2173      {1:<<<}{19: }empo^r            |
2174      {19:  3 }incididunt ut lab|
2175      {19:    }ore et dolore mag|
2176      {19:    }na aliqua.       |
2177      {19:  4 }Ut enim ad minim |
2178      {19:    }veniam, quis n{1:@@@}|
2179    ]],
2180      win_viewport = {
2181        [2] = { win = 1000, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0 },
2182        [5] = { win = 1002, topline = 1, botline = 4, curline = 1, curcol = 38, linecount = 11, sum_scroll_delta = 5 },
2183      },
2184    }
2185
2186    feed('<C-Y>')
2187    screen:expect {
2188      grid = [[
2189    ## grid 1
2190      [5:---------------------]│[2:--------------------------]|*6
2191      {11:[No Name] [+]         }{12:[No Name] [+]             }|
2192      [3:------------------------------------------------]|
2193    ## grid 2
2194      Lorem ipsum dolor sit amet|
2195      , consectetur             |
2196      adipisicing elit, sed do e|
2197      iusmod tempor             |
2198      incididunt ut labore et do|
2199      lore magna aliqua.        |
2200    ## grid 3
2201                                                      |
2202    ## grid 5
2203      {1:<<<}{19: } sed do eiusmod t|
2204      {19:    }empo^r            |
2205      {19:  3 }incididunt ut lab|
2206      {19:    }ore et dolore mag|
2207      {19:    }na aliqua.       |
2208      {19:  4 }Ut enim ad min{1:@@@}|
2209    ]],
2210      win_viewport = {
2211        [2] = { win = 1000, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0 },
2212        [5] = { win = 1002, topline = 1, botline = 4, curline = 1, curcol = 38, linecount = 11, sum_scroll_delta = 4 },
2213      },
2214    }
2215
2216    command('set cpoptions+=n')
2217    screen:expect {
2218      grid = [[
2219    ## grid 1
2220      [5:---------------------]│[2:--------------------------]|*6
2221      {11:[No Name] [+]         }{12:[No Name] [+]             }|
2222      [3:------------------------------------------------]|
2223    ## grid 2
2224      Lorem ipsum dolor sit amet|
2225      , consectetur             |
2226      adipisicing elit, sed do e|
2227      iusmod tempor             |
2228      incididunt ut labore et do|
2229      lore magna aliqua.        |
2230    ## grid 3
2231                                                      |
2232    ## grid 5
2233      {1:<<<}d do eiusmod tempo|
2234      ^r                    |
2235      {19:  3 }incididunt ut lab|
2236      ore et dolore magna a|
2237      liqua.               |
2238      {19:  4 }Ut enim ad min{1:@@@}|
2239    ]],
2240      win_viewport = {
2241        [2] = { win = 1000, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0 },
2242        [5] = { win = 1002, topline = 1, botline = 4, curline = 1, curcol = 38, linecount = 11, sum_scroll_delta = 4 },
2243      },
2244    }
2245
2246    feed('4<C-E>')
2247    screen:expect {
2248      grid = [[
2249    ## grid 1
2250      [5:---------------------]│[2:--------------------------]|*6
2251      {11:[No Name] [+]         }{12:[No Name] [+]             }|
2252      [3:------------------------------------------------]|
2253    ## grid 2
2254      Lorem ipsum dolor sit amet|
2255      , consectetur             |
2256      adipisicing elit, sed do e|
2257      iusmod tempor             |
2258      incididunt ut labore et do|
2259      lore magna aliqua.        |
2260    ## grid 3
2261                                                      |
2262    ## grid 5
2263      {1:<<<}ua^.               |
2264      {19:  4 }Ut enim ad minim |
2265      veniam, quis nostrud |
2266      {19:  5 }exercitation ulla|
2267      mco laboris nisi ut a|
2268      liquip ex            |
2269    ]],
2270      win_viewport = {
2271        [2] = { win = 1000, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0 },
2272        [5] = { win = 1002, topline = 2, botline = 6, curline = 2, curcol = 43, linecount = 11, sum_scroll_delta = 8 },
2273      },
2274    }
2275
2276    feed('2<C-Y>')
2277    screen:expect {
2278      grid = [[
2279    ## grid 1
2280      [5:---------------------]│[2:--------------------------]|*6
2281      {11:[No Name] [+]         }{12:[No Name] [+]             }|
2282      [3:------------------------------------------------]|
2283    ## grid 2
2284      Lorem ipsum dolor sit amet|
2285      , consectetur             |
2286      adipisicing elit, sed do e|
2287      iusmod tempor             |
2288      incididunt ut labore et do|
2289      lore magna aliqua.        |
2290    ## grid 3
2291                                                      |
2292    ## grid 5
2293      {19:  3 }incididunt ut lab|
2294      ore et dolore magna a|
2295      liqua^.               |
2296      {19:  4 }Ut enim ad minim |
2297      veniam, quis nostrud |
2298      {19:  5 }exercitation u{1:@@@}|
2299    ]],
2300      win_viewport = {
2301        [2] = { win = 1000, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0 },
2302        [5] = { win = 1002, topline = 2, botline = 5, curline = 2, curcol = 43, linecount = 11, sum_scroll_delta = 6 },
2303      },
2304    }
2305
2306    command('setlocal numberwidth=12')
2307    screen:expect {
2308      grid = [[
2309    ## grid 1
2310      [5:---------------------]│[2:--------------------------]|*6
2311      {11:[No Name] [+]         }{12:[No Name] [+]             }|
2312      [3:------------------------------------------------]|
2313    ## grid 2
2314      Lorem ipsum dolor sit amet|
2315      , consectetur             |
2316      adipisicing elit, sed do e|
2317      iusmod tempor             |
2318      incididunt ut labore et do|
2319      lore magna aliqua.        |
2320    ## grid 3
2321                                                      |
2322    ## grid 5
2323      {19:          3 }incididun|
2324      t ut labore et dolore|
2325       magna aliqua^.       |
2326      {19:          4 }Ut enim a|
2327      d minim veniam, quis |
2328      nostrud              |
2329    ]],
2330      win_viewport = {
2331        [2] = { win = 1000, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0 },
2332        [5] = { win = 1002, topline = 2, botline = 5, curline = 2, curcol = 43, linecount = 11, sum_scroll_delta = 6 },
2333      },
2334    }
2335
2336    feed('2<C-E>')
2337    screen:expect {
2338      grid = [[
2339    ## grid 1
2340      [5:---------------------]│[2:--------------------------]|*6
2341      {11:[No Name] [+]         }{12:[No Name] [+]             }|
2342      [3:------------------------------------------------]|
2343    ## grid 2
2344      Lorem ipsum dolor sit amet|
2345      , consectetur             |
2346      adipisicing elit, sed do e|
2347      iusmod tempor             |
2348      incididunt ut labore et do|
2349      lore magna aliqua.        |
2350    ## grid 3
2351                                                      |
2352    ## grid 5
2353      {1:<<<}gna aliqua^.       |
2354      {19:          4 }Ut enim a|
2355      d minim veniam, quis |
2356      nostrud              |
2357      {19:          5 }exercitat|
2358      ion ullamco labori{1:@@@}|
2359    ]],
2360      win_viewport = {
2361        [2] = { win = 1000, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0 },
2362        [5] = { win = 1002, topline = 2, botline = 5, curline = 2, curcol = 43, linecount = 11, sum_scroll_delta = 8 },
2363      },
2364    }
2365
2366    feed('<C-E>')
2367    screen:expect {
2368      grid = [[
2369    ## grid 1
2370      [5:---------------------]│[2:--------------------------]|*6
2371      {11:[No Name] [+]         }{12:[No Name] [+]             }|
2372      [3:------------------------------------------------]|
2373    ## grid 2
2374      Lorem ipsum dolor sit amet|
2375      , consectetur             |
2376      adipisicing elit, sed do e|
2377      iusmod tempor             |
2378      incididunt ut labore et do|
2379      lore magna aliqua.        |
2380    ## grid 3
2381                                                      |
2382    ## grid 5
2383      {19:          4 }Ut enim a|
2384      d minim veniam, quis |
2385      nostru^d              |
2386      {19:          5 }exercitat|
2387      ion ullamco laboris n|
2388      isi ut aliquip ex    |
2389    ]],
2390      win_viewport = {
2391        [2] = { win = 1000, topline = 0, botline = 4, curline = 0, curcol = 10, linecount = 11, sum_scroll_delta = 0 },
2392        [5] = { win = 1002, topline = 3, botline = 6, curline = 3, curcol = 36, linecount = 11, sum_scroll_delta = 9 },
2393      },
2394    }
2395  end)
2396
2397  it('scroll_delta is approximated reasonably when scrolling many lines #24234', function()
2398    command('setlocal number nowrap')
2399    command('edit test/functional/fixtures/bigfile.txt')
2400    screen:expect {
2401      grid = [[
2402    ## grid 1
2403      [2:-----------------------------------------------------]|*12
2404      {11:test/functional/fixtures/bigfile.txt                 }|
2405      [3:-----------------------------------------------------]|
2406    ## grid 2
2407      {19:    1 }^0000;<control>;Cc;0;BN;;;;;N;NULL;;;;          |
2408      {19:    2 }0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;|
2409      {19:    3 }0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; |
2410      {19:    4 }0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;;   |
2411      {19:    5 }0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSIO|
2412      {19:    6 }0005;<control>;Cc;0;BN;;;;;N;ENQUIRY;;;;       |
2413      {19:    7 }0006;<control>;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;;   |
2414      {19:    8 }0007;<control>;Cc;0;BN;;;;;N;BELL;;;;          |
2415      {19:    9 }0008;<control>;Cc;0;BN;;;;;N;BACKSPACE;;;;     |
2416      {19:   10 }0009;<control>;Cc;0;S;;;;;N;CHARACTER TABULATIO|
2417      {19:   11 }000A;<control>;Cc;0;B;;;;;N;LINE FEED (LF);;;; |
2418      {19:   12 }000B;<control>;Cc;0;S;;;;;N;LINE TABULATION;;;;|
2419    ## grid 3
2420                                                           |
2421    ]],
2422      win_viewport = {
2423        [2] = {
2424          win = 1000,
2425          topline = 0,
2426          botline = 13,
2427          curline = 0,
2428          curcol = 0,
2429          linecount = 30592,
2430          sum_scroll_delta = 0,
2431        },
2432      },
2433    }
2434    feed('G')
2435    screen:expect {
2436      grid = [[
2437    ## grid 1
2438      [2:-----------------------------------------------------]|*12
2439      {11:test/functional/fixtures/bigfile.txt                 }|
2440      [3:-----------------------------------------------------]|
2441    ## grid 2
2442      {19:30581 }E01E8;VARIATION SELECTOR-249;Mn;0;NSM;;;;;N;;;;|
2443      {19:30582 }E01E9;VARIATION SELECTOR-250;Mn;0;NSM;;;;;N;;;;|
2444      {19:30583 }E01EA;VARIATION SELECTOR-251;Mn;0;NSM;;;;;N;;;;|
2445      {19:30584 }E01EB;VARIATION SELECTOR-252;Mn;0;NSM;;;;;N;;;;|
2446      {19:30585 }E01EC;VARIATION SELECTOR-253;Mn;0;NSM;;;;;N;;;;|
2447      {19:30586 }E01ED;VARIATION SELECTOR-254;Mn;0;NSM;;;;;N;;;;|
2448      {19:30587 }E01EE;VARIATION SELECTOR-255;Mn;0;NSM;;;;;N;;;;|
2449      {19:30588 }E01EF;VARIATION SELECTOR-256;Mn;0;NSM;;;;;N;;;;|
2450      {19:30589 }F0000;<Plane 15 Private Use, First>;Co;0;L;;;;;|
2451      {19:30590 }FFFFD;<Plane 15 Private Use, Last>;Co;0;L;;;;;N|
2452      {19:30591 }100000;<Plane 16 Private Use, First>;Co;0;L;;;;|
2453      {19:30592 }^10FFFD;<Plane 16 Private Use, Last>;Co;0;L;;;;;|
2454    ## grid 3
2455                                                           |
2456    ]],
2457      win_viewport = {
2458        [2] = {
2459          win = 1000,
2460          topline = 30580,
2461          botline = 30592,
2462          curline = 30591,
2463          curcol = 0,
2464          linecount = 30592,
2465          sum_scroll_delta = 30580,
2466        },
2467      },
2468    }
2469    feed('gg')
2470    screen:expect {
2471      grid = [[
2472    ## grid 1
2473      [2:-----------------------------------------------------]|*12
2474      {11:test/functional/fixtures/bigfile.txt                 }|
2475      [3:-----------------------------------------------------]|
2476    ## grid 2
2477      {19:    1 }^0000;<control>;Cc;0;BN;;;;;N;NULL;;;;          |
2478      {19:    2 }0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;|
2479      {19:    3 }0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; |
2480      {19:    4 }0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;;   |
2481      {19:    5 }0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSIO|
2482      {19:    6 }0005;<control>;Cc;0;BN;;;;;N;ENQUIRY;;;;       |
2483      {19:    7 }0006;<control>;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;;   |
2484      {19:    8 }0007;<control>;Cc;0;BN;;;;;N;BELL;;;;          |
2485      {19:    9 }0008;<control>;Cc;0;BN;;;;;N;BACKSPACE;;;;     |
2486      {19:   10 }0009;<control>;Cc;0;S;;;;;N;CHARACTER TABULATIO|
2487      {19:   11 }000A;<control>;Cc;0;B;;;;;N;LINE FEED (LF);;;; |
2488      {19:   12 }000B;<control>;Cc;0;S;;;;;N;LINE TABULATION;;;;|
2489    ## grid 3
2490                                                           |
2491    ]],
2492      win_viewport = {
2493        [2] = {
2494          win = 1000,
2495          topline = 0,
2496          botline = 13,
2497          curline = 0,
2498          curcol = 0,
2499          linecount = 30592,
2500          sum_scroll_delta = 0,
2501        },
2502      },
2503    }
2504    command('setlocal wrap')
2505    screen:expect {
2506      grid = [[
2507    ## grid 1
2508      [2:-----------------------------------------------------]|*12
2509      {11:test/functional/fixtures/bigfile.txt                 }|
2510      [3:-----------------------------------------------------]|
2511    ## grid 2
2512      {19:    1 }^0000;<control>;Cc;0;BN;;;;;N;NULL;;;;          |
2513      {19:    2 }0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;|
2514      {19:      };;                                             |
2515      {19:    3 }0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; |
2516      {19:    4 }0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;;   |
2517      {19:    5 }0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSIO|
2518      {19:      }N;;;;                                          |
2519      {19:    6 }0005;<control>;Cc;0;BN;;;;;N;ENQUIRY;;;;       |
2520      {19:    7 }0006;<control>;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;;   |
2521      {19:    8 }0007;<control>;Cc;0;BN;;;;;N;BELL;;;;          |
2522      {19:    9 }0008;<control>;Cc;0;BN;;;;;N;BACKSPACE;;;;     |
2523      {19:   10 }0009;<control>;Cc;0;S;;;;;N;CHARACTER TABULA{1:@@@}|
2524    ## grid 3
2525                                                           |
2526    ]],
2527      win_viewport = {
2528        [2] = {
2529          win = 1000,
2530          topline = 0,
2531          botline = 10,
2532          curline = 0,
2533          curcol = 0,
2534          linecount = 30592,
2535          sum_scroll_delta = 0,
2536        },
2537      },
2538    }
2539    feed('G')
2540    screen:expect {
2541      grid = [[
2542    ## grid 1
2543      [2:-----------------------------------------------------]|*12
2544      {11:test/functional/fixtures/bigfile.txt                 }|
2545      [3:-----------------------------------------------------]|
2546    ## grid 2
2547      {19:30587 }E01EE;VARIATION SELECTOR-255;Mn;0;NSM;;;;;N;;;;|
2548      {19:      };                                              |
2549      {19:30588 }E01EF;VARIATION SELECTOR-256;Mn;0;NSM;;;;;N;;;;|
2550      {19:      };                                              |
2551      {19:30589 }F0000;<Plane 15 Private Use, First>;Co;0;L;;;;;|
2552      {19:      }N;;;;;                                         |
2553      {19:30590 }FFFFD;<Plane 15 Private Use, Last>;Co;0;L;;;;;N|
2554      {19:      };;;;;                                          |
2555      {19:30591 }100000;<Plane 16 Private Use, First>;Co;0;L;;;;|
2556      {19:      };N;;;;;                                        |
2557      {19:30592 }^10FFFD;<Plane 16 Private Use, Last>;Co;0;L;;;;;|
2558      {19:      }N;;;;;                                         |
2559    ## grid 3
2560                                                           |
2561    ]],
2562      win_viewport = {
2563        [2] = {
2564          win = 1000,
2565          topline = 30586,
2566          botline = 30592,
2567          curline = 30591,
2568          curcol = 0,
2569          linecount = 30592,
2570          sum_scroll_delta = 30588,
2571        },
2572      },
2573    }
2574    feed('gg')
2575    screen:expect {
2576      grid = [[
2577    ## grid 1
2578      [2:-----------------------------------------------------]|*12
2579      {11:test/functional/fixtures/bigfile.txt                 }|
2580      [3:-----------------------------------------------------]|
2581    ## grid 2
2582      {19:    1 }^0000;<control>;Cc;0;BN;;;;;N;NULL;;;;          |
2583      {19:    2 }0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;|
2584      {19:      };;                                             |
2585      {19:    3 }0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; |
2586      {19:    4 }0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;;   |
2587      {19:    5 }0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSIO|
2588      {19:      }N;;;;                                          |
2589      {19:    6 }0005;<control>;Cc;0;BN;;;;;N;ENQUIRY;;;;       |
2590      {19:    7 }0006;<control>;Cc;0;BN;;;;;N;ACKNOWLEDGE;;;;   |
2591      {19:    8 }0007;<control>;Cc;0;BN;;;;;N;BELL;;;;          |
2592      {19:    9 }0008;<control>;Cc;0;BN;;;;;N;BACKSPACE;;;;     |
2593      {19:   10 }0009;<control>;Cc;0;S;;;;;N;CHARACTER TABULA{1:@@@}|
2594    ## grid 3
2595                                                           |
2596    ]],
2597      win_viewport = {
2598        [2] = {
2599          win = 1000,
2600          topline = 0,
2601          botline = 10,
2602          curline = 0,
2603          curcol = 0,
2604          linecount = 30592,
2605          sum_scroll_delta = 0,
2606        },
2607      },
2608    }
2609  end)
2610
2611  it('does not crash when dragging mouse across grid boundary', function()
2612    screen:try_resize(48, 8)
2613    screen:expect {
2614      grid = [[
2615    ## grid 1
2616      [2:------------------------------------------------]|*6
2617      {11:[No Name]                                       }|
2618      [3:------------------------------------------------]|
2619    ## grid 2
2620      ^                                                |
2621      {1:~                                               }|*5
2622    ## grid 3
2623                                                      |
2624    ]],
2625      win_viewport = {
2626        [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2627      },
2628    }
2629    insert([[
2630      Lorem ipsum dolor sit amet, consectetur
2631      adipisicing elit, sed do eiusmod tempor
2632      incididunt ut labore et dolore magna aliqua.
2633      Ut enim ad minim veniam, quis nostrud
2634      exercitation ullamco laboris nisi ut aliquip ex
2635      ea commodo consequat. Duis aute irure dolor in
2636      reprehenderit in voluptate velit esse cillum
2637      dolore eu fugiat nulla pariatur. Excepteur sint
2638      occaecat cupidatat non proident, sunt in culpa
2639      qui officia deserunt mollit anim id est
2640      laborum.]])
2641
2642    screen:expect {
2643      grid = [[
2644    ## grid 1
2645      [2:------------------------------------------------]|*6
2646      {11:[No Name] [+]                                   }|
2647      [3:------------------------------------------------]|
2648    ## grid 2
2649      ea commodo consequat. Duis aute irure dolor in  |
2650      reprehenderit in voluptate velit esse cillum    |
2651      dolore eu fugiat nulla pariatur. Excepteur sint |
2652      occaecat cupidatat non proident, sunt in culpa  |
2653      qui officia deserunt mollit anim id est         |
2654      laborum^.                                        |
2655    ## grid 3
2656                                                      |
2657    ]],
2658      win_viewport = {
2659        [2] = { win = 1000, topline = 5, botline = 11, curline = 10, curcol = 7, linecount = 11, sum_scroll_delta = 5 },
2660      },
2661    }
2662
2663    api.nvim_input_mouse('left', 'press', '', 1, 5, 1)
2664    poke_eventloop()
2665    api.nvim_input_mouse('left', 'drag', '', 1, 6, 1)
2666
2667    screen:expect {
2668      grid = [[
2669    ## grid 1
2670      [2:------------------------------------------------]|*6
2671      {11:[No Name] [+]                                   }|
2672      [3:------------------------------------------------]|
2673    ## grid 2
2674      reprehenderit in voluptate velit esse cillum    |
2675      dolore eu fugiat nulla pariatur. Excepteur sint |
2676      occaecat cupidatat non proident, sunt in culpa  |
2677      qui officia deserunt mollit anim id est         |
2678      l{20:^a}borum.                                        |
2679      {1:~                                               }|
2680    ## grid 3
2681      {7:-- VISUAL --}                                    |
2682    ]],
2683      win_viewport = {
2684        [2] = { win = 1000, topline = 6, botline = 12, curline = 10, curcol = 1, linecount = 11, sum_scroll_delta = 6 },
2685      },
2686    }
2687  end)
2688
2689  it('with winbar', function()
2690    command('split')
2691    local win_pos = {
2692      [2] = {
2693        height = 5,
2694        startcol = 0,
2695        startrow = 7,
2696        width = 53,
2697        win = 1000,
2698      },
2699      [4] = {
2700        height = 6,
2701        startcol = 0,
2702        startrow = 0,
2703        width = 53,
2704        win = 1001,
2705      },
2706    }
2707    screen:expect {
2708      grid = [[
2709    ## grid 1
2710      [4:-----------------------------------------------------]|*6
2711      {11:[No Name]                                            }|
2712      [2:-----------------------------------------------------]|*5
2713      {12:[No Name]                                            }|
2714      [3:-----------------------------------------------------]|
2715    ## grid 2
2716                                                           |
2717      {1:~                                                    }|*4
2718    ## grid 3
2719                                                           |
2720    ## grid 4
2721      ^                                                     |
2722      {1:~                                                    }|*5
2723    ]],
2724      win_viewport = {
2725        [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2726        [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2727      },
2728      win_viewport_margins = {
2729        [2] = { win = 1000, top = 0, bottom = 0, left = 0, right = 0 },
2730        [4] = { win = 1001, top = 0, bottom = 0, left = 0, right = 0 },
2731      },
2732      win_pos = win_pos,
2733    }
2734
2735    command('setlocal winbar=very%=bar')
2736    screen:expect {
2737      grid = [[
2738    ## grid 1
2739      [4:-----------------------------------------------------]|*6
2740      {11:[No Name]                                            }|
2741      [2:-----------------------------------------------------]|*5
2742      {12:[No Name]                                            }|
2743      [3:-----------------------------------------------------]|
2744    ## grid 2
2745                                                           |
2746      {1:~                                                    }|*4
2747    ## grid 3
2748                                                           |
2749    ## grid 4
2750      {7:very                                              bar}|
2751      ^                                                     |
2752      {1:~                                                    }|*4
2753    ]],
2754      win_viewport = {
2755        [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2756        [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2757      },
2758      win_viewport_margins = {
2759        [2] = { win = 1000, top = 0, bottom = 0, left = 0, right = 0 },
2760        [4] = { win = 1001, top = 1, bottom = 0, left = 0, right = 0 },
2761      },
2762      win_pos = win_pos,
2763    }
2764
2765    command('setlocal winbar=')
2766    screen:expect {
2767      grid = [[
2768    ## grid 1
2769      [4:-----------------------------------------------------]|*6
2770      {11:[No Name]                                            }|
2771      [2:-----------------------------------------------------]|*5
2772      {12:[No Name]                                            }|
2773      [3:-----------------------------------------------------]|
2774    ## grid 2
2775                                                           |
2776      {1:~                                                    }|*4
2777    ## grid 3
2778                                                           |
2779    ## grid 4
2780      ^                                                     |
2781      {1:~                                                    }|*5
2782    ]],
2783      win_viewport = {
2784        [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2785        [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2786      },
2787      win_viewport_margins = {
2788        [2] = { win = 1000, top = 0, bottom = 0, left = 0, right = 0 },
2789        [4] = { win = 1001, top = 0, bottom = 0, left = 0, right = 0 },
2790      },
2791      win_pos = win_pos,
2792    }
2793  end)
2794
2795  it('with winbar dragging statusline with mouse works correctly', function()
2796    api.nvim_set_option_value('winbar', 'Set Up The Bars', {})
2797    command('split')
2798    screen:expect([[
2799    ## grid 1
2800      [4:-----------------------------------------------------]|*6
2801      {11:[No Name]                                            }|
2802      [2:-----------------------------------------------------]|*5
2803      {12:[No Name]                                            }|
2804      [3:-----------------------------------------------------]|
2805    ## grid 2
2806      {7:Set Up The Bars                                      }|
2807                                                           |
2808      {1:~                                                    }|*3
2809    ## grid 3
2810                                                           |
2811    ## grid 4
2812      {7:Set Up The Bars                                      }|
2813      ^                                                     |
2814      {1:~                                                    }|*4
2815    ]])
2816
2817    api.nvim_input_mouse('left', 'press', '', 1, 6, 20)
2818    poke_eventloop()
2819    api.nvim_input_mouse('left', 'drag', '', 1, 7, 20)
2820    screen:expect([[
2821    ## grid 1
2822      [4:-----------------------------------------------------]|*7
2823      {11:[No Name]                                            }|
2824      [2:-----------------------------------------------------]|*4
2825      {12:[No Name]                                            }|
2826      [3:-----------------------------------------------------]|
2827    ## grid 2
2828      {7:Set Up The Bars                                      }|
2829                                                           |
2830      {1:~                                                    }|*2
2831    ## grid 3
2832                                                           |
2833    ## grid 4
2834      {7:Set Up The Bars                                      }|
2835      ^                                                     |
2836      {1:~                                                    }|*5
2837    ]])
2838
2839    api.nvim_input_mouse('left', 'drag', '', 1, 4, 20)
2840    screen:expect([[
2841    ## grid 1
2842      [4:-----------------------------------------------------]|*4
2843      {11:[No Name]                                            }|
2844      [2:-----------------------------------------------------]|*7
2845      {12:[No Name]                                            }|
2846      [3:-----------------------------------------------------]|
2847    ## grid 2
2848      {7:Set Up The Bars                                      }|
2849                                                           |
2850      {1:~                                                    }|*5
2851    ## grid 3
2852                                                           |
2853    ## grid 4
2854      {7:Set Up The Bars                                      }|
2855      ^                                                     |
2856      {1:~                                                    }|*2
2857    ]])
2858
2859    api.nvim_input_mouse('left', 'press', '', 1, 12, 10)
2860    poke_eventloop()
2861    api.nvim_input_mouse('left', 'drag', '', 1, 10, 10)
2862    screen:expect([[
2863    ## grid 1
2864      [4:-----------------------------------------------------]|*4
2865      {11:[No Name]                                            }|
2866      [2:-----------------------------------------------------]|*5
2867      {12:[No Name]                                            }|
2868      [3:-----------------------------------------------------]|*3
2869    ## grid 2
2870      {7:Set Up The Bars                                      }|
2871                                                           |
2872      {1:~                                                    }|*3
2873    ## grid 3
2874                                                           |*3
2875    ## grid 4
2876      {7:Set Up The Bars                                      }|
2877      ^                                                     |
2878      {1:~                                                    }|*2
2879    ]])
2880    eq(3, api.nvim_get_option_value('cmdheight', {}))
2881
2882    api.nvim_input_mouse('left', 'drag', '', 1, 12, 10)
2883    screen:expect([[
2884    ## grid 1
2885      [4:-----------------------------------------------------]|*4
2886      {11:[No Name]                                            }|
2887      [2:-----------------------------------------------------]|*7
2888      {12:[No Name]                                            }|
2889      [3:-----------------------------------------------------]|
2890    ## grid 2
2891      {7:Set Up The Bars                                      }|
2892                                                           |
2893      {1:~                                                    }|*5
2894    ## grid 3
2895                                                           |
2896    ## grid 4
2897      {7:Set Up The Bars                                      }|
2898      ^                                                     |
2899      {1:~                                                    }|*2
2900    ]])
2901    eq(1, api.nvim_get_option_value('cmdheight', {}))
2902  end)
2903
2904  describe('centered cursorline', function()
2905    before_each(function()
2906      -- Force a centered cursorline, this caused some redrawing problems described in #30576.
2907      -- Most importantly, win_viewport was not received in time, and sum_scroll_delta did not refresh.
2908      command('set cursorline scrolloff=9999')
2909    end)
2910    it('insert line scrolls correctly', function()
2911      for i = 1, 11 do
2912        insert('line' .. i .. '\n')
2913      end
2914      screen:expect({
2915        grid = [[
2916        ## grid 1
2917          [2:-----------------------------------------------------]|*12
2918          {11:[No Name] [+]                                        }|
2919          [3:-----------------------------------------------------]|
2920        ## grid 2
2921          line1                                                |
2922          line2                                                |
2923          line3                                                |
2924          line4                                                |
2925          line5                                                |
2926          line6                                                |
2927          line7                                                |
2928          line8                                                |
2929          line9                                                |
2930          line10                                               |
2931          line11                                               |
2932          {23:^                                                     }|
2933        ## grid 3
2934                                                               |
2935        ]],
2936        win_viewport = {
2937          [2] = {
2938            win = 1000,
2939            topline = 0,
2940            botline = 12,
2941            curline = 11,
2942            curcol = 0,
2943            linecount = 12,
2944            sum_scroll_delta = 0,
2945          },
2946        },
2947        win_viewport_margins = {
2948          [2] = {
2949            bottom = 0,
2950            left = 0,
2951            right = 0,
2952            top = 0,
2953            win = 1000,
2954          },
2955        },
2956      })
2957      insert('line12\n')
2958      screen:expect({
2959        grid = [[
2960        ## grid 1
2961          [2:-----------------------------------------------------]|*12
2962          {11:[No Name] [+]                                        }|
2963          [3:-----------------------------------------------------]|
2964        ## grid 2
2965          line2                                                |
2966          line3                                                |
2967          line4                                                |
2968          line5                                                |
2969          line6                                                |
2970          line7                                                |
2971          line8                                                |
2972          line9                                                |
2973          line10                                               |
2974          line11                                               |
2975          line12                                               |
2976          {23:^                                                     }|
2977        ## grid 3
2978                                                               |
2979        ]],
2980        win_viewport = {
2981          [2] = {
2982            win = 1000,
2983            topline = 1,
2984            botline = 13,
2985            curline = 12,
2986            curcol = 0,
2987            linecount = 13,
2988            sum_scroll_delta = 1,
2989          },
2990        },
2991        win_viewport_margins = {
2992          [2] = {
2993            bottom = 0,
2994            left = 0,
2995            right = 0,
2996            top = 0,
2997            win = 1000,
2998          },
2999        },
3000      })
3001    end)
3002
3003    it('got to top scrolls correctly', function()
3004      for i = 1, 20 do
3005        insert('line' .. i .. '\n')
3006      end
3007      screen:expect({
3008        grid = [[
3009        ## grid 1
3010          [2:-----------------------------------------------------]|*12
3011          {11:[No Name] [+]                                        }|
3012          [3:-----------------------------------------------------]|
3013        ## grid 2
3014          line10                                               |
3015          line11                                               |
3016          line12                                               |
3017          line13                                               |
3018          line14                                               |
3019          line15                                               |
3020          line16                                               |
3021          line17                                               |
3022          line18                                               |
3023          line19                                               |
3024          line20                                               |
3025          {23:^                                                     }|
3026        ## grid 3
3027                                                               |
3028        ]],
3029        win_viewport = {
3030          [2] = {
3031            win = 1000,
3032            topline = 9,
3033            botline = 21,
3034            curline = 20,
3035            curcol = 0,
3036            linecount = 21,
3037            sum_scroll_delta = 9,
3038          },
3039        },
3040        win_viewport_margins = {
3041          [2] = {
3042            bottom = 0,
3043            left = 0,
3044            right = 0,
3045            top = 0,
3046            win = 1000,
3047          },
3048        },
3049      })
3050      feed('gg')
3051      screen:expect({
3052        grid = [[
3053        ## grid 1
3054          [2:-----------------------------------------------------]|*12
3055          {11:[No Name] [+]                                        }|
3056          [3:-----------------------------------------------------]|
3057        ## grid 2
3058          {23:^line1                                                }|
3059          line2                                                |
3060          line3                                                |
3061          line4                                                |
3062          line5                                                |
3063          line6                                                |
3064          line7                                                |
3065          line8                                                |
3066          line9                                                |
3067          line10                                               |
3068          line11                                               |
3069          line12                                               |
3070        ## grid 3
3071                                                               |
3072        ]],
3073        win_viewport = {
3074          [2] = { win = 1000, topline = 0, botline = 13, curline = 0, curcol = 0, linecount = 21, sum_scroll_delta = 0 },
3075        },
3076        win_viewport_margins = {
3077          [2] = {
3078            bottom = 0,
3079            left = 0,
3080            right = 0,
3081            top = 0,
3082            win = 1000,
3083          },
3084        },
3085      })
3086    end)
3087
3088    it('scrolls in the middle', function()
3089      for i = 1, 20 do
3090        insert('line' .. i .. '\n')
3091      end
3092      screen:expect({
3093        grid = [[
3094        ## grid 1
3095          [2:-----------------------------------------------------]|*12
3096          {11:[No Name] [+]                                        }|
3097          [3:-----------------------------------------------------]|
3098        ## grid 2
3099          line10                                               |
3100          line11                                               |
3101          line12                                               |
3102          line13                                               |
3103          line14                                               |
3104          line15                                               |
3105          line16                                               |
3106          line17                                               |
3107          line18                                               |
3108          line19                                               |
3109          line20                                               |
3110          {23:^                                                     }|
3111        ## grid 3
3112                                                               |
3113        ]],
3114        win_viewport = {
3115          [2] = {
3116            win = 1000,
3117            topline = 9,
3118            botline = 21,
3119            curline = 20,
3120            curcol = 0,
3121            linecount = 21,
3122            sum_scroll_delta = 9,
3123          },
3124        },
3125        win_viewport_margins = {
3126          [2] = {
3127            bottom = 0,
3128            left = 0,
3129            right = 0,
3130            top = 0,
3131            win = 1000,
3132          },
3133        },
3134      })
3135      feed('M')
3136      screen:expect({
3137        grid = [[
3138        ## grid 1
3139          [2:-----------------------------------------------------]|*12
3140          {11:[No Name] [+]                                        }|
3141          [3:-----------------------------------------------------]|
3142        ## grid 2
3143          line10                                               |
3144          line11                                               |
3145          line12                                               |
3146          line13                                               |
3147          line14                                               |
3148          {23:^line15                                               }|
3149          line16                                               |
3150          line17                                               |
3151          line18                                               |
3152          line19                                               |
3153          line20                                               |
3154                                                               |
3155        ## grid 3
3156                                                               |
3157        ]],
3158        win_viewport = {
3159          [2] = {
3160            win = 1000,
3161            topline = 9,
3162            botline = 21,
3163            curline = 14,
3164            curcol = 0,
3165            linecount = 21,
3166            sum_scroll_delta = 9,
3167          },
3168        },
3169        win_viewport_margins = {
3170          [2] = {
3171            bottom = 0,
3172            left = 0,
3173            right = 0,
3174            top = 0,
3175            win = 1000,
3176          },
3177        },
3178      })
3179      feed('k')
3180      screen:expect({
3181        grid = [[
3182        ## grid 1
3183          [2:-----------------------------------------------------]|*12
3184          {11:[No Name] [+]                                        }|
3185          [3:-----------------------------------------------------]|
3186        ## grid 2
3187          line9                                                |
3188          line10                                               |
3189          line11                                               |
3190          line12                                               |
3191          line13                                               |
3192          {23:^line14                                               }|
3193          line15                                               |
3194          line16                                               |
3195          line17                                               |
3196          line18                                               |
3197          line19                                               |
3198          line20                                               |
3199        ## grid 3
3200                                                               |
3201        ]],
3202        win_viewport = {
3203          [2] = {
3204            win = 1000,
3205            topline = 8,
3206            botline = 21,
3207            curline = 13,
3208            curcol = 0,
3209            linecount = 21,
3210            sum_scroll_delta = 8,
3211          },
3212        },
3213        win_viewport_margins = {
3214          [2] = {
3215            bottom = 0,
3216            left = 0,
3217            right = 0,
3218            top = 0,
3219            win = 1000,
3220          },
3221        },
3222      })
3223    end)
3224  end)
3225
3226  it('message grid is shown at the correct position remote re-attach', function()
3227    feed(':test')
3228    local expected = {
3229      grid = [[
3230        ## grid 1
3231          [2:-----------------------------------------------------]|*12
3232          {11:[No Name]                                            }|
3233          [3:-----------------------------------------------------]|
3234        ## grid 2
3235                                                               |
3236          {1:~                                                    }|*11
3237        ## grid 3
3238          :test^                                                |
3239        ]],
3240      win_pos = {
3241        [2] = {
3242          height = 12,
3243          startcol = 0,
3244          startrow = 0,
3245          width = 53,
3246          win = 1000,
3247        },
3248      },
3249      win_viewport = {
3250        [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3251      },
3252      win_viewport_margins = {
3253        [2] = {
3254          bottom = 0,
3255          left = 0,
3256          right = 0,
3257          top = 0,
3258          win = 1000,
3259        },
3260      },
3261      reset = true,
3262    }
3263    screen:expect(expected)
3264    feed('<cr>')
3265    screen:detach()
3266    screen:attach()
3267    feed(':test')
3268    screen:expect(expected)
3269  end)
3270end)
3271
3272it('headless attach with showcmd', function()
3273  clear { args = { '--headless' } }
3274  local screen = Screen.new(80, 24, { ext_multigrid = true })
3275  command('set showcmd')
3276  feed('1234')
3277  screen:expect({
3278    grid = [[
3279    ## grid 1
3280      [2:--------------------------------------------------------------------------------]|*23
3281      [3:--------------------------------------------------------------------------------]|
3282    ## grid 2
3283      ^                                                                                |
3284      {1:~                                                                               }|*22
3285    ## grid 3
3286                                                                           1234       |
3287    ]],
3288    win_viewport = {
3289      [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3290    },
3291  })
3292end)