robin/laufey

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

robinmerge: 1dc9728daa1d8a2702

master
66.6 KiB1487 linesraw
1-- Tests for (protocol-driven) ui2, intended to replace the legacy message grid UI.
2
3local t = require('test.testutil')
4local n = require('test.functional.testnvim')()
5local Screen = require('test.functional.ui.screen')
6
7local describe, it, before_each, after_each, finally =
8  t.describe, t.it, t.before_each, t.after_each, t.finally
9local api, clear, command, exec_lua, feed = n.api, n.clear, n.command, n.exec_lua, n.feed
10
11local msg_timeout = 400
12local function set_msg_target_zero_ch()
13  exec_lua(function()
14    vim.o.messagesopt = 'hit-enter,history:500,progress:c,timeout:' .. msg_timeout
15    require('vim._core.ui2').enable({ msg = { targets = 'msg' } })
16    vim.o.cmdheight = 0
17  end)
18end
19
20describe('messages2', function()
21  local screen
22  before_each(function()
23    clear()
24    screen = Screen.new()
25    screen:add_extra_attr_ids({
26      [100] = { foreground = Screen.colors.Magenta1, bold = true },
27    })
28    exec_lua(function()
29      require('vim._core.ui2').enable({})
30    end)
31  end)
32  after_each(function()
33    -- Since ui2 module lasts until Nvim exits, there may be unfinished timers.
34    -- Close unfinished timers to avoid 2s delay on exit with ASAN or TSAN.
35    exec_lua(function()
36      vim.uv.walk(function(handle)
37        if not handle:is_closing() then
38          handle:close()
39        end
40      end)
41    end)
42  end)
43
44  it('multiline messages and pager', function()
45    command('set ruler showcmd noshowmode | echo "foo\nbar"')
46    screen:expect([[
47      ^                                                     |
48      {1:~                                                    }|*10
49      {3:                                                     }|
50      foo                                                  |
51      bar                                                  |
52    ]])
53    feed('g')
54    screen:expect([[
55      ^                                                     |
56      {1:~                                                    }|*10
57      {3:                                                     }|
58      foo                                                  |
59      bar                                       g          |
60    ]])
61    feed('<lt>')
62    screen:expect([[
63                                                           |
64      {1:~                                                    }|*9
65      {3:                                                     }|
66      ^foo                                                  |
67      bar                                                  |
68                                         1,1            All|
69    ]])
70    -- Multiple messages in same event loop iteration are appended and shown in full.
71    feed([[q:echo "foo" | echo "bar\nbaz\n"->repeat(&lines)<CR>]])
72    screen:expect([[
73      ^                                                     |
74      {1:~                                                    }|*5
75      {3:                                                     }|
76      foo                                                  |
77      bar                                                  |
78      baz                                                  |
79      bar                                                  |
80      baz                                                  |
81      bar                                                  |
82      baz{6: [+23]}                                            |
83    ]])
84    -- Any key press resizes the cmdline and updates the spill indicator.
85    feed('j')
86    screen:expect({ any = { '+29' } })
87    command('echo "foo"')
88    -- New message clears spill indicator.
89    screen:expect([[
90      ^                                                     |
91      {1:~                                                    }|*12
92      foo                                0,0-1          All|
93    ]])
94    command('echo "foo"')
95    -- Ruler still positioned correctly after dupe message.
96    screen:expect([[
97      ^                                                     |
98      {1:~                                                    }|*12
99      foo(1)                             0,0-1          All|
100    ]])
101    command('echo "foo"')
102    -- Dupe counter increases beyond 1
103    screen:expect([[
104      ^                                                     |
105      {1:~                                                    }|*12
106      foo(2)                             0,0-1          All|
107    ]])
108    -- No error for ruler virt_text msg_row exceeding buffer length.
109    command([[map Q <cmd>echo "foo\nbar" <bar> ls<CR>]])
110    feed('Q')
111    screen:expect([[
112      ^                                                     |
113      {1:~                                                    }|*9
114      {3:                                                     }|
115      foo                                                  |
116      bar                                                  |
117        1 %a   "[No Name]"                    line 1       |
118    ]])
119    feed('<C-L>')
120    screen:expect([[
121      ^                                                     |
122      {1:~                                                    }|*12
123                                         0,0-1          All|
124    ]])
125    -- g< shows messages from last command
126    feed('g<lt>')
127    screen:expect([[
128                                                           |
129      {1:~                                                    }|*8
130      {3:                                                     }|
131      ^foo                                                  |
132      bar                                                  |
133        1 %a   "[No Name]"                    line 1       |
134                                         1,1            All|
135    ]])
136    -- edit_unputchar() does not clear already updated screen #34515.
137    feed('qix<Esc>dwi<C-r>')
138    screen:expect([[
139      {18:^"}                                                    |
140      {1:~                                                    }|*12
141                              ^R         1,1            All|
142    ]])
143    feed('-<Esc>')
144    screen:expect([[
145      ^x                                                    |
146      {1:~                                                    }|*12
147                                         1,1            All|
148    ]])
149    -- Switching tabpage closes expanded cmdline #37659.
150    command('tabnew | echo "foo\nbar"')
151    screen:expect([[
152      {24: + [No Name] }{5: [No Name] }{2:                            }{24:X}|
153      ^                                                     |
154      {1:~                                                    }|*9
155      {3:                                                     }|
156      foo                                                  |
157      bar                                                  |
158    ]])
159    feed('gt')
160    screen:expect([[
161      {5: + [No Name] }{24: [No Name] }{2:                            }{24:X}|
162      ^x                                                    |
163      {1:~                                                    }|*11
164      foo{6: [+1]}                           1,1            All|
165    ]])
166    -- Don't enter the pager in insert mode.
167    command('tabonly | call nvim_echo([["foo\n"]]->repeat(&lines), 1, {}) | startinsert')
168    screen:expect([[
169      ^x                                                    |
170      {1:~                                                    }|*5
171      {3:                                                     }|
172      foo                                                  |*6
173      foo{6: [+8]}                                             |
174    ]])
175    feed('<CR>')
176    screen:expect([[
177                                                           |
178      ^x                                                    |
179      {1:~                                                    }|*11
180      foo{6: [+14]}                          2,1            All|
181    ]])
182    feed('<BS><Esc>')
183    -- First multiline message expands cmdline, additional message updates spill indicator.
184    command('call nvim_echo([["foo\n"]]->repeat(&lines), 1, {}) | echo "bar"')
185    screen:expect([[
186      ^x                                                    |
187      {1:~                                                    }|*5
188      {3:                                                     }|
189      foo                                                  |*6
190      foo{6: [+9]}                                             |
191    ]])
192    -- Do enter the pager in normal mode (with keybinding setup).
193    -- Also checks that "messagesopt=pager:…" is normalized to the keytrans() form.
194    command('set messagesopt+=pager:<cr>')
195    command('nmap <Esc> <Cmd>fclose<CR>')
196    feed('<CR>')
197    screen:expect([[
198      ^foo                                                  |
199      foo                                                  |*12
200                                         1,1            Top|
201    ]])
202    command('set messagesopt-=pager:<cr>')
203    -- Changing 'laststatus' reveals the global statusline with a pager height
204    -- exceeding the available lines: #38008.
205    command('set laststatus=3')
206    screen:expect([[
207      ^foo                                                  |
208      foo                                                  |*11
209      {3:[Pager]                            1,1            Top}|
210                                                           |
211    ]])
212    feed(':<C-F>')
213    screen:expect([[
214      x                                                    |
215      {1:~                                                    }|*3
216      ─────────────────────────────────────────────────────|
217      {1::}echo "foo" | echo "bar\nbaz\n"->repeat(&lines)      |
218      {1::}^                                                    |
219      {1:~                                                    }|*5
220      {3:[Command Line]                     2,0-1          All}|
221                                                           |
222    ]])
223    command('wincmd +')
224    screen:expect([[
225      x                                                    |
226      {1:~                                                    }|*2
227      ─────────────────────────────────────────────────────|
228      {1::}echo "foo" | echo "bar\nbaz\n"->repeat(&lines)      |
229      {1::}^                                                    |
230      {1:~                                                    }|*6
231      {3:[Command Line]                     2,0-1          All}|
232                                                           |
233    ]])
234    command('echo "foo"')
235    screen:expect([[
236      x                                                    |
237      {1:~                                                    }|*2
238      ─────────────────────────────────────────────────────|
239      {1::}echo "foo" | echo "bar\nbaz\n"->repeat(&lines)      |
240      {1::}^                                                    |
241      {1:~                                                    }|*6
242      {3:[Command Line]                     2,0-1          All}|
243      foo                                                  |
244    ]])
245    -- <C-C> closes the cmdwin and drops back into pre-filled cmdline. The pager remains visible.
246    feed('<C-C>')
247    screen:expect([[
248      x                                                    |
249      {1:~                                                    }|*11
250      {3:[Pager]                            1,1            Top}|
251      {16::}^                                                    |
252    ]])
253    feed('<Esc><Esc>')
254    -- Can enter pager from cmdwin (use cmdwin.open() since "q" is consumed by the pager on_key
255    -- callback before nv_record can read it).
256    exec_lua([[require('vim._core.cmdwin').open(':')]])
257    screen:expect([[
258      x                                                    |
259      {1:~                                                    }|*3
260      ─────────────────────────────────────────────────────|
261      {1::}echo "foo" | echo "bar\nbaz\n"->repeat(&lines)      |
262      {1::}^                                                    |
263      {1:~                                                    }|*5
264      {3:[Command Line]                     2,0-1          All}|
265                                                           |
266    ]])
267    feed(':messages<CR>')
268    -- Cmdwin stays open behind the pager: it is a regular window (#40312).
269    screen:expect([[
270      ^foo                                                  |
271      foo                                                  |*4
272      {1::}echo "foo" | echo "bar\nbaz\n"->repeat(&lines)      |
273      {1::}                                                    |
274      {1:~                                                    }|*5
275      {3:[Pager]                            1,1            Top}|
276      {16::}{15:messages}                                            |
277    ]])
278    -- Closing the pager returns to the cmdwin, unchanged (it was never closed).
279    feed('q')
280    screen:expect([[
281      x                                                    |
282      {1:~                                                    }|*3
283      ─────────────────────────────────────────────────────|
284      {1::}echo "foo" | echo "bar\nbaz\n"->repeat(&lines)      |
285      {1::}^                                                    |
286      {1:~                                                    }|*5
287      {3:[Command Line]                     2,0-1          All}|
288      {16::}{15:messages}                                            |
289    ]])
290    -- Configured maximum height.
291    command('quit | lua require("vim._core.ui2").enable({msg = {pager = {height = 2 } } })')
292    command('messages')
293    screen:expect([[
294      x                                                    |
295      {1:~                                                    }|*8
296      {3:                                                     }|
297      ^foo                                                  |
298      foo                                                  |
299      {3:[Pager]                            1,1            Top}|
300      {16::}{15:messages}                                            |
301    ]])
302  end)
303
304  it('new buffer, window and options after closing a buffer or switching tabpage', function()
305    command('set nomodifiable | echom "foo" | messages')
306    screen:expect([[
307                                                           |
308      {1:~                                                    }|*10
309      {3:                                                     }|
310      ^foo                                                  |
311      foo                                                  |
312    ]])
313    command('bdelete | messages')
314    screen:expect_unchanged()
315    set_msg_target_zero_ch()
316    command('quit | echo "foo\nbar" | tabnew')
317    screen:expect([[
318      {24: [No Name] }{5: [No Name] }{2:                              }{24:X}|
319      ^                                                     |
320      {1:~                                                    }|*10
321      {1:~                                                 }{4:foo}|
322      {1:~                                                 }{4:bar}|
323    ]])
324  end)
325
326  it('screenclear and empty message clears messages', function()
327    command('echo "foo"')
328    screen:expect([[
329      ^                                                     |
330      {1:~                                                    }|*12
331      foo                                                  |
332    ]])
333    command('mode')
334    screen:expect([[
335      ^                                                     |
336      {1:~                                                    }|*12
337                                                           |
338    ]])
339    command('echo "foo"')
340    screen:expect([[
341      ^                                                     |
342      {1:~                                                    }|*12
343      foo                                                  |
344    ]])
345    command('echo ""')
346    screen:expect([[
347      ^                                                     |
348      {1:~                                                    }|*12
349                                                           |
350    ]])
351    -- A redraw indicates the start of messages in the cmdline, which empty should clear.
352    command('echo "foo" | redraw | echo "bar"')
353    screen:expect([[
354      ^                                                     |
355      {1:~                                                    }|*12
356      bar                                                  |
357    ]])
358    command('echo "foo" | redraw | echo ""')
359    screen:expect([[
360      ^                                                     |
361      {1:~                                                    }|*12
362                                                           |
363    ]])
364    set_msg_target_zero_ch()
365    command('echo "foo"')
366    screen:expect([[
367      ^                                                     |
368      {1:~                                                    }|*12
369      {1:~                                                 }{4:foo}|
370    ]])
371    command('mode')
372    screen:expect([[
373      ^                                                     |
374      {1:~                                                    }|*13
375    ]])
376    -- But not with target='msg'
377    command('echo "foo"')
378    screen:expect([[
379      ^                                                     |
380      {1:~                                                    }|*12
381      {1:~                                                 }{4:foo}|
382    ]])
383    command('echo ""')
384    screen:expect_unchanged()
385    -- Or a screen resize
386    screen:try_resize(screen._width, screen._height - 1)
387    screen:expect([[
388      ^                                                     |
389      {1:~                                                    }|*11
390      {1:~                                                 }{4:foo}|
391    ]])
392    -- Moved up when opening cmdline
393    feed(':')
394    screen:expect([[
395                                                           |
396      {1:~                                                    }|*10
397      {1:~                                                 }{4:foo}|
398      {16::}^                                                    |
399    ]])
400    -- Highlighter disabled when message is moved to cmdline #34884
401    feed([[echo "bar\n"->repeat(&lines)<CR>]])
402    screen:expect([[
403      ^                                                     |
404      {1:~                                                    }|*5
405      foo                                                  |
406      bar                                                  |*5
407      bar{6: [+8]}                                             |
408    ]])
409  end)
410
411  it('does not draw the message seperator with cmdheight=0', function()
412    command('set laststatus=2 statusline=%f')
413    command('set cmdheight=0')
414    command('echo "hello"')
415
416    screen:expect([[
417      ^                                                     |
418      {1:~                                                    }|*12
419      hello                                                |
420    ]])
421  end)
422
423  it('no prompt and newlines with Visual filter command #38273', function()
424    set_msg_target_zero_ch()
425    feed('V:w !printf foo<CR>')
426    screen:expect([[
427      ^                                                     |
428      {1:~                                                    }|*12
429      {1:~                                                 }{4:foo}|
430    ]])
431  end)
432
433  it('empty kind after message that does not flush immediately', function()
434    command('echon "foo" | echo')
435    screen:expect([[
436      ^                                                     |
437      {1:~                                                    }|*12
438      foo                                                  |
439    ]])
440  end)
441
442  it("deleting buffer restores 'buftype'", function()
443    feed(':%bdelete<CR>')
444    screen:expect([[
445      ^                                                     |
446      {1:~                                                    }|*12
447      5 buffers deleted                                    |
448    ]])
449    -- Would trigger changed dialog if 'buftype' was not restored.
450    command('%bdelete')
451    screen:expect_unchanged()
452  end)
453
454  it('showmode does not overwrite important messages', function()
455    command('set readonly')
456    feed('i')
457    screen:expect([[
458      ^                                                     |
459      {1:~                                                    }|*12
460      {19:W10: Warning: Changing a readonly file}               |
461    ]])
462    feed('<Esc>@@i')
463    screen:expect([[
464      ^                                                     |
465      {1:~                                                    }|*12
466      {9:E748: No previously used register}                    |
467    ]])
468  end)
469
470  it('showmode does not overwrite Visual word count #40824', function()
471    if t.is_os('win') then
472      t.pending('FIXME #40843')
473    end
474    api.nvim_buf_set_lines(0, 0, -1, true, { 'one two', 'three four' })
475    feed('Vj')
476    screen:expect([[
477      {17:one two}                                              |
478      {17:^three four}                                           |
479      {1:~                                                    }|*11
480      {5:-- VISUAL LINE --}                                    |
481    ]])
482    feed('g<C-G>')
483    screen:expect([[
484      {17:one two}                                              |
485      {17:^three four}                                           |
486      {1:~                                                    }|*11
487      Selected 2 of 2 Lines; 4 of 4 Words; 19 of 19 Bytes  |
488    ]])
489  end)
490
491  it('hit-enter prompt does not error for invalid window #35095', function()
492    command('echo "foo\nbar"')
493    screen:expect([[
494      ^                                                     |
495      {1:~                                                    }|*10
496      {3:                                                     }|
497      foo                                                  |
498      bar                                                  |
499    ]])
500    feed('<C-w>o')
501    screen:expect([[
502      ^                                                     |
503      {1:~                                                    }|*12
504      foo{6: [+1]}                                             |
505    ]])
506  end)
507
508  it('entering cmdline below expanded messages', function()
509    command('echo "foo\n"->repeat(&lines)')
510    screen:expect([[
511      ^                                                     |
512      {1:~                                                    }|*5
513      {3:                                                     }|
514      foo                                                  |*6
515      foo{6: [+8]}                                             |
516    ]])
517    -- Place cmdline below expanded messages: #37653, without "more" title #38481.
518    feed(':call setline(1, "foo")')
519    screen:expect([[
520                                                           |
521      {1:~                                                    }|*4
522      {3:                                                     }|
523      foo                                                  |*6
524      foo{6: [+8]}                                             |
525      {16::}{15:call} {25:setline}{16:(}{26:1}{16:,} {26:"foo"}{16:)}^                              |
526    ]])
527    -- No message closes expanded cmdline and keeps the entered command.
528    feed('<CR>')
529    screen:expect([[
530      ^foo                                                  |
531      {1:~                                                    }|*12
532      {16::}{15:call} {25:setline}{16:(}{26:1}{16:,} {26:"foo"}{16:)}                              |
533    ]])
534    -- If command emits another message it is opened in the pager without focusing
535    -- it, to closely mimic useful UI1 behavior. #41061
536    command('echo "foo\nbar"')
537    feed(':echo "baz"<CR>')
538    screen:expect([[
539      ^foo                                                  |
540      {1:~                                                    }|*8
541      {3:                                                     }|
542      foo                                                  |
543      bar                                                  |
544      baz                                                  |
545      {16::}{15:echo} {26:"baz"}                                          |
546    ]])
547    -- Moving the mouse does not dismiss the pager.
548    api.nvim_input_mouse('move', '', '', 0, 0, 3)
549    -- Subsequent typed commands are appended to the pager.
550    feed(':echo "typed append"<CR>')
551    screen:expect([[
552      ^foo                                                  |
553      {1:~                                                    }|*7
554      {3:                                                     }|
555      foo                                                  |
556      bar                                                  |
557      baz                                                  |
558      typed append                                         |
559      {16::}{15:echo} {26:"typed append"}                                 |
560    ]])
561    -- Any other typed key dismisses the pager.
562    feed('n')
563    screen:expect([[
564      ^foo                                                  |
565      {1:~                                                    }|*12
566      {9:E35: No previous regular expression}                  |
567    ]])
568    -- Non-typed key doesn't dismiss expanded cmdline #39221
569    command('nnoremap b :ls!<cr>:b<space>')
570    feed('b')
571    screen:expect([[
572      foo                                                  |
573      {1:~                                                    }|*6
574      {3:                                                     }|
575        1 %a + "[No Name]"                    line 1       |
576        2u a   "[Cmd]"                        line 0       |
577        3u a   "[Dialog]"                     line 0       |
578        4u a   "[Msg]"                        line 0       |
579        5u a   "[Pager]"                      line 0       |
580      {16::}{15:b} ^                                                  |
581    ]])
582  end)
583
584  it('pager for consecutive command messages is not focused #41061', function()
585    local win = api.nvim_get_current_win()
586    command('nnoremap j gj')
587    command('echo "foo\nbar"')
588    feed(':echo "baz"<CR>')
589    screen:expect([[
590      ^                                                     |
591      {1:~                                                    }|*8
592      {3:                                                     }|
593      foo                                                  |
594      bar                                                  |
595      baz                                                  |
596      {16::}{15:echo} {26:"baz"}                                          |
597    ]])
598    t.eq(win, api.nvim_get_current_win())
599    -- "g<" enters the pager (showing the previous command output).
600    feed('g<lt>')
601    screen:expect([[
602                                                           |
603      {1:~                                                    }|*10
604      {3:                                                     }|
605      ^baz                                                  |
606                                                           |
607    ]])
608    t.neq(win, api.nvim_get_current_win())
609    -- "q" closes the entered pager.
610    feed('q')
611    t.eq(win, api.nvim_get_current_win())
612    -- ":messages" from inside the pager does not make the next unfocused pager steal focus.
613    command('echo "foo\nbar"')
614    feed(':echo "baz"<CR>')
615    feed('g<lt>')
616    n.poke_eventloop()
617    t.neq(win, api.nvim_get_current_win())
618    feed(':messages<CR>')
619    n.poke_eventloop()
620    feed('q')
621    n.poke_eventloop()
622    t.eq(win, api.nvim_get_current_win())
623    command('echo "foo\nbar"')
624    feed(':echo "baz"<CR>')
625    n.poke_eventloop()
626    t.eq(win, api.nvim_get_current_win())
627    feed('j')
628    screen:expect([[
629      ^                                                     |
630      {1:~                                                    }|*12
631      {16::}{15:echo} {26:"baz"}                                          |
632    ]])
633    -- A typed command that emits no message keeps the pager; the next key dismisses it.
634    command('echo "foo\nbar"')
635    feed(':echo "baz"<CR>')
636    feed(':let g:x = 1<CR>')
637    screen:expect([[
638      ^                                                     |
639      {1:~                                                    }|*8
640      {3:                                                     }|
641      foo                                                  |
642      bar                                                  |
643      baz                                                  |
644      {16::}{15:let} {25:g:x} {15:=} {26:1}                                         |
645    ]])
646    feed('j')
647    screen:expect([[
648      ^                                                     |
649      {1:~                                                    }|*12
650      {16::}{15:let} {25:g:x} {15:=} {26:1}                                         |
651    ]])
652  end)
653
654  it('paging prompt dialog #35191', function()
655    screen:try_resize(71, screen._height)
656    -- Don't consume <Esc> when paging is not necessary.
657    feed(':call confirm("Ok?")<CR>')
658    screen:expect([[
659                                                                             |
660      {1:~                                                                      }|*10
661      {3:                                                                       }|
662      {6:Ok?}                                                                    |
663      {6:[O]k: }^                                                                 |
664    ]])
665    feed('<Esc>')
666    screen:expect([[
667      ^                                                                       |
668      {1:~                                                                      }|*12
669                                                                             |
670    ]])
671    local top = [[
672                                                                             |
673      {1:~                                                                      }|*4
674      {3:                                                                       }|
675      0                                                                      |
676      1                                                                      |
677      2                                                                      |
678      3                                                                      |
679      4                                                                      |
680      5                                                                      |
681      6{6: [+93]}                                                                |
682      Type number and <Enter> (q or empty cancels): ^                         |
683    ]]
684    command('set mousescroll=ver:2')
685    feed(':call inputlist(range(100))<CR>')
686    screen:expect(top)
687    feed('<Down>')
688    screen:expect([[
689                                                                             |
690      {1:~                                                                      }|*4
691      {3:                                                                       }|
692      1{6: [+1]}                                                                 |
693      2                                                                      |
694      3                                                                      |
695      4                                                                      |
696      5                                                                      |
697      6                                                                      |
698      7{6: [+92]}                                                                |
699      Type number and <Enter> (q or empty cancels): ^                         |
700    ]])
701    feed('<Up>')
702    screen:expect(top)
703    feed('<PageDown>')
704    screen:expect([[
705                                                                             |
706      {1:~                                                                      }|*4
707      {3:                                                                       }|
708      5{6: [+5]}                                                                 |
709      6                                                                      |
710      7                                                                      |
711      8                                                                      |
712      9                                                                      |
713      10                                                                     |
714      11{6: [+88]}                                                               |
715      Type number and <Enter> (q or empty cancels): ^                         |
716    ]])
717    feed('<PageUp>')
718    screen:expect(top)
719    feed('<End>')
720    screen:expect([[
721                                                                             |
722      {1:~                                                                      }|*4
723      {3:                                                                       }|
724      93{6: [+93]}                                                               |
725      94                                                                     |
726      95                                                                     |
727      96                                                                     |
728      97                                                                     |
729      98                                                                     |
730      99                                                                     |
731      Type number and <Enter> (q or empty cancels): ^                         |
732    ]])
733    -- No scrolling beyond end of buffer #36114
734    feed('<PageDown>')
735    screen:expect_unchanged()
736    feed('<Home>')
737    screen:expect(top)
738    -- The wheel scrolls by 'mousescroll'; the arrow keys above still scrolled by one #39172
739    feed('<ScrollWheelDown><0,0>')
740    screen:expect([[
741                                                                             |
742      {1:~                                                                      }|*4
743      {3:                                                                       }|
744      2{6: [+2]}                                                                 |
745      3                                                                      |
746      4                                                                      |
747      5                                                                      |
748      6                                                                      |
749      7                                                                      |
750      8{6: [+91]}                                                                |
751      Type number and <Enter> (q or empty cancels): ^                         |
752    ]])
753    feed('<Up>')
754    screen:expect([[
755                                                                             |
756      {1:~                                                                      }|*4
757      {3:                                                                       }|
758      1{6: [+1]}                                                                 |
759      2                                                                      |
760      3                                                                      |
761      4                                                                      |
762      5                                                                      |
763      6                                                                      |
764      7{6: [+92]}                                                                |
765      Type number and <Enter> (q or empty cancels): ^                         |
766    ]])
767    feed('<ScrollWheelUp><0,0>')
768    screen:expect(top)
769  end)
770
771  it('FileType is fired after default options are set', function()
772    n.exec([[
773      let g:set = {}
774      au FileType pager set nowrap
775      au OptionSet * let g:set[expand('<amatch>')] = g:set->get(expand('<amatch>'), 0) + 1
776      echom 'foo'->repeat(&columns)
777      messages
778    ]])
779    screen:expect([[
780                                                           |
781      {1:~                                                    }|*10
782      {3:                                                     }|
783      ^foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofo|
784                                                           |
785    ]])
786    t.eq(5, n.eval('g:set').filetype) -- still fires for 'filetype'
787  end)
788
789  it('Search highlights only apply to pager', function()
790    screen:add_extra_attr_ids({
791      [100] = { background = Screen.colors.Blue1, foreground = Screen.colors.Red },
792      [101] = { background = Screen.colors.Red1, foreground = Screen.colors.Blue1 },
793      [102] = {
794        background = Screen.colors.Blue,
795        foreground = Screen.colors.Red1,
796        reverse = true,
797        bold = true,
798      },
799    })
800    command('hi MsgArea guifg=Red guibg=Blue')
801    command('hi Search guifg=Blue guibg=Red')
802    command('set hlsearch shortmess+=s')
803    feed('/foo<CR>')
804    screen:expect([[
805      ^                                                     |
806      {1:~                                                    }|*12
807      {9:E486: Pattern not found: foo}{100:                         }|
808    ]])
809    set_msg_target_zero_ch()
810    command('echo "foo"')
811    screen:expect([[
812      ^                                                     |
813      {1:~                                                    }|*12
814      {1:~                                                 }{4:foo}|
815    ]])
816    feed('g<lt>')
817    screen:expect([[
818                                                           |
819      {1:~                                                    }|*11
820      {102:                                                     }|
821      {101:^foo}{100:                                                  }|
822    ]])
823  end)
824
825  it(':echon appends message', function()
826    command([[echo 1 | echon 2]])
827    screen:expect([[
828      ^                                                     |
829      {1:~                                                    }|*12
830      12                                                   |
831    ]])
832    feed('g<lt>')
833    screen:expect([[
834                                                           |
835      {1:~                                                    }|*10
836      {3:                                                     }|
837      ^12                                                   |
838                                                           |
839    ]])
840    feed([[q:echo 1 | echon 2 | echon 2 | echon 3<CR>]])
841    screen:expect([[
842      ^                                                     |
843      {1:~                                                    }|*12
844      1223                                                 |
845    ]])
846    feed('g<lt>')
847    screen:expect([[
848                                                           |
849      {1:~                                                    }|*10
850      {3:                                                     }|
851      ^1223                                                 |
852                                                           |
853    ]])
854  end)
855
856  it('shows message from still running command', function()
857    exec_lua(function()
858      vim.schedule(function()
859        print('foo')
860        vim.fn.getchar()
861      end)
862    end)
863    screen:expect([[
864      ^                                                     |
865      {1:~                                                    }|*12
866      foo                                                  |
867    ]])
868    feed('<CR>')
869    -- Fast context is not determined by message kind #39666
870    exec_lua(function()
871      vim.schedule(function()
872        vim.api.nvim_echo({ { 'bar' } }, false, { kind = 'search_cmd' })
873        vim.fn.getchar()
874      end)
875    end)
876    screen:expect([[
877      ^                                                     |
878      {1:~                                                    }|*12
879      bar                                                  |
880    ]])
881  end)
882
883  it('properly formatted carriage return messages', function()
884    screen:try_resize(screen._width, 20)
885    command([[echon "\r" | echon "Hello" | echon " " | echon "World"]])
886    screen:expect([[
887      ^                                                     |
888      {1:~                                                    }|*18
889      Hello World                                          |
890    ]])
891    exec_lua(function()
892      vim.api.nvim_echo({ { 'fooo\nbarbaz\n\nlol', 'statement' }, { '\rbar' } }, true, {})
893      vim.api.nvim_echo({ { 'foooooooo', 'statement' }, { 'baz\rb', 'error' } }, true, {})
894      vim.api.nvim_echo({ { 'fooobar', 'statement' }, { '\rbaz\n' } }, true, {})
895      vim.api.nvim_echo({ { 'fooobar', 'statement' }, { '\rbaz\rb', 'error' } }, true, {})
896      vim.api.nvim_echo({ { 'fooo\rbar', 'statement' }, { 'baz', 'error' } }, true, {})
897    end)
898    screen:expect([[
899      ^                                                     |
900      {1:~                                                    }|*9
901      {3:                                                     }|
902      {15:fooo}                                                 |
903      {15:barbaz}                                               |
904                                                           |
905      bar                                                  |
906      {9:b}{15:oooooooo}{9:baz}                                         |
907      baz{15:obar}                                              |
908                                                           |
909      {9:baz}{15:obar}                                              |
910      {15:bar}{9:baz}                                               |
911    ]])
912  end)
913
914  it('can show message during textlock', function()
915    exec_lua(function()
916      _G.omnifunc = function()
917        print('x!')
918        vim.cmd.sleep('100m')
919      end
920      vim.bo.omnifunc = 'v:lua.omnifunc'
921    end)
922    feed('i<C-X>')
923    screen:expect([[
924      ^                                                     |
925      {1:~                                                    }|*12
926      {5:-- ^X mode (^]^D^E^F^I^K^L^N^O^P^Rs^U^V^Y)}           |
927    ]])
928    feed('<C-O>')
929    screen:expect([[
930      ^                                                     |
931      {1:~                                                    }|*12
932      x!                                                   |
933    ]])
934    screen:expect([[
935      ^                                                     |
936      {1:~                                                    }|*12
937      {5:-- Omni completion (^O^N^P) }{9:Pattern not found}        |
938    ]])
939    exec_lua(function()
940      vim.keymap.set('n', '<F1>', function()
941        print('i hate locks so much!!!!')
942        vim.cmd.messages()
943      end, { expr = true })
944    end)
945    feed('<Esc><F1>')
946    screen:expect([[
947                                                           |
948      {1:~                                                    }|*8
949      {3:                                                     }|
950      ^x!                                                   |
951      x!                                                   |
952      i hate locks so much!!!!                             |*2
953    ]])
954  end)
955
956  it('replace by message ID', function()
957    exec_lua(function()
958      assert(1 == vim.api.nvim_echo({ { 'foo' } }, true, {}))
959      assert(2 == vim.api.nvim_echo({ { 'bar\nbaz' } }, true, {}))
960      assert(3 == vim.api.nvim_echo({ { 'foo' } }, true, {}))
961      vim.keymap.set('n', 'Q', function()
962        vim.api.nvim_echo({ { 'Syntax', 23 }, { '\n  - ', 0 }, { 'cCommentL', 439 } }, false, {})
963      end)
964    end)
965    screen:expect([[
966      ^                                                     |
967      {1:~                                                    }|*8
968      {3:                                                     }|
969      foo                                                  |
970      bar                                                  |
971      baz                                                  |
972      foo                                                  |
973    ]])
974    api.nvim_echo({ { 'foo' } }, true, { id = 2 })
975    screen:expect([[
976      ^                                                     |
977      {1:~                                                    }|*9
978      {3:                                                     }|
979      foo                                                  |*3
980    ]])
981    api.nvim_echo({ { 'bar\nbaz' } }, true, { id = 1 })
982    screen:expect([[
983      ^                                                     |
984      {1:~                                                    }|*8
985      {3:                                                     }|
986      bar                                                  |
987      baz                                                  |
988      foo                                                  |*2
989    ]])
990    -- Pressing a key immediately dismisses an expanded cmdline, and
991    -- replacing a multiline, multicolored message doesn't error due
992    -- to unnecessarily inserted lines #37994.
993    feed('Q')
994    screen:expect([[
995      ^                                                     |
996      {1:~                                                    }|*10
997      {3:                                                     }|
998      {100:Syntax}                                               |
999        - cCommentL                                        |
1000    ]])
1001    feed('Q')
1002    screen:expect_unchanged(true)
1003    feed('<C-L>') -- close expanded cmdline
1004    set_msg_target_zero_ch()
1005    api.nvim_echo({ { 'foo' } }, true, { id = 1 })
1006    api.nvim_echo({ { 'bar\nbaz' } }, true, { id = 2 })
1007    api.nvim_echo({ { 'foo' } }, true, { id = 3 })
1008    screen:expect([[
1009      ^                                                     |
1010      {1:~                                                    }|*9
1011      {1:~                                                 }{4:foo}|
1012      {1:~                                                 }{4:bar}|
1013      {1:~                                                 }{4:baz}|
1014      {1:~                                                 }{4:foo}|
1015    ]])
1016    api.nvim_echo({ { 'foo' } }, true, { id = 2 })
1017    screen:expect([[
1018      ^                                                     |
1019      {1:~                                                    }|*10
1020      {1:~                                                 }{4:foo}|*3
1021    ]])
1022    api.nvim_echo({ { 'f', 'Conceal' }, { 'oo\nbar' } }, true, { id = 3 })
1023    screen:expect([[
1024      ^                                                     |
1025      {1:~                                                    }|*9
1026      {1:~                                                 }{4:foo}|*2
1027      {1:~                                                 }{14:f}{4:oo}|
1028      {1:~                                                 }{4:bar}|
1029    ]])
1030    -- No error expanding the cmdline when trying to copy over message span marks #37672.
1031    screen:try_resize(screen._width, 6)
1032    command('ls!')
1033    screen:expect([[
1034      ^                                                     |
1035      {1:~                                                    }|*2
1036      foo                                                  |*2
1037      {14:f}oo{6: [+6]}                                             |
1038    ]])
1039    feed('<Esc>')
1040    screen:expect([[
1041      ^                                                     |
1042      {1:~                                                    }|*5
1043    ]])
1044  end)
1045
1046  it('while cmdline is open', function()
1047    command('cnoremap <C-A> <Cmd>lua error("foo")<CR>')
1048    feed(':echo "bar"<C-A>')
1049    screen:expect([[
1050                                                           |
1051      {1:~                                                    }|*7
1052      {3:                                                     }|
1053      {9:E5108: Lua: [string ":lua"]:1: foo}                   |
1054      {9:stack traceback:}                                     |
1055      {9:        [C]: in function 'error'}                     |
1056      {9:        [string ":lua"]:1: in main chunk}             |
1057      {16::}{15:echo} {26:"bar"}^                                          |
1058    ]])
1059    feed('<CR>')
1060    screen:expect([[
1061      ^                                                     |
1062      {1:~                                                    }|*12
1063      bar                                                  |
1064    ]])
1065    set_msg_target_zero_ch()
1066    feed([[:call confirm("foo\nbar")<C-A>]])
1067    screen:expect([[
1068                                                           |
1069      {1:~                                                    }|*8
1070      {1:~            }{9:E5108: Lua: [string ":lua"]:1: foo}{4:      }|
1071      {1:~            }{9:stack traceback:}{4:                        }|
1072      {1:~            }{9:        [C]: in function 'error'}{4:        }|
1073      {1:~            }{9:        [string ":lua"]:1: in main chunk}|
1074      {16::}{15:call} {25:confirm}{16:(}{26:"foo\nbar"}{16:)}^                            |
1075    ]])
1076    feed('<CR>')
1077    screen:expect([[
1078                                                           |
1079      {1:~                                                    }|*8
1080      {1:~            }{9:E5108: Lua: [string ":lua"]:1: foo}{4:      }|
1081      {3:                                                     }|
1082      {6:foo}                                                  |
1083      {6:bar}                                                  |
1084      {6:[O]k: }^                                               |
1085    ]])
1086  end)
1087
1088  it('no search_cmd with cmdheight=0', function()
1089    set_msg_target_zero_ch()
1090    feed('ifoo<Esc>?foo<CR>')
1091    screen:expect([[
1092      {10:^foo}                                                  |
1093      {1:~                                                    }|*13
1094    ]])
1095  end)
1096
1097  it('closed msg window timer removes empty lines', function()
1098    set_msg_target_zero_ch()
1099    command('echo "foo" | echo "bar\n"')
1100    screen:expect([[
1101      ^                                                     |
1102      {1:~                                                    }|*10
1103      {1:~                                                 }{4:foo}|
1104      {1:~                                                 }{4:bar}|
1105      {1:~                                                 }{4:   }|
1106    ]])
1107    command('fclose!')
1108    screen:sleep(msg_timeout + 50)
1109    command('echo "baz"')
1110    screen:expect([[
1111      ^                                                     |
1112      {1:~                                                    }|*12
1113      {1:~                                                 }{4:baz}|
1114    ]])
1115    -- Last message line is at bottom of window after closing it.
1116    screen:try_resize(screen._width, 8)
1117    command('mode | echo "1\n" | echo "2\n" | echo "3\n" | echo "4\n"')
1118    screen:expect([[
1119      ^                                                     |
1120      {1:~                                                    }|*3
1121      {1:~                                                   }{4:3}|
1122      {1:~                                                   }{4: }|
1123      {1:~                                                   }{4:4}|
1124      {1:~                                                   }{4: }|
1125    ]])
1126    command('fclose!')
1127    screen:expect([[
1128      ^                                                     |
1129      {1:~                                                    }|*7
1130    ]])
1131    command('echo "5\n"')
1132    screen:expect([[
1133      ^                                                     |
1134      {1:~                                                    }|*3
1135      {1:~                                                   }{4:4}|
1136      {1:~                                                   }{4: }|
1137      {1:~                                                   }{4:5}|
1138      {1:~                                                   }{4: }|
1139    ]])
1140  end)
1141
1142  it('msg window timer does not trigger ModeChanged #40780', function()
1143    exec_lua(function()
1144      vim.o.messagesopt = 'hit-enter,history:500,progress:c,timeout:50'
1145      require('vim._core.ui2').enable({ msg = { targets = 'msg' } })
1146    end)
1147    command('let g:modechanged = []')
1148    command([[autocmd ModeChanged i:n call add(g:modechanged, copy(v:event))]])
1149    command([[echo "a" | echo "b" | startinsert]])
1150    screen:sleep(100)
1151    t.eq({}, n.eval('g:modechanged'))
1152    feed('<Esc>')
1153    t.eq({ { old_mode = 'i', new_mode = 'n' } }, n.eval('g:modechanged'))
1154  end)
1155
1156  it('configured targets per kind', function()
1157    exec_lua(function()
1158      local targets = { echo = 'msg', list_cmd = 'pager', bufwrite = 'cmd', lua_print = 'cmd' }
1159      require('vim._core.ui2').enable({ msg = { targets = targets } })
1160      print('foo') -- "lua_print" kind goes to cmd
1161      vim.cmd.echo('"bar"') -- "echo" kind goes to msg
1162      vim.cmd.highlight('VisualNC') -- "list_cmd" kind goes to pager
1163    end)
1164    screen:expect([[
1165      ^                                                     |
1166      {1:~                                                    }|*10
1167      {3:                                                     }|
1168      VisualNC       xxx cleared                        {4:bar}|
1169      foo                                                  |
1170    ]])
1171    command('hi VisualNC') -- appended to the pager without focusing it
1172    screen:expect([[
1173      ^                                                     |
1174      {1:~                                                    }|*9
1175      {3:                                                     }|
1176      VisualNC       xxx cleared                           |
1177      VisualNC       xxx cleared                        {4:bar}|
1178      foo                                                  |
1179    ]])
1180    -- Any typed key dismisses the unfocused pager.
1181    feed('<Esc>')
1182    -- Duplicate indicator in msg and cmd target simultaneously
1183    command('echo "bar" | lua print("foo")')
1184    command('echo "bar" | lua print("foo")')
1185    screen:expect([[
1186      ^                                                     |
1187      {1:~                                                    }|*11
1188      {1:~                                              }{4:bar(2)}|
1189      foo(1)                                               |
1190    ]])
1191    finally(function()
1192      os.remove('Xfile')
1193    end)
1194    -- Route bufwrite as a pattern to the message ID #39341
1195    command('edit Xfile | write')
1196    screen:expect([[
1197      ^                                                     |
1198      {1:~                                                    }|*11
1199      {1:~                                              }{4:bar(2)}|
1200      "Xfile" [New] 0L, 0B written                         |
1201    ]])
1202  end)
1203
1204  it('message survives after closing tabpage without error #39055', function()
1205    set_msg_target_zero_ch()
1206    command('tabnew')
1207    command('echo "hello"')
1208    screen:expect([[
1209      {24: [No Name] }{5: [No Name] }{2:                              }{24:X}|
1210      ^                                                     |
1211      {1:~                                                    }|*11
1212      {1:~                                               }{4:hello}|
1213    ]])
1214    command('quit!')
1215    screen:expect([[
1216      ^                                                     |
1217      {1:~                                                    }|*12
1218      {1:~                                               }{4:hello}|
1219    ]])
1220  end)
1221
1222  it('no modal/blocking prompt on exit', function()
1223    api.nvim_buf_set_lines(0, 0, -1, true, { 'one' })
1224    feed(':quit<CR>')
1225    screen:expect([[
1226      ^one                                                  |
1227      {1:~                                                    }|*12
1228      {9:E37: No write since last change}{6: [+2]}                 |
1229    ]])
1230  end)
1231
1232  it('no crash for resized grid during redraw #39075', function()
1233    exec_lua(function()
1234      vim.api.nvim_set_decoration_provider(vim.api.nvim_create_namespace(''), {
1235        on_win = function()
1236          print('\n')
1237        end,
1238      })
1239    end)
1240    feed(':')
1241    screen:expect([[
1242                                                           |
1243      {1:~                                                    }|*12
1244      {16::}^                                                    |
1245    ]])
1246    feed('f')
1247    screen:expect([[
1248                                                           |
1249      {1:~                                                    }|*9
1250      {3:                                                     }|
1251                                                           |*2
1252      {16::}{15:f}^                                                   |
1253    ]])
1254  end)
1255
1256  it('configured cmd window height prevents expanded message #39375', function()
1257    command('set messagesopt+=maxheight:1') -- Rounds up to a single row.
1258    command('echo "foo\nbar"')
1259    screen:expect([[
1260      ^                                                     |
1261      {1:~                                                    }|*12
1262      foo{6: [+1]}                                             |
1263    ]])
1264  end)
1265
1266  it('search count is cleared', function()
1267    command('set ruler showcmd shortmess-=S | call setline(1, ["foo", "bar"])')
1268    feed('/foo<CR>')
1269    local search_count = [[
1270      {10:^foo}                                                  |
1271      bar                                                  |
1272      {1:~                                                    }|*11
1273      /foo           W [1/1]             1,1            All|
1274    ]]
1275    screen:expect(search_count)
1276    feed('<C-L>j')
1277    screen:expect([[
1278      {10:foo}                                                  |
1279      ^bar                                                  |
1280      {1:~                                                    }|*11
1281                                         2,1            All|
1282    ]])
1283    feed('n')
1284    screen:expect(search_count)
1285    command('echo "-"->repeat(&columns)')
1286    screen:expect([[
1287      {10:^foo}                                                  |
1288      bar                                                  |
1289      {1:~                                                    }|*11
1290      -----------------------------------1,1            All|
1291    ]])
1292  end)
1293
1294  it('search offset with semicolon #41929', function()
1295    command(
1296      'set shortmess-=S | call setline(1, ["odd line", "even line", "odd line", "even line"])'
1297    )
1298    feed('/even/;/even<CR>')
1299    screen:expect([[
1300      odd line                                             |
1301      {10:even} line                                            |
1302      odd line                                             |
1303      {10:^even} line                                            |
1304      {1:~                                                    }|*9
1305      /even                              [2/2]             |
1306    ]])
1307  end)
1308
1309  it('crops long messages to make place for ruler', function()
1310    command('set noruler | echo "-"->repeat(&columns)')
1311    screen:expect([[
1312      ^                                                     |
1313      {1:~                                                    }|*12
1314      -----------------------------------------------------|
1315    ]])
1316    feed('<C-L>')
1317    command('set ruler showcmd | echo "-"->repeat(&columns)')
1318    screen:expect([[
1319      ^                                                     |
1320      {1:~                                                    }|*12
1321      -----------------------------------0,0-1          All|
1322    ]])
1323    feed('<C-L>')
1324    -- message with multibyte characters
1325    command('echo "∙"->repeat(&columns)')
1326    screen:expect([[
1327      ^                                                     |
1328      {1:~                                                    }|*12
1329      ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙0,0-1          All|
1330    ]])
1331    feed('<C-L>')
1332    -- message with multicell characters
1333    command('echo "-".."🙂"->repeat(&columns/2-1)')
1334    screen:expect([[
1335      ^                                                     |
1336      {1:~                                                    }|*12
1337      -🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂0,0-1          All|
1338    ]])
1339    feed('<C-L>')
1340    command('echo "🙂"->repeat(&columns/2)')
1341    screen:expect([[
1342      ^                                                     |
1343      {1:~                                                    }|*12
1344      🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂🙂 0,0-1          All|
1345    ]])
1346    feed('<C-L>')
1347    -- when cmdheight>1, only the last line is cropped
1348    command('set cmdheight=2 | redraw | echo "-"->repeat(2*&columns)')
1349    screen:expect([[
1350      ^                                                     |
1351      {1:~                                                    }|*11
1352      -----------------------------------------------------|
1353      -----------------------------------0,0-1          All|
1354    ]])
1355    feed('<C-L>')
1356    command('set cmdheight=2 showbreak=> | redraw | echo "-"->repeat(2*&columns-1)')
1357    screen:expect([[
1358      ^                                                     |
1359      {1:~                                                    }|*11
1360      -----------------------------------------------------|
1361      {1:>}----------------------------------0,0-1          All|
1362    ]])
1363    command('set showbreak&')
1364    feed('<C-L>')
1365    -- ruler is not shown after dismissing expanded cmdline with key press -> no need to crop
1366    command('set cmdheight=1 | redraw | echo "-"->repeat(2*&columns)')
1367    feed('k')
1368    screen:expect([[
1369      ^                                                     |
1370      {1:~                                                    }|*12
1371      -----------------------------------------------------|
1372    ]])
1373    feed('<C-L>')
1374    -- messages are deferred until showcmd is cleared -> no need to crop for showcmd
1375    command('lua vim.defer_fn(function() vim.cmd[[echo "-"->repeat(&columns)]] end, 50)')
1376    feed('g')
1377    screen:expect([[
1378      ^                                                     |
1379      {1:~                                                    }|*12
1380                              g          0,0-1          All|
1381    ]])
1382    screen:sleep(100)
1383    feed('<Esc>')
1384    screen:expect([[
1385      ^                                                     |
1386      {1:~                                                    }|*12
1387      -----------------------------------0,0-1          All|
1388    ]])
1389    feed('<C-L>')
1390    -- message with repetition indicator keeps ruler intact
1391    command('echo "-"->repeat(&columns)')
1392    command('echo "-"->repeat(&columns)')
1393    screen:expect([[
1394      ^                                                     |
1395      {1:~                                                    }|*12
1396      --------------------------------(1)0,0-1          All|
1397    ]])
1398    feed('<C-L>')
1399    -- when the ruler is configured smaller, there is more space for messages
1400    command('set rulerformat=%l | redraw | echo "-"->repeat(&columns)')
1401    screen:expect([[
1402      ^                                                     |
1403      {1:~                                                    }|*12
1404      ----------------------------------------------------0|
1405    ]])
1406  end)
1407
1408  it('pager statusline is not clobbered by DiagnosticChanged redraw #41130', function()
1409    exec_lua(function()
1410      vim.o.laststatus = 3
1411      vim.print('message')
1412      vim.cmd.mes()
1413    end)
1414    screen:expect([[
1415                                                           |
1416      {1:~                                                    }|*9
1417      {3:                                                     }|
1418      ^message                                              |
1419      {3:[Pager]                                              }|
1420      message                                              |
1421    ]])
1422    exec_lua(function()
1423      vim.diagnostic.config({ signs = false, virtual_text = false, underline = false })
1424      local ns = vim.api.nvim_create_namespace('repro-41130')
1425      vim.diagnostic.set(ns, 1, { { lnum = 0, message = 'random error' } }, {})
1426    end)
1427    screen:expect_unchanged()
1428  end)
1429
1430  it('correct end_row for highlights copied to pager #41419', function()
1431    command('echo "a" | echo "b"') -- Two lines; end_row should be offset by 2
1432    screen:expect([[
1433      ^                                                     |
1434      {1:~                                                    }|*10
1435      {3:                                                     }|
1436      a                                                    |
1437      b                                                    |
1438    ]])
1439    feed('g<lt>')
1440    screen:expect([[
1441                                                           |
1442      {1:~                                                    }|*9
1443      {3:                                                     }|
1444      ^a                                                    |
1445      b                                                    |
1446                                                           |
1447    ]])
1448    command('echohl WarningMsg | echo "c" | echohl ErrorMsg | echo "de"')
1449    screen:expect([[
1450                                                           |
1451      {1:~                                                    }|*7
1452      {3:                                                     }|
1453      ^a                                                    |
1454      b                                                    |
1455      {19:c}                                                    |
1456      {9:de}                                                   |
1457                                                           |
1458    ]])
1459    feed('g<lt>')
1460    screen:expect([[
1461                                                           |
1462      {1:~                                                    }|*9
1463      {3:                                                     }|
1464      {19:^c}                                                    |
1465      {9:de}                                                   |
1466                                                           |
1467    ]])
1468
1469    -- A prompt with pending cmd messages moves them to the dialog (cmdline.lua). The pager is
1470    -- still shown, but its line count must not offset the marks copied into the dialog.
1471    exec_lua(function()
1472      local ui = require('vim._core.ui2')
1473      vim.api.nvim_buf_set_lines(ui.bufs.cmd, 0, -1, false, { 'err' })
1474      local o = { end_row = 0, end_col = 3, hl_group = 'ErrorMsg' }
1475      vim.api.nvim_buf_set_extmark(ui.bufs.cmd, ui.ns, 0, 0, o)
1476      ui.msg.expand_msg('cmd', 'dialog')
1477    end)
1478    screen:expect([[
1479                                                           |
1480      {1:~                                                    }|*9
1481      {3:                                                     }|
1482      {3:^                                                     }|
1483      {9:err}                                                  |
1484                                                           |
1485    ]])
1486  end)
1487end)