robin/laufey

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

robinmerge: 1dc9728daa1d8a2702

master
487.8 KiB12607 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4local os = require('os')
5
6local describe, it, before_each, after_each, pending = t.describe, t.it, t.before_each, t.after_each, t.pending
7local clear, feed = n.clear, n.feed
8local assert_alive = n.assert_alive
9local command, feed_command = n.command, n.feed_command
10local eval = n.eval
11local eq = t.eq
12local neq = t.neq
13local matches = t.matches
14local expect = n.expect
15local exec = n.exec
16local exec_lua = n.exec_lua
17local insert = n.insert
18local api = n.api
19local fn = n.fn
20local run = n.run
21local pcall_err = t.pcall_err
22local tbl_contains = vim.tbl_contains
23local curbuf = n.api.nvim_get_current_buf
24local curwin = n.api.nvim_get_current_win
25local curtab = n.api.nvim_get_current_tabpage
26local NIL = vim.NIL
27
28describe('float window', function()
29  before_each(function()
30    clear()
31    command('hi VertSplit gui=reverse')
32  end)
33
34  it('behavior', function()
35    -- Create three windows and test that ":wincmd <direction>" changes to the
36    -- first window, if the previous window is invalid.
37    command('split')
38    api.nvim_open_win(0, true, { width = 10, height = 10, relative = 'editor', row = 0, col = 0 })
39    eq(1002, fn.win_getid())
40    eq('editor', api.nvim_win_get_config(1002).relative)
41    command([[
42      call nvim_win_close(1001, v:false)
43      wincmd j
44    ]])
45    eq(1000, fn.win_getid())
46  end)
47
48  it('validation', function()
49    local buf = api.nvim_create_buf(false, false)
50    eq("Invalid key: 'bork'", pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, bork = true }))
51    eq("Required: 'relative' or 'external' when creating a float", pcall_err(api.nvim_open_win, buf, false, { win = 0 }))
52    eq(
53      "Conflict: 'vertical' not allowed with floating windows",
54      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, vertical = true })
55    )
56    eq(
57      "Conflict: 'split' not allowed with floating windows",
58      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, split = 'left' })
59    )
60    eq(
61      "Conflict: 'relative' not allowed with 'external'",
62      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, external = true })
63    )
64    eq(
65      "Invalid 'relative': 'shell'",
66      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'shell', row = 0, col = 0 })
67    )
68    eq(
69      "Invalid 'anchor': 'bottom'",
70      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, anchor = 'bottom' })
71    )
72    eq(
73      "Required: 'relative' requires 'row'/'col' or 'bufpos'",
74      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor' })
75    )
76    eq(
77      "Invalid 'width': expected positive Integer",
78      pcall_err(api.nvim_open_win, buf, false, { width = -1, height = 2, relative = 'editor', row = 0, col = 0 })
79    )
80    eq(
81      "Invalid 'height': expected positive Integer",
82      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = -1, relative = 'editor', row = 0, col = 0 })
83    )
84    eq(
85      "Invalid 'height': expected positive Integer",
86      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 0, relative = 'editor', row = 0, col = 0 })
87    )
88    eq("Required: 'width'", pcall_err(api.nvim_open_win, buf, false, { relative = 'editor', row = 0, col = 0 }))
89    eq("Required: 'height'", pcall_err(api.nvim_open_win, buf, false, { relative = 'editor', row = 0, col = 0, width = 2 }))
90
91    eq("Invalid 'split': 'up'", pcall_err(api.nvim_open_win, buf, false, { split = 'up' }))
92    eq(
93      "Invalid 'bufpos': expected [row, col] array",
94      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, bufpos = { 0 } })
95    )
96    eq(
97      "Invalid 'zindex': expected positive Integer",
98      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, zindex = 0 })
99    )
100    eq(
101      "Invalid 'zindex': expected positive Integer",
102      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, zindex = -1 })
103    )
104    eq(
105      "Invalid 'style': 'bogus'",
106      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, style = 'bogus' })
107    )
108    eq(
109      "Invalid 'border': 'bogus'",
110      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, border = 'bogus' })
111    )
112    eq(
113      "Invalid 'border': expected 1, 2, 4, or 8 chars",
114      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, border = { '', '', '' } })
115    )
116    eq(
117      "Invalid 'border': expected 1 or 2-item Array",
118      pcall_err(
119        api.nvim_open_win,
120        buf,
121        false,
122        { width = 20, height = 2, relative = 'editor', row = 0, col = 0, border = { { 'a', 'b', 'c' } } }
123      )
124    )
125    eq(
126      "Invalid 'border': expected Array of Strings",
127      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, border = { { 1 } } })
128    )
129    eq(
130      "Invalid 'border': expected String or Array, got Integer",
131      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, border = { 42 } })
132    )
133    eq(
134      "Invalid 'border': expected only one-cell chars",
135      pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, border = { 'aa' } })
136    )
137    eq(
138      "Invalid 'border': expected corner char between edge chars",
139      pcall_err(
140        api.nvim_open_win,
141        buf,
142        false,
143        { width = 20, height = 2, relative = 'editor', row = 0, col = 0, border = { '', '-', '', '|', '', '-', '', '|' } }
144      )
145    )
146
147    -- title_pos/footer_pos validation
148    eq(
149      "Invalid 'title_pos': 'bogus'",
150      pcall_err(
151        api.nvim_open_win,
152        buf,
153        false,
154        { width = 20, height = 2, relative = 'editor', row = 0, col = 0, border = 'single', title = 'T', title_pos = 'bogus' }
155      )
156    )
157    eq(
158      "Invalid 'footer_pos': 'bogus'",
159      pcall_err(
160        api.nvim_open_win,
161        buf,
162        false,
163        { width = 20, height = 2, relative = 'editor', row = 0, col = 0, border = 'single', footer = 'F', footer_pos = 'bogus' }
164      )
165    )
166    eq(
167      "Required: 'footer' requires 'footer_pos'",
168      pcall_err(
169        api.nvim_open_win,
170        buf,
171        false,
172        { relative = 'editor', width = 9, height = 2, row = 2, col = 5, border = 'single', footer_pos = 'left' }
173      )
174    )
175    eq(
176      "Required: 'title' requires 'title_pos'",
177      pcall_err(
178        api.nvim_open_win,
179        buf,
180        false,
181        { relative = 'editor', width = 9, height = 2, row = 2, col = 5, border = 'single', title_pos = 'left' }
182      )
183    )
184  end)
185
186  it('validation: split window', function()
187    local buf = api.nvim_create_buf(false, true)
188    eq("Conflict: 'zindex' not allowed with non-float window", pcall_err(api.nvim_open_win, buf, false, { split = 'left', zindex = 100 }))
189    eq("Conflict: 'title' not allowed with non-float window", pcall_err(api.nvim_open_win, buf, false, { split = 'left', title = 'T' }))
190    eq("Conflict: 'footer' not allowed with non-float window", pcall_err(api.nvim_open_win, buf, false, { split = 'left', footer = 'F' }))
191    eq(
192      "Conflict: 'border' not allowed with non-float window",
193      pcall_err(api.nvim_open_win, buf, false, { split = 'left', border = 'single' })
194    )
195    eq("Conflict: 'row' not allowed with non-float window", pcall_err(api.nvim_open_win, buf, true, { split = 'right', row = 10 }))
196    eq("Conflict: 'col' not allowed with non-float window", pcall_err(api.nvim_open_win, buf, true, { split = 'right', col = 10 }))
197    eq(
198      "Conflict: 'bufpos' not allowed with non-float window",
199      pcall_err(api.nvim_open_win, buf, true, { split = 'right', bufpos = { 0, 0 } })
200    )
201
202    local winid = api.nvim_open_win(buf, true, { split = 'right' })
203    eq("Conflict: 'row' not allowed with non-float window", pcall_err(api.nvim_win_set_config, winid, { split = 'right', row = 10 }))
204    eq("Conflict: 'col' not allowed with non-float window", pcall_err(api.nvim_win_set_config, winid, { split = 'right', col = 10 }))
205    eq(
206      "Conflict: 'bufpos' not allowed with non-float window",
207      pcall_err(api.nvim_win_set_config, winid, { split = 'right', bufpos = { 0, 0 } })
208    )
209
210    -- Reconfiguring split
211    local not_allowed = { hide = true, zindex = 1, title = '', footer = '', border = 'single' }
212    for k, v in pairs(not_allowed) do
213      local err = ("Conflict: '%s' not allowed with non-float window"):format(k)
214      eq(err, pcall_err(api.nvim_win_set_config, winid, { [k] = v }))
215    end
216  end)
217
218  it('win_execute() should work', function()
219    local buf = api.nvim_create_buf(false, false)
220    api.nvim_buf_set_lines(buf, 0, -1, true, { 'the floatwin', 'abc', 'def' })
221    local win = api.nvim_open_win(buf, false, { relative = 'win', width = 16, height = 1, row = 0, col = 10 })
222    local line = fn.win_execute(win, 'echo getline(1)')
223    eq('\nthe floatwin', line)
224    eq('\n1', fn.win_execute(win, 'echo line(".",' .. win .. ')'))
225    eq('\n3', fn.win_execute(win, 'echo line("$",' .. win .. ')'))
226    eq('\n0', fn.win_execute(win, 'echo line("$", 123456)'))
227    fn.win_execute(win, 'bwipe!')
228  end)
229
230  it("win_execute() call commands that are not allowed when 'hidden' is not set", function()
231    command('set nohidden')
232    local buf = api.nvim_create_buf(false, false)
233    api.nvim_buf_set_lines(buf, 0, -1, true, { 'the floatwin' })
234    local win = api.nvim_open_win(buf, true, { relative = 'win', width = 16, height = 1, row = 0, col = 10 })
235    eq('Vim(close):E37: No write since last change (add ! to override)', pcall_err(fn.win_execute, win, 'close'))
236    eq('Vim(bdelete):E89: No write since last change for buffer 2 (add ! to override)', pcall_err(fn.win_execute, win, 'bdelete'))
237    fn.win_execute(win, 'bwipe!')
238  end)
239
240  it('closed immediately by autocmd #11383', function()
241    eq(
242      'Window was closed immediately',
243      pcall_err(
244        exec_lua,
245        [[
246        local api = vim.api
247        local function crashes(contents)
248          local buf = api.nvim_create_buf(false, true)
249          local floatwin = api.nvim_open_win(buf, true, {
250            relative = 'cursor';
251            style = 'minimal';
252            row = 0; col = 0;
253            height = #contents;
254            width = 10;
255          })
256          api.nvim_buf_set_lines(buf, 0, -1, true, contents)
257          local winnr = vim.fn.win_id2win(floatwin)
258          api.nvim_command('wincmd p')
259          api.nvim_command('autocmd BufEnter * ++once '..winnr..'wincmd c')
260          return buf, floatwin
261        end
262        crashes{'foo'}
263        crashes{'bar'}
264    ]]
265      )
266    )
267    assert_alive()
268  end)
269
270  it('closed immediately by autocmd after win_enter #15548', function()
271    eq(
272      'Window was closed immediately',
273      pcall_err(
274        exec_lua,
275        [[
276        vim.cmd "autocmd BufLeave * ++once quit!"
277        local buf = vim.api.nvim_create_buf(true, true)
278        vim.api.nvim_open_win(buf, true, {
279          relative = "win",
280          row = 0, col = 0,
281          width = 1, height = 1,
282          noautocmd = false,
283        })
284    ]]
285      )
286    )
287    assert_alive()
288  end)
289
290  it('open with WinNew autocmd', function()
291    local new_triggered_before_enter, new_curwin, win = unpack(exec_lua([[
292      local enter_triggered = false
293      local new_triggered_before_enter = false
294      local new_curwin
295      local buf = vim.api.nvim_create_buf(true, true)
296      vim.api.nvim_create_autocmd('WinEnter', {
297        callback = function()
298          enter_triggered = true
299        end
300      })
301      vim.api.nvim_create_autocmd('WinNew', {
302        callback = function()
303          new_triggered_before_enter = not enter_triggered
304          new_curwin = vim.api.nvim_get_current_win()
305        end
306      })
307      local opts = { relative = "win", row = 0, col = 0, width = 1, height = 1, noautocmd = false }
308      local win = vim.api.nvim_open_win(buf, true, opts)
309      return {new_triggered_before_enter, new_curwin, win}
310    ]]))
311    eq(true, new_triggered_before_enter)
312    eq(win, new_curwin)
313  end)
314
315  it('opened with correct height', function()
316    local height = exec_lua([[
317      vim.go.winheight = 20
318      local bufnr = vim.api.nvim_create_buf(false, true)
319      local opts = { height = 10, col = 5, row = 1, relative = 'editor', style = 'minimal', width = 15 }
320      local win_id = vim.api.nvim_open_win(bufnr, true, opts)
321      return vim.api.nvim_win_get_height(win_id)
322    ]])
323    eq(10, height)
324  end)
325
326  it('opened with correct width', function()
327    local width = exec_lua([[
328      vim.go.winwidth = 20
329      local bufnr = vim.api.nvim_create_buf(false, true)
330      local opts = { height = 10, col = 5, row = 1, relative = 'editor', style = 'minimal', width = 10 }
331      local win_id = vim.api.nvim_open_win(bufnr, true, opts)
332      return vim.api.nvim_win_get_width(win_id)
333    ]])
334    eq(10, width)
335  end)
336
337  it('opened with correct position', function()
338    local pos = exec_lua([[
339      local bufnr = vim.api.nvim_create_buf(false, true)
340      local opts = { width = 10, height = 10, col = 7, row = 9, relative = 'editor', style = 'minimal' }
341      local win_id = vim.api.nvim_open_win(bufnr, false, opts)
342      return vim.api.nvim_win_get_position(win_id)
343    ]])
344    eq({ 9, 7 }, { pos[1], pos[2] })
345  end)
346
347  it('opened with correct position relative to the mouse', function()
348    api.nvim_input_mouse('left', 'press', '', 0, 10, 10)
349    local pos = exec_lua([[
350      local bufnr = vim.api.nvim_create_buf(false, true)
351      local opts = { width = 10, height = 10, col = 1, row = 2, relative = 'mouse', style = 'minimal' }
352      local win_id = vim.api.nvim_open_win(bufnr, false, opts)
353      return vim.api.nvim_win_get_position(win_id)
354    ]])
355    eq({ 12, 11 }, { pos[1], pos[2] })
356  end)
357
358  it('opened with correct position relative to the cursor', function()
359    local pos = exec_lua([[
360      local lines = {}
361      for _ = 1, 100 do lines[#lines + 1] = 'foo' end
362      vim.api.nvim_buf_set_lines(0, 0, -1, false, lines)
363      vim.api.nvim_win_set_cursor(0, { 50, 0 })
364      vim.cmd('normal! zz')
365
366      local view = vim.fn.winsaveview()
367      vim.api.nvim_win_set_cursor(0, { 1, 0 })
368      vim.fn.winrestview(view)
369
370      local bufnr = vim.api.nvim_create_buf(false, true)
371      local opts = { width = 10, height = 10, col = 7, row = 9, relative = 'cursor', style = 'minimal' }
372      local win_id = vim.api.nvim_open_win(bufnr, false, opts)
373      return { vim.api.nvim_win_get_position(win_id), vim.fn.winline() - 1 }
374    ]])
375    eq(pos[2] + 9, pos[1][1])
376    eq(7, pos[1][2])
377  end)
378
379  it('opened with correct position relative to another window', function()
380    local pos = exec_lua([[
381      local bufnr = vim.api.nvim_create_buf(false, true)
382      local par_opts = { width = 50, height = 50, col = 7, row = 9, relative = 'editor', style = 'minimal' }
383      local par_win_id = vim.api.nvim_open_win(bufnr, false, par_opts)
384      local opts = { width = 10, height = 10, col = 7, row = 9, relative = 'win', style = 'minimal', win = par_win_id }
385      local win_id = vim.api.nvim_open_win(bufnr, false, opts)
386      return vim.api.nvim_win_get_position(win_id)
387    ]])
388    eq({ 18, 14 }, { pos[1], pos[2] })
389  end)
390
391  it('opened with correct position relative to another relative window', function()
392    local pos = exec_lua([[
393      local bufnr = vim.api.nvim_create_buf(false, true)
394      local root_opts = { width = 50, height = 50, col = 7, row = 9, relative = 'editor', style = 'minimal' }
395      local root_win_id = vim.api.nvim_open_win(bufnr, false, root_opts)
396      local par_opts = { width = 20, height = 20, col = 2, row = 3, relative = 'win', win = root_win_id, style = 'minimal' }
397      local par_win_id = vim.api.nvim_open_win(bufnr, false, par_opts)
398      local opts = { width = 10, height = 10, col = 3, row = 2, relative = 'win', win = par_win_id, style = 'minimal' }
399      local win_id = vim.api.nvim_open_win(bufnr, false, opts)
400      return vim.api.nvim_win_get_position(win_id)
401    ]])
402
403    eq({ 14, 12 }, { pos[1], pos[2] })
404  end)
405
406  it('error when reconfig missing relative field', function()
407    local bufnr = api.nvim_create_buf(false, true)
408    local opts = { width = 10, height = 10, col = 5, row = 5, relative = 'editor', style = 'minimal' }
409    local winid = api.nvim_open_win(bufnr, true, opts)
410    eq(
411      "Required: 'relative' when reconfiguring floating window 1001",
412      pcall_err(api.nvim_win_set_config, winid, { width = 3, height = 3, row = 10, col = 10 })
413    )
414  end)
415
416  it('no error message when reconfig relative field on closed win', function()
417    command('split')
418    local winid = api.nvim_open_win(0, false, { relative = 'win', width = 1, height = 1, col = 1, row = 1 })
419    eq(1001, api.nvim_win_get_config(winid).win)
420    -- But unrelated config doesn't clear parent win #34286
421    api.nvim_win_set_config(winid, { title = 'foo' })
422    eq(1001, api.nvim_win_get_config(winid).win)
423    command('close')
424    api.nvim_win_set_config(winid, { title = 'bar' })
425    api.nvim_win_set_config(winid, { relative = 'editor', row = 1, col = 1 })
426    eq(nil, api.nvim_win_get_config(winid).win)
427  end)
428
429  it('is not operated on by windo when non-focusable #15374', function()
430    command([[
431      let winids = []
432      windo call add(winids, win_getid())
433    ]])
434    local windo_count_before = eval('len(winids)')
435    local winid = exec_lua([[
436      local bufnr = vim.api.nvim_create_buf(false, true)
437      local opts = { relative = 'editor', focusable = false, height = 5, width = 5, col = 5, row = 5 }
438      return vim.api.nvim_open_win(bufnr, false, opts)
439    ]])
440    command([[
441      let winids = []
442      windo call add(winids, win_getid())
443    ]])
444    local windo_count_after = eval('len(winids)')
445    eq(windo_count_before, windo_count_after)
446    eq(false, tbl_contains(eval('winids'), winid))
447  end)
448
449  it('is operated on by windo when focusable', function()
450    command([[
451      let winids = []
452      windo call add(winids, win_getid())
453    ]])
454    local windo_count_before = eval('len(winids)')
455    local winid = exec_lua([[
456      local bufnr = vim.api.nvim_create_buf(false, true)
457      local opts = { relative = 'editor', focusable = true, height = 5, width = 5, col = 5, row = 5 }
458      return vim.api.nvim_open_win(bufnr, false, opts)
459    ]])
460    command([[
461      let winids = []
462      windo call add(winids, win_getid())
463    ]])
464    local windo_count_after = eval('len(winids)')
465    eq(windo_count_before + 1, windo_count_after)
466    eq(true, tbl_contains(eval('winids'), winid))
467  end)
468
469  it('is not active after windo when non-focusable #15374', function()
470    local winid = exec_lua([[
471      local bufnr = vim.api.nvim_create_buf(false, true)
472      local opts = { relative = 'editor', focusable = false, height = 5, width = 5, col = 5, row = 5 }
473      return vim.api.nvim_open_win(bufnr, false, opts)
474    ]])
475    command('windo echo')
476    neq(winid, eval('win_getid()'))
477  end)
478
479  it('is active after windo when focusable', function()
480    local winid = exec_lua([[
481      local bufnr = vim.api.nvim_create_buf(false, true)
482      local opts = { relative = 'editor', focusable = true, height = 5, width = 5, col = 5, row = 5 }
483      return vim.api.nvim_open_win(bufnr, false, opts)
484    ]])
485    command('windo echo')
486    eq(winid, eval('win_getid()'))
487  end)
488
489  it('is not active after closing window when non-focusable #28454', function()
490    command('copen')
491    local winid = exec_lua([[
492      local bufnr = vim.api.nvim_create_buf(false, true)
493      local opts = { relative = 'editor', focusable = false, height = 5, width = 5, col = 5, row = 5 }
494      return vim.api.nvim_open_win(bufnr, false, opts)
495    ]])
496    command('wincmd t')
497    command('wincmd q')
498    neq(winid, curwin())
499  end)
500
501  it('supports windo with focusable and non-focusable floats', function()
502    local winids = exec_lua([[
503      local result = {vim.api.nvim_get_current_win()}
504      local bufnr = vim.api.nvim_create_buf(false, true)
505      local opts = { relative = 'editor', focusable = false, height = 5, width = 5, col = 5, row = 5 }
506      vim.api.nvim_open_win(bufnr, false, opts)
507      opts.focusable = true
508      table.insert(result, vim.api.nvim_open_win(bufnr, false, opts))
509      opts.focusable = false
510      vim.api.nvim_open_win(bufnr, false, opts)
511      opts.focusable = true
512      table.insert(result, vim.api.nvim_open_win(bufnr, false, opts))
513      opts.focusable = false
514      vim.api.nvim_open_win(bufnr, false, opts)
515      return result
516    ]])
517    table.sort(winids)
518    command([[
519      let winids = []
520      windo call add(winids, win_getid())
521      call sort(winids)
522    ]])
523    eq(winids, eval('winids'))
524  end)
525
526  it('open does not trigger BufEnter #15300', function()
527    local res = exec_lua [[
528      local times = {}
529      local buf = vim.api.nvim_create_buf(fasle, true)
530      vim.api.nvim_create_autocmd('BufEnter', {
531        callback = function(opt)
532          if opt.buf == buf then
533            times[#times + 1] = 1
534          end
535        end
536      })
537      local win_id
538      local fconfig = { relative = 'editor', row = 10, col = 10, width = 10, height = 10 }
539      --enter is false doesn't trigger
540      win_id = vim.api.nvim_open_win(buf, false, fconfig)
541      vim.api.nvim_win_close(win_id, true)
542      times[#times + 1] = #times == 0 and true or nil
543
544      --enter is true trigger
545      win_id = vim.api.nvim_open_win(buf, true, fconfig)
546      vim.api.nvim_win_close(win_id, true)
547      times[#times + 1] = #times == 2 and true or nil
548
549      --enter is true and fconfig.noautocmd is true doesn't trigger
550      fconfig.noautocmd = true
551      win_id = vim.api.nvim_open_win(buf, true, fconfig)
552      vim.api.nvim_win_close(win_id, true)
553      times[#times + 1] = #times == 2 and true or nil
554
555      return times
556    ]]
557    eq({ true, 1, true }, res)
558  end)
559
560  it('no crash with bufpos and non-existent window', function()
561    command('new')
562    local closed_win = api.nvim_get_current_win()
563    command('close')
564    local buf = api.nvim_create_buf(false, false)
565    eq(
566      'Invalid window id: ' .. closed_win,
567      pcall_err(api.nvim_open_win, buf, true, { relative = 'win', win = closed_win, width = 1, height = 1, bufpos = { 0, 0 } })
568    )
569    assert_alive()
570  end)
571
572  it("no segfault when setting minimal style after clearing local 'fillchars' #19510", function()
573    local float_opts = { relative = 'editor', row = 1, col = 1, width = 1, height = 1 }
574    local float_win = api.nvim_open_win(0, true, float_opts)
575    api.nvim_set_option_value('fillchars', NIL, { win = float_win })
576    float_opts.style = 'minimal'
577    api.nvim_win_set_config(float_win, float_opts)
578    assert_alive()
579  end)
580
581  it("should not leak 'style' option values to normal windows", function()
582    local buf = api.nvim_create_buf(true, false)
583    local buf2 = api.nvim_create_buf(true, false)
584    local float_opts = { style = 'minimal', relative = 'editor', row = 1, col = 1, width = 1, height = 1 }
585    local float_win = api.nvim_open_win(buf, true, float_opts)
586    -- minimal float should preserve its own options when switching buffers
587    api.nvim_set_option_value('listchars', 'extends:…,precedes:…', { win = float_win, scope = 'local' })
588    api.nvim_win_set_buf(float_win, buf2)
589    api.nvim_win_set_buf(float_win, buf)
590    eq('extends:…,precedes:…', api.nvim_get_option_value('listchars', { win = float_win, scope = 'local' }))
591    -- closing the float should not leak minimal style options to normal windows
592    api.nvim_win_close(float_win, true)
593    api.nvim_set_option_value('number', true, { win = 0 })
594    command('bnext')
595    eq(true, api.nvim_get_option_value('number', { win = 0 }))
596  end)
597
598  it('style=minimal options should not leak to other windows via wininfo', function()
599    command('set noswapfile cursorline')
600    command('edit foo')
601    local foo_buf = api.nvim_get_current_buf()
602    fn.setline(1, 'foo')
603    command('edit bar')
604    local bar_buf = api.nvim_get_current_buf()
605    fn.setline(1, 'bar')
606    local float_opts = { style = 'minimal', relative = 'editor', row = 5, col = 5, width = 5, height = 5 }
607    local minimal_win = api.nvim_open_win(foo_buf, false, float_opts)
608    eq(false, api.nvim_get_option_value('cursorline', { win = minimal_win }))
609    api.nvim_win_set_buf(minimal_win, bar_buf)
610    eq('', api.nvim_win_get_config(0).relative)
611    command('split foo')
612    eq(true, api.nvim_get_option_value('cursorline', { win = 0 }))
613  end)
614
615  it("should not re-apply 'style' when missing", function()
616    local float_opts = { style = 'minimal', relative = 'editor', row = 1, col = 1, width = 1, height = 1 }
617    local float_win = api.nvim_open_win(0, true, float_opts)
618    api.nvim_set_option_value('number', true, { win = float_win })
619    float_opts.row = 2
620    float_opts.style = nil
621    api.nvim_win_set_config(float_win, float_opts)
622    eq(true, api.nvim_get_option_value('number', { win = float_win }))
623  end)
624
625  it("'scroll' is computed correctly when opening float with splitkeep=screen #20684", function()
626    api.nvim_set_option_value('splitkeep', 'screen', {})
627    local float_opts = { relative = 'editor', row = 1, col = 1, width = 10, height = 10 }
628    local float_win = api.nvim_open_win(0, true, float_opts)
629    eq(5, api.nvim_get_option_value('scroll', { win = float_win }))
630  end)
631
632  it("lines('w$') after nvim_win_set_height with 'splitkeep=screen' #36056", function()
633    api.nvim_set_option_value('splitkeep', 'screen', {})
634    local buf = api.nvim_create_buf(false, true)
635    local win = api.nvim_open_win(buf, false, { width = 5, height = 1, col = 0, row = 0, relative = 'cursor' })
636    api.nvim_buf_set_lines(buf, 0, -1, true, { ('1'):rep(10), ('2'):rep(10) })
637    local line = exec_lua(function()
638      vim.api.nvim_win_set_height(win, vim.api.nvim_win_get_height(win) + 3)
639      return vim.fn.line('w$', win)
640    end)
641    eq(2, line)
642  end)
643
644  it(':unhide works when there are floating windows', function()
645    local float_opts = { relative = 'editor', row = 1, col = 1, width = 5, height = 5 }
646    local w0 = curwin()
647    api.nvim_open_win(0, false, float_opts)
648    api.nvim_open_win(0, false, float_opts)
649    eq(3, #api.nvim_list_wins())
650    command('unhide')
651    eq({ w0 }, api.nvim_list_wins())
652  end)
653
654  it(':all works when there are floating windows', function()
655    command('args Xa.txt')
656    local float_opts = { relative = 'editor', row = 1, col = 1, width = 5, height = 5 }
657    local w0 = curwin()
658    api.nvim_open_win(0, false, float_opts)
659    api.nvim_open_win(0, false, float_opts)
660    eq(3, #api.nvim_list_wins())
661    command('all')
662    eq({ w0 }, api.nvim_list_wins())
663  end)
664
665  it('win_splitmove() can move float into a split', function()
666    command('split')
667    eq({ 'col', { { 'leaf', 1001 }, { 'leaf', 1000 } } }, fn.winlayout())
668
669    local win1 = api.nvim_open_win(0, true, { relative = 'editor', row = 1, col = 1, width = 5, height = 5 })
670    fn.win_splitmove(win1, 1001, { vertical = true })
671    eq({ 'col', { { 'row', { { 'leaf', win1 }, { 'leaf', 1001 } } }, { 'leaf', 1000 } } }, fn.winlayout())
672    eq('', api.nvim_win_get_config(win1).relative)
673
674    -- Should be unable to create a split relative to a float, though.
675    local win2 = api.nvim_open_win(0, true, { relative = 'editor', row = 1, col = 1, width = 5, height = 5 })
676    eq('Vim:E957: Invalid window number', pcall_err(fn.win_splitmove, win1, win2, { vertical = true }))
677  end)
678
679  it('tp_curwin updated if external window is moved into split', function()
680    local _ = Screen.new(20, 7, { ext_multigrid = true })
681
682    command('tabnew')
683    local external_win = api.nvim_open_win(0, true, { external = true, width = 5, height = 5 })
684    eq(external_win, api.nvim_get_current_win())
685    eq(2, fn.tabpagenr())
686    command('tabfirst')
687    api.nvim_set_current_win(external_win)
688    eq(external_win, api.nvim_get_current_win())
689    eq(1, fn.tabpagenr())
690
691    command('wincmd J')
692    eq(external_win, api.nvim_get_current_win())
693    eq(false, api.nvim_win_get_config(external_win).external)
694    command('tabnext')
695    eq(2, fn.tabpagenr())
696    neq(external_win, api.nvim_get_current_win())
697  end)
698
699  it('no crash with relative="win" after %bdelete #30569', function()
700    exec([[
701      botright vsplit
702      %bdelete
703    ]])
704    api.nvim_open_win(0, false, { relative = 'win', win = 0, row = 0, col = 5, width = 5, height = 5 })
705    assert_alive()
706  end)
707
708  describe('with only one tabpage,', function()
709    local float_opts = { relative = 'editor', row = 1, col = 1, width = 1, height = 1 }
710    local old_buf, old_win
711    before_each(function()
712      insert('foo')
713      old_buf = curbuf()
714      old_win = curwin()
715    end)
716    describe('closing the last non-floating window gives E444', function()
717      before_each(function()
718        api.nvim_open_win(old_buf, true, float_opts)
719      end)
720      it('if called from non-floating window', function()
721        api.nvim_set_current_win(old_win)
722        eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, old_win, false))
723        -- Start with many tab pages, but make autocommands from closing floats leave us with just
724        -- one (where we're now the last window).
725        command('tabnew | autocmd WinClosed * ++once tabonly')
726        api.nvim_open_win(0, false, float_opts)
727        eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, 0, true))
728      end)
729      it('if called from floating window', function()
730        eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, old_win, false))
731      end)
732    end)
733    describe("deleting the last non-floating window's buffer", function()
734      describe('leaves one window with an empty buffer when there is only one buffer', function()
735        local same_buf_float
736        before_each(function()
737          same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
738        end)
739        after_each(function()
740          eq(old_win, curwin())
741          expect('')
742          eq(1, #api.nvim_list_wins())
743        end)
744        it('if called from non-floating window', function()
745          api.nvim_buf_delete(old_buf, { force = true })
746        end)
747        it('if called from floating window', function()
748          api.nvim_set_current_win(same_buf_float)
749          command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()')
750          command('autocmd WinEnter * let g:win_enter = nvim_get_current_win()')
751          api.nvim_buf_delete(old_buf, { force = true })
752          eq(same_buf_float, eval('g:win_leave'))
753          eq(old_win, eval('g:win_enter'))
754        end)
755      end)
756      describe('closes other windows with that buffer when there are other buffers', function()
757        local same_buf_float, other_buf, other_buf_float
758        before_each(function()
759          same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
760          other_buf = api.nvim_create_buf(true, false)
761          other_buf_float = api.nvim_open_win(other_buf, true, float_opts)
762          insert('bar')
763          api.nvim_set_current_win(old_win)
764        end)
765        after_each(function()
766          eq(other_buf, curbuf())
767          expect('bar')
768          eq(2, #api.nvim_list_wins())
769        end)
770        it('if called from non-floating window', function()
771          api.nvim_buf_delete(old_buf, { force = true })
772          eq(old_win, curwin())
773        end)
774        it('if called from floating window with the same buffer', function()
775          api.nvim_set_current_win(same_buf_float)
776          command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()')
777          command('autocmd WinEnter * let g:win_enter = nvim_get_current_win()')
778          api.nvim_buf_delete(old_buf, { force = true })
779          eq(same_buf_float, eval('g:win_leave'))
780          eq(old_win, eval('g:win_enter'))
781          eq(old_win, curwin())
782        end)
783        it('if called from floating window with another buffer', function()
784          api.nvim_set_current_win(other_buf_float)
785          api.nvim_buf_delete(old_buf, { force = true })
786          eq(other_buf_float, curwin())
787        end)
788      end)
789      describe('creates an empty buffer when there is only one listed buffer', function()
790        local same_buf_float, unlisted_buf_float
791        before_each(function()
792          same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
793          local unlisted_buf = api.nvim_create_buf(true, false)
794          unlisted_buf_float = api.nvim_open_win(unlisted_buf, true, float_opts)
795          insert('unlisted')
796          command('set nobuflisted')
797          api.nvim_set_current_win(old_win)
798        end)
799        it('if called from non-floating window', function()
800          api.nvim_buf_delete(old_buf, { force = true })
801          eq(old_win, curwin())
802          expect('')
803          eq(2, #api.nvim_list_wins())
804        end)
805        it('if called from floating window with the same buffer', function()
806          api.nvim_set_current_win(same_buf_float)
807          command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()')
808          command('autocmd WinEnter * let g:win_enter = nvim_get_current_win()')
809          api.nvim_buf_delete(old_buf, { force = true })
810          eq(same_buf_float, eval('g:win_leave'))
811          eq(old_win, eval('g:win_enter'))
812          eq(old_win, curwin())
813          expect('')
814          eq(2, #api.nvim_list_wins())
815        end)
816        it('if called from floating window with an unlisted buffer', function()
817          api.nvim_set_current_win(unlisted_buf_float)
818          api.nvim_buf_delete(old_buf, { force = true })
819          eq(unlisted_buf_float, curwin())
820          expect('unlisted')
821          eq('', fn.bufname(api.nvim_win_get_buf(old_win)))
822          eq(false, api.nvim_buf_is_valid(old_buf))
823          eq(2, #api.nvim_list_wins())
824        end)
825      end)
826      it('keeps focus in the floating window #39800', function()
827        api.nvim_open_win(old_buf, false, float_opts)
828        local other_float = api.nvim_open_win(api.nvim_create_buf(true, false), true, float_opts)
829        api.nvim_buf_delete(old_buf, { force = true })
830        eq(other_float, curwin())
831      end)
832
833      it('does not trigger BufEnter for deleted buffer #39800', function()
834        api.nvim_open_win(old_buf, false, float_opts)
835        api.nvim_open_win(api.nvim_create_buf(true, false), true, float_opts)
836        command('let g:abufs = []')
837        command('autocmd BufEnter * call add(g:abufs, +expand("<abuf>"))')
838        api.nvim_buf_delete(old_buf, { force = true })
839        for _, b in ipairs(eval('g:abufs')) do
840          neq(old_buf, b)
841        end
842      end)
843    end)
844    describe('with splits, deleting the last listed buffer creates an empty buffer', function()
845      describe('when a non-floating window has an unlisted buffer', function()
846        local same_buf_float
847        before_each(function()
848          command('botright vnew')
849          insert('unlisted')
850          command('set nobuflisted')
851          api.nvim_set_current_win(old_win)
852          same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
853        end)
854        after_each(function()
855          expect('')
856          eq(2, #api.nvim_list_wins())
857        end)
858        it('if called from non-floating window with the deleted buffer', function()
859          api.nvim_buf_delete(old_buf, { force = true })
860          eq(old_win, curwin())
861        end)
862        it('if called from floating window with the deleted buffer', function()
863          api.nvim_set_current_win(same_buf_float)
864          api.nvim_buf_delete(old_buf, { force = true })
865          eq(same_buf_float, curwin())
866        end)
867      end)
868    end)
869  end)
870
871  describe('with multiple tabpages but only one listed buffer,', function()
872    local float_opts = { relative = 'editor', row = 1, col = 1, width = 1, height = 1 }
873    local unlisted_buf, old_buf, old_win
874    before_each(function()
875      insert('unlisted')
876      command('set nobuflisted')
877      unlisted_buf = curbuf()
878      command('tabnew')
879      insert('foo')
880      old_buf = curbuf()
881      old_win = curwin()
882    end)
883    describe('without splits, deleting the last listed buffer creates an empty buffer', function()
884      local same_buf_float
885      before_each(function()
886        api.nvim_set_current_win(old_win)
887        same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
888      end)
889      after_each(function()
890        expect('')
891        eq(2, #api.nvim_list_wins())
892        eq(2, #api.nvim_list_tabpages())
893      end)
894      it('if called from non-floating window', function()
895        api.nvim_buf_delete(old_buf, { force = true })
896        eq(old_win, curwin())
897      end)
898      it('if called from non-floating window in another tabpage', function()
899        command('tab split')
900        eq(3, #api.nvim_list_tabpages())
901        api.nvim_buf_delete(old_buf, { force = true })
902      end)
903      it('if called from floating window with the same buffer', function()
904        api.nvim_set_current_win(same_buf_float)
905        command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()')
906        command('autocmd WinEnter * let g:win_enter = nvim_get_current_win()')
907        api.nvim_buf_delete(old_buf, { force = true })
908        eq(same_buf_float, eval('g:win_leave'))
909        eq(old_win, eval('g:win_enter'))
910        eq(old_win, curwin())
911      end)
912    end)
913    describe('with splits, deleting the last listed buffer creates an empty buffer', function()
914      local same_buf_float
915      before_each(function()
916        command('botright vsplit')
917        api.nvim_set_current_buf(unlisted_buf)
918        api.nvim_set_current_win(old_win)
919        same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
920      end)
921      after_each(function()
922        expect('')
923        eq(3, #api.nvim_list_wins())
924        eq(2, #api.nvim_list_tabpages())
925      end)
926      it('if called from non-floating window with the deleted buffer', function()
927        api.nvim_buf_delete(old_buf, { force = true })
928        eq(old_win, curwin())
929      end)
930      it('if called from floating window with the deleted buffer', function()
931        api.nvim_set_current_win(same_buf_float)
932        api.nvim_buf_delete(old_buf, { force = true })
933        eq(same_buf_float, curwin())
934      end)
935    end)
936  end)
937
938  describe('with multiple tabpages and multiple listed buffers,', function()
939    local float_opts = { relative = 'editor', row = 1, col = 1, width = 1, height = 1 }
940    local old_tabpage, old_buf, old_win
941    before_each(function()
942      old_tabpage = curtab()
943      insert('oldtab')
944      command('tabnew')
945      old_buf = curbuf()
946      old_win = curwin()
947    end)
948    describe('closing the last non-floating window', function()
949      describe('closes the tabpage when all floating windows are closeable', function()
950        local same_buf_float
951        before_each(function()
952          same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
953        end)
954        after_each(function()
955          eq(old_tabpage, curtab())
956          expect('oldtab')
957          eq(1, #api.nvim_list_tabpages())
958        end)
959        it('if called from non-floating window', function()
960          api.nvim_win_close(old_win, false)
961        end)
962        it('if called from floating window', function()
963          api.nvim_set_current_win(same_buf_float)
964          api.nvim_win_close(old_win, false)
965        end)
966      end)
967      describe('gives E5601 when there are non-closeable floating windows', function()
968        local other_buf_float
969        before_each(function()
970          command('set nohidden')
971          local other_buf = api.nvim_create_buf(true, false)
972          other_buf_float = api.nvim_open_win(other_buf, true, float_opts)
973          insert('foo')
974          api.nvim_set_current_win(old_win)
975        end)
976        it('if called from non-floating window', function()
977          eq('Vim:E5601: Cannot close window, only floating window would remain', pcall_err(api.nvim_win_close, old_win, false))
978        end)
979        it('if called from floating window', function()
980          api.nvim_set_current_win(other_buf_float)
981          eq('Vim:E5601: Cannot close window, only floating window would remain', pcall_err(api.nvim_win_close, old_win, false))
982        end)
983      end)
984    end)
985    describe("deleting the last non-floating window's buffer", function()
986      describe('closes the tabpage when all floating windows are closeable', function()
987        local same_buf_float, other_buf, other_buf_float
988        before_each(function()
989          same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
990          other_buf = api.nvim_create_buf(true, false)
991          other_buf_float = api.nvim_open_win(other_buf, true, float_opts)
992          api.nvim_set_current_win(old_win)
993        end)
994        after_each(function()
995          eq(old_tabpage, curtab())
996          expect('oldtab')
997          eq(1, #api.nvim_list_tabpages())
998        end)
999        it('if called from non-floating window', function()
1000          api.nvim_buf_delete(old_buf, { force = false })
1001        end)
1002        it('if called from floating window with the same buffer', function()
1003          api.nvim_set_current_win(same_buf_float)
1004          api.nvim_buf_delete(old_buf, { force = false })
1005        end)
1006        it('if called from floating window with another buffer', function()
1007          api.nvim_set_current_win(other_buf_float)
1008          api.nvim_buf_delete(old_buf, { force = false })
1009        end)
1010      end)
1011      -- TODO: what to do when there are non-closeable floating windows?
1012    end)
1013  end)
1014
1015  describe(':close on non-float with floating windows', function()
1016    -- XXX: it isn't really clear whether this should quit Nvim, as if the autocommand
1017    -- here is BufUnload then it does quit Nvim.
1018    -- But with BufWinLeave, this doesn't quit Nvim if there are no floating windows,
1019    -- so it shouldn't quit Nvim if there are floating windows.
1020    it('does not quit Nvim if BufWinLeave makes it the only non-float', function()
1021      exec([[
1022        let g:buf = bufnr()
1023        new
1024        let s:midwin = win_getid()
1025        new
1026        setlocal bufhidden=wipe
1027        call nvim_win_set_config(s:midwin,
1028              \ #{relative: 'editor', row: 5, col: 5, width: 5, height: 5})
1029        autocmd BufWinLeave * ++once exe g:buf .. 'bwipe!'
1030      ]])
1031      eq('Vim(close):E855: Autocommands caused command to abort', pcall_err(command, 'close'))
1032      assert_alive()
1033    end)
1034
1035    it('does not crash if BufUnload makes it the only non-float in tabpage', function()
1036      exec([[
1037        tabnew
1038        let g:buf = bufnr()
1039        new
1040        let s:midwin = win_getid()
1041        new
1042        setlocal bufhidden=wipe
1043        call nvim_win_set_config(s:midwin,
1044              \ #{relative: 'editor', row: 5, col: 5, width: 5, height: 5})
1045        autocmd BufUnload * ++once exe g:buf .. 'bwipe!'
1046      ]])
1047      eq('Vim(close):E5601: Cannot close window, only floating window would remain', pcall_err(command, 'close'))
1048      assert_alive()
1049    end)
1050
1051    describe('does not crash if WinClosed makes it the only non-float', function()
1052      before_each(function()
1053        exec([[
1054          let g:buf = bufnr()
1055          new
1056          setlocal bufhidden=wipe
1057          autocmd WinClosed * ++once exe g:buf .. 'bwipe!'
1058        ]])
1059      end)
1060
1061      local opts = { relative = 'editor', row = 5, col = 5, width = 5, height = 5 }
1062      local floatwin
1063
1064      describe('and there is a float window with the same buffer', function()
1065        before_each(function()
1066          floatwin = api.nvim_open_win(0, false, opts)
1067        end)
1068
1069        it('with multiple tabpages', function()
1070          command('tabnew | tabprev')
1071          eq('Vim(close):E5601: Cannot close window, only floating window would remain', pcall_err(command, 'close'))
1072          api.nvim_win_close(floatwin, true)
1073          assert_alive()
1074        end)
1075
1076        it('with only one tabpage', function()
1077          command('close')
1078          api.nvim_win_close(floatwin, true)
1079          assert_alive()
1080        end)
1081      end)
1082
1083      describe('and there is a float with a different buffer', function()
1084        before_each(function()
1085          floatwin = api.nvim_open_win(api.nvim_create_buf(true, false), false, opts)
1086        end)
1087
1088        it('with multiple tabpages', function()
1089          command('tabnew | tabprev')
1090          eq('Vim(close):E855: Autocommands caused command to abort', pcall_err(command, 'close'))
1091          assert_alive()
1092        end)
1093
1094        it('with only one tabpage', function()
1095          eq('Vim(close):E855: Autocommands caused command to abort', pcall_err(command, 'close'))
1096          assert_alive()
1097        end)
1098      end)
1099    end)
1100
1101    it('does not crash if WinClosed from floating window closes it', function()
1102      exec([[
1103        tabnew
1104        new
1105        let s:win = win_getid()
1106        call nvim_win_set_config(s:win,
1107              \ #{relative: 'editor', row: 5, col: 5, width: 5, height: 5})
1108        wincmd t
1109        exe $"autocmd WinClosed {s:win} 1close"
1110      ]])
1111      command('close')
1112      assert_alive()
1113    end)
1114
1115    it('does not unload bufhidden=hide buffer', function()
1116      local buf = api.nvim_create_buf(false, true)
1117      command('set nohidden')
1118      api.nvim_open_tabpage(0, true, {})
1119      api.nvim_open_win(buf, false, { relative = 'editor', width = 1, height = 1, row = 0, col = 0 })
1120      command('close!')
1121      eq(true, api.nvim_buf_is_loaded(buf))
1122    end)
1123  end)
1124
1125  it('placed relative to tabline and laststatus', function()
1126    local screen = Screen.new(20, 10)
1127    screen:add_extra_attr_ids({ [100] = { bold = true, foreground = Screen.colors.Magenta } })
1128    command('set showtabline=1 laststatus=1')
1129    api.nvim_open_win(0, false, { relative = 'laststatus', border = 'single', anchor = 'SE', width = 5, height = 1, row = 0, col = 1000 })
1130    local tabwin = api.nvim_open_win(0, false, { relative = 'tabline', border = 'single', width = 5, height = 1, row = 0, col = 1000 })
1131    screen:expect([[
1132      ^             {31:┌─────┐}|
1133      {1:~            }{31:│}{4:     }{31:│}|
1134      {1:~            }{31:└─────┘}|
1135      {1:~                   }|*3
1136      {1:~            }{31:┌─────┐}|
1137      {1:~            }{31:│}{4:     }{31:│}|
1138      {1:~            }{31:└─────┘}|
1139                          |
1140    ]])
1141    command('tabnew | tabnext')
1142    screen:expect([[
1143      {5: }{100:3}{5:  Name] }{24: No Name]X}|
1144      ^             {31:┌─────┐}|
1145      {1:~            }{31:│}{4:     }{31:│}|
1146      {1:~            }{31:└─────┘}|
1147      {1:~                   }|*2
1148      {1:~            }{31:┌─────┐}|
1149      {1:~            }{31:│}{4:     }{31:│}|
1150      {1:~            }{31:└─────┘}|
1151                          |
1152    ]])
1153    command('vsplit')
1154    screen:expect([[
1155      {5: }{100:4}{5:  Name] }{24: No Name]X}|
1156      ^             {31:┌─────┐}|
1157      {1:~            }{31:│}{4:     }{31:│}|
1158      {1:~            }{31:└─────┘}|
1159      {1:~                 }{2:│}{1:~}|
1160      {1:~            }{31:┌─────┐}|
1161      {1:~            }{31:│}{4:     }{31:│}|
1162      {1:~            }{31:└─────┘}|
1163      {3:[No Name]          }{2:<}|
1164                          |
1165    ]])
1166    command('quit')
1167    api.nvim_win_set_config(tabwin, { relative = 'tabline', border = 'single', width = 5, height = 1, row = 1, col = 0 })
1168    screen:expect([[
1169      {5: }{100:3}{5:  Name] }{24: No Name]X}|
1170      ^                    |
1171      {31:┌─────┐}{1:             }|
1172      {31:│}{4:     }{31:│}{1:             }|
1173      {31:└─────┘}{1:             }|
1174      {1:~                   }|
1175      {1:~            }{31:┌─────┐}|
1176      {1:~            }{31:│}{4:     }{31:│}|
1177      {1:~            }{31:└─────┘}|
1178                          |
1179    ]])
1180    command('tabonly')
1181    screen:expect([[
1182      ^                    |
1183      {31:┌─────┐}{1:             }|
1184      {31:│}{4:     }{31:│}{1:             }|
1185      {31:└─────┘}{1:             }|
1186      {1:~                   }|*2
1187      {1:~            }{31:┌─────┐}|
1188      {1:~            }{31:│}{4:     }{31:│}|
1189      {1:~            }{31:└─────┘}|
1190                          |
1191    ]])
1192  end)
1193
1194  it('non-visible/focusable are not assigned a window number', function()
1195    command('tabnew')
1196    local tp = api.nvim_get_current_tabpage()
1197    local split_win = api.nvim_get_current_win()
1198    local float_buf = api.nvim_create_buf(true, true)
1199    local win = api.nvim_open_win(float_buf, false, { relative = 'editor', width = 2, height = 2, row = 2, col = 2, focusable = false })
1200    api.nvim_open_win(0, false, { relative = 'editor', width = 2, height = 2, row = 2, col = 2, hide = true })
1201    api.nvim_open_win(0, false, { relative = 'editor', width = 2, height = 2, row = 2, col = 2 })
1202
1203    eq(2, fn.winnr('$'))
1204    eq(0, fn.win_id2win(win))
1205    eq(0, fn.getwininfo(win)[1].winnr)
1206    eq({ 0, 0 }, fn.win_id2tabwin(win))
1207    eq(2, fn.tabpagewinnr(2, '$'))
1208    eq(0, fn.win_getid(3))
1209    eq(0, fn.win_getid(3, 2))
1210    eq(-1, fn.bufwinnr(float_buf))
1211    eq(win, fn.bufwinid(float_buf)) -- bufwinid unaffected.
1212    eq(nil, fn.winrestcmd():match('3resize'))
1213
1214    -- Unless it is the current window.
1215    api.nvim_set_current_win(win)
1216    eq(3, fn.winnr('$'))
1217    eq(3, fn.winnr())
1218    eq(3, fn.win_id2win(win))
1219    eq(3, fn.getwininfo(win)[1].winnr)
1220    eq({ 2, 3 }, fn.win_id2tabwin(win))
1221    eq(3, fn.tabpagewinnr(2, '$'))
1222    eq(3, fn.tabpagewinnr(2))
1223    eq(win, fn.win_getid(3))
1224    eq(win, fn.win_getid(3, 2))
1225    eq(3, fn.bufwinnr(float_buf))
1226    matches('3resize', fn.winrestcmd())
1227
1228    -- When switching tabpages it should still have a winnr, as it's current in the other tabpage.
1229    command('tabfirst')
1230    eq({ 2, 3 }, fn.win_id2tabwin(win))
1231    eq(3, fn.getwininfo(win)[1].winnr)
1232    eq(win, fn.win_getid(3, 2))
1233    eq(3, fn.tabpagewinnr(2, '$'))
1234    eq(3, fn.tabpagewinnr(2))
1235
1236    -- ...but not if it's non-current in that tabpage.
1237    api.nvim_tabpage_set_win(tp, split_win)
1238    eq({ 0, 0 }, fn.win_id2tabwin(win))
1239    eq(0, fn.getwininfo(win)[1].winnr)
1240    eq(0, fn.win_getid(3, 2))
1241    eq(2, fn.tabpagewinnr(2, '$'))
1242    eq(1, fn.tabpagewinnr(2))
1243  end)
1244
1245  it('non-visible/focusable is not a valid previous window', function()
1246    local win = api.nvim_open_win(0, true, { relative = 'editor', width = 2, height = 2, row = 2, col = 2, focusable = false })
1247    command('wincmd p')
1248    command('wincmd p')
1249    neq(win, api.nvim_get_current_win())
1250    api.nvim_win_set_config(win, { focusable = true, hide = true })
1251    command('wincmd p')
1252    neq(win, api.nvim_get_current_win())
1253    api.nvim_win_set_config(win, { hide = false })
1254    command('wincmd p')
1255    eq(win, api.nvim_get_current_win())
1256  end)
1257
1258  it('no crash for unallocated relative window grid', function()
1259    local win = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, height = 1, width = 1 })
1260    exec_lua(function()
1261      vim.api.nvim_create_autocmd('CmdwinEnter', {
1262        callback = function()
1263          vim.api.nvim_win_set_config(win, { relative = 'win', win = 0, row = 0, col = 0 })
1264          vim.api.nvim__redraw({ flush = true })
1265        end,
1266      })
1267    end)
1268    feed('q:')
1269    assert_alive()
1270  end)
1271
1272  it("no error for zero height with 'winminheight'", function()
1273    local win = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, height = 1, width = 1 })
1274    api.nvim_set_option_value('winminheight', 0, {})
1275    api.nvim_win_set_height(win, 0)
1276    api.nvim_win_set_config(win, api.nvim_win_get_config(win))
1277  end)
1278
1279  it(':fclose does not crash from nasty autocommands', function()
1280    local w1 = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, width = 5, height = 5, zindex = 6 })
1281    local w2 = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, width = 5, height = 5, zindex = 5 })
1282    local w3 = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, width = 5, height = 5, zindex = 4 })
1283    local w4 = api.nvim_open_win(0, true, { relative = 'editor', row = 0, col = 0, width = 5, height = 5, zindex = 3 })
1284    exec_lua(function()
1285      vim.api.nvim_create_autocmd('WinClosed', {
1286        once = true,
1287        callback = function()
1288          vim.api.nvim_win_close(w2, true)
1289        end,
1290      })
1291    end)
1292    -- We close just the first three floats with highest zindex, so w4 remains open.
1293    -- (despite w2 being closed early by the autocommand rather than directly by :fclose)
1294    command('3fclose')
1295    eq(false, api.nvim_win_is_valid(w1))
1296    eq(false, api.nvim_win_is_valid(w2))
1297    eq(false, api.nvim_win_is_valid(w3))
1298    eq(true, api.nvim_win_is_valid(w4))
1299
1300    -- Try switching tab pages and moving windows between tab pages via nvim_win_set_config.
1301    -- Simplest if :fclose skips windows in non-current tabpages.
1302    local w5 = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, width = 5, height = 5, zindex = 2 })
1303    command('tabnew | tabprevious')
1304    command('autocmd WinEnter * ++once tabnext')
1305    eq(w4, api.nvim_get_current_win())
1306    local tp1 = api.nvim_get_current_tabpage()
1307    command('fclose!')
1308    eq(false, api.nvim_win_is_valid(w4))
1309    eq(true, api.nvim_win_is_valid(w5))
1310    neq(tp1, api.nvim_get_current_tabpage())
1311
1312    local w_tp2 = api.nvim_get_current_win()
1313    api.nvim_set_current_tabpage(tp1)
1314    local w6 = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, width = 5, height = 5, zindex = 1 })
1315    exec_lua(function()
1316      vim.api.nvim_create_autocmd('WinClosed', {
1317        once = true,
1318        callback = function()
1319          vim.api.nvim_win_set_config(w6, { win = w_tp2, split = 'below' })
1320        end,
1321      })
1322    end)
1323    command('fclose!')
1324    eq(false, api.nvim_win_is_valid(w5))
1325    eq(true, api.nvim_win_is_valid(w6))
1326    neq(tp1, api.nvim_win_get_tabpage(w6))
1327  end)
1328
1329  it('compositor clears old position when configuring reallocates grid #38143', function()
1330    local screen = Screen.new()
1331    local w1 = api.nvim_open_win(0, true, { relative = 'editor', border = 'single', row = 0, col = 0, width = 5, height = 5 })
1332    screen:expect([[
1333      {31:┌─────┐}                                              |
1334      {31:│}{4:^     }{31:│}{1:                                              }|
1335      {31:│}{11:~    }{31:│}{1:                                              }|*4
1336      {31:└─────┘}{1:                                              }|
1337      {1:~                                                    }|*6
1338                                                           |
1339    ]])
1340    api.nvim_win_set_config(w1, { relative = 'cursor', row = 1, col = 1, height = 4, width = 4 })
1341    screen:expect([[
1342                                                           |
1343      {1:~                                                    }|
1344      {1:~ }{31:┌────┐}{1:                                             }|
1345      {1:~ }{31:│}{4:^    }{31:│}{1:                                             }|
1346      {1:~ }{31:│}{11:~   }{31:│}{1:                                             }|*3
1347      {1:~ }{31:└────┘}{1:                                             }|
1348      {1:~                                                    }|*5
1349                                                           |
1350    ]])
1351  end)
1352
1353  local function with_ext_multigrid(multigrid, send_mouse_grid)
1354    local screen, attrs
1355    before_each(function()
1356      screen = Screen.new(40, 7, { ext_multigrid = multigrid })
1357      attrs = {
1358        [0] = { bold = true, foreground = Screen.colors.Blue },
1359        [1] = { background = Screen.colors.LightMagenta },
1360        [2] = { background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1 },
1361        [3] = { bold = true },
1362        [4] = { bold = true, reverse = true },
1363        [5] = { reverse = true },
1364        [6] = { background = Screen.colors.LightMagenta, bold = true, reverse = true },
1365        [7] = { foreground = Screen.colors.White, background = Screen.colors.Red },
1366        [8] = { bold = true, foreground = Screen.colors.SeaGreen4 },
1367        [9] = { background = Screen.colors.LightGrey, underline = true },
1368        [10] = { background = Screen.colors.LightGrey, underline = true, bold = true, foreground = Screen.colors.Magenta },
1369        [11] = { bold = true, foreground = Screen.colors.Fuchsia, background = Screen.colors.LightMagenta },
1370        [12] = { background = Screen.colors.Red, bold = true, foreground = Screen.colors.Blue1 },
1371        [13] = { background = Screen.colors.WebGray },
1372        [14] = { foreground = Screen.colors.Brown },
1373        [15] = { background = Screen.colors.Grey20 },
1374        [16] = { background = Screen.colors.Grey20, bold = true, foreground = Screen.colors.Blue1 },
1375        [17] = { background = Screen.colors.Yellow },
1376        [18] = { foreground = Screen.colors.Brown, background = Screen.colors.Grey20 },
1377        [19] = { foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray },
1378        [20] = { bold = true, foreground = Screen.colors.Brown },
1379        [21] = { background = Screen.colors.Gray90 },
1380        [22] = { background = Screen.colors.LightRed },
1381        [23] = { foreground = Screen.colors.Black, background = Screen.colors.White },
1382        [24] = { foreground = Screen.colors.Black, background = Screen.colors.Grey80 },
1383        [25] = { blend = 100, background = Screen.colors.Gray0 },
1384        [26] = { blend = 80, background = Screen.colors.Gray0 },
1385        [27] = { foreground = Screen.colors.Black, background = Screen.colors.LightGrey },
1386        [28] = { foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey },
1387        [29] = { background = Screen.colors.Yellow1, foreground = Screen.colors.Blue4 },
1388        [30] = { background = Screen.colors.Grey, foreground = Screen.colors.Blue4, bold = true },
1389        [31] = { foreground = Screen.colors.Grey0 },
1390        [32] = { background = Screen.colors.LightMagenta, foreground = Screen.colors.Brown },
1391        [33] = { background = Screen.colors.LightMagenta, reverse = true },
1392        [34] = { foreground = Screen.colors.Fuchsia, bold = true },
1393        [35] = { foreground = Screen.colors.White, background = Screen.colors.Red1, reverse = true },
1394        [36] = { foreground = Screen.colors.Fuchsia, background = Screen.colors.Red1, bold = true },
1395        [37] = { foreground = Screen.colors.SeaGreen, reverse = true, bold = true },
1396      }
1397      screen:set_default_attr_ids(attrs)
1398    end)
1399
1400    it('can be created and reconfigured', function()
1401      local buf = api.nvim_create_buf(false, false)
1402      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
1403      local expected_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } }
1404
1405      if multigrid then
1406        screen:expect {
1407          grid = [[
1408        ## grid 1
1409          [2:----------------------------------------]|*6
1410          [3:----------------------------------------]|
1411        ## grid 2
1412          ^                                        |
1413          {0:~                                       }|*5
1414        ## grid 3
1415                                                  |
1416        ## grid 4
1417          {1:                    }|
1418          {2:~                   }|
1419        ]],
1420          float_pos = expected_pos,
1421        }
1422      else
1423        screen:expect([[
1424          ^                                        |
1425          {0:~                                       }|
1426          {0:~    }{1:                    }{0:               }|
1427          {0:~    }{2:~                   }{0:               }|
1428          {0:~                                       }|*2
1429                                                  |
1430          ]])
1431      end
1432
1433      api.nvim_win_set_config(win, { relative = 'editor', row = 0, col = 10 })
1434      expected_pos[4][4] = 0
1435      expected_pos[4][5] = 10
1436      expected_pos[4][9] = 0
1437      expected_pos[4][10] = 10
1438      if multigrid then
1439        screen:expect {
1440          grid = [[
1441        ## grid 1
1442          [2:----------------------------------------]|*6
1443          [3:----------------------------------------]|
1444        ## grid 2
1445          ^                                        |
1446          {0:~                                       }|*5
1447        ## grid 3
1448                                                  |
1449        ## grid 4
1450          {1:                    }|
1451          {2:~                   }|
1452        ]],
1453          float_pos = expected_pos,
1454        }
1455      else
1456        screen:expect([[
1457          ^          {1:                    }          |
1458          {0:~         }{2:~                   }{0:          }|
1459          {0:~                                       }|*4
1460                                                  |
1461        ]])
1462      end
1463
1464      api.nvim_win_close(win, false)
1465      if multigrid then
1466        screen:expect([[
1467        ## grid 1
1468          [2:----------------------------------------]|*6
1469          [3:----------------------------------------]|
1470        ## grid 2
1471          ^                                        |
1472          {0:~                                       }|*5
1473        ## grid 3
1474                                                  |
1475        ]])
1476      else
1477        screen:expect([[
1478          ^                                        |
1479          {0:~                                       }|*5
1480                                                  |
1481        ]])
1482      end
1483    end)
1484
1485    it('window position fixed', function()
1486      command('rightbelow 20vsplit')
1487      local buf = api.nvim_create_buf(false, false)
1488      local win = api.nvim_open_win(buf, false, {
1489        relative = 'win',
1490        width = 15,
1491        height = 2,
1492        row = 2,
1493        col = 10,
1494        anchor = 'NW',
1495        fixed = true,
1496      })
1497
1498      if multigrid then
1499        screen:expect {
1500          grid = [[
1501        ## grid 1
1502          [2:-------------------]{5:│}[4:--------------------]|*5
1503          {5:[No Name]           }{4:[No Name]           }|
1504          [3:----------------------------------------]|
1505        ## grid 2
1506                             |
1507          {0:~                  }|*4
1508        ## grid 3
1509                                                  |
1510        ## grid 4
1511          ^                    |
1512          {0:~                   }|*4
1513        ## grid 5
1514          {1:               }|
1515          {2:~              }|
1516        ]],
1517          float_pos = { [5] = { 1002, 'NW', 4, 2, 10, true, 50, 1, 2, 30 } },
1518        }
1519      else
1520        screen:expect([[
1521                             {5:│}^                    |
1522          {0:~                  }{5:│}{0:~                   }|
1523          {0:~                  }{5:│}{0:~         }{1:          }|
1524          {0:~                  }{5:│}{0:~         }{2:~         }|
1525          {0:~                  }{5:│}{0:~                   }|
1526          {5:[No Name]           }{4:[No Name]           }|
1527                                                  |
1528        ]])
1529      end
1530
1531      api.nvim_win_set_config(win, { fixed = false })
1532
1533      if multigrid then
1534        screen:expect {
1535          grid = [[
1536        ## grid 1
1537          [2:-------------------]{5:│}[4:--------------------]|*5
1538          {5:[No Name]           }{4:[No Name]           }|
1539          [3:----------------------------------------]|
1540        ## grid 2
1541                             |
1542          {0:~                  }|*4
1543        ## grid 3
1544                                                  |
1545        ## grid 4
1546          ^                    |
1547          {0:~                   }|*4
1548        ## grid 5
1549          {1:               }|
1550          {2:~              }|
1551        ]],
1552          float_pos = { [5] = { 1002, 'NW', 4, 2, 10, true, 50, 1, 2, 25 } },
1553        }
1554      else
1555        screen:expect([[
1556                             {5:│}^                    |
1557          {0:~                  }{5:│}{0:~                   }|
1558          {0:~                  }{5:│}{0:~    }{1:               }|
1559          {0:~                  }{5:│}{0:~    }{2:~              }|
1560          {0:~                  }{5:│}{0:~                   }|
1561          {5:[No Name]           }{4:[No Name]           }|
1562                                                  |
1563        ]])
1564      end
1565    end)
1566
1567    it('draws correctly with redrawdebug=compositor', function()
1568      -- NB: we do not test that it produces the "correct" debug info
1569      -- (as it is intermediate only, and is allowed to change by internal
1570      -- refactors). Only check that it doesn't cause permanent glitches,
1571      -- or something.
1572      command('set redrawdebug=compositor')
1573      command('set wd=1')
1574      local buf = api.nvim_create_buf(false, false)
1575      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
1576      local expected_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } }
1577
1578      if multigrid then
1579        screen:expect {
1580          grid = [[
1581        ## grid 1
1582          [2:----------------------------------------]|*6
1583          [3:----------------------------------------]|
1584        ## grid 2
1585          ^                                        |
1586          {0:~                                       }|*5
1587        ## grid 3
1588                                                  |
1589        ## grid 4
1590          {1:                    }|
1591          {2:~                   }|
1592        ]],
1593          float_pos = expected_pos,
1594        }
1595      else
1596        screen:expect([[
1597          ^                                        |
1598          {0:~                                       }|
1599          {0:~    }{1:                    }{0:               }|
1600          {0:~    }{2:~                   }{0:               }|
1601          {0:~                                       }|*2
1602                                                  |
1603          ]])
1604      end
1605
1606      api.nvim_win_set_config(win, { relative = 'editor', row = 0, col = 10 })
1607      expected_pos[4][4] = 0
1608      expected_pos[4][5] = 10
1609      expected_pos[4][9] = 0
1610      expected_pos[4][10] = 10
1611      if multigrid then
1612        screen:expect {
1613          grid = [[
1614        ## grid 1
1615          [2:----------------------------------------]|*6
1616          [3:----------------------------------------]|
1617        ## grid 2
1618          ^                                        |
1619          {0:~                                       }|*5
1620        ## grid 3
1621                                                  |
1622        ## grid 4
1623          {1:                    }|
1624          {2:~                   }|
1625        ]],
1626          float_pos = expected_pos,
1627        }
1628      else
1629        screen:expect([[
1630          ^          {1:                    }          |
1631          {0:~         }{2:~                   }{0:          }|
1632          {0:~                                       }|*4
1633                                                  |
1634        ]])
1635      end
1636
1637      api.nvim_win_close(win, false)
1638      if multigrid then
1639        screen:expect([[
1640        ## grid 1
1641          [2:----------------------------------------]|*6
1642          [3:----------------------------------------]|
1643        ## grid 2
1644          ^                                        |
1645          {0:~                                       }|*5
1646        ## grid 3
1647                                                  |
1648        ]])
1649      else
1650        screen:expect([[
1651          ^                                        |
1652          {0:~                                       }|*5
1653                                                  |
1654        ]])
1655      end
1656    end)
1657
1658    it('return their configuration', function()
1659      local buf = api.nvim_create_buf(false, false)
1660      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 3, col = 5, zindex = 60 })
1661      local expected = {
1662        anchor = 'NW',
1663        border = 'none',
1664        style = '',
1665        col = 5,
1666        external = false,
1667        focusable = true,
1668        mouse = true,
1669        height = 2,
1670        relative = 'editor',
1671        row = 3,
1672        width = 20,
1673        zindex = 60,
1674        hide = false,
1675      }
1676      eq(expected, api.nvim_win_get_config(win))
1677      eq(
1678        true,
1679        exec_lua(
1680          [[
1681        local expected, win = ...
1682        local actual = vim.api.nvim_win_get_config(win)
1683        for k,v in pairs(expected) do
1684          if v ~= actual[k] then
1685            error(k)
1686          end
1687        end
1688        return true]],
1689          expected,
1690          win
1691        )
1692      )
1693
1694      eq({
1695        external = false,
1696        focusable = true,
1697        mouse = true,
1698        hide = false,
1699        relative = '',
1700        style = '',
1701        split = 'left',
1702        width = 40,
1703        height = 6,
1704      }, api.nvim_win_get_config(0))
1705
1706      if multigrid then
1707        api.nvim_win_set_config(win, { external = true, width = 10, height = 1 })
1708        eq({
1709          external = true,
1710          focusable = true,
1711          mouse = true,
1712          width = 10,
1713          height = 1,
1714          relative = '',
1715          style = '',
1716          hide = false,
1717          border = 'none',
1718        }, api.nvim_win_get_config(win))
1719      end
1720    end)
1721
1722    it('defaults to NormalFloat highlight and inherited options', function()
1723      command('set number')
1724      command('hi NormalFloat guibg=#333333 guifg=NONE')
1725      feed('ix<cr>y<cr><esc>gg')
1726      local win = api.nvim_open_win(0, false, { relative = 'editor', width = 20, height = 4, row = 4, col = 10 })
1727      if multigrid then
1728        screen:expect {
1729          grid = [[
1730        ## grid 1
1731          [2:----------------------------------------]|*6
1732          [3:----------------------------------------]|
1733        ## grid 2
1734          {14:  1 }^x                                   |
1735          {14:  2 }y                                   |
1736          {14:  3 }                                    |
1737          {0:~                                       }|*3
1738        ## grid 3
1739                                                  |
1740        ## grid 4
1741          {18:  1 }{15:x               }|
1742          {18:  2 }{15:y               }|
1743          {18:  3 }{15:                }|
1744          {16:~                   }|
1745        ]],
1746          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
1747        }
1748      else
1749        screen:expect([[
1750          {14:  1 }^x                                   |
1751          {14:  2 }y                                   |
1752          {14:  3 }      {18:  1 }{15:x               }          |
1753          {0:~         }{18:  2 }{15:y               }{0:          }|
1754          {0:~         }{18:  3 }{15:                }{0:          }|
1755          {0:~         }{16:~                   }{0:          }|
1756                                                  |
1757        ]])
1758      end
1759
1760      local buf = api.nvim_create_buf(false, true)
1761      api.nvim_win_set_buf(win, buf)
1762      if multigrid then
1763        screen:expect {
1764          grid = [[
1765        ## grid 1
1766          [2:----------------------------------------]|*6
1767          [3:----------------------------------------]|
1768        ## grid 2
1769          {14:  1 }^x                                   |
1770          {14:  2 }y                                   |
1771          {14:  3 }                                    |
1772          {0:~                                       }|*3
1773        ## grid 3
1774                                                  |
1775        ## grid 4
1776          {18:  1 }{15:                }|
1777          {16:~                   }|*3
1778        ]],
1779          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
1780        }
1781      else
1782        screen:expect([[
1783          {14:  1 }^x                                   |
1784          {14:  2 }y                                   |
1785          {14:  3 }      {18:  1 }{15:                }          |
1786          {0:~         }{16:~                   }{0:          }|*3
1787                                                  |
1788        ]])
1789      end
1790
1791      --
1792      -- floating windows inherit NormalFloat from global-ns.
1793      --
1794      command('fclose')
1795      command('hi NormalFloat guibg=LightRed')
1796      api.nvim_open_win(0, false, { relative = 'win', row = 3, col = 3, width = 12, height = 3, style = 'minimal' })
1797      api.nvim_set_hl_ns(api.nvim_create_namespace('test1'))
1798      if multigrid then
1799        screen:expect({
1800          grid = [[
1801          ## grid 1
1802            [2:----------------------------------------]|*6
1803            [3:----------------------------------------]|
1804          ## grid 2
1805            {14:  1 }^x                                   |
1806            {14:  2 }y                                   |
1807            {14:  3 }                                    |
1808            {0:~                                       }|*3
1809          ## grid 3
1810                                                    |
1811          ## grid 5
1812            {22:x           }|
1813            {22:y           }|
1814            {22:            }|
1815          ]],
1816          float_pos = { [5] = { 1002, 'NW', 2, 3, 3, true, 50, 1, 3, 3 } },
1817          win_viewport = {
1818            [2] = { win = 1000, topline = 0, botline = 4, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
1819            [5] = { win = 1002, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
1820          },
1821          win_viewport_margins = {
1822            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
1823            [5] = { bottom = 0, left = 0, right = 0, top = 0, win = 1002 },
1824          },
1825        })
1826      else
1827        screen:expect({
1828          grid = [[
1829            {14:  1 }^x                                   |
1830            {14:  2 }y                                   |
1831            {14:  3 }                                    |
1832            {0:~  }{22:x           }{0:                         }|
1833            {0:~  }{22:y           }{0:                         }|
1834            {0:~  }{22:            }{0:                         }|
1835                                                    |
1836          ]],
1837        })
1838      end
1839    end)
1840
1841    it("can use 'minimal' style", function()
1842      command('set number')
1843      command('set signcolumn=yes')
1844      command('set colorcolumn=1')
1845      command('set cursorline')
1846      command('set foldcolumn=1')
1847      command('hi NormalFloat guibg=#333333 guifg=NONE')
1848      feed('ix<cr>y<cr><esc>gg')
1849      local win = api.nvim_open_win(0, false, { relative = 'editor', width = 20, height = 4, row = 4, col = 10, style = 'minimal' })
1850      if multigrid then
1851        screen:expect {
1852          grid = [[
1853        ## grid 1
1854          [2:----------------------------------------]|*6
1855          [3:----------------------------------------]|
1856        ## grid 2
1857          {19:   }{20:  1 }{22:^x}{21:                                }|
1858          {19:   }{14:  2 }{22:y}                                |
1859          {19:   }{14:  3 }{22: }                                |
1860          {0:~                                       }|*3
1861        ## grid 3
1862                                                  |
1863        ## grid 4
1864          {15:x                   }|
1865          {15:y                   }|
1866          {15:                    }|*2
1867        ]],
1868          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
1869        }
1870      else
1871        screen:expect {
1872          grid = [[
1873          {19:   }{20:  1 }{22:^x}{21:                                }|
1874          {19:   }{14:  2 }{22:y}                                |
1875          {19:   }{14:  3 }{22: }  {15:x                   }          |
1876          {0:~         }{15:y                   }{0:          }|
1877          {0:~         }{15:                    }{0:          }|*2
1878                                                  |
1879        ]],
1880        }
1881      end
1882
1883      --  signcolumn=yes still works if there actually are signs
1884      command('sign define piet1 text=𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄ texthl=Search')
1885      command('sign place 1 line=1 name=piet1 buffer=1')
1886      if multigrid then
1887        screen:expect {
1888          grid = [[
1889        ## grid 1
1890          [2:----------------------------------------]|*6
1891          [3:----------------------------------------]|
1892        ## grid 2
1893          {19: }{29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{20:  1 }{22:^x}{21:                                }|
1894          {19:   }{14:  2 }{22:y}                                |
1895          {19:   }{14:  3 }{22: }                                |
1896          {0:~                                       }|*3
1897        ## grid 3
1898                                                  |
1899        ## grid 4
1900          {29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{15:x                 }|
1901          {19:  }{15:y                 }|
1902          {19:  }{15:                  }|
1903          {15:                    }|
1904        ]],
1905          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
1906        }
1907      else
1908        screen:expect([[
1909          {19: }{29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{20:  1 }{22:^x}{21:                                }|
1910          {19:   }{14:  2 }{22:y}                                |
1911          {19:   }{14:  3 }{22: }  {29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{15:x                 }          |
1912          {0:~         }{19:  }{15:y                 }{0:          }|
1913          {0:~         }{19:  }{15:                  }{0:          }|
1914          {0:~         }{15:                    }{0:          }|
1915                                                  |
1916        ]])
1917      end
1918      command('sign unplace 1 buffer=1')
1919
1920      local buf = api.nvim_create_buf(false, true)
1921      api.nvim_win_set_buf(win, buf)
1922      if multigrid then
1923        screen:expect {
1924          grid = [[
1925        ## grid 1
1926          [2:----------------------------------------]|*6
1927          [3:----------------------------------------]|
1928        ## grid 2
1929          {19:   }{20:  1 }{22:^x}{21:                                }|
1930          {19:   }{14:  2 }{22:y}                                |
1931          {19:   }{14:  3 }{22: }                                |
1932          {0:~                                       }|*3
1933        ## grid 3
1934                                                  |
1935        ## grid 4
1936          {15:                    }|*4
1937        ]],
1938          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
1939        }
1940      else
1941        screen:expect([[
1942          {19:   }{20:  1 }{22:^x}{21:                                }|
1943          {19:   }{14:  2 }{22:y}                                |
1944          {19:   }{14:  3 }{22: }  {15:                    }          |
1945          {0:~         }{15:                    }{0:          }|*3
1946                                                  |
1947        ]])
1948      end
1949    end)
1950
1951    it("would not break 'minimal' style with signcolumn=auto:[min]-[max]", function()
1952      command('set number')
1953      command('set signcolumn=auto:1-3')
1954      command('set colorcolumn=1')
1955      command('set cursorline')
1956      command('set foldcolumn=1')
1957      command('hi NormalFloat guibg=#333333 guifg=NONE')
1958      feed('ix<cr>y<cr><esc>gg')
1959      local win = api.nvim_open_win(0, false, { relative = 'editor', width = 20, height = 4, row = 4, col = 10, style = 'minimal' })
1960      if multigrid then
1961        screen:expect {
1962          grid = [[
1963        ## grid 1
1964          [2:----------------------------------------]|*6
1965          [3:----------------------------------------]|
1966        ## grid 2
1967          {19:   }{20:  1 }{22:^x}{21:                                }|
1968          {19:   }{14:  2 }{22:y}                                |
1969          {19:   }{14:  3 }{22: }                                |
1970          {0:~                                       }|*3
1971        ## grid 3
1972                                                  |
1973        ## grid 4
1974          {15:x                   }|
1975          {15:y                   }|
1976          {15:                    }|*2
1977        ]],
1978          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
1979        }
1980      else
1981        screen:expect {
1982          grid = [[
1983          {19:   }{20:  1 }{22:^x}{21:                                }|
1984          {19:   }{14:  2 }{22:y}                                |
1985          {19:   }{14:  3 }{22: }  {15:x                   }          |
1986          {0:~         }{15:y                   }{0:          }|
1987          {0:~         }{15:                    }{0:          }|*2
1988                                                  |
1989        ]],
1990        }
1991      end
1992
1993      command('sign define piet1 text=𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄ texthl=Search')
1994      command('sign place 1 line=1 name=piet1 buffer=1')
1995      --  signcolumn=auto:1-3 still works if there actually are signs
1996      if multigrid then
1997        screen:expect {
1998          grid = [[
1999        ## grid 1
2000          [2:----------------------------------------]|*6
2001          [3:----------------------------------------]|
2002        ## grid 2
2003          {19: }{29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{20:  1 }{22:^x}{21:                                }|
2004          {19:   }{14:  2 }{22:y}                                |
2005          {19:   }{14:  3 }{22: }                                |
2006          {0:~                                       }|*3
2007        ## grid 3
2008                                                  |
2009        ## grid 4
2010          {29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{15:x                 }|
2011          {19:  }{15:y                 }|
2012          {19:  }{15:                  }|
2013          {15:                    }|
2014        ]],
2015          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
2016        }
2017      else
2018        screen:expect([[
2019          {19: }{29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{20:  1 }{22:^x}{21:                                }|
2020          {19:   }{14:  2 }{22:y}                                |
2021          {19:   }{14:  3 }{22: }  {29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{15:x                 }          |
2022          {0:~         }{19:  }{15:y                 }{0:          }|
2023          {0:~         }{19:  }{15:                  }{0:          }|
2024          {0:~         }{15:                    }{0:          }|
2025                                                  |
2026        ]])
2027      end
2028      command('sign unplace 1 buffer=1')
2029
2030      local buf = api.nvim_create_buf(false, true)
2031      api.nvim_win_set_buf(win, buf)
2032      if multigrid then
2033        screen:expect {
2034          grid = [[
2035        ## grid 1
2036          [2:----------------------------------------]|*6
2037          [3:----------------------------------------]|
2038        ## grid 2
2039          {19:   }{20:  1 }{22:^x}{21:                                }|
2040          {19:   }{14:  2 }{22:y}                                |
2041          {19:   }{14:  3 }{22: }                                |
2042          {0:~                                       }|*3
2043        ## grid 3
2044                                                  |
2045        ## grid 4
2046          {15:                    }|*4
2047        ]],
2048          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
2049        }
2050      else
2051        screen:expect([[
2052          {19:   }{20:  1 }{22:^x}{21:                                }|
2053          {19:   }{14:  2 }{22:y}                                |
2054          {19:   }{14:  3 }{22: }  {15:                    }          |
2055          {0:~         }{15:                    }{0:          }|*3
2056                                                  |
2057        ]])
2058      end
2059    end)
2060
2061    it("would not break 'minimal' style with statuscolumn set", function()
2062      command('set number')
2063      command('set signcolumn=yes')
2064      command('set colorcolumn=1')
2065      command('set cursorline')
2066      command('set foldcolumn=1')
2067      command('set statuscolumn=%l%s%C')
2068      command('hi NormalFloat guibg=#333333 guifg=NONE')
2069      feed('ix<cr>y<cr><esc>gg')
2070      api.nvim_open_win(0, false, { relative = 'editor', width = 20, height = 4, row = 4, col = 10, style = 'minimal' })
2071      if multigrid then
2072        screen:expect({
2073          grid = [[
2074          ## grid 1
2075            [2:----------------------------------------]|*6
2076            [3:----------------------------------------]|
2077          ## grid 2
2078            {20:   1}{19:   }{22:^x}{21:                                }|
2079            {14:   2}{19:   }{22:y}                                |
2080            {14:   3}{19:   }{22: }                                |
2081            {0:~                                       }|*3
2082          ## grid 3
2083                                                    |
2084          ## grid 4
2085            {15:x                   }|
2086            {15:y                   }|
2087            {15:                    }|*2
2088          ]],
2089          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
2090        })
2091      else
2092        screen:expect([[
2093          {20:   1}{19:   }{22:^x}{21:                                }|
2094          {14:   2}{19:   }{22:y}                                |
2095          {14:   3}{19:   }{22: }  {15:x                   }          |
2096          {0:~         }{15:y                   }{0:          }|
2097          {0:~         }{15:                    }{0:          }|*2
2098                                                  |
2099        ]])
2100      end
2101    end)
2102
2103    it('can have border', function()
2104      local buf = api.nvim_create_buf(false, false)
2105      api.nvim_buf_set_lines(buf, 0, -1, true, { ' halloj! ', ' BORDAA  ' })
2106      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 9, height = 2, row = 2, col = 5, border = 'double' })
2107      eq('╔', api.nvim_win_get_config(win).border[1])
2108
2109      api.nvim_win_set_config(win, { border = 'single' })
2110      eq('┌', api.nvim_win_get_config(win).border[1])
2111
2112      api.nvim_win_set_config(win, { border = 'rounded' })
2113      eq('╭', api.nvim_win_get_config(win).border[1])
2114
2115      api.nvim_win_set_config(win, { border = 'solid' })
2116      eq(' ', api.nvim_win_get_config(win).border[1])
2117
2118      -- support: ascii char, UTF-8 char, composed char, highlight per char
2119      api.nvim_win_set_config(win, { border = { 'x', { 'å', 'ErrorMsg' }, { '\\' }, { 'n̈̊', 'Search' } } })
2120      eq(
2121        { 'x', { 'å', 'ErrorMsg' }, '\\', { 'n̈̊', 'Search' }, 'x', { 'å', 'ErrorMsg' }, '\\', { 'n̈̊', 'Search' } },
2122        api.nvim_win_get_config(win).border
2123      )
2124      if multigrid then
2125        screen:expect {
2126          grid = [[
2127        ## grid 1
2128          [2:----------------------------------------]|*6
2129          [3:----------------------------------------]|
2130        ## grid 2
2131          ^                                        |
2132          {0:~                                       }|*5
2133        ## grid 3
2134                                                  |
2135        ## grid 4
2136          {33:x}{7:ååååååååå}{33:\}|
2137          {17:n̈̊}{1: halloj! }{17:n̈̊}|
2138          {17:n̈̊}{1: BORDAA  }{17:n̈̊}|
2139          {33:\}{7:ååååååååå}{33:x}|
2140        ]],
2141          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2142          win_viewport = {
2143            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2144            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2145          },
2146        }
2147      else
2148        screen:expect {
2149          grid = [[
2150          ^                                        |
2151          {0:~                                       }|
2152          {0:~    }{33:x}{7:ååååååååå}{33:\}{0:                        }|
2153          {0:~    }{17:n̈̊}{1: halloj! }{17:n̈̊}{0:                        }|
2154          {0:~    }{17:n̈̊}{1: BORDAA  }{17:n̈̊}{0:                        }|
2155          {0:~    }{33:\}{7:ååååååååå}{33:x}{0:                        }|
2156                                                  |
2157        ]],
2158        }
2159      end
2160
2161      api.nvim_win_set_config(win, { border = 'none' })
2162      eq('none', api.nvim_win_get_config(win).border)
2163
2164      api.nvim_win_set_config(win, { border = { '', '', '', '>', '', '', '', '<' } })
2165      eq({ '', '', '', '>', '', '', '', '<' }, api.nvim_win_get_config(win).border)
2166      if multigrid then
2167        screen:expect {
2168          grid = [[
2169        ## grid 1
2170          [2:----------------------------------------]|*6
2171          [3:----------------------------------------]|
2172        ## grid 2
2173          ^                                        |
2174          {0:~                                       }|*5
2175        ## grid 3
2176                                                  |
2177        ## grid 4
2178          {33:<}{1: halloj! }{33:>}|
2179          {33:<}{1: BORDAA  }{33:>}|
2180        ]],
2181          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2182          win_viewport = {
2183            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2184            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2185          },
2186          win_viewport_margins = {
2187            [2] = { win = 1000, top = 0, bottom = 0, left = 0, right = 0 },
2188            [4] = { win = 1001, top = 0, bottom = 0, left = 1, right = 1 },
2189          },
2190        }
2191      else
2192        screen:expect {
2193          grid = [[
2194          ^                                        |
2195          {0:~                                       }|
2196          {0:~    }{33:<}{1: halloj! }{33:>}{0:                        }|
2197          {0:~    }{33:<}{1: BORDAA  }{33:>}{0:                        }|
2198          {0:~                                       }|*2
2199                                                  |
2200        ]],
2201        }
2202      end
2203
2204      api.nvim_win_set_config(win, { border = { '', '_', '', '', '', '-', '', '' } })
2205      eq({ '', '_', '', '', '', '-', '', '' }, api.nvim_win_get_config(win).border)
2206      if multigrid then
2207        screen:expect {
2208          grid = [[
2209        ## grid 1
2210          [2:----------------------------------------]|*6
2211          [3:----------------------------------------]|
2212        ## grid 2
2213          ^                                        |
2214          {0:~                                       }|*5
2215        ## grid 3
2216                                                  |
2217        ## grid 4
2218          {33:_________}|
2219          {1: halloj! }|
2220          {1: BORDAA  }|
2221          {33:---------}|
2222        ]],
2223          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2224          win_viewport = {
2225            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2226            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2227          },
2228          win_viewport_margins = {
2229            [2] = { win = 1000, top = 0, bottom = 0, left = 0, right = 0 },
2230            [4] = { win = 1001, top = 1, bottom = 1, left = 0, right = 0 },
2231          },
2232        }
2233      else
2234        screen:expect {
2235          grid = [[
2236          ^                                        |
2237          {0:~                                       }|
2238          {0:~    }{33:_________}{0:                          }|
2239          {0:~    }{1: halloj! }{0:                          }|
2240          {0:~    }{1: BORDAA  }{0:                          }|
2241          {0:~    }{33:---------}{0:                          }|
2242                                                  |
2243        ]],
2244        }
2245      end
2246
2247      insert [[
2248        neeed some dummy
2249        background text
2250        to show the effect
2251        of color blending
2252        of border shadow
2253      ]]
2254
2255      api.nvim_win_set_config(win, { border = 'shadow' })
2256      if multigrid then
2257        screen:expect {
2258          grid = [[
2259        ## grid 1
2260          [2:----------------------------------------]|*6
2261          [3:----------------------------------------]|
2262        ## grid 2
2263          neeed some dummy                        |
2264          background text                         |
2265          to show the effect                      |
2266          of color blending                       |
2267          of border shadow                        |
2268          ^                                        |
2269        ## grid 3
2270                                                  |
2271        ## grid 4
2272          {1: halloj! }{25: }|
2273          {1: BORDAA  }{26: }|
2274          {25: }{26:         }|
2275        ]],
2276          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2277          win_viewport = {
2278            [2] = { win = 1000, topline = 0, botline = 6, curline = 5, curcol = 0, linecount = 6, sum_scroll_delta = 0 },
2279            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2280          },
2281          win_viewport_margins = {
2282            [2] = { win = 1000, top = 0, bottom = 0, left = 0, right = 0 },
2283            [4] = { win = 1001, top = 0, bottom = 1, left = 0, right = 1 },
2284          },
2285        }
2286      else
2287        screen:expect {
2288          grid = [[
2289          neeed some dummy                        |
2290          background text                         |
2291          to sh{1: halloj! }{31:f}ect                      |
2292          of co{1: BORDAA  }{24:i}ng                       |
2293          of bo{31:r}{24:der shado}w                        |
2294          ^                                        |
2295                                                  |
2296        ]],
2297        }
2298      end
2299    end)
2300
2301    it('nvim_win_get_config.title_pos', function()
2302      local title_pos = exec_lua([[
2303        local bufnr = vim.api.nvim_create_buf(false, false)
2304        local opts = {
2305          relative = 'editor',
2306          col = 2,
2307          row = 5,
2308          height = 2,
2309          width = 9,
2310          border = 'double',
2311          title = 'Test',
2312          title_pos = 'center'
2313        }
2314
2315        local win_id = vim.api.nvim_open_win(bufnr, true, opts)
2316        return vim.api.nvim_win_get_config(win_id).title_pos
2317      ]])
2318
2319      eq('center', title_pos)
2320    end)
2321
2322    it('nvim_win_get_config.footer_pos', function()
2323      local footer_pos = exec_lua([[
2324        local bufnr = vim.api.nvim_create_buf(false, false)
2325        local opts = {
2326          relative = 'editor',
2327          col = 2,
2328          row = 5,
2329          height = 2,
2330          width = 9,
2331          border = 'double',
2332          footer = 'Test',
2333          footer_pos = 'center'
2334        }
2335
2336        local win_id = vim.api.nvim_open_win(bufnr, true, opts)
2337        return vim.api.nvim_win_get_config(win_id).footer_pos
2338      ]])
2339
2340      eq('center', footer_pos)
2341    end)
2342
2343    it('truncates title longer than window width #25746 #23602', function()
2344      local buf = api.nvim_create_buf(false, false)
2345      api.nvim_buf_set_lines(buf, 0, -1, true, { ' halloj! ', ' BORDAA  ' })
2346      local config = {
2347        relative = 'editor',
2348        width = 9,
2349        height = 2,
2350        row = 2,
2351        col = 5,
2352        border = 'double',
2353        title = 'abcdefghijklmnopqrstuvwxyz',
2354        title_pos = 'center',
2355        footer = 'abcdefghi', -- exactly fits window width #36872
2356      }
2357      local win = api.nvim_open_win(buf, false, config)
2358      if multigrid then
2359        screen:expect {
2360          grid = [[
2361        ## grid 1
2362          [2:----------------------------------------]|*6
2363          [3:----------------------------------------]|
2364        ## grid 2
2365          ^                                        |
2366          {0:~                                       }|*5
2367        ## grid 3
2368                                                  |
2369        ## grid 4
2370          {33:╔}{11:<stuvwxyz}{33:╗}|
2371          {33:║}{1: halloj! }{33:║}|
2372          {33:║}{1: BORDAA  }{33:║}|
2373          {33:╚}{11:abcdefghi}{33:╝}|
2374        ]],
2375          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2376          win_viewport = {
2377            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2378            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2379          },
2380        }
2381      else
2382        screen:expect {
2383          grid = [[
2384          ^                                        |
2385          {0:~                                       }|
2386          {0:~    }{33:╔}{11:<stuvwxyz}{33:╗}{0:                        }|
2387          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
2388          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
2389          {0:~    }{33:╚}{11:abcdefghi}{33:╝}{0:                        }|
2390                                                  |
2391        ]],
2392        }
2393      end
2394      config.title = { { 'abcd' }, { 'stuvw' }, { 'xyz' } }
2395      api.nvim_win_set_config(win, config)
2396      screen:expect_unchanged()
2397      api.nvim_win_close(win, false)
2398      assert_alive()
2399    end)
2400
2401    it('no border with title and footer', function()
2402      local buf = api.nvim_create_buf(false, false)
2403      api.nvim_buf_set_lines(buf, 0, -1, true, { 'Hello' })
2404      api.nvim_open_win(buf, false, {
2405        relative = 'editor',
2406        width = 9,
2407        height = 2,
2408        row = 2,
2409        col = 5,
2410        title = 'Title',
2411        footer = 'Footer',
2412      })
2413
2414      if multigrid then
2415        screen:expect({
2416          grid = [[
2417          ## grid 1
2418            [2:----------------------------------------]|*6
2419            [3:----------------------------------------]|
2420          ## grid 2
2421            ^                                        |
2422            {0:~                                       }|*5
2423          ## grid 3
2424                                                    |
2425          ## grid 4
2426            {1:Hello    }|
2427            {2:~        }|
2428          ]],
2429          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2430          win_viewport = {
2431            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2432            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2433          },
2434        })
2435      else
2436        screen:expect([[
2437          ^                                        |
2438          {0:~                                       }|
2439          {0:~    }{1:Hello    }{0:                          }|
2440          {0:~    }{2:~        }{0:                          }|
2441          {0:~                                       }|*2
2442                                                  |
2443        ]])
2444      end
2445    end)
2446
2447    it('border with title', function()
2448      local buf = api.nvim_create_buf(false, false)
2449      api.nvim_buf_set_lines(buf, 0, -1, true, { ' halloj! ', ' BORDAA  ' })
2450      local win = api.nvim_open_win(buf, false, {
2451        relative = 'editor',
2452        width = 9,
2453        height = 2,
2454        row = 2,
2455        col = 5,
2456        border = 'double',
2457        title = 'Left',
2458        title_pos = 'left',
2459      })
2460
2461      if multigrid then
2462        screen:expect {
2463          grid = [[
2464        ## grid 1
2465          [2:----------------------------------------]|*6
2466          [3:----------------------------------------]|
2467        ## grid 2
2468          ^                                        |
2469          {0:~                                       }|*5
2470        ## grid 3
2471                                                  |
2472        ## grid 4
2473          {33:╔}{11:Left}{33:═════╗}|
2474          {33:║}{1: halloj! }{33:║}|
2475          {33:║}{1: BORDAA  }{33:║}|
2476          {33:╚═════════╝}|
2477        ]],
2478          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2479          win_viewport = {
2480            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2481            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2482          },
2483        }
2484      else
2485        screen:expect {
2486          grid = [[
2487          ^                                        |
2488          {0:~                                       }|
2489          {0:~    }{33:╔}{11:Left}{33:═════╗}{0:                        }|
2490          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
2491          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
2492          {0:~    }{33:╚═════════╝}{0:                        }|
2493                                                  |
2494        ]],
2495        }
2496      end
2497
2498      api.nvim_win_set_config(win, { title = 'Center', title_pos = 'center' })
2499      if multigrid then
2500        screen:expect {
2501          grid = [[
2502        ## grid 1
2503          [2:----------------------------------------]|*6
2504          [3:----------------------------------------]|
2505        ## grid 2
2506          ^                                        |
2507          {0:~                                       }|*5
2508        ## grid 3
2509                                                  |
2510        ## grid 4
2511          {33:╔═}{11:Center}{33:══╗}|
2512          {33:║}{1: halloj! }{33:║}|
2513          {33:║}{1: BORDAA  }{33:║}|
2514          {33:╚═════════╝}|
2515        ]],
2516          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2517          win_viewport = {
2518            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2519            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2520          },
2521        }
2522      else
2523        screen:expect {
2524          grid = [[
2525          ^                                        |
2526          {0:~                                       }|
2527          {0:~    }{33:╔═}{11:Center}{33:══╗}{0:                        }|
2528          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
2529          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
2530          {0:~    }{33:╚═════════╝}{0:                        }|
2531                                                  |
2532        ]],
2533        }
2534      end
2535
2536      api.nvim_win_set_config(win, { title = 'Right', title_pos = 'right' })
2537      if multigrid then
2538        screen:expect {
2539          grid = [[
2540        ## grid 1
2541          [2:----------------------------------------]|*6
2542          [3:----------------------------------------]|
2543        ## grid 2
2544          ^                                        |
2545          {0:~                                       }|*5
2546        ## grid 3
2547                                                  |
2548        ## grid 4
2549          {33:╔════}{11:Right}{33:╗}|
2550          {33:║}{1: halloj! }{33:║}|
2551          {33:║}{1: BORDAA  }{33:║}|
2552          {33:╚═════════╝}|
2553        ]],
2554          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2555          win_viewport = {
2556            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2557            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2558          },
2559        }
2560      else
2561        screen:expect {
2562          grid = [[
2563          ^                                        |
2564          {0:~                                       }|
2565          {0:~    }{33:╔════}{11:Right}{33:╗}{0:                        }|
2566          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
2567          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
2568          {0:~    }{33:╚═════════╝}{0:                        }|
2569                                                  |
2570        ]],
2571        }
2572      end
2573
2574      api.nvim_win_set_config(win, { title = { { '🦄' }, { 'BB' } }, title_pos = 'right' })
2575      if multigrid then
2576        screen:expect {
2577          grid = [[
2578        ## grid 1
2579          [2:----------------------------------------]|*6
2580          [3:----------------------------------------]|
2581        ## grid 2
2582          ^                                        |
2583          {0:~                                       }|*5
2584        ## grid 3
2585                                                  |
2586        ## grid 4
2587          {33:╔═════}{11:🦄BB}{33:╗}|
2588          {33:║}{1: halloj! }{33:║}|
2589          {33:║}{1: BORDAA  }{33:║}|
2590          {33:╚═════════╝}|
2591        ]],
2592          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2593          win_viewport = {
2594            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2595            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2596          },
2597        }
2598      else
2599        screen:expect {
2600          grid = [[
2601          ^                                        |
2602          {0:~                                       }|
2603          {0:~    }{33:╔═════}{11:🦄BB}{33:╗}{0:                        }|
2604          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
2605          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
2606          {0:~    }{33:╚═════════╝}{0:                        }|
2607                                                  |
2608        ]],
2609        }
2610      end
2611
2612      -- reuse before title pos
2613      api.nvim_win_set_config(win, { title = 'new' })
2614      if multigrid then
2615        screen:expect({
2616          grid = [[
2617          ## grid 1
2618            [2:----------------------------------------]|*6
2619            [3:----------------------------------------]|
2620          ## grid 2
2621            ^                                        |
2622            {0:~                                       }|*5
2623          ## grid 3
2624                                                    |
2625          ## grid 4
2626            {33:╔══════}{11:new}{33:╗}|
2627            {33:║}{1: halloj! }{33:║}|
2628            {33:║}{1: BORDAA  }{33:║}|
2629            {33:╚═════════╝}|
2630          ]],
2631          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2632          win_viewport = {
2633            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2634            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2635          },
2636          win_viewport_margins = {
2637            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
2638            [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 },
2639          },
2640        })
2641      else
2642        screen:expect([[
2643          ^                                        |
2644          {0:~                                       }|
2645          {0:~    }{33:╔══════}{11:new}{33:╗}{0:                        }|
2646          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
2647          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
2648          {0:~    }{33:╚═════════╝}{0:                        }|
2649                                                  |
2650        ]])
2651      end
2652    end)
2653
2654    it('border with footer', function()
2655      local buf = api.nvim_create_buf(false, false)
2656      api.nvim_buf_set_lines(buf, 0, -1, true, { ' halloj! ', ' BORDAA  ' })
2657      local win = api.nvim_open_win(buf, false, {
2658        relative = 'editor',
2659        width = 9,
2660        height = 2,
2661        row = 2,
2662        col = 5,
2663        border = 'double',
2664        footer = 'Left',
2665        footer_pos = 'left',
2666      })
2667
2668      if multigrid then
2669        screen:expect {
2670          grid = [[
2671        ## grid 1
2672          [2:----------------------------------------]|*6
2673          [3:----------------------------------------]|
2674        ## grid 2
2675          ^                                        |
2676          {0:~                                       }|*5
2677        ## grid 3
2678                                                  |
2679        ## grid 4
2680          {33:╔═════════╗}|
2681          {33:║}{1: halloj! }{33:║}|
2682          {33:║}{1: BORDAA  }{33:║}|
2683          {33:╚}{11:Left}{33:═════╝}|
2684        ]],
2685          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2686          win_viewport = {
2687            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2688            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2689          },
2690        }
2691      else
2692        screen:expect {
2693          grid = [[
2694          ^                                        |
2695          {0:~                                       }|
2696          {0:~    }{33:╔═════════╗}{0:                        }|
2697          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
2698          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
2699          {0:~    }{33:╚}{11:Left}{33:═════╝}{0:                        }|
2700                                                  |
2701        ]],
2702        }
2703      end
2704
2705      api.nvim_win_set_config(win, { footer = 'Center', footer_pos = 'center' })
2706      if multigrid then
2707        screen:expect {
2708          grid = [[
2709        ## grid 1
2710          [2:----------------------------------------]|*6
2711          [3:----------------------------------------]|
2712        ## grid 2
2713          ^                                        |
2714          {0:~                                       }|*5
2715        ## grid 3
2716                                                  |
2717        ## grid 4
2718          {33:╔═════════╗}|
2719          {33:║}{1: halloj! }{33:║}|
2720          {33:║}{1: BORDAA  }{33:║}|
2721          {33:╚═}{11:Center}{33:══╝}|
2722        ]],
2723          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
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 = 2, sum_scroll_delta = 0 },
2727          },
2728        }
2729      else
2730        screen:expect {
2731          grid = [[
2732          ^                                        |
2733          {0:~                                       }|
2734          {0:~    }{33:╔═════════╗}{0:                        }|
2735          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
2736          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
2737          {0:~    }{33:╚═}{11:Center}{33:══╝}{0:                        }|
2738                                                  |
2739        ]],
2740        }
2741      end
2742
2743      api.nvim_win_set_config(win, { footer = 'Right', footer_pos = 'right' })
2744      if multigrid then
2745        screen:expect {
2746          grid = [[
2747        ## grid 1
2748          [2:----------------------------------------]|*6
2749          [3:----------------------------------------]|
2750        ## grid 2
2751          ^                                        |
2752          {0:~                                       }|*5
2753        ## grid 3
2754                                                  |
2755        ## grid 4
2756          {33:╔═════════╗}|
2757          {33:║}{1: halloj! }{33:║}|
2758          {33:║}{1: BORDAA  }{33:║}|
2759          {33:╚════}{11:Right}{33:╝}|
2760        ]],
2761          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2762          win_viewport = {
2763            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2764            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2765          },
2766        }
2767      else
2768        screen:expect {
2769          grid = [[
2770          ^                                        |
2771          {0:~                                       }|
2772          {0:~    }{33:╔═════════╗}{0:                        }|
2773          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
2774          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
2775          {0:~    }{33:╚════}{11:Right}{33:╝}{0:                        }|
2776                                                  |
2777        ]],
2778        }
2779      end
2780
2781      api.nvim_win_set_config(win, { footer = { { '🦄' }, { 'BB' } }, footer_pos = 'right' })
2782      if multigrid then
2783        screen:expect {
2784          grid = [[
2785        ## grid 1
2786          [2:----------------------------------------]|*6
2787          [3:----------------------------------------]|
2788        ## grid 2
2789          ^                                        |
2790          {0:~                                       }|*5
2791        ## grid 3
2792                                                  |
2793        ## grid 4
2794          {33:╔═════════╗}|
2795          {33:║}{1: halloj! }{33:║}|
2796          {33:║}{1: BORDAA  }{33:║}|
2797          {33:╚═════}{11:🦄BB}{33:╝}|
2798        ]],
2799          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2800          win_viewport = {
2801            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2802            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2803          },
2804        }
2805      else
2806        screen:expect {
2807          grid = [[
2808          ^                                        |
2809          {0:~                                       }|
2810          {0:~    }{33:╔═════════╗}{0:                        }|
2811          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
2812          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
2813          {0:~    }{33:╚═════}{11:🦄BB}{33:╝}{0:                        }|
2814                                                  |
2815        ]],
2816        }
2817      end
2818
2819      -- reuse before footer pos
2820      api.nvim_win_set_config(win, { footer = 'new' })
2821      if multigrid then
2822        screen:expect({
2823          grid = [[
2824          ## grid 1
2825            [2:----------------------------------------]|*6
2826            [3:----------------------------------------]|
2827          ## grid 2
2828            ^                                        |
2829            {0:~                                       }|*5
2830          ## grid 3
2831                                                    |
2832          ## grid 4
2833            {33:╔═════════╗}|
2834            {33:║}{1: halloj! }{33:║}|
2835            {33:║}{1: BORDAA  }{33:║}|
2836            {33:╚══════}{11:new}{33:╝}|
2837          ]],
2838          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2839          win_viewport = {
2840            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2841            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2842          },
2843          win_viewport_margins = {
2844            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
2845            [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 },
2846          },
2847        })
2848      else
2849        screen:expect([[
2850          ^                                        |
2851          {0:~                                       }|
2852          {0:~    }{33:╔═════════╗}{0:                        }|
2853          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
2854          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
2855          {0:~    }{33:╚══════}{11:new}{33:╝}{0:                        }|
2856                                                  |
2857        ]])
2858      end
2859    end)
2860
2861    it('border with title and footer', function()
2862      local buf = api.nvim_create_buf(false, false)
2863      api.nvim_buf_set_lines(buf, 0, -1, true, { ' halloj! ', ' BORDAA  ' })
2864      local win = api.nvim_open_win(buf, false, {
2865        relative = 'editor',
2866        width = 9,
2867        height = 2,
2868        row = 2,
2869        col = 5,
2870        border = 'double',
2871        title = 'Left',
2872        title_pos = 'left',
2873        footer = 'Right',
2874        footer_pos = 'right',
2875      })
2876
2877      if multigrid then
2878        screen:expect {
2879          grid = [[
2880        ## grid 1
2881          [2:----------------------------------------]|*6
2882          [3:----------------------------------------]|
2883        ## grid 2
2884          ^                                        |
2885          {0:~                                       }|*5
2886        ## grid 3
2887                                                  |
2888        ## grid 4
2889          {33:╔}{11:Left}{33:═════╗}|
2890          {33:║}{1: halloj! }{33:║}|
2891          {33:║}{1: BORDAA  }{33:║}|
2892          {33:╚════}{11:Right}{33:╝}|
2893        ]],
2894          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2895          win_viewport = {
2896            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2897            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2898          },
2899        }
2900      else
2901        screen:expect {
2902          grid = [[
2903          ^                                        |
2904          {0:~                                       }|
2905          {0:~    }{33:╔}{11:Left}{33:═════╗}{0:                        }|
2906          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
2907          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
2908          {0:~    }{33:╚════}{11:Right}{33:╝}{0:                        }|
2909                                                  |
2910        ]],
2911        }
2912      end
2913
2914      api.nvim_win_set_config(win, { title = 'Center', title_pos = 'center', footer = 'Center', footer_pos = 'center' })
2915      if multigrid then
2916        screen:expect {
2917          grid = [[
2918        ## grid 1
2919          [2:----------------------------------------]|*6
2920          [3:----------------------------------------]|
2921        ## grid 2
2922          ^                                        |
2923          {0:~                                       }|*5
2924        ## grid 3
2925                                                  |
2926        ## grid 4
2927          {33:╔═}{11:Center}{33:══╗}|
2928          {33:║}{1: halloj! }{33:║}|
2929          {33:║}{1: BORDAA  }{33:║}|
2930          {33:╚═}{11:Center}{33:══╝}|
2931        ]],
2932          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2933          win_viewport = {
2934            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2935            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2936          },
2937        }
2938      else
2939        screen:expect {
2940          grid = [[
2941          ^                                        |
2942          {0:~                                       }|
2943          {0:~    }{33:╔═}{11:Center}{33:══╗}{0:                        }|
2944          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
2945          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
2946          {0:~    }{33:╚═}{11:Center}{33:══╝}{0:                        }|
2947                                                  |
2948        ]],
2949        }
2950      end
2951
2952      api.nvim_win_set_config(win, { title = 'Right', title_pos = 'right', footer = 'Left', footer_pos = 'left' })
2953      if multigrid then
2954        screen:expect {
2955          grid = [[
2956        ## grid 1
2957          [2:----------------------------------------]|*6
2958          [3:----------------------------------------]|
2959        ## grid 2
2960          ^                                        |
2961          {0:~                                       }|*5
2962        ## grid 3
2963                                                  |
2964        ## grid 4
2965          {33:╔════}{11:Right}{33:╗}|
2966          {33:║}{1: halloj! }{33:║}|
2967          {33:║}{1: BORDAA  }{33:║}|
2968          {33:╚}{11:Left}{33:═════╝}|
2969        ]],
2970          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
2971          win_viewport = {
2972            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
2973            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
2974          },
2975        }
2976      else
2977        screen:expect {
2978          grid = [[
2979          ^                                        |
2980          {0:~                                       }|
2981          {0:~    }{33:╔════}{11:Right}{33:╗}{0:                        }|
2982          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
2983          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
2984          {0:~    }{33:╚}{11:Left}{33:═════╝}{0:                        }|
2985                                                  |
2986        ]],
2987        }
2988      end
2989
2990      command('hi B0 guibg=Red guifg=Black')
2991      command('hi B1 guifg=White')
2992
2993      api.nvim_win_set_config(win, {
2994        title = { { '🦄' }, { 'BB', { 'B0', 'B1' } } },
2995        title_pos = 'right',
2996        footer = { { '🦄' }, { 'BB', { 'B0', 'B1' } } },
2997        footer_pos = 'right',
2998      })
2999      if multigrid then
3000        screen:expect {
3001          grid = [[
3002        ## grid 1
3003          [2:----------------------------------------]|*6
3004          [3:----------------------------------------]|
3005        ## grid 2
3006          ^                                        |
3007          {0:~                                       }|*5
3008        ## grid 3
3009                                                  |
3010        ## grid 4
3011          {33:╔═════}{11:🦄}{7:BB}{33:╗}|
3012          {33:║}{1: halloj! }{33:║}|
3013          {33:║}{1: BORDAA  }{33:║}|
3014          {33:╚═════}{11:🦄}{7:BB}{33:╝}|
3015        ]],
3016          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
3017          win_viewport = {
3018            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3019            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
3020          },
3021        }
3022      else
3023        screen:expect {
3024          grid = [[
3025          ^                                        |
3026          {0:~                                       }|
3027          {0:~    }{33:╔═════}{11:🦄}{7:BB}{33:╗}{0:                        }|
3028          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
3029          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
3030          {0:~    }{33:╚═════}{11:🦄}{7:BB}{33:╝}{0:                        }|
3031                                                  |
3032        ]],
3033        }
3034      end
3035      eq({ { '🦄' }, { 'BB', { 'B0', 'B1' } } }, api.nvim_win_get_config(win).title)
3036      eq({ { '🦄' }, { 'BB', { 'B0', 'B1' } } }, api.nvim_win_get_config(win).footer)
3037
3038      api.nvim_win_set_config(win, {
3039        title = { { '🦄', '' }, { 'BB', { 'B0', 'B1', '' } } },
3040        title_pos = 'left',
3041        footer = { { '🦄', '' }, { 'BB', { 'B0', 'B1', '' } } },
3042        footer_pos = 'left',
3043      })
3044      if multigrid then
3045        screen:expect {
3046          grid = [[
3047        ## grid 1
3048          [2:----------------------------------------]|*6
3049          [3:----------------------------------------]|
3050        ## grid 2
3051          ^                                        |
3052          {0:~                                       }|*5
3053        ## grid 3
3054                                                  |
3055        ## grid 4
3056          {33:╔}{1:🦄}{7:BB}{33:═════╗}|
3057          {33:║}{1: halloj! }{33:║}|
3058          {33:║}{1: BORDAA  }{33:║}|
3059          {33:╚}{1:🦄}{7:BB}{33:═════╝}|
3060        ]],
3061          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
3062          win_viewport = {
3063            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3064            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
3065          },
3066        }
3067      else
3068        screen:expect {
3069          grid = [[
3070          ^                                        |
3071          {0:~                                       }|
3072          {0:~    }{33:╔}{1:🦄}{7:BB}{33:═════╗}{0:                        }|
3073          {0:~    }{33:║}{1: halloj! }{33:║}{0:                        }|
3074          {0:~    }{33:║}{1: BORDAA  }{33:║}{0:                        }|
3075          {0:~    }{33:╚}{1:🦄}{7:BB}{33:═════╝}{0:                        }|
3076                                                  |
3077        ]],
3078        }
3079      end
3080      eq({ { '🦄', '' }, { 'BB', { 'B0', 'B1', '' } } }, api.nvim_win_get_config(win).title)
3081      eq({ { '🦄', '' }, { 'BB', { 'B0', 'B1', '' } } }, api.nvim_win_get_config(win).footer)
3082
3083      api.nvim_win_set_config(win, { border = 'single', title = 'a\tb', footer = 'A\tB' })
3084      if multigrid then
3085        screen:expect({
3086          grid = [[
3087          ## grid 1
3088            [2:----------------------------------------]|*6
3089            [3:----------------------------------------]|
3090          ## grid 2
3091            ^                                        |
3092            {0:~                                       }|*5
3093          ## grid 3
3094                                                    |
3095          ## grid 4
3096            {33:┌}{11:a^Ib}{33:─────┐}|
3097            {33:│}{1: halloj! }{33:│}|
3098            {33:│}{1: BORDAA  }{33:│}|
3099            {33:└}{11:A^IB}{33:─────┘}|
3100          ]],
3101          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
3102          win_viewport = {
3103            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3104            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
3105          },
3106        })
3107      else
3108        screen:expect([[
3109          ^                                        |
3110          {0:~                                       }|
3111          {0:~    }{33:┌}{11:a^Ib}{33:─────┐}{0:                        }|
3112          {0:~    }{33:│}{1: halloj! }{33:│}{0:                        }|
3113          {0:~    }{33:│}{1: BORDAA  }{33:│}{0:                        }|
3114          {0:~    }{33:└}{11:A^IB}{33:─────┘}{0:                        }|
3115                                                  |
3116        ]])
3117      end
3118
3119      api.nvim_win_set_config(win, { title = { { 'a\tb' } }, footer = { { 'A\tB' } } })
3120      screen:expect_unchanged()
3121
3122      -- making it a split should not leak memory
3123      api.nvim_win_set_config(win, { vertical = true })
3124      if multigrid then
3125        screen:expect {
3126          grid = [[
3127        ## grid 1
3128          [4:--------------------]{5:│}[2:-------------------]|*5
3129          {5:[No Name] [+]        }{4:[No Name]          }|
3130          [3:----------------------------------------]|
3131        ## grid 2
3132          ^                   |
3133          {0:~                  }|*4
3134        ## grid 3
3135                                                  |
3136        ## grid 4
3137           halloj!            |
3138           BORDAA             |
3139          {0:~                   }|*3
3140        ]],
3141          win_viewport = {
3142            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3143            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
3144          },
3145        }
3146      else
3147        screen:expect {
3148          grid = [[
3149           halloj!            {5:│}^                   |
3150           BORDAA             {5:│}{0:~                  }|
3151          {0:~                   }{5:│}{0:~                  }|*3
3152          {5:[No Name] [+]        }{4:[No Name]          }|
3153                                                  |
3154        ]],
3155        }
3156      end
3157    end)
3158
3159    it('terminates border on edge of viewport when window extends past viewport', function()
3160      local buf = api.nvim_create_buf(false, false)
3161      api.nvim_open_win(buf, false, { relative = 'editor', width = 40, height = 7, row = 0, col = 0, border = 'single', zindex = 201 })
3162      if multigrid then
3163        screen:expect {
3164          grid = [[
3165        ## grid 1
3166          [2:----------------------------------------]|*6
3167          [3:----------------------------------------]|
3168        ## grid 2
3169          ^                                        |
3170          {0:~                                       }|*5
3171        ## grid 3
3172                                                  |
3173        ## grid 4
3174          {33:┌────────────────────────────────────────┐}|
3175          {33:│}{1:                                        }{33:│}|
3176          {33:│}{2:~                                       }{33:│}|*6
3177          {33:└────────────────────────────────────────┘}|
3178        ]],
3179          float_pos = { [4] = { 1001, 'NW', 1, 0, 0, true, 201, 2, 0, 0 } },
3180          win_viewport = {
3181            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3182            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3183          },
3184        }
3185      else
3186        screen:expect {
3187          grid = [[
3188          {33:^┌──────────────────────────────────────┐}|
3189          {33:│}{1:                                      }{33:│}|
3190          {33:│}{2:~                                     }{33:│}|*4
3191          {33:└──────────────────────────────────────┘}|
3192        ]],
3193        }
3194      end
3195    end)
3196
3197    it('with border show popupmenu', function()
3198      screen:try_resize(40, 10)
3199      local buf = api.nvim_create_buf(false, false)
3200      api.nvim_buf_set_lines(buf, 0, -1, true, {
3201        'aaa aab ',
3202        'abb acc ',
3203        '',
3204      })
3205      api.nvim_open_win(buf, true, { relative = 'editor', width = 9, height = 3, row = 0, col = 5, border = 'double' })
3206      feed 'G'
3207
3208      if multigrid then
3209        screen:expect {
3210          grid = [[
3211        ## grid 1
3212          [2:----------------------------------------]|*9
3213          [3:----------------------------------------]|
3214        ## grid 2
3215                                                  |
3216          {0:~                                       }|*8
3217        ## grid 3
3218                                                  |
3219        ## grid 4
3220          {33:╔═════════╗}|
3221          {33:║}{1:aaa aab  }{33:║}|
3222          {33:║}{1:abb acc  }{33:║}|
3223          {33:║}{1:^         }{33:║}|
3224          {33:╚═════════╝}|
3225        ]],
3226          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
3227          win_viewport = {
3228            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3229            [4] = { win = 1001, topline = 0, botline = 3, curline = 2, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
3230          },
3231        }
3232      else
3233        screen:expect {
3234          grid = [[
3235               {33:╔═════════╗}                        |
3236          {0:~    }{33:║}{1:aaa aab  }{33:║}{0:                        }|
3237          {0:~    }{33:║}{1:abb acc  }{33:║}{0:                        }|
3238          {0:~    }{33:║}{1:^         }{33:║}{0:                        }|
3239          {0:~    }{33:╚═════════╝}{0:                        }|
3240          {0:~                                       }|*4
3241                                                  |
3242        ]],
3243        }
3244      end
3245
3246      feed 'i<c-x><c-p>'
3247      if multigrid then
3248        screen:expect {
3249          grid = [[
3250        ## grid 1
3251          [2:----------------------------------------]|*9
3252          [3:----------------------------------------]|
3253        ## grid 2
3254                                                  |
3255          {0:~                                       }|*8
3256        ## grid 3
3257          {3:-- }{8:match 1 of 4}                         |
3258        ## grid 4
3259          {33:╔═════════╗}|
3260          {33:║}{1:aaa aab  }{33:║}|
3261          {33:║}{1:abb acc  }{33:║}|
3262          {33:║}{1:acc^      }{33:║}|
3263          {33:╚═════════╝}|
3264        ## grid 5
3265          {1: aaa            }|
3266          {1: aab            }|
3267          {1: abb            }|
3268          {13: acc            }|
3269        ]],
3270          float_pos = {
3271            [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 },
3272            [5] = { -1, 'NW', 4, 4, 0, false, 100, 2, 4, 5 },
3273          },
3274          win_viewport = {
3275            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3276            [4] = { win = 1001, topline = 0, botline = 3, curline = 2, curcol = 3, linecount = 3, sum_scroll_delta = 0 },
3277          },
3278        }
3279      else
3280        screen:expect {
3281          grid = [[
3282               {33:╔═════════╗}                        |
3283          {0:~    }{33:║}{1:aaa aab  }{33:║}{0:                        }|
3284          {0:~    }{33:║}{1:abb acc  }{33:║}{0:                        }|
3285          {0:~    }{33:║}{1:acc^      }{33:║}{0:                        }|
3286          {0:~    }{1: aaa            }{0:                   }|
3287          {0:~    }{1: aab            }{0:                   }|
3288          {0:~    }{1: abb            }{0:                   }|
3289          {0:~    }{13: acc            }{0:                   }|
3290          {0:~                                       }|
3291          {3:-- }{8:match 1 of 4}                         |
3292        ]],
3293        }
3294      end
3295
3296      feed '<esc>'
3297      if multigrid then
3298        screen:expect {
3299          grid = [[
3300        ## grid 1
3301          [2:----------------------------------------]|*9
3302          [3:----------------------------------------]|
3303        ## grid 2
3304                                                  |
3305          {0:~                                       }|*8
3306        ## grid 3
3307                                                  |
3308        ## grid 4
3309          {33:╔═════════╗}|
3310          {33:║}{1:aaa aab  }{33:║}|
3311          {33:║}{1:abb acc  }{33:║}|
3312          {33:║}{1:ac^c      }{33:║}|
3313          {33:╚═════════╝}|
3314        ]],
3315          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
3316          win_viewport = {
3317            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3318            [4] = { win = 1001, topline = 0, botline = 3, curline = 2, curcol = 2, linecount = 3, sum_scroll_delta = 0 },
3319          },
3320        }
3321      else
3322        screen:expect {
3323          grid = [[
3324               {33:╔═════════╗}                        |
3325          {0:~    }{33:║}{1:aaa aab  }{33:║}{0:                        }|
3326          {0:~    }{33:║}{1:abb acc  }{33:║}{0:                        }|
3327          {0:~    }{33:║}{1:ac^c      }{33:║}{0:                        }|
3328          {0:~    }{33:╚═════════╝}{0:                        }|
3329          {0:~                                       }|*4
3330                                                  |
3331        ]],
3332        }
3333      end
3334
3335      exec([[
3336        nnoremenu Test.foo :
3337        nnoremenu Test.bar :
3338        nnoremenu Test.baz :
3339      ]])
3340      feed ':popup Test<CR>'
3341      if multigrid then
3342        screen:expect {
3343          grid = [[
3344        ## grid 1
3345          [2:----------------------------------------]|*9
3346          [3:----------------------------------------]|
3347        ## grid 2
3348                                                  |
3349          {0:~                                       }|*8
3350        ## grid 3
3351          :popup Test                             |
3352        ## grid 4
3353          {33:╔═════════╗}|
3354          {33:║}{1:aaa aab  }{33:║}|
3355          {33:║}{1:abb acc  }{33:║}|
3356          {33:║}{1:ac^c      }{33:║}|
3357          {33:╚═════════╝}|
3358        ## grid 5
3359          {1: foo }|
3360          {1: bar }|
3361          {1: baz }|
3362        ]],
3363          float_pos = {
3364            [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 },
3365            [5] = { -1, 'NW', 4, 4, 2, false, 250, 3, 4, 7 },
3366          },
3367          win_viewport = {
3368            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3369            [4] = { win = 1001, topline = 0, botline = 3, curline = 2, curcol = 2, linecount = 3, sum_scroll_delta = 0 },
3370          },
3371        }
3372      else
3373        screen:expect {
3374          grid = [[
3375               {33:╔═════════╗}                        |
3376          {0:~    }{33:║}{1:aaa aab  }{33:║}{0:                        }|
3377          {0:~    }{33:║}{1:abb acc  }{33:║}{0:                        }|
3378          {0:~    }{33:║}{1:ac^c      }{33:║}{0:                        }|
3379          {0:~    }{33:╚═}{1: foo }{33:═══╝}{0:                        }|
3380          {0:~      }{1: bar }{0:                            }|
3381          {0:~      }{1: baz }{0:                            }|
3382          {0:~                                       }|*2
3383          :popup Test                             |
3384        ]],
3385        }
3386      end
3387    end)
3388
3389    it("doesn't wrap with vertical border", function()
3390      screen:try_resize(40, 10)
3391      local buf = api.nvim_create_buf(false, false)
3392      api.nvim_open_win(buf, false, { relative = 'editor', width = 9, height = 3, row = 0, col = 5, border = 'double' })
3393      -- make sure text is drawn after border
3394      if multigrid then
3395        screen:expect {
3396          grid = [[
3397          ## grid 1
3398            [2:----------------------------------------]|*9
3399            [3:----------------------------------------]|
3400          ## grid 2
3401            ^                                        |
3402            {0:~                                       }|*8
3403          ## grid 3
3404                                                    |
3405          ## grid 4
3406            {33:╔═════════╗}|
3407            {33:║}{1:         }{33:║}|
3408            {33:║}{2:~        }{33:║}|*2
3409            {33:╚═════════╝}|
3410          ]],
3411          win_pos = { [2] = { height = 9, startcol = 0, startrow = 0, width = 40, win = 1000 } },
3412          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
3413          win_viewport = {
3414            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3415            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3416          },
3417          win_viewport_margins = {
3418            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
3419            [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 },
3420          },
3421        }
3422      else
3423        screen:expect([[
3424          ^     {33:╔═════════╗}                        |
3425          {0:~    }{33:║}{1:         }{33:║}{0:                        }|
3426          {0:~    }{33:║}{2:~        }{33:║}{0:                        }|*2
3427          {0:~    }{33:╚═════════╝}{0:                        }|
3428          {0:~                                       }|*4
3429                                                  |
3430        ]])
3431      end
3432      api.nvim_buf_set_lines(buf, 0, -1, true, { 'aaa long line', 'abb acc ' })
3433      if multigrid then
3434        screen:expect {
3435          grid = [[
3436          ## grid 1
3437            [2:----------------------------------------]|*9
3438            [3:----------------------------------------]|
3439          ## grid 2
3440            ^                                        |
3441            {0:~                                       }|*8
3442          ## grid 3
3443                                                    |
3444          ## grid 4
3445            {33:╔═════════╗}|
3446            {33:║}{1:aaa long }{33:║}|
3447            {33:║}{1:line     }{33:║}|
3448            {33:║}{1:abb acc  }{33:║}|
3449            {33:╚═════════╝}|
3450          ]],
3451          win_pos = { [2] = { height = 9, startcol = 0, startrow = 0, width = 40, win = 1000 } },
3452          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
3453          win_viewport = {
3454            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3455            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
3456          },
3457          win_viewport_margins = {
3458            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
3459            [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 },
3460          },
3461          condition = function()
3462            for i = 1, 5 do
3463              eq(false, screen._grids[4].rows[i].wrap, i)
3464            end
3465          end,
3466        }
3467      else
3468        screen:expect([[
3469          ^     {33:╔═════════╗}                        |
3470          {0:~    }{33:║}{1:aaa long }{33:║}{0:                        }|
3471          {0:~    }{33:║}{1:line     }{33:║}{0:                        }|
3472          {0:~    }{33:║}{1:abb acc  }{33:║}{0:                        }|
3473          {0:~    }{33:╚═════════╝}{0:                        }|
3474          {0:~                                       }|*4
3475                                                  |
3476        ]])
3477      end
3478    end)
3479
3480    it('does wrap without vertical border', function()
3481      screen:try_resize(40, 10)
3482      local buf = api.nvim_create_buf(false, false)
3483      api.nvim_buf_set_lines(buf, 0, -1, true, { 'aaa long line', 'abb acc ' })
3484      api.nvim_open_win(buf, false, { relative = 'editor', width = 9, height = 3, row = 0, col = 5 })
3485      if multigrid then
3486        screen:expect {
3487          grid = [[
3488          ## grid 1
3489            [2:----------------------------------------]|*9
3490            [3:----------------------------------------]|
3491          ## grid 2
3492            ^                                        |
3493            {0:~                                       }|*8
3494          ## grid 3
3495                                                    |
3496          ## grid 4
3497            {1:aaa long }|
3498            {1:line     }|
3499            {1:abb acc  }|
3500          ]],
3501          win_pos = { [2] = { height = 9, startcol = 0, startrow = 0, width = 40, win = 1000 } },
3502          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
3503          win_viewport = {
3504            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3505            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
3506          },
3507          win_viewport_margins = {
3508            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
3509            [4] = { bottom = 0, left = 0, right = 0, top = 0, win = 1001 },
3510          },
3511          condition = function()
3512            for i = 1, 3 do
3513              eq(i == 1, screen._grids[4].rows[i].wrap, i)
3514            end
3515          end,
3516        }
3517      else
3518        screen:expect([[
3519          ^     {1:aaa long }                          |
3520          {0:~    }{1:line     }{0:                          }|
3521          {0:~    }{1:abb acc  }{0:                          }|
3522          {0:~                                       }|*6
3523                                                  |
3524        ]])
3525      end
3526    end)
3527
3528    it('border is drawn properly when number column is too wide #35431', function()
3529      local buf = api.nvim_create_buf(false, false)
3530      local opts = { relative = 'editor', row = 1, col = 1, width = 3, height = 3, border = 'rounded' }
3531      local win = api.nvim_open_win(buf, false, opts)
3532      api.nvim_set_option_value('number', true, { win = win })
3533      if multigrid then
3534        screen:expect({
3535          grid = [[
3536        ## grid 1
3537          [2:----------------------------------------]|*6
3538          [3:----------------------------------------]|
3539        ## grid 2
3540          ^                                        |
3541          {0:~                                       }|*5
3542        ## grid 3
3543                                                  |
3544        ## grid 4
3545          {33:╭───╮}|
3546          {33:│}{32:  1}{33:│}|
3547          {33:│}{32:   }{33:│}|*2
3548          {33:╰───╯}|
3549        ]],
3550          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
3551        })
3552      else
3553        screen:expect([[
3554          ^                                        |
3555          {0:~}{33:╭───╮}{0:                                  }|
3556          {0:~}{33:│}{32:  1}{33:│}{0:                                  }|
3557          {0:~}{33:│}{32:   }{33:│}{0:                                  }|*2
3558          {0:~}{33:╰───╯}{0:                                  }|
3559                                                  |
3560        ]])
3561      end
3562    end)
3563
3564    it('show ruler of current floating window', function()
3565      command 'set ruler'
3566      local buf = api.nvim_create_buf(false, false)
3567      api.nvim_buf_set_lines(buf, 0, -1, true, { 'aaa aab ', 'abb acc ' })
3568      api.nvim_open_win(buf, true, { relative = 'editor', width = 9, height = 3, row = 0, col = 5 })
3569      feed 'gg'
3570
3571      if multigrid then
3572        screen:expect {
3573          grid = [[
3574        ## grid 1
3575          [2:----------------------------------------]|*6
3576          [3:----------------------------------------]|
3577        ## grid 2
3578                                                  |
3579          {0:~                                       }|*5
3580        ## grid 3
3581                                1,1            All|
3582        ## grid 4
3583          {1:^aaa aab  }|
3584          {1:abb acc  }|
3585          {2:~        }|
3586        ]],
3587          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
3588          win_viewport = {
3589            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3590            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
3591          },
3592        }
3593      else
3594        screen:expect {
3595          grid = [[
3596               {1:^aaa aab  }                          |
3597          {0:~    }{1:abb acc  }{0:                          }|
3598          {0:~    }{2:~        }{0:                          }|
3599          {0:~                                       }|*3
3600                                1,1            All|
3601        ]],
3602        }
3603      end
3604
3605      feed 'w'
3606      if multigrid then
3607        screen:expect {
3608          grid = [[
3609        ## grid 1
3610          [2:----------------------------------------]|*6
3611          [3:----------------------------------------]|
3612        ## grid 2
3613                                                  |
3614          {0:~                                       }|*5
3615        ## grid 3
3616                                1,5            All|
3617        ## grid 4
3618          {1:aaa ^aab  }|
3619          {1:abb acc  }|
3620          {2:~        }|
3621        ]],
3622          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
3623          win_viewport = {
3624            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3625            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 4, linecount = 2, sum_scroll_delta = 0 },
3626          },
3627        }
3628      else
3629        screen:expect {
3630          grid = [[
3631               {1:aaa ^aab  }                          |
3632          {0:~    }{1:abb acc  }{0:                          }|
3633          {0:~    }{2:~        }{0:                          }|
3634          {0:~                                       }|*3
3635                                1,5            All|
3636        ]],
3637        }
3638      end
3639    end)
3640
3641    it("correct ruler position in current float with 'rulerformat' set", function()
3642      command 'set ruler rulerformat=fish:<><'
3643      api.nvim_open_win(0, true, { relative = 'editor', width = 9, height = 3, row = 0, col = 5 })
3644      if multigrid then
3645        screen:expect {
3646          grid = [[
3647        ## grid 1
3648          [2:----------------------------------------]|*6
3649          [3:----------------------------------------]|
3650        ## grid 2
3651                                                  |
3652          {0:~                                       }|*5
3653        ## grid 3
3654                                fish:<><          |
3655        ## grid 4
3656          {1:^         }|
3657          {2:~        }|*2
3658        ]],
3659          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
3660          win_viewport = {
3661            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3662            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3663          },
3664        }
3665      else
3666        screen:expect {
3667          grid = [[
3668               {1:^         }                          |
3669          {0:~    }{2:~        }{0:                          }|*2
3670          {0:~                                       }|*3
3671                                fish:<><          |
3672        ]],
3673        }
3674      end
3675    end)
3676
3677    it('does not show ruler of not-last current float during ins-completion', function()
3678      screen:try_resize(50, 9)
3679      command 'set ruler showmode'
3680      api.nvim_open_win(0, false, { relative = 'editor', width = 3, height = 3, row = 0, col = 0 })
3681      api.nvim_open_win(0, false, { relative = 'editor', width = 3, height = 3, row = 0, col = 5 })
3682      feed '<c-w>w'
3683      neq('', api.nvim_win_get_config(0).relative)
3684      neq(fn.winnr '$', fn.winnr())
3685      if multigrid then
3686        screen:expect {
3687          grid = [[
3688        ## grid 1
3689          [2:--------------------------------------------------]|*8
3690          [3:--------------------------------------------------]|
3691        ## grid 2
3692                                                            |
3693          {0:~                                                 }|*7
3694        ## grid 3
3695                                          0,0-1          All|
3696        ## grid 4
3697          {1:   }|
3698          {2:~  }|*2
3699        ## grid 5
3700          {1:^   }|
3701          {2:~  }|*2
3702        ]],
3703          float_pos = {
3704            [4] = { 1001, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
3705            [5] = { 1002, 'NW', 1, 0, 5, true, 50, 2, 0, 5 },
3706          },
3707          win_viewport = {
3708            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3709            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3710            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3711          },
3712        }
3713      else
3714        screen:expect {
3715          grid = [[
3716          {1:   }  {1:^   }                                          |
3717          {2:~  }{0:  }{2:~  }{0:                                          }|*2
3718          {0:~                                                 }|*5
3719                                          0,0-1          All|
3720        ]],
3721        }
3722      end
3723      feed 'i<c-x>'
3724      if multigrid then
3725        screen:expect {
3726          grid = [[
3727        ## grid 1
3728          [2:--------------------------------------------------]|*8
3729          [3:--------------------------------------------------]|
3730        ## grid 2
3731                                                            |
3732          {0:~                                                 }|*7
3733        ## grid 3
3734          {3:-- ^X mode (^]^D^E^F^I^K^L^N^O^P^Rs^U^V^Y)}        |
3735        ## grid 4
3736          {1:   }|
3737          {2:~  }|*2
3738        ## grid 5
3739          {1:^   }|
3740          {2:~  }|*2
3741        ]],
3742          float_pos = {
3743            [4] = { 1001, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
3744            [5] = { 1002, 'NW', 1, 0, 5, true, 50, 2, 0, 5 },
3745          },
3746          win_viewport = {
3747            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3748            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3749            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3750          },
3751        }
3752      else
3753        screen:expect {
3754          grid = [[
3755          {1:   }  {1:^   }                                          |
3756          {2:~  }{0:  }{2:~  }{0:                                          }|*2
3757          {0:~                                                 }|*5
3758          {3:-- ^X mode (^]^D^E^F^I^K^L^N^O^P^Rs^U^V^Y)}        |
3759        ]],
3760        }
3761      end
3762    end)
3763
3764    it('can have minimum size', function()
3765      insert('the background text')
3766      local buf = api.nvim_create_buf(false, true)
3767      api.nvim_buf_set_lines(buf, 0, -1, true, { 'x' })
3768      local win = api.nvim_open_win(buf, false, { relative = 'win', width = 1, height = 1, row = 0, col = 4, focusable = false })
3769      if multigrid then
3770        screen:expect {
3771          grid = [[
3772        ## grid 1
3773          [2:----------------------------------------]|*6
3774          [3:----------------------------------------]|
3775        ## grid 2
3776          the background tex^t                     |
3777          {0:~                                       }|*5
3778        ## grid 3
3779                                                  |
3780        ## grid 4
3781          {1:x}|
3782        ]],
3783          float_pos = { [4] = { 1001, 'NW', 2, 0, 4, false, 50, 1, 0, 4 } },
3784        }
3785      else
3786        screen:expect([[
3787          the {1:x}ackground tex^t                     |
3788          {0:~                                       }|*5
3789                                                  |
3790        ]])
3791      end
3792
3793      api.nvim_win_set_config(win, { relative = 'win', row = 0, col = 15 })
3794      if multigrid then
3795        screen:expect {
3796          grid = [[
3797        ## grid 1
3798          [2:----------------------------------------]|*6
3799          [3:----------------------------------------]|
3800        ## grid 2
3801          the background tex^t                     |
3802          {0:~                                       }|*5
3803        ## grid 3
3804                                                  |
3805        ## grid 4
3806          {1:x}|
3807        ]],
3808          float_pos = { [4] = { 1001, 'NW', 2, 0, 15, false, 50, 1, 0, 15 } },
3809        }
3810      else
3811        screen:expect([[
3812          the background {1:x}ex^t                     |
3813          {0:~                                       }|*5
3814                                                  |
3815        ]])
3816      end
3817
3818      api.nvim_win_close(win, false)
3819      if multigrid then
3820        screen:expect([[
3821        ## grid 1
3822          [2:----------------------------------------]|*6
3823          [3:----------------------------------------]|
3824        ## grid 2
3825          the background tex^t                     |
3826          {0:~                                       }|*5
3827        ## grid 3
3828                                                  |
3829        ]])
3830      else
3831        screen:expect([[
3832          the background tex^t                     |
3833          {0:~                                       }|*5
3834                                                  |
3835        ]])
3836      end
3837    end)
3838
3839    describe('no crash when rearranging windows', function()
3840      local function test_rearrange_windows(cmd)
3841        command('set laststatus=2')
3842        screen:try_resize(40, 13)
3843
3844        command('args X1 X2 X3 X4 X5 X6')
3845        command('sargument 2')
3846        command('sargument 3')
3847        local w3 = curwin()
3848        command('sargument 4')
3849        local w4 = curwin()
3850        command('sargument 5')
3851        command('sargument 6')
3852
3853        local float_opts = { relative = 'editor', row = 6, col = 0, width = 40, height = 1 }
3854        api.nvim_win_set_config(w3, float_opts)
3855        api.nvim_win_set_config(w4, float_opts)
3856        command('wincmd =')
3857        if multigrid then
3858          screen:expect {
3859            grid = [[
3860          ## grid 1
3861            [8:----------------------------------------]|*2
3862            {4:X6                                      }|
3863            [7:----------------------------------------]|*2
3864            {5:X5                                      }|
3865            [4:----------------------------------------]|*2
3866            {5:X2                                      }|
3867            [2:----------------------------------------]|*2
3868            {5:X1                                      }|
3869            [3:----------------------------------------]|
3870          ## grid 2
3871                                                    |
3872            {0:~                                       }|
3873          ## grid 3
3874                                                    |
3875          ## grid 4
3876                                                    |
3877            {0:~                                       }|
3878          ## grid 5
3879            {1:                                        }|
3880          ## grid 6
3881            {1:                                        }|
3882          ## grid 7
3883                                                    |
3884            {0:~                                       }|
3885          ## grid 8
3886            ^                                        |
3887            {0:~                                       }|
3888          ]],
3889            float_pos = {
3890              [5] = { 1002, 'NW', 1, 6, 0, true, 50, 1, 6, 0 },
3891              [6] = { 1003, 'NW', 1, 6, 0, true, 50, 2, 6, 0 },
3892            },
3893            win_viewport = {
3894              [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3895              [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3896              [5] = { win = 1002, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3897              [6] = { win = 1003, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3898              [7] = { win = 1004, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3899              [8] = { win = 1005, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3900            },
3901          }
3902        else
3903          screen:expect {
3904            grid = [[
3905            ^                                        |
3906            {0:~                                       }|
3907            {4:X6                                      }|
3908                                                    |
3909            {0:~                                       }|
3910            {5:X5                                      }|
3911            {1:                                        }|
3912            {0:~                                       }|
3913            {5:X2                                      }|
3914                                                    |
3915            {0:~                                       }|
3916            {5:X1                                      }|
3917                                                    |
3918          ]],
3919          }
3920        end
3921
3922        command(cmd)
3923        if multigrid then
3924          screen:expect {
3925            grid = [[
3926          ## grid 1
3927            [2:----------------------------------------]|
3928            {4:X1                                      }|
3929            [4:----------------------------------------]|
3930            {5:X2                                      }|
3931            [9:----------------------------------------]|
3932            {5:X3                                      }|
3933            [10:----------------------------------------]|
3934            {5:X4                                      }|
3935            [7:----------------------------------------]|
3936            {5:X5                                      }|
3937            [8:----------------------------------------]|
3938            {5:X6                                      }|
3939            [3:----------------------------------------]|
3940          ## grid 2
3941            ^                                        |
3942          ## grid 3
3943                                                    |
3944          ## grid 4
3945                                                    |
3946          ## grid 7
3947                                                    |
3948          ## grid 8
3949                                                    |
3950          ## grid 9
3951                                                    |
3952          ## grid 10
3953                                                    |
3954          ]],
3955            win_viewport = {
3956              [2] = { win = 1000, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3957              [4] = { win = 1001, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3958              [7] = { win = 1004, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3959              [8] = { win = 1005, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3960              [9] = { win = 1006, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3961              [10] = { win = 1007, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
3962            },
3963          }
3964        else
3965          screen:expect {
3966            grid = [[
3967            ^                                        |
3968            {4:X1                                      }|
3969                                                    |
3970            {5:X2                                      }|
3971                                                    |
3972            {5:X3                                      }|
3973                                                    |
3974            {5:X4                                      }|
3975                                                    |
3976            {5:X5                                      }|
3977                                                    |
3978            {5:X6                                      }|
3979                                                    |
3980          ]],
3981          }
3982        end
3983      end
3984
3985      it('using :unhide', function()
3986        test_rearrange_windows('unhide')
3987      end)
3988
3989      it('using :all', function()
3990        test_rearrange_windows('all')
3991      end)
3992    end)
3993
3994    it('validation: multigrid', function()
3995      if multigrid then
3996        local buf = api.nvim_create_buf(false, false)
3997        eq(
3998          "Conflict: 'win' not allowed with external window",
3999          pcall_err(api.nvim_open_win, buf, false, { external = true, win = 0, width = 10, height = 10 })
4000        )
4001        api.nvim_open_win(buf, true, { external = true, width = 10, height = 10 })
4002        eq("Conflict: 'win' not allowed with external window", pcall_err(api.nvim_win_set_config, 0, { win = 0 }))
4003        -- OK to include "win" if external window is also reconfigured to a normal float.
4004        api.nvim_win_set_config(0, { relative = 'editor', win = 0, row = 0, col = 0, width = 5, height = 5 })
4005        eq('editor', api.nvim_win_get_config(0).relative)
4006      end
4007    end)
4008
4009    it('can be placed relative window or cursor', function()
4010      screen:try_resize(40, 9)
4011      api.nvim_buf_set_lines(0, 0, -1, true, { 'just some', 'example text' })
4012      feed('gge')
4013      local oldwin = api.nvim_get_current_win()
4014      command('below split')
4015      if multigrid then
4016        screen:expect([[
4017        ## grid 1
4018          [2:----------------------------------------]|*3
4019          {5:[No Name] [+]                           }|
4020          [4:----------------------------------------]|*3
4021          {4:[No Name] [+]                           }|
4022          [3:----------------------------------------]|
4023        ## grid 2
4024          just some                               |
4025          example text                            |
4026          {0:~                                       }|
4027        ## grid 3
4028                                                  |
4029        ## grid 4
4030          jus^t some                               |
4031          example text                            |
4032          {0:~                                       }|
4033        ]])
4034      else
4035        screen:expect([[
4036          just some                               |
4037          example text                            |
4038          {0:~                                       }|
4039          {5:[No Name] [+]                           }|
4040          jus^t some                               |
4041          example text                            |
4042          {0:~                                       }|
4043          {4:[No Name] [+]                           }|
4044                                                  |
4045        ]])
4046      end
4047
4048      local buf = api.nvim_create_buf(false, false)
4049      -- no 'win' arg, relative default window
4050      local win = api.nvim_open_win(buf, false, { relative = 'win', width = 20, height = 2, row = 0, col = 10 })
4051      if multigrid then
4052        screen:expect {
4053          grid = [[
4054        ## grid 1
4055          [2:----------------------------------------]|*3
4056          {5:[No Name] [+]                           }|
4057          [4:----------------------------------------]|*3
4058          {4:[No Name] [+]                           }|
4059          [3:----------------------------------------]|
4060        ## grid 2
4061          just some                               |
4062          example text                            |
4063          {0:~                                       }|
4064        ## grid 3
4065                                                  |
4066        ## grid 4
4067          jus^t some                               |
4068          example text                            |
4069          {0:~                                       }|
4070        ## grid 5
4071          {1:                    }|
4072          {2:~                   }|
4073        ]],
4074          float_pos = { [5] = { 1002, 'NW', 4, 0, 10, true, 50, 1, 4, 10 } },
4075        }
4076      else
4077        screen:expect([[
4078          just some                               |
4079          example text                            |
4080          {0:~                                       }|
4081          {5:[No Name] [+]                           }|
4082          jus^t some {1:                    }          |
4083          example te{2:~                   }          |
4084          {0:~                                       }|
4085          {4:[No Name] [+]                           }|
4086                                                  |
4087        ]])
4088      end
4089
4090      api.nvim_win_set_config(win, { relative = 'cursor', row = 1, col = -2 })
4091      if multigrid then
4092        screen:expect {
4093          grid = [[
4094        ## grid 1
4095          [2:----------------------------------------]|*3
4096          {5:[No Name] [+]                           }|
4097          [4:----------------------------------------]|*3
4098          {4:[No Name] [+]                           }|
4099          [3:----------------------------------------]|
4100        ## grid 2
4101          just some                               |
4102          example text                            |
4103          {0:~                                       }|
4104        ## grid 3
4105                                                  |
4106        ## grid 4
4107          jus^t some                               |
4108          example text                            |
4109          {0:~                                       }|
4110        ## grid 5
4111          {1:                    }|
4112          {2:~                   }|
4113        ]],
4114          float_pos = { [5] = { 1002, 'NW', 4, 1, 1, true, 50, 1, 5, 1 } },
4115        }
4116      else
4117        screen:expect([[
4118          just some                               |
4119          example text                            |
4120          {0:~                                       }|
4121          {5:[No Name] [+]                           }|
4122          jus^t some                               |
4123          e{1:                    }                   |
4124          {0:~}{2:~                   }{0:                   }|
4125          {4:[No Name] [+]                           }|
4126                                                  |
4127        ]])
4128      end
4129
4130      api.nvim_win_set_config(win, { relative = 'cursor', row = 0, col = 0, anchor = 'SW' })
4131      if multigrid then
4132        screen:expect {
4133          grid = [[
4134        ## grid 1
4135          [2:----------------------------------------]|*3
4136          {5:[No Name] [+]                           }|
4137          [4:----------------------------------------]|*3
4138          {4:[No Name] [+]                           }|
4139          [3:----------------------------------------]|
4140        ## grid 2
4141          just some                               |
4142          example text                            |
4143          {0:~                                       }|
4144        ## grid 3
4145                                                  |
4146        ## grid 4
4147          jus^t some                               |
4148          example text                            |
4149          {0:~                                       }|
4150        ## grid 5
4151          {1:                    }|
4152          {2:~                   }|
4153        ]],
4154          float_pos = { [5] = { 1002, 'SW', 4, 0, 3, true, 50, 1, 2, 3 } },
4155        }
4156      else
4157        screen:expect([[
4158          just some                               |
4159          example text                            |
4160          {0:~  }{1:                    }{0:                 }|
4161          {5:[No}{2:~                   }{5:                 }|
4162          jus^t some                               |
4163          example text                            |
4164          {0:~                                       }|
4165          {4:[No Name] [+]                           }|
4166                                                  |
4167        ]])
4168      end
4169
4170      api.nvim_win_set_config(win, { relative = 'win', win = oldwin, row = 1, col = 10, anchor = 'NW' })
4171      if multigrid then
4172        screen:expect {
4173          grid = [[
4174        ## grid 1
4175          [2:----------------------------------------]|*3
4176          {5:[No Name] [+]                           }|
4177          [4:----------------------------------------]|*3
4178          {4:[No Name] [+]                           }|
4179          [3:----------------------------------------]|
4180        ## grid 2
4181          just some                               |
4182          example text                            |
4183          {0:~                                       }|
4184        ## grid 3
4185                                                  |
4186        ## grid 4
4187          jus^t some                               |
4188          example text                            |
4189          {0:~                                       }|
4190        ## grid 5
4191          {1:                    }|
4192          {2:~                   }|
4193        ]],
4194          float_pos = { [5] = { 1002, 'NW', 2, 1, 10, true, 50, 1, 1, 10 } },
4195        }
4196      else
4197        screen:expect([[
4198          just some                               |
4199          example te{1:                    }          |
4200          {0:~         }{2:~                   }{0:          }|
4201          {5:[No Name] [+]                           }|
4202          jus^t some                               |
4203          example text                            |
4204          {0:~                                       }|
4205          {4:[No Name] [+]                           }|
4206                                                  |
4207        ]])
4208      end
4209
4210      api.nvim_win_set_config(win, { relative = 'win', win = oldwin, row = 3, col = 39, anchor = 'SE' })
4211      if multigrid then
4212        screen:expect {
4213          grid = [[
4214        ## grid 1
4215          [2:----------------------------------------]|*3
4216          {5:[No Name] [+]                           }|
4217          [4:----------------------------------------]|*3
4218          {4:[No Name] [+]                           }|
4219          [3:----------------------------------------]|
4220        ## grid 2
4221          just some                               |
4222          example text                            |
4223          {0:~                                       }|
4224        ## grid 3
4225                                                  |
4226        ## grid 4
4227          jus^t some                               |
4228          example text                            |
4229          {0:~                                       }|
4230        ## grid 5
4231          {1:                    }|
4232          {2:~                   }|
4233        ]],
4234          float_pos = { [5] = { 1002, 'SE', 2, 3, 39, true, 50, 1, 1, 19 } },
4235        }
4236      else
4237        screen:expect([[
4238          just some                               |
4239          example text       {1:                    } |
4240          {0:~                  }{2:~                   }{0: }|
4241          {5:[No Name] [+]                           }|
4242          jus^t some                               |
4243          example text                            |
4244          {0:~                                       }|
4245          {4:[No Name] [+]                           }|
4246                                                  |
4247        ]])
4248      end
4249
4250      api.nvim_win_set_config(win, { relative = 'win', win = 0, row = 0, col = 50, anchor = 'NE' })
4251      if multigrid then
4252        screen:expect {
4253          grid = [[
4254        ## grid 1
4255          [2:----------------------------------------]|*3
4256          {5:[No Name] [+]                           }|
4257          [4:----------------------------------------]|*3
4258          {4:[No Name] [+]                           }|
4259          [3:----------------------------------------]|
4260        ## grid 2
4261          just some                               |
4262          example text                            |
4263          {0:~                                       }|
4264        ## grid 3
4265                                                  |
4266        ## grid 4
4267          jus^t some                               |
4268          example text                            |
4269          {0:~                                       }|
4270        ## grid 5
4271          {1:                    }|
4272          {2:~                   }|
4273        ]],
4274          float_pos = { [5] = { 1002, 'NE', 4, 0, 50, true, 50, 1, 4, 20 } },
4275          win_viewport = {
4276            [2] = { topline = 0, botline = 3, curline = 0, curcol = 3, linecount = 2, sum_scroll_delta = 0, win = 1000 },
4277            [4] = { topline = 0, botline = 3, curline = 0, curcol = 3, linecount = 2, sum_scroll_delta = 0, win = 1001 },
4278            [5] = { topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0, win = 1002 },
4279          },
4280        }
4281      else
4282        screen:expect([[
4283          just some                               |
4284          example text                            |
4285          {0:~                                       }|
4286          {5:[No Name] [+]                           }|
4287          jus^t some           {1:                    }|
4288          example text        {2:~                   }|
4289          {0:~                                       }|
4290          {4:[No Name] [+]                           }|
4291                                                  |
4292        ]])
4293      end
4294    end)
4295
4296    it('always anchor to corner including border', function()
4297      screen:try_resize(40, 13)
4298      api.nvim_buf_set_lines(0, 0, -1, true, { 'just some example text', 'some more example text' })
4299      feed('ggeee')
4300      command('below split')
4301      if multigrid then
4302        screen:expect([[
4303        ## grid 1
4304          [2:----------------------------------------]|*5
4305          {5:[No Name] [+]                           }|
4306          [4:----------------------------------------]|*5
4307          {4:[No Name] [+]                           }|
4308          [3:----------------------------------------]|
4309        ## grid 2
4310          just some example text                  |
4311          some more example text                  |
4312          {0:~                                       }|*3
4313        ## grid 3
4314                                                  |
4315        ## grid 4
4316          just some exampl^e text                  |
4317          some more example text                  |
4318          {0:~                                       }|*3
4319        ]])
4320      else
4321        screen:expect([[
4322          just some example text                  |
4323          some more example text                  |
4324          {0:~                                       }|*3
4325          {5:[No Name] [+]                           }|
4326          just some exampl^e text                  |
4327          some more example text                  |
4328          {0:~                                       }|*3
4329          {4:[No Name] [+]                           }|
4330                                                  |
4331        ]])
4332      end
4333
4334      local buf = api.nvim_create_buf(false, false)
4335      api.nvim_buf_set_lines(buf, 0, -1, true, { ' halloj! ', ' BORDAA  ' })
4336      local win = api.nvim_open_win(buf, false, { relative = 'cursor', width = 9, height = 2, row = 1, col = -2, border = 'double' })
4337
4338      if multigrid then
4339        screen:expect {
4340          grid = [[
4341        ## grid 1
4342          [2:----------------------------------------]|*5
4343          {5:[No Name] [+]                           }|
4344          [4:----------------------------------------]|*5
4345          {4:[No Name] [+]                           }|
4346          [3:----------------------------------------]|
4347        ## grid 2
4348          just some example text                  |
4349          some more example text                  |
4350          {0:~                                       }|*3
4351        ## grid 3
4352                                                  |
4353        ## grid 4
4354          just some exampl^e text                  |
4355          some more example text                  |
4356          {0:~                                       }|*3
4357        ## grid 5
4358          {33:╔═════════╗}|
4359          {33:║}{1: halloj! }{33:║}|
4360          {33:║}{1: BORDAA  }{33:║}|
4361          {33:╚═════════╝}|
4362        ]],
4363          float_pos = { [5] = { 1002, 'NW', 4, 1, 14, true, 50, 1, 7, 14 } },
4364        }
4365      else
4366        screen:expect([[
4367          just some example text                  |
4368          some more example text                  |
4369          {0:~                                       }|*3
4370          {5:[No Name] [+]                           }|
4371          just some exampl^e text                  |
4372          some more exam{33:╔═════════╗}               |
4373          {0:~             }{33:║}{1: halloj! }{33:║}{0:               }|
4374          {0:~             }{33:║}{1: BORDAA  }{33:║}{0:               }|
4375          {0:~             }{33:╚═════════╝}{0:               }|
4376          {4:[No Name] [+]                           }|
4377                                                  |
4378        ]])
4379      end
4380
4381      api.nvim_win_set_config(win, { relative = 'cursor', row = 0, col = -2, anchor = 'NE' })
4382      if multigrid then
4383        screen:expect {
4384          grid = [[
4385        ## grid 1
4386          [2:----------------------------------------]|*5
4387          {5:[No Name] [+]                           }|
4388          [4:----------------------------------------]|*5
4389          {4:[No Name] [+]                           }|
4390          [3:----------------------------------------]|
4391        ## grid 2
4392          just some example text                  |
4393          some more example text                  |
4394          {0:~                                       }|*3
4395        ## grid 3
4396                                                  |
4397        ## grid 4
4398          just some exampl^e text                  |
4399          some more example text                  |
4400          {0:~                                       }|*3
4401        ## grid 5
4402          {33:╔═════════╗}|
4403          {33:║}{1: halloj! }{33:║}|
4404          {33:║}{1: BORDAA  }{33:║}|
4405          {33:╚═════════╝}|
4406        ]],
4407          float_pos = { [5] = { 1002, 'NE', 4, 0, 14, true, 50, 1, 6, 3 } },
4408        }
4409      else
4410        screen:expect([[
4411          just some example text                  |
4412          some more example text                  |
4413          {0:~                                       }|*3
4414          {5:[No Name] [+]                           }|
4415          jus{33:╔═════════╗}pl^e text                  |
4416          som{33:║}{1: halloj! }{33:║}ple text                  |
4417          {0:~  }{33:║}{1: BORDAA  }{33:║}{0:                          }|
4418          {0:~  }{33:╚═════════╝}{0:                          }|
4419          {0:~                                       }|
4420          {4:[No Name] [+]                           }|
4421                                                  |
4422        ]])
4423      end
4424
4425      api.nvim_win_set_config(win, { relative = 'cursor', row = 1, col = -2, anchor = 'SE' })
4426      if multigrid then
4427        screen:expect {
4428          grid = [[
4429        ## grid 1
4430          [2:----------------------------------------]|*5
4431          {5:[No Name] [+]                           }|
4432          [4:----------------------------------------]|*5
4433          {4:[No Name] [+]                           }|
4434          [3:----------------------------------------]|
4435        ## grid 2
4436          just some example text                  |
4437          some more example text                  |
4438          {0:~                                       }|*3
4439        ## grid 3
4440                                                  |
4441        ## grid 4
4442          just some exampl^e text                  |
4443          some more example text                  |
4444          {0:~                                       }|*3
4445        ## grid 5
4446          {33:╔═════════╗}|
4447          {33:║}{1: halloj! }{33:║}|
4448          {33:║}{1: BORDAA  }{33:║}|
4449          {33:╚═════════╝}|
4450        ]],
4451          float_pos = { [5] = { 1002, 'SE', 4, 1, 14, true, 50, 1, 3, 3 } },
4452        }
4453      else
4454        screen:expect([[
4455          just some example text                  |
4456          some more example text                  |
4457          {0:~                                       }|
4458          {0:~  }{33:╔═════════╗}{0:                          }|
4459          {0:~  }{33:║}{1: halloj! }{33:║}{0:                          }|
4460          {5:[No}{33:║}{1: BORDAA  }{33:║}{5:                          }|
4461          jus{33:╚═════════╝}pl^e text                  |
4462          some more example text                  |
4463          {0:~                                       }|*3
4464          {4:[No Name] [+]                           }|
4465                                                  |
4466        ]])
4467      end
4468
4469      api.nvim_win_set_config(win, { relative = 'cursor', row = 0, col = -2, anchor = 'SW' })
4470      if multigrid then
4471        screen:expect {
4472          grid = [[
4473        ## grid 1
4474          [2:----------------------------------------]|*5
4475          {5:[No Name] [+]                           }|
4476          [4:----------------------------------------]|*5
4477          {4:[No Name] [+]                           }|
4478          [3:----------------------------------------]|
4479        ## grid 2
4480          just some example text                  |
4481          some more example text                  |
4482          {0:~                                       }|*3
4483        ## grid 3
4484                                                  |
4485        ## grid 4
4486          just some exampl^e text                  |
4487          some more example text                  |
4488          {0:~                                       }|*3
4489        ## grid 5
4490          {33:╔═════════╗}|
4491          {33:║}{1: halloj! }{33:║}|
4492          {33:║}{1: BORDAA  }{33:║}|
4493          {33:╚═════════╝}|
4494        ]],
4495          float_pos = { [5] = { 1002, 'SW', 4, 0, 14, true, 50, 1, 2, 14 } },
4496        }
4497      else
4498        screen:expect([[
4499          just some example text                  |
4500          some more example text                  |
4501          {0:~             }{33:╔═════════╗}{0:               }|
4502          {0:~             }{33:║}{1: halloj! }{33:║}{0:               }|
4503          {0:~             }{33:║}{1: BORDAA  }{33:║}{0:               }|
4504          {5:[No Name] [+] }{33:╚═════════╝}{5:               }|
4505          just some exampl^e text                  |
4506          some more example text                  |
4507          {0:~                                       }|*3
4508          {4:[No Name] [+]                           }|
4509                                                  |
4510        ]])
4511      end
4512    end)
4513
4514    it('anchored to another floating window updated in the same call #14735', function()
4515      feed('i<CR><CR><CR><Esc>')
4516
4517      exec([[
4518        let b1 = nvim_create_buf(v:true, v:false)
4519        let b2 = nvim_create_buf(v:true, v:false)
4520        let b3 = nvim_create_buf(v:true, v:false)
4521        let b4 = nvim_create_buf(v:true, v:false)
4522        let b5 = nvim_create_buf(v:true, v:false)
4523        let b6 = nvim_create_buf(v:true, v:false)
4524        let b7 = nvim_create_buf(v:true, v:false)
4525        let b8 = nvim_create_buf(v:true, v:false)
4526        call setbufline(b1, 1, '1')
4527        call setbufline(b2, 1, '2')
4528        call setbufline(b3, 1, '3')
4529        call setbufline(b4, 1, '4')
4530        call setbufline(b5, 1, '5')
4531        call setbufline(b6, 1, '6')
4532        call setbufline(b7, 1, '7')
4533        call setbufline(b8, 1, '8')
4534        let o1 = #{relative: 'editor', row: 1, col: 10, width: 5, height: 1}
4535        let w1 = nvim_open_win(b1, v:false, o1)
4536        let o2 = extendnew(o1, #{col: 30})
4537        let w2 = nvim_open_win(b2, v:false, o2)
4538        let o3 = extendnew(o1, #{relative: 'win', win: w1, anchor: 'NE', col: 0})
4539        let w3 = nvim_open_win(b3, v:false, o3)
4540        let o4 = extendnew(o3, #{win: w2})
4541        let w4 = nvim_open_win(b4, v:false, o4)
4542        let o5 = extendnew(o3, #{win: w3, anchor: 'SE', row: 0})
4543        let w5 = nvim_open_win(b5, v:false, o5)
4544        let o6 = extendnew(o5, #{win: w4})
4545        let w6 = nvim_open_win(b6, v:false, o6)
4546        let o7 = extendnew(o5, #{win: w5, anchor: 'SW', col: 5})
4547        let w7 = nvim_open_win(b7, v:false, o7)
4548        let o8 = extendnew(o7, #{win: w6})
4549        let w8 = nvim_open_win(b8, v:false, o8)
4550      ]])
4551      if multigrid then
4552        screen:expect {
4553          grid = [[
4554        ## grid 1
4555          [2:----------------------------------------]|*6
4556          [3:----------------------------------------]|
4557        ## grid 2
4558                                                  |*3
4559          ^                                        |
4560          {0:~                                       }|*2
4561        ## grid 3
4562                                                  |
4563        ## grid 5
4564          {1:1    }|
4565        ## grid 6
4566          {1:2    }|
4567        ## grid 7
4568          {1:3    }|
4569        ## grid 8
4570          {1:4    }|
4571        ## grid 9
4572          {1:5    }|
4573        ## grid 10
4574          {1:6    }|
4575        ## grid 11
4576          {1:7    }|
4577        ## grid 12
4578          {1:8    }|
4579        ]],
4580          float_pos = {
4581            [5] = { 1002, 'NW', 1, 1, 10, true, 50, 5, 1, 10 },
4582            [6] = { 1003, 'NW', 1, 1, 30, true, 50, 1, 1, 30 },
4583            [7] = { 1004, 'NE', 5, 1, 0, true, 50, 6, 2, 5 },
4584            [8] = { 1005, 'NE', 6, 1, 0, true, 50, 2, 2, 25 },
4585            [9] = { 1006, 'SE', 7, 0, 0, true, 50, 7, 1, 0 },
4586            [10] = { 1007, 'SE', 8, 0, 0, true, 50, 3, 1, 20 },
4587            [11] = { 1008, 'SW', 9, 0, 5, true, 50, 8, 0, 5 },
4588            [12] = { 1009, 'SW', 10, 0, 5, true, 50, 4, 0, 25 },
4589          },
4590        }
4591      else
4592        screen:expect([[
4593               {1:7    }               {1:8    }          |
4594          {1:5    }     {1:1    }     {1:6    }     {1:2    }     |
4595               {1:3    }               {1:4    }          |
4596          ^                                        |
4597          {0:~                                       }|*2
4598                                                  |
4599        ]])
4600      end
4601
4602      -- Reconfigure in different directions
4603      exec([[
4604        let o1 = extendnew(o1, #{anchor: 'NW'})
4605        call nvim_win_set_config(w8, o1)
4606        let o2 = extendnew(o2, #{anchor: 'NW'})
4607        call nvim_win_set_config(w4, o2)
4608        let o3 = extendnew(o3, #{win: w8})
4609        call nvim_win_set_config(w2, o3)
4610        let o4 = extendnew(o4, #{win: w4})
4611        call nvim_win_set_config(w1, o4)
4612        let o5 = extendnew(o5, #{win: w2})
4613        call nvim_win_set_config(w6, o5)
4614        let o6 = extendnew(o6, #{win: w1})
4615        call nvim_win_set_config(w3, o6)
4616        let o7 = extendnew(o7, #{win: w6})
4617        call nvim_win_set_config(w5, o7)
4618        let o8 = extendnew(o8, #{win: w3})
4619        call nvim_win_set_config(w7, o8)
4620      ]])
4621      if multigrid then
4622        screen:expect {
4623          grid = [[
4624        ## grid 1
4625          [2:----------------------------------------]|*6
4626          [3:----------------------------------------]|
4627        ## grid 2
4628                                                  |*3
4629          ^                                        |
4630          {0:~                                       }|*2
4631        ## grid 3
4632                                                  |
4633        ## grid 5
4634          {1:1    }|
4635        ## grid 6
4636          {1:2    }|
4637        ## grid 7
4638          {1:3    }|
4639        ## grid 8
4640          {1:4    }|
4641        ## grid 9
4642          {1:5    }|
4643        ## grid 10
4644          {1:6    }|
4645        ## grid 11
4646          {1:7    }|
4647        ## grid 12
4648          {1:8    }|
4649        ]],
4650          float_pos = {
4651            [5] = { 1002, 'NE', 8, 1, 0, true, 50, 5, 2, 25 },
4652            [6] = { 1003, 'NE', 12, 1, 0, true, 50, 1, 2, 5 },
4653            [7] = { 1004, 'SE', 5, 0, 0, true, 50, 6, 1, 20 },
4654            [8] = { 1005, 'NW', 1, 1, 30, true, 50, 2, 1, 30 },
4655            [9] = { 1006, 'SW', 10, 0, 5, true, 50, 7, 0, 5 },
4656            [10] = { 1007, 'SE', 6, 0, 0, true, 50, 3, 1, 0 },
4657            [11] = { 1008, 'SW', 7, 0, 5, true, 50, 8, 0, 25 },
4658            [12] = { 1009, 'NW', 1, 1, 10, true, 50, 4, 1, 10 },
4659          },
4660        }
4661      else
4662        screen:expect([[
4663               {1:5    }               {1:7    }          |
4664          {1:6    }     {1:8    }     {1:3    }     {1:4    }     |
4665               {1:2    }               {1:1    }          |
4666          ^                                        |
4667          {0:~                                       }|*2
4668                                                  |
4669        ]])
4670      end
4671
4672      -- Not clear how cycles should behave, but they should not hang or crash
4673      exec([[
4674        let o1 = extendnew(o1, #{relative: 'win', win: w7})
4675        call nvim_win_set_config(w1, o1)
4676        let o2 = extendnew(o2, #{relative: 'win', win: w8})
4677        call nvim_win_set_config(w2, o2)
4678        let o3 = extendnew(o3, #{win: w1})
4679        call nvim_win_set_config(w3, o3)
4680        let o4 = extendnew(o4, #{win: w2})
4681        call nvim_win_set_config(w4, o4)
4682        let o5 = extendnew(o5, #{win: w3})
4683        call nvim_win_set_config(w5, o5)
4684        let o6 = extendnew(o6, #{win: w4})
4685        call nvim_win_set_config(w6, o6)
4686        let o7 = extendnew(o7, #{win: w5})
4687        call nvim_win_set_config(w7, o7)
4688        let o8 = extendnew(o8, #{win: w6})
4689        call nvim_win_set_config(w8, o8)
4690        redraw
4691      ]])
4692    end)
4693
4694    it('can be placed relative text in a window', function()
4695      screen:try_resize(30, 5)
4696      local firstwin = api.nvim_get_current_win()
4697      api.nvim_buf_set_lines(0, 0, -1, true, { 'just some', 'example text that is wider than the window', '', '', 'more text' })
4698      if multigrid then
4699        screen:expect {
4700          grid = [[
4701        ## grid 1
4702          [2:------------------------------]|*4
4703          [3:------------------------------]|
4704        ## grid 2
4705          ^just some                     |
4706          example text that is wider tha|
4707          n the window                  |
4708                                        |
4709        ## grid 3
4710                                        |
4711        ]],
4712        }
4713      else
4714        screen:expect {
4715          grid = [[
4716          ^just some                     |
4717          example text that is wider tha|
4718          n the window                  |
4719                                        |*2
4720        ]],
4721        }
4722      end
4723
4724      local buf = api.nvim_create_buf(false, false)
4725      api.nvim_buf_set_lines(buf, 0, -1, true, { 'some info!' })
4726
4727      local win = api.nvim_open_win(buf, false, { relative = 'win', width = 12, height = 1, bufpos = { 1, 32 } })
4728      if multigrid then
4729        screen:expect {
4730          grid = [[
4731        ## grid 1
4732          [2:------------------------------]|*4
4733          [3:------------------------------]|
4734        ## grid 2
4735          ^just some                     |
4736          example text that is wider tha|
4737          n the window                  |
4738                                        |
4739        ## grid 3
4740                                        |
4741        ## grid 4
4742          {1:some info!  }|
4743        ]],
4744          float_pos = { [4] = { 1001, 'NW', 2, 3, 2, true, 50, 1, 3, 2 } },
4745        }
4746      else
4747        screen:expect {
4748          grid = [[
4749          ^just some                     |
4750          example text that is wider tha|
4751          n the window                  |
4752            {1:some info!  }                |
4753                                        |
4754        ]],
4755        }
4756      end
4757      eq({
4758        relative = 'win',
4759        width = 12,
4760        height = 1,
4761        bufpos = { 1, 32 },
4762        anchor = 'NW',
4763        border = 'none',
4764        style = '',
4765        hide = false,
4766        external = false,
4767        col = 0,
4768        row = 1,
4769        win = firstwin,
4770        focusable = true,
4771        mouse = true,
4772        zindex = 50,
4773      }, api.nvim_win_get_config(win))
4774
4775      feed('<c-e>')
4776      if multigrid then
4777        screen:expect {
4778          grid = [[
4779        ## grid 1
4780          [2:------------------------------]|*4
4781          [3:------------------------------]|
4782        ## grid 2
4783          ^example text that is wider tha|
4784          n the window                  |
4785                                        |*2
4786        ## grid 3
4787                                        |
4788        ## grid 4
4789          {1:some info!  }|
4790        ]],
4791          float_pos = { [4] = { 1001, 'NW', 2, 2, 2, true, 50, 1, 2, 2 } },
4792        }
4793      else
4794        screen:expect {
4795          grid = [[
4796          ^example text that is wider tha|
4797          n the window                  |
4798            {1:some info!  }                |
4799                                        |*2
4800        ]],
4801        }
4802      end
4803
4804      screen:try_resize(45, 5)
4805      if multigrid then
4806        screen:expect {
4807          grid = [[
4808        ## grid 1
4809          [2:---------------------------------------------]|*4
4810          [3:---------------------------------------------]|
4811        ## grid 2
4812          ^example text that is wider than the window   |
4813                                                       |*2
4814          more text                                    |
4815        ## grid 3
4816                                                       |
4817        ## grid 4
4818          {1:some info!  }|
4819        ]],
4820          float_pos = { [4] = { 1001, 'NW', 2, 1, 32, true, 50, 1, 1, 32 } },
4821        }
4822      else
4823        -- note: appears misaligned due to cursor
4824        screen:expect {
4825          grid = [[
4826          ^example text that is wider than the window   |
4827                                          {1:some info!  } |
4828                                                       |
4829          more text                                    |
4830                                                       |
4831        ]],
4832        }
4833      end
4834
4835      screen:try_resize(25, 10)
4836      if multigrid then
4837        screen:expect {
4838          grid = [[
4839        ## grid 1
4840          [2:-------------------------]|*9
4841          [3:-------------------------]|
4842        ## grid 2
4843          ^example text that is wide|
4844          r than the window        |
4845                                   |*2
4846          more text                |
4847          {0:~                        }|*4
4848        ## grid 3
4849                                   |
4850        ## grid 4
4851          {1:some info!  }|
4852        ]],
4853          float_pos = { [4] = { 1001, 'NW', 2, 2, 7, true, 50, 1, 2, 7 } },
4854        }
4855      else
4856        screen:expect {
4857          grid = [[
4858          ^example text that is wide|
4859          r than the window        |
4860                 {1:some info!  }      |
4861                                   |
4862          more text                |
4863          {0:~                        }|*4
4864                                   |
4865        ]],
4866        }
4867      end
4868
4869      api.nvim_win_set_config(win, { relative = 'win', bufpos = { 1, 32 }, anchor = 'SW' })
4870      if multigrid then
4871        screen:expect {
4872          grid = [[
4873        ## grid 1
4874          [2:-------------------------]|*9
4875          [3:-------------------------]|
4876        ## grid 2
4877          ^example text that is wide|
4878          r than the window        |
4879                                   |*2
4880          more text                |
4881          {0:~                        }|*4
4882        ## grid 3
4883                                   |
4884        ## grid 4
4885          {1:some info!  }|
4886        ]],
4887          float_pos = { [4] = { 1001, 'SW', 2, 1, 7, true, 50, 1, 0, 7 } },
4888        }
4889      else
4890        screen:expect {
4891          grid = [[
4892          ^example{1:some info!  }s wide|
4893          r than the window        |
4894                                   |*2
4895          more text                |
4896          {0:~                        }|*4
4897                                   |
4898        ]],
4899        }
4900      end
4901
4902      command('set laststatus=0')
4903      command('botright vnew')
4904      if multigrid then
4905        screen:expect {
4906          grid = [[
4907        ## grid 1
4908          [2:----]{5:│}[5:--------------------]|*9
4909          [3:-------------------------]|
4910        ## grid 2
4911          exam|
4912          ple |
4913          text|
4914           tha|
4915          t is|
4916           wid|
4917          er t|
4918          han |
4919          the |
4920        ## grid 3
4921                                   |
4922        ## grid 4
4923          {1:some info!  }|
4924        ## grid 5
4925          ^                    |
4926          {0:~                   }|*8
4927        ]],
4928          float_pos = {
4929            [4] = { 1001, 'SW', 2, 8, 0, true, 50, 1, 7, 0 },
4930          },
4931        }
4932      else
4933        screen:expect {
4934          grid = [[
4935          exam{5:│}^                    |
4936          ple {5:│}{0:~                   }|
4937          text{5:│}{0:~                   }|
4938           tha{5:│}{0:~                   }|
4939          t is{5:│}{0:~                   }|
4940           wid{5:│}{0:~                   }|
4941          er t{5:│}{0:~                   }|
4942          {1:some info!  }{0:             }|
4943          the {5:│}{0:~                   }|
4944                                   |
4945        ]],
4946        }
4947      end
4948      command('close')
4949
4950      api.nvim_win_set_config(win, { relative = 'win', bufpos = { 1, 32 }, anchor = 'NW', col = -2 })
4951      if multigrid then
4952        screen:expect {
4953          grid = [[
4954        ## grid 1
4955          [2:-------------------------]|*9
4956          [3:-------------------------]|
4957        ## grid 2
4958          ^example text that is wide|
4959          r than the window        |
4960                                   |*2
4961          more text                |
4962          {0:~                        }|*4
4963        ## grid 3
4964                                   |
4965        ## grid 4
4966          {1:some info!  }|
4967        ]],
4968          float_pos = { [4] = { 1001, 'NW', 2, 2, 5, true, 50, 1, 2, 5 } },
4969        }
4970      else
4971        screen:expect {
4972          grid = [[
4973          ^example text that is wide|
4974          r than the window        |
4975               {1:some info!  }        |
4976                                   |
4977          more text                |
4978          {0:~                        }|*4
4979                                   |
4980        ]],
4981        }
4982      end
4983
4984      api.nvim_win_set_config(win, { relative = 'win', bufpos = { 1, 32 }, row = 2 })
4985      if multigrid then
4986        screen:expect {
4987          grid = [[
4988        ## grid 1
4989          [2:-------------------------]|*9
4990          [3:-------------------------]|
4991        ## grid 2
4992          ^example text that is wide|
4993          r than the window        |
4994                                   |*2
4995          more text                |
4996          {0:~                        }|*4
4997        ## grid 3
4998                                   |
4999        ## grid 4
5000          {1:some info!  }|
5001        ]],
5002          float_pos = { [4] = { 1001, 'NW', 2, 3, 7, true, 50, 1, 3, 7 } },
5003        }
5004      else
5005        screen:expect {
5006          grid = [[
5007          ^example text that is wide|
5008          r than the window        |
5009                                   |
5010                 {1:some info!  }      |
5011          more text                |
5012          {0:~                        }|*4
5013                                   |
5014        ]],
5015        }
5016      end
5017
5018      command('%fold')
5019      if multigrid then
5020        screen:expect {
5021          grid = [[
5022        ## grid 1
5023          [2:-------------------------]|*9
5024          [3:-------------------------]|
5025        ## grid 2
5026          {28:^+--  5 lines: just some··}|
5027          {0:~                        }|*8
5028        ## grid 3
5029                                   |
5030        ## grid 4
5031          {1:some info!  }|
5032        ]],
5033          float_pos = { [4] = { 1001, 'NW', 2, 2, 0, true, 50, 1, 2, 0 } },
5034        }
5035      else
5036        screen:expect {
5037          grid = [[
5038          {28:^+--  5 lines: just some··}|
5039          {0:~                        }|
5040          {1:some info!  }{0:             }|
5041          {0:~                        }|*6
5042                                   |
5043        ]],
5044        }
5045      end
5046    end)
5047
5048    it('validates cursor even when window is not entered', function()
5049      screen:try_resize(30, 5)
5050      command('set nowrap')
5051      insert([[some text that is wider than the window]])
5052      if multigrid then
5053        screen:expect([[
5054        ## grid 1
5055          [2:------------------------------]|*4
5056          [3:------------------------------]|
5057        ## grid 2
5058          that is wider than the windo^w |
5059          {0:~                             }|*3
5060        ## grid 3
5061                                        |
5062        ]])
5063      else
5064        screen:expect([[
5065          that is wider than the windo^w |
5066          {0:~                             }|*3
5067                                        |
5068        ]])
5069      end
5070
5071      local buf = api.nvim_create_buf(false, true)
5072      api.nvim_buf_set_lines(buf, 0, -1, true, { 'some floaty text' })
5073      api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 1, row = 3, col = 1 })
5074      if multigrid then
5075        screen:expect {
5076          grid = [[
5077        ## grid 1
5078          [2:------------------------------]|*4
5079          [3:------------------------------]|
5080        ## grid 2
5081          that is wider than the windo^w |
5082          {0:~                             }|*3
5083        ## grid 3
5084                                        |
5085        ## grid 4
5086          {1:some floaty text    }|
5087        ]],
5088          float_pos = { [4] = { 1001, 'NW', 1, 3, 1, true, 50, 1, 3, 1 } },
5089        }
5090      else
5091        screen:expect([[
5092          that is wider than the windo^w |
5093          {0:~                             }|*2
5094          {0:~}{1:some floaty text    }{0:         }|
5095                                        |
5096        ]])
5097      end
5098    end)
5099
5100    if multigrid then
5101      pending('supports second UI without multigrid', function()
5102        local session2 = n.connect(eval('v:servername'))
5103        print(session2:request('nvim_eval', '2+2'))
5104        local screen2 = Screen.new(40, 7)
5105        screen2:attach(nil, session2)
5106        screen2:set_default_attr_ids(attrs)
5107        local buf = api.nvim_create_buf(false, false)
5108        api.nvim_open_win(buf, true, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
5109        local expected_pos = { [2] = { 1001, 'NW', 1, 2, 5 } }
5110        screen:expect {
5111          grid = [[
5112        ## grid 1
5113                                                  |
5114          {0:~                                       }|*5
5115                                                  |
5116        ## grid 2
5117          {1:^                    }|
5118          {2:~                   }|
5119        ]],
5120          float_pos = expected_pos,
5121        }
5122        screen2:expect([[
5123                                                  |
5124          {0:~                                       }|
5125          {0:~    }{1:^                    }{0:               }|
5126          {0:~    }{2:~                   }{0:               }|
5127          {0:~                                       }|*2
5128                                                  |
5129          ]])
5130      end)
5131    end
5132
5133    it('handles resized screen', function()
5134      local buf = api.nvim_create_buf(false, false)
5135      api.nvim_buf_set_lines(buf, 0, -1, true, { 'such', 'very', 'float' })
5136      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 15, height = 4, row = 2, col = 10 })
5137      if multigrid then
5138        screen:expect {
5139          grid = [[
5140        ## grid 1
5141          [2:----------------------------------------]|*6
5142          [3:----------------------------------------]|
5143        ## grid 2
5144          ^                                        |
5145          {0:~                                       }|*5
5146        ## grid 3
5147                                                  |
5148        ## grid 4
5149          {1:such           }|
5150          {1:very           }|
5151          {1:float          }|
5152          {2:~              }|
5153        ]],
5154          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 10 } },
5155        }
5156      else
5157        screen:expect([[
5158          ^                                        |
5159          {0:~                                       }|
5160          {0:~         }{1:such           }{0:               }|
5161          {0:~         }{1:very           }{0:               }|
5162          {0:~         }{1:float          }{0:               }|
5163          {0:~         }{2:~              }{0:               }|
5164                                                  |
5165        ]])
5166      end
5167
5168      screen:try_resize(40, 5)
5169      if multigrid then
5170        screen:expect {
5171          grid = [[
5172        ## grid 1
5173          [2:----------------------------------------]|*4
5174          [3:----------------------------------------]|
5175        ## grid 2
5176          ^                                        |
5177          {0:~                                       }|*3
5178        ## grid 3
5179                                                  |
5180        ## grid 4
5181          {1:such           }|
5182          {1:very           }|
5183          {1:float          }|
5184          {2:~              }|
5185        ]],
5186          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 0, 10 } },
5187        }
5188      else
5189        screen:expect([[
5190          ^          {1:such           }               |
5191          {0:~         }{1:very           }{0:               }|
5192          {0:~         }{1:float          }{0:               }|
5193          {0:~         }{2:~              }{0:               }|
5194                                                  |
5195        ]])
5196      end
5197
5198      screen:try_resize(40, 4)
5199      if multigrid then
5200        screen:expect {
5201          grid = [[
5202        ## grid 1
5203          [2:----------------------------------------]|*3
5204          [3:----------------------------------------]|
5205        ## grid 2
5206          ^                                        |
5207          {0:~                                       }|*2
5208        ## grid 3
5209                                                  |
5210        ## grid 4
5211          {1:such           }|
5212          {1:very           }|
5213          {1:float          }|
5214          {2:~              }|
5215        ]],
5216          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 0, 10 } },
5217        }
5218      else
5219        screen:expect([[
5220          ^          {1:such           }               |
5221          {0:~         }{1:very           }{0:               }|
5222          {0:~         }{1:float          }{0:               }|
5223                                                  |
5224        ]])
5225      end
5226
5227      screen:try_resize(40, 3)
5228      if multigrid then
5229        screen:expect {
5230          grid = [[
5231        ## grid 1
5232          [2:----------------------------------------]|*2
5233          [3:----------------------------------------]|
5234        ## grid 2
5235          ^                                        |
5236          {0:~                                       }|
5237        ## grid 3
5238                                                  |
5239        ## grid 4
5240          {1:such           }|
5241          {1:very           }|
5242          {1:float          }|
5243          {2:~              }|
5244        ]],
5245          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 0, 10 } },
5246        }
5247      else
5248        screen:expect([[
5249          ^          {1:such           }               |
5250          {0:~         }{1:very           }{0:               }|
5251                                                  |
5252        ]])
5253      end
5254      feed('<c-w>wjj')
5255      if multigrid then
5256        screen:expect {
5257          grid = [[
5258        ## grid 1
5259          [2:----------------------------------------]|*2
5260          [3:----------------------------------------]|
5261        ## grid 2
5262                                                  |
5263          {0:~                                       }|
5264        ## grid 3
5265                                                  |
5266        ## grid 4
5267          {1:such           }|
5268          {1:very           }|
5269          {1:^float          }|
5270          {2:~              }|
5271        ]],
5272          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 0, 10 } },
5273        }
5274      else
5275        screen:expect([[
5276                    {1:very           }               |
5277          {0:~         }{1:^float          }{0:               }|
5278                                                  |
5279        ]])
5280      end
5281
5282      screen:try_resize(40, 7)
5283      if multigrid then
5284        screen:expect {
5285          grid = [[
5286        ## grid 1
5287          [2:----------------------------------------]|*6
5288          [3:----------------------------------------]|
5289        ## grid 2
5290                                                  |
5291          {0:~                                       }|*5
5292        ## grid 3
5293                                                  |
5294        ## grid 4
5295          {1:such           }|
5296          {1:very           }|
5297          {1:^float          }|
5298          {2:~              }|
5299        ]],
5300          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 10 } },
5301        }
5302      else
5303        screen:expect([[
5304                                                  |
5305          {0:~                                       }|
5306          {0:~         }{1:such           }{0:               }|
5307          {0:~         }{1:very           }{0:               }|
5308          {0:~         }{1:^float          }{0:               }|
5309          {0:~         }{2:~              }{0:               }|
5310                                                  |
5311        ]])
5312      end
5313
5314      api.nvim_win_set_config(win, { height = 3 })
5315      feed('gg')
5316      if multigrid then
5317        screen:expect {
5318          grid = [[
5319        ## grid 1
5320          [2:----------------------------------------]|*6
5321          [3:----------------------------------------]|
5322        ## grid 2
5323                                                  |
5324          {0:~                                       }|*5
5325        ## grid 3
5326                                                  |
5327        ## grid 4
5328          {1:^such           }|
5329          {1:very           }|
5330          {1:float          }|
5331        ]],
5332          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 10 } },
5333        }
5334      else
5335        screen:expect([[
5336                                                  |
5337          {0:~                                       }|
5338          {0:~         }{1:^such           }{0:               }|
5339          {0:~         }{1:very           }{0:               }|
5340          {0:~         }{1:float          }{0:               }|
5341          {0:~                                       }|
5342                                                  |
5343        ]])
5344      end
5345
5346      screen:try_resize(26, 7)
5347      if multigrid then
5348        screen:expect {
5349          grid = [[
5350        ## grid 1
5351          [2:--------------------------]|*6
5352          [3:--------------------------]|
5353        ## grid 2
5354                                    |
5355          {0:~                         }|*5
5356        ## grid 3
5357                                    |
5358        ## grid 4
5359          {1:^such           }|
5360          {1:very           }|
5361          {1:float          }|
5362        ]],
5363          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 10 } },
5364        }
5365      else
5366        screen:expect([[
5367                                    |
5368          {0:~                         }|
5369          {0:~         }{1:^such           }{0: }|
5370          {0:~         }{1:very           }{0: }|
5371          {0:~         }{1:float          }{0: }|
5372          {0:~                         }|
5373                                    |
5374        ]])
5375      end
5376
5377      screen:try_resize(25, 7)
5378      if multigrid then
5379        screen:expect {
5380          grid = [[
5381        ## grid 1
5382          [2:-------------------------]|*6
5383          [3:-------------------------]|
5384        ## grid 2
5385                                   |
5386          {0:~                        }|*5
5387        ## grid 3
5388                                   |
5389        ## grid 4
5390          {1:^such           }|
5391          {1:very           }|
5392          {1:float          }|
5393        ]],
5394          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 10 } },
5395        }
5396      else
5397        screen:expect([[
5398                                   |
5399          {0:~                        }|
5400          {0:~         }{1:^such           }|
5401          {0:~         }{1:very           }|
5402          {0:~         }{1:float          }|
5403          {0:~                        }|
5404                                   |
5405        ]])
5406      end
5407
5408      screen:try_resize(24, 7)
5409      if multigrid then
5410        screen:expect {
5411          grid = [[
5412        ## grid 1
5413          [2:------------------------]|*6
5414          [3:------------------------]|
5415        ## grid 2
5416                                  |
5417          {0:~                       }|*5
5418        ## grid 3
5419                                  |
5420        ## grid 4
5421          {1:^such           }|
5422          {1:very           }|
5423          {1:float          }|
5424        ]],
5425          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 9 } },
5426        }
5427      else
5428        screen:expect([[
5429                                  |
5430          {0:~                       }|
5431          {0:~        }{1:^such           }|
5432          {0:~        }{1:very           }|
5433          {0:~        }{1:float          }|
5434          {0:~                       }|
5435                                  |
5436        ]])
5437      end
5438
5439      screen:try_resize(16, 7)
5440      if multigrid then
5441        screen:expect {
5442          grid = [[
5443        ## grid 1
5444          [2:----------------]|*6
5445          [3:----------------]|
5446        ## grid 2
5447                          |
5448          {0:~               }|*5
5449        ## grid 3
5450                          |
5451        ## grid 4
5452          {1:^such           }|
5453          {1:very           }|
5454          {1:float          }|
5455        ]],
5456          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 1 } },
5457        }
5458      else
5459        screen:expect([[
5460                          |
5461          {0:~               }|
5462          {0:~}{1:^such           }|
5463          {0:~}{1:very           }|
5464          {0:~}{1:float          }|
5465          {0:~               }|
5466                          |
5467        ]])
5468      end
5469
5470      screen:try_resize(15, 7)
5471      if multigrid then
5472        screen:expect {
5473          grid = [[
5474        ## grid 1
5475          [2:---------------]|*6
5476          [3:---------------]|
5477        ## grid 2
5478                         |
5479          {0:~              }|*5
5480        ## grid 3
5481                         |
5482        ## grid 4
5483          {1:^such           }|
5484          {1:very           }|
5485          {1:float          }|
5486        ]],
5487          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 0 } },
5488        }
5489      else
5490        screen:expect([[
5491                         |
5492          {0:~              }|
5493          {1:^such           }|
5494          {1:very           }|
5495          {1:float          }|
5496          {0:~              }|
5497                         |
5498        ]])
5499      end
5500
5501      screen:try_resize(14, 7)
5502      if multigrid then
5503        screen:expect {
5504          grid = [[
5505        ## grid 1
5506          [2:--------------]|*6
5507          [3:--------------]|
5508        ## grid 2
5509                        |
5510          {0:~             }|*5
5511        ## grid 3
5512                        |
5513        ## grid 4
5514          {1:^such           }|
5515          {1:very           }|
5516          {1:float          }|
5517        ]],
5518          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 0 } },
5519        }
5520      else
5521        screen:expect([[
5522                        |
5523          {0:~             }|
5524          {1:^such          }|
5525          {1:very          }|
5526          {1:float         }|
5527          {0:~             }|
5528                        |
5529        ]])
5530      end
5531
5532      screen:try_resize(12, 7)
5533      if multigrid then
5534        screen:expect {
5535          grid = [[
5536        ## grid 1
5537          [2:------------]|*6
5538          [3:------------]|
5539        ## grid 2
5540                      |
5541          {0:~           }|*5
5542        ## grid 3
5543                      |
5544        ## grid 4
5545          {1:^such           }|
5546          {1:very           }|
5547          {1:float          }|
5548        ]],
5549          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 0 } },
5550        }
5551      else
5552        screen:expect([[
5553                      |
5554          {0:~           }|
5555          {1:^such        }|
5556          {1:very        }|
5557          {1:float       }|
5558          {0:~           }|
5559                      |
5560        ]])
5561      end
5562
5563      -- Doesn't make much sense, but check nvim doesn't crash
5564      screen:try_resize(1, 1)
5565      if multigrid then
5566        screen:expect {
5567          grid = [[
5568        ## grid 1
5569          [2:------------]|
5570          [3:------------]|
5571        ## grid 2
5572                      |
5573        ## grid 3
5574                      |
5575        ## grid 4
5576          {1:^such           }|
5577          {1:very           }|
5578          {1:float          }|
5579        ]],
5580          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 0, 0 } },
5581        }
5582      else
5583        screen:expect([[
5584          {1:^such        }|
5585                      |
5586        ]])
5587      end
5588
5589      screen:try_resize(40, 7)
5590      if multigrid then
5591        screen:expect {
5592          grid = [[
5593        ## grid 1
5594          [2:----------------------------------------]|*6
5595          [3:----------------------------------------]|
5596        ## grid 2
5597                                                  |
5598          {0:~                                       }|*5
5599        ## grid 3
5600                                                  |
5601        ## grid 4
5602          {1:^such           }|
5603          {1:very           }|
5604          {1:float          }|
5605        ]],
5606          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 10 } },
5607        }
5608      else
5609        screen:expect([[
5610                                                  |
5611          {0:~                                       }|
5612          {0:~         }{1:^such           }{0:               }|
5613          {0:~         }{1:very           }{0:               }|
5614          {0:~         }{1:float          }{0:               }|
5615          {0:~                                       }|
5616                                                  |
5617        ]])
5618      end
5619    end)
5620
5621    it('does not crash with inccommand #9379', function()
5622      local expected_pos = { [4] = { 1001, 'NW', 1, 2, 0, true, 50, 1, 2, 0 } }
5623      command('set inccommand=split')
5624      command('set laststatus=2')
5625      local buf = api.nvim_create_buf(false, false)
5626      api.nvim_open_win(buf, true, { relative = 'editor', width = 30, height = 3, row = 2, col = 0 })
5627      insert([[
5628      foo
5629      bar
5630      ]])
5631
5632      if multigrid then
5633        screen:expect {
5634          grid = [[
5635          ## grid 1
5636            [2:----------------------------------------]|*5
5637            {5:[No Name]                               }|
5638            [3:----------------------------------------]|
5639          ## grid 2
5640                                                    |
5641            {0:~                                       }|*4
5642          ## grid 3
5643                                                    |
5644          ## grid 4
5645            {1:foo                           }|
5646            {1:bar                           }|
5647            {1:^                              }|
5648        ]],
5649          float_pos = expected_pos,
5650        }
5651      else
5652        screen:expect([[
5653                                                  |
5654          {0:~                                       }|
5655          {1:foo                           }{0:          }|
5656          {1:bar                           }{0:          }|
5657          {1:^                              }{0:          }|
5658          {5:[No Name]                               }|
5659                                                  |
5660        ]])
5661      end
5662
5663      feed(':%s/.')
5664      if multigrid then
5665        screen:expect {
5666          grid = [[
5667          ## grid 1
5668            [2:----------------------------------------]|*5
5669            {5:[Preview]                               }|
5670            [3:----------------------------------------]|
5671          ## grid 2
5672                                                    |
5673          ## grid 3
5674            :%s/.^                                   |
5675          ## grid 4
5676            {17:f}{1:oo                           }|
5677            {17:b}{1:ar                           }|
5678            {1:                              }|
5679        ]],
5680          float_pos = expected_pos,
5681        }
5682      else
5683        screen:expect([[
5684                                                  |
5685          {5:[No Name]                               }|
5686          {17:f}{1:oo                           }          |
5687          {17:b}{1:ar                           }          |
5688          {1:                              }{0:          }|
5689          {5:[Preview]                               }|
5690          :%s/.^                                   |
5691        ]])
5692      end
5693
5694      feed('<Esc>')
5695
5696      if multigrid then
5697        screen:expect {
5698          grid = [[
5699          ## grid 1
5700            [2:----------------------------------------]|*5
5701            {5:[No Name]                               }|
5702            [3:----------------------------------------]|
5703          ## grid 2
5704                                                    |
5705            {0:~                                       }|*4
5706          ## grid 3
5707                                                    |
5708          ## grid 4
5709            {1:foo                           }|
5710            {1:bar                           }|
5711            {1:^                              }|
5712        ]],
5713          float_pos = expected_pos,
5714        }
5715      else
5716        screen:expect([[
5717                                                  |
5718          {0:~                                       }|
5719          {1:foo                           }{0:          }|
5720          {1:bar                           }{0:          }|
5721          {1:^                              }{0:          }|
5722          {5:[No Name]                               }|
5723                                                  |
5724        ]])
5725      end
5726    end)
5727
5728    it('does not crash when set cmdheight #9680', function()
5729      local buf = api.nvim_create_buf(false, false)
5730      api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
5731      command('set cmdheight=2')
5732      eq(1, api.nvim_eval('1'))
5733    end)
5734
5735    describe('and completion', function()
5736      before_each(function()
5737        local buf = api.nvim_create_buf(false, false)
5738        local win = api.nvim_open_win(buf, true, { relative = 'editor', width = 12, height = 4, row = 2, col = 5 })
5739        api.nvim_set_option_value('winhl', 'Normal:ErrorMsg', { win = win })
5740        if multigrid then
5741          screen:expect {
5742            grid = [[
5743          ## grid 1
5744            [2:----------------------------------------]|*6
5745            [3:----------------------------------------]|
5746          ## grid 2
5747                                                    |
5748            {0:~                                       }|*5
5749          ## grid 3
5750                                                    |
5751          ## grid 4
5752            {7:^            }|
5753            {12:~           }|*3
5754          ]],
5755            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
5756          }
5757        else
5758          screen:expect([[
5759                                                    |
5760            {0:~                                       }|
5761            {0:~    }{7:^            }{0:                       }|
5762            {0:~    }{12:~           }{0:                       }|*3
5763                                                    |
5764          ]])
5765        end
5766      end)
5767
5768      it('with builtin popupmenu', function()
5769        feed('ix ')
5770        fn.complete(3, { 'aa', 'word', 'longtext' })
5771        if multigrid then
5772          screen:expect {
5773            grid = [[
5774          ## grid 1
5775            [2:----------------------------------------]|*6
5776            [3:----------------------------------------]|
5777          ## grid 2
5778                                                    |
5779            {0:~                                       }|*5
5780          ## grid 3
5781            {3:-- INSERT --}                            |
5782          ## grid 4
5783            {7:x aa^        }|
5784            {12:~           }|*3
5785          ## grid 5
5786            {13: aa             }|
5787            {1: word           }|
5788            {1: longtext       }|
5789          ]],
5790            float_pos = {
5791              [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 },
5792              [5] = { -1, 'NW', 4, 1, 1, false, 100, 2, 3, 6 },
5793            },
5794          }
5795        else
5796          screen:expect([[
5797                                                    |
5798            {0:~                                       }|
5799            {0:~    }{7:x aa^        }{0:                       }|
5800            {0:~    }{12:~}{13: aa             }{0:                  }|
5801            {0:~    }{12:~}{1: word           }{0:                  }|
5802            {0:~    }{12:~}{1: longtext       }{0:                  }|
5803            {3:-- INSERT --}                            |
5804          ]])
5805        end
5806
5807        feed('<esc>')
5808        if multigrid then
5809          screen:expect {
5810            grid = [[
5811          ## grid 1
5812            [2:----------------------------------------]|*6
5813            [3:----------------------------------------]|
5814          ## grid 2
5815                                                    |
5816            {0:~                                       }|*5
5817          ## grid 3
5818                                                    |
5819          ## grid 4
5820            {7:x a^a        }|
5821            {12:~           }|*3
5822          ]],
5823            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
5824          }
5825        else
5826          screen:expect([[
5827                                                    |
5828            {0:~                                       }|
5829            {0:~    }{7:x a^a        }{0:                       }|
5830            {0:~    }{12:~           }{0:                       }|*3
5831                                                    |
5832          ]])
5833        end
5834
5835        feed('<c-w>wi')
5836        fn.complete(1, { 'xx', 'yy', 'zz' })
5837        if multigrid then
5838          screen:expect {
5839            grid = [[
5840          ## grid 1
5841            [2:----------------------------------------]|*6
5842            [3:----------------------------------------]|
5843          ## grid 2
5844            xx^                                      |
5845            {0:~                                       }|*5
5846          ## grid 3
5847            {3:-- INSERT --}                            |
5848          ## grid 4
5849            {7:x aa        }|
5850            {12:~           }|*3
5851          ## grid 5
5852            {13:xx             }|
5853            {1:yy             }|
5854            {1:zz             }|
5855          ]],
5856            float_pos = {
5857              [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 },
5858              [5] = { -1, 'NW', 2, 1, 0, false, 100, 2, 1, 0 },
5859            },
5860          }
5861        else
5862          screen:expect([[
5863            xx^                                      |
5864            {13:xx             }{0:                         }|
5865            {1:yy             }{7:  }{0:                       }|
5866            {1:zz             }{12:  }{0:                       }|
5867            {0:~    }{12:~           }{0:                       }|*2
5868            {3:-- INSERT --}                            |
5869          ]])
5870        end
5871
5872        feed('<c-y>')
5873        if multigrid then
5874          screen:expect {
5875            grid = [[
5876          ## grid 1
5877            [2:----------------------------------------]|*6
5878            [3:----------------------------------------]|
5879          ## grid 2
5880            xx^                                      |
5881            {0:~                                       }|*5
5882          ## grid 3
5883            {3:-- INSERT --}                            |
5884          ## grid 4
5885            {7:x aa        }|
5886            {12:~           }|*3
5887          ]],
5888            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
5889          }
5890        else
5891          screen:expect([[
5892            xx^                                      |
5893            {0:~                                       }|
5894            {0:~    }{7:x aa        }{0:                       }|
5895            {0:~    }{12:~           }{0:                       }|*3
5896            {3:-- INSERT --}                            |
5897          ]])
5898        end
5899      end)
5900
5901      it('command menu rendered above cursor (pum_above)', function()
5902        command('set wildmenu wildmode=longest:full wildoptions=pum')
5903        feed(':sign u<tab>')
5904        if multigrid then
5905          screen:expect {
5906            grid = [[
5907          ## grid 1
5908            [2:----------------------------------------]|*6
5909            [3:----------------------------------------]|
5910          ## grid 2
5911                                                    |
5912            {0:~                                       }|*5
5913          ## grid 3
5914            :sign un^                                |
5915          ## grid 4
5916            {7:            }|
5917            {12:~           }|*3
5918          ## grid 5
5919            {1: undefine       }|
5920            {1: unplace        }|
5921          ]],
5922            float_pos = {
5923              [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 },
5924              [5] = { -1, 'SW', 1, 6, 5, false, 250, 3, 4, 5 },
5925            },
5926          }
5927        else
5928          screen:expect {
5929            grid = [[
5930                                                    |
5931            {0:~                                       }|
5932            {0:~    }{7:            }{0:                       }|
5933            {0:~    }{12:~           }{0:                       }|
5934            {0:~    }{1: undefine       }{0:                   }|
5935            {0:~    }{1: unplace        }{0:                   }|
5936            :sign un^                                |
5937          ]],
5938          }
5939        end
5940      end)
5941
5942      it('with ext_popupmenu', function()
5943        screen:set_option('ext_popupmenu', true)
5944        feed('ix ')
5945        fn.complete(3, { 'aa', 'word', 'longtext' })
5946        local items = { { 'aa', '', '', '' }, { 'word', '', '', '' }, { 'longtext', '', '', '' } }
5947        if multigrid then
5948          screen:expect {
5949            grid = [[
5950          ## grid 1
5951            [2:----------------------------------------]|*6
5952            [3:----------------------------------------]|
5953          ## grid 2
5954                                                    |
5955            {0:~                                       }|*5
5956          ## grid 3
5957            {3:-- INSERT --}                            |
5958          ## grid 4
5959            {7:x aa^        }|
5960            {12:~           }|*3
5961          ]],
5962            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
5963            popupmenu = { anchor = { 4, 0, 2 }, items = items, pos = 0 },
5964          }
5965        else
5966          screen:expect {
5967            grid = [[
5968                                                    |
5969            {0:~                                       }|
5970            {0:~    }{7:x aa^        }{0:                       }|
5971            {0:~    }{12:~           }{0:                       }|*3
5972            {3:-- INSERT --}                            |
5973          ]],
5974            popupmenu = { anchor = { 1, 2, 7 }, items = items, pos = 0 },
5975          }
5976        end
5977
5978        feed('<esc>')
5979        if multigrid then
5980          screen:expect {
5981            grid = [[
5982          ## grid 1
5983            [2:----------------------------------------]|*6
5984            [3:----------------------------------------]|
5985          ## grid 2
5986                                                    |
5987            {0:~                                       }|*5
5988          ## grid 3
5989                                                    |
5990          ## grid 4
5991            {7:x a^a        }|
5992            {12:~           }|*3
5993          ]],
5994            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
5995          }
5996        else
5997          screen:expect([[
5998                                                    |
5999            {0:~                                       }|
6000            {0:~    }{7:x a^a        }{0:                       }|
6001            {0:~    }{12:~           }{0:                       }|*3
6002                                                    |
6003          ]])
6004        end
6005
6006        feed('<c-w>wi')
6007        fn.complete(1, { 'xx', 'yy', 'zz' })
6008        items = { { 'xx', '', '', '' }, { 'yy', '', '', '' }, { 'zz', '', '', '' } }
6009        if multigrid then
6010          screen:expect {
6011            grid = [[
6012          ## grid 1
6013            [2:----------------------------------------]|*6
6014            [3:----------------------------------------]|
6015          ## grid 2
6016            xx^                                      |
6017            {0:~                                       }|*5
6018          ## grid 3
6019            {3:-- INSERT --}                            |
6020          ## grid 4
6021            {7:x aa        }|
6022            {12:~           }|*3
6023          ]],
6024            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
6025            popupmenu = { anchor = { 2, 0, 0 }, items = items, pos = 0 },
6026          }
6027        else
6028          screen:expect {
6029            grid = [[
6030            xx^                                      |
6031            {0:~                                       }|
6032            {0:~    }{7:x aa        }{0:                       }|
6033            {0:~    }{12:~           }{0:                       }|*3
6034            {3:-- INSERT --}                            |
6035          ]],
6036            popupmenu = { anchor = { 1, 0, 0 }, items = items, pos = 0 },
6037          }
6038        end
6039
6040        feed('<c-y>')
6041        if multigrid then
6042          screen:expect {
6043            grid = [[
6044          ## grid 1
6045            [2:----------------------------------------]|*6
6046            [3:----------------------------------------]|
6047          ## grid 2
6048            xx^                                      |
6049            {0:~                                       }|*5
6050          ## grid 3
6051            {3:-- INSERT --}                            |
6052          ## grid 4
6053            {7:x aa        }|
6054            {12:~           }|*3
6055          ]],
6056            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
6057          }
6058        else
6059          screen:expect([[
6060            xx^                                      |
6061            {0:~                                       }|
6062            {0:~    }{7:x aa        }{0:                       }|
6063            {0:~    }{12:~           }{0:                       }|*3
6064            {3:-- INSERT --}                            |
6065          ]])
6066        end
6067      end)
6068    end)
6069
6070    describe('float shown after pum', function()
6071      local win
6072      before_each(function()
6073        command('hi NormalFloat guibg=#333333 guifg=NONE')
6074        feed('i')
6075        fn.complete(1, { 'aa', 'word', 'longtext' })
6076        if multigrid then
6077          screen:expect {
6078            grid = [[
6079          ## grid 1
6080            [2:----------------------------------------]|*6
6081            [3:----------------------------------------]|
6082          ## grid 2
6083            aa^                                      |
6084            {0:~                                       }|*5
6085          ## grid 3
6086            {3:-- INSERT --}                            |
6087          ## grid 4
6088            {13:aa             }|
6089            {1:word           }|
6090            {1:longtext       }|
6091          ]],
6092            float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
6093          }
6094        else
6095          screen:expect([[
6096            aa^                                      |
6097            {13:aa             }{0:                         }|
6098            {1:word           }{0:                         }|
6099            {1:longtext       }{0:                         }|
6100            {0:~                                       }|*2
6101            {3:-- INSERT --}                            |
6102          ]])
6103        end
6104
6105        local buf = api.nvim_create_buf(false, true)
6106        api.nvim_buf_set_lines(buf, 0, -1, true, { 'some info', 'about item' })
6107        win = api.nvim_open_win(buf, false, { relative = 'cursor', width = 12, height = 2, row = 1, col = 10 })
6108        if multigrid then
6109          screen:expect {
6110            grid = [[
6111          ## grid 1
6112            [2:----------------------------------------]|*6
6113            [3:----------------------------------------]|
6114          ## grid 2
6115            aa^                                      |
6116            {0:~                                       }|*5
6117          ## grid 3
6118            {3:-- INSERT --}                            |
6119          ## grid 4
6120            {13:aa             }|
6121            {1:word           }|
6122            {1:longtext       }|
6123          ## grid 5
6124            {15:some info   }|
6125            {15:about item  }|
6126          ]],
6127            float_pos = {
6128              [5] = { 1001, 'NW', 2, 1, 12, true, 50, 1, 1, 12 },
6129              [4] = { -1, 'NW', 2, 1, 0, false, 100, 2, 1, 0 },
6130            },
6131          }
6132        else
6133          screen:expect([[
6134            aa^                                      |
6135            {13:aa             }{15:e info   }{0:                }|
6136            {1:word           }{15:ut item  }{0:                }|
6137            {1:longtext       }{0:                         }|
6138            {0:~                                       }|*2
6139            {3:-- INSERT --}                            |
6140          ]])
6141        end
6142      end)
6143
6144      it('and close pum first', function()
6145        feed('<c-y>')
6146        if multigrid then
6147          screen:expect {
6148            grid = [[
6149          ## grid 1
6150            [2:----------------------------------------]|*6
6151            [3:----------------------------------------]|
6152          ## grid 2
6153            aa^                                      |
6154            {0:~                                       }|*5
6155          ## grid 3
6156            {3:-- INSERT --}                            |
6157          ## grid 5
6158            {15:some info   }|
6159            {15:about item  }|
6160          ]],
6161            float_pos = { [5] = { 1001, 'NW', 2, 1, 12, true, 50, 1, 1, 12 } },
6162          }
6163        else
6164          screen:expect([[
6165            aa^                                      |
6166            {0:~           }{15:some info   }{0:                }|
6167            {0:~           }{15:about item  }{0:                }|
6168            {0:~                                       }|*3
6169            {3:-- INSERT --}                            |
6170          ]])
6171        end
6172
6173        api.nvim_win_close(win, false)
6174        if multigrid then
6175          screen:expect([[
6176          ## grid 1
6177            [2:----------------------------------------]|*6
6178            [3:----------------------------------------]|
6179          ## grid 2
6180            aa^                                      |
6181            {0:~                                       }|*5
6182          ## grid 3
6183            {3:-- INSERT --}                            |
6184          ]])
6185        else
6186          screen:expect([[
6187            aa^                                      |
6188            {0:~                                       }|*5
6189            {3:-- INSERT --}                            |
6190          ]])
6191        end
6192      end)
6193
6194      it('and close float first', function()
6195        api.nvim_win_close(win, false)
6196        if multigrid then
6197          screen:expect {
6198            grid = [[
6199          ## grid 1
6200            [2:----------------------------------------]|*6
6201            [3:----------------------------------------]|
6202          ## grid 2
6203            aa^                                      |
6204            {0:~                                       }|*5
6205          ## grid 3
6206            {3:-- INSERT --}                            |
6207          ## grid 4
6208            {13:aa             }|
6209            {1:word           }|
6210            {1:longtext       }|
6211          ]],
6212            float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
6213          }
6214        else
6215          screen:expect([[
6216            aa^                                      |
6217            {13:aa             }{0:                         }|
6218            {1:word           }{0:                         }|
6219            {1:longtext       }{0:                         }|
6220            {0:~                                       }|*2
6221            {3:-- INSERT --}                            |
6222          ]])
6223        end
6224
6225        feed('<c-y>')
6226        if multigrid then
6227          screen:expect([[
6228          ## grid 1
6229            [2:----------------------------------------]|*6
6230            [3:----------------------------------------]|
6231          ## grid 2
6232            aa^                                      |
6233            {0:~                                       }|*5
6234          ## grid 3
6235            {3:-- INSERT --}                            |
6236          ]])
6237        else
6238          screen:expect([[
6239            aa^                                      |
6240            {0:~                                       }|*5
6241            {3:-- INSERT --}                            |
6242          ]])
6243        end
6244      end)
6245    end)
6246
6247    it('can use Normal as background', function()
6248      local buf = api.nvim_create_buf(false, false)
6249      api.nvim_buf_set_lines(buf, 0, -1, true, { 'here', 'float' })
6250      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
6251      api.nvim_set_option_value('winhl', 'Normal:Normal', { win = win })
6252
6253      if multigrid then
6254        screen:expect {
6255          grid = [[
6256        ## grid 1
6257          [2:----------------------------------------]|*6
6258          [3:----------------------------------------]|
6259        ## grid 2
6260          ^                                        |
6261          {0:~                                       }|*5
6262        ## grid 3
6263                                                  |
6264        ## grid 4
6265          here                |
6266          float               |
6267        ]],
6268          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
6269          win_viewport = {
6270            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
6271            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
6272          },
6273        }
6274      else
6275        screen:expect {
6276          grid = [[
6277          ^                                        |
6278          {0:~                                       }|
6279          {0:~    }here                {0:               }|
6280          {0:~    }float               {0:               }|
6281          {0:~                                       }|*2
6282                                                  |
6283        ]],
6284        }
6285      end
6286    end)
6287
6288    describe('handles :wincmd', function()
6289      local win
6290      local expected_pos
6291      before_each(function()
6292        -- the default, but be explicit:
6293        command('set laststatus=1')
6294        command('set hidden')
6295        api.nvim_buf_set_lines(0, 0, -1, true, { 'x' })
6296        local buf = api.nvim_create_buf(false, false)
6297        win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
6298        api.nvim_buf_set_lines(buf, 0, -1, true, { 'y' })
6299        expected_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } }
6300        if multigrid then
6301          screen:expect {
6302            grid = [[
6303          ## grid 1
6304            [2:----------------------------------------]|*6
6305            [3:----------------------------------------]|
6306          ## grid 2
6307            ^x                                       |
6308            {0:~                                       }|*5
6309          ## grid 3
6310                                                    |
6311          ## grid 4
6312            {1:y                   }|
6313            {2:~                   }|
6314          ]],
6315            float_pos = expected_pos,
6316          }
6317        else
6318          screen:expect([[
6319            ^x                                       |
6320            {0:~                                       }|
6321            {0:~    }{1:y                   }{0:               }|
6322            {0:~    }{2:~                   }{0:               }|
6323            {0:~                                       }|*2
6324                                                    |
6325          ]])
6326        end
6327      end)
6328
6329      it('w', function()
6330        feed('<c-w>w')
6331        if multigrid then
6332          screen:expect {
6333            grid = [[
6334          ## grid 1
6335            [2:----------------------------------------]|*6
6336            [3:----------------------------------------]|
6337          ## grid 2
6338            x                                       |
6339            {0:~                                       }|*5
6340          ## grid 3
6341                                                    |
6342          ## grid 4
6343            {1:^y                   }|
6344            {2:~                   }|
6345          ]],
6346            float_pos = expected_pos,
6347          }
6348        else
6349          screen:expect([[
6350            x                                       |
6351            {0:~                                       }|
6352            {0:~    }{1:^y                   }{0:               }|
6353            {0:~    }{2:~                   }{0:               }|
6354            {0:~                                       }|*2
6355                                                    |
6356          ]])
6357        end
6358
6359        feed('<c-w>w')
6360        if multigrid then
6361          screen:expect {
6362            grid = [[
6363          ## grid 1
6364            [2:----------------------------------------]|*6
6365            [3:----------------------------------------]|
6366          ## grid 2
6367            ^x                                       |
6368            {0:~                                       }|*5
6369          ## grid 3
6370                                                    |
6371          ## grid 4
6372            {1:y                   }|
6373            {2:~                   }|
6374          ]],
6375            float_pos = expected_pos,
6376          }
6377        else
6378          screen:expect([[
6379            ^x                                       |
6380            {0:~                                       }|
6381            {0:~    }{1:y                   }{0:               }|
6382            {0:~    }{2:~                   }{0:               }|
6383            {0:~                                       }|*2
6384                                                    |
6385          ]])
6386        end
6387      end)
6388
6389      it('w with focusable=false', function()
6390        api.nvim_win_set_config(win, { focusable = false })
6391        expected_pos[4][6] = false
6392        feed('<c-w>wi') -- i to provoke redraw
6393        if multigrid then
6394          screen:expect {
6395            grid = [[
6396          ## grid 1
6397            [2:----------------------------------------]|*6
6398            [3:----------------------------------------]|
6399          ## grid 2
6400            ^x                                       |
6401            {0:~                                       }|*5
6402          ## grid 3
6403            {3:-- INSERT --}                            |
6404          ## grid 4
6405            {1:y                   }|
6406            {2:~                   }|
6407          ]],
6408            float_pos = expected_pos,
6409          }
6410        else
6411          screen:expect([[
6412            ^x                                       |
6413            {0:~                                       }|
6414            {0:~    }{1:y                   }{0:               }|
6415            {0:~    }{2:~                   }{0:               }|
6416            {0:~                                       }|*2
6417            {3:-- INSERT --}                            |
6418          ]])
6419        end
6420
6421        feed('<esc><c-w>w')
6422        if multigrid then
6423          screen:expect {
6424            grid = [[
6425          ## grid 1
6426            [2:----------------------------------------]|*6
6427            [3:----------------------------------------]|
6428          ## grid 2
6429            ^x                                       |
6430            {0:~                                       }|*5
6431          ## grid 3
6432                                                    |
6433          ## grid 4
6434            {1:y                   }|
6435            {2:~                   }|
6436          ]],
6437            float_pos = expected_pos,
6438          }
6439        else
6440          screen:expect([[
6441            ^x                                       |
6442            {0:~                                       }|
6443            {0:~    }{1:y                   }{0:               }|
6444            {0:~    }{2:~                   }{0:               }|
6445            {0:~                                       }|*2
6446                                                    |
6447          ]])
6448        end
6449
6450        api.nvim_open_win(0, false, { relative = 'editor', width = 1, height = 1, row = 0, col = 0 })
6451        api.nvim_open_win(0, false, { relative = 'editor', width = 1, height = 1, row = 0, col = 0, focusable = false })
6452        api.nvim_open_win(0, false, { relative = 'editor', width = 1, height = 1, row = 0, col = 0, focusable = false })
6453        api.nvim_open_win(0, false, { relative = 'editor', width = 1, height = 1, row = 0, col = 0, focusable = true })
6454        api.nvim_open_win(0, false, { relative = 'editor', width = 1, height = 1, row = 0, col = 0, focusable = false })
6455        local nr_focusable = {}
6456        for _, winid in ipairs(api.nvim_tabpage_list_wins(0)) do
6457          table.insert(nr_focusable, api.nvim_win_get_config(winid).focusable)
6458        end
6459        eq({ true, false, true, false, false, true, false }, nr_focusable)
6460
6461        command('1wincmd w')
6462        eq({ 1, 1000 }, { fn.winnr(), fn.win_getid() })
6463        command('2wincmd w')
6464        eq({ 2, 1005 }, { fn.winnr(), fn.win_getid() })
6465        command('3wincmd w')
6466        eq({ 2, 1005 }, { fn.winnr(), fn.win_getid() })
6467        command('4wincmd w')
6468        eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
6469        command('5wincmd w')
6470        eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
6471        command('6wincmd w')
6472        eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
6473        command('7wincmd w')
6474        eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
6475
6476        feed('1<c-w>w')
6477        eq({ 1, 1000 }, { fn.winnr(), fn.win_getid() })
6478        feed('2<c-w>w')
6479        eq({ 2, 1005 }, { fn.winnr(), fn.win_getid() })
6480        feed('999<c-w>w')
6481        eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
6482      end)
6483
6484      it('W', function()
6485        feed('<c-w>W')
6486        if multigrid then
6487          screen:expect {
6488            grid = [[
6489          ## grid 1
6490            [2:----------------------------------------]|*6
6491            [3:----------------------------------------]|
6492          ## grid 2
6493            x                                       |
6494            {0:~                                       }|*5
6495          ## grid 3
6496                                                    |
6497          ## grid 4
6498            {1:^y                   }|
6499            {2:~                   }|
6500          ]],
6501            float_pos = expected_pos,
6502          }
6503        else
6504          screen:expect([[
6505            x                                       |
6506            {0:~                                       }|
6507            {0:~    }{1:^y                   }{0:               }|
6508            {0:~    }{2:~                   }{0:               }|
6509            {0:~                                       }|*2
6510                                                    |
6511          ]])
6512        end
6513
6514        feed('<c-w>W')
6515        if multigrid then
6516          screen:expect {
6517            grid = [[
6518          ## grid 1
6519            [2:----------------------------------------]|*6
6520            [3:----------------------------------------]|
6521          ## grid 2
6522            ^x                                       |
6523            {0:~                                       }|*5
6524          ## grid 3
6525                                                    |
6526          ## grid 4
6527            {1:y                   }|
6528            {2:~                   }|
6529          ]],
6530            float_pos = expected_pos,
6531          }
6532        else
6533          screen:expect([[
6534            ^x                                       |
6535            {0:~                                       }|
6536            {0:~    }{1:y                   }{0:               }|
6537            {0:~    }{2:~                   }{0:               }|
6538            {0:~                                       }|*2
6539                                                    |
6540          ]])
6541        end
6542      end)
6543
6544      local function test_float_mouse_focus()
6545        if send_mouse_grid then
6546          api.nvim_input_mouse('left', 'press', '', 4, 0, 0)
6547        else
6548          api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
6549        end
6550        if multigrid then
6551          screen:expect {
6552            grid = [[
6553          ## grid 1
6554            [2:----------------------------------------]|*6
6555            [3:----------------------------------------]|
6556          ## grid 2
6557            x                                       |
6558            {0:~                                       }|*5
6559          ## grid 3
6560                                                    |
6561          ## grid 4
6562            {1:^y                   }|
6563            {2:~                   }|
6564          ]],
6565            float_pos = expected_pos,
6566          }
6567        else
6568          screen:expect([[
6569            x                                       |
6570            {0:~                                       }|
6571            {0:~    }{1:^y                   }{0:               }|
6572            {0:~    }{2:~                   }{0:               }|
6573            {0:~                                       }|*2
6574                                                    |
6575          ]])
6576        end
6577
6578        if send_mouse_grid then
6579          api.nvim_input_mouse('left', 'press', '', 2, 0, 0)
6580        else
6581          api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
6582        end
6583        if multigrid then
6584          screen:expect {
6585            grid = [[
6586          ## grid 1
6587            [2:----------------------------------------]|*6
6588            [3:----------------------------------------]|
6589          ## grid 2
6590            ^x                                       |
6591            {0:~                                       }|*5
6592          ## grid 3
6593                                                    |
6594          ## grid 4
6595            {1:y                   }|
6596            {2:~                   }|
6597          ]],
6598            float_pos = expected_pos,
6599          }
6600        else
6601          screen:expect([[
6602            ^x                                       |
6603            {0:~                                       }|
6604            {0:~    }{1:y                   }{0:               }|
6605            {0:~    }{2:~                   }{0:               }|
6606            {0:~                                       }|*2
6607                                                    |
6608          ]])
6609        end
6610      end
6611
6612      it('focus by mouse (focusable=true)', function()
6613        test_float_mouse_focus()
6614      end)
6615
6616      it('focus by mouse (focusable=false, mouse=true)', function()
6617        api.nvim_win_set_config(win, { focusable = false, mouse = true })
6618        test_float_mouse_focus()
6619      end)
6620
6621      local function test_float_mouse_no_focus()
6622        api.nvim_buf_set_lines(0, -1, -1, true, { 'a' })
6623        expected_pos[4][6] = false
6624        if send_mouse_grid then
6625          api.nvim_input_mouse('left', 'press', '', 4, 0, 0)
6626        else
6627          api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
6628        end
6629        if multigrid then
6630          if send_mouse_grid then
6631            -- Sending input to grid 4 is a user error, you are not supposed to pass a grid
6632            -- that isn't focusable. In this case, nothing happens and the input is not passed
6633            -- through to grid 4, like normally happens when you pass grid 0.
6634            screen:expect {
6635              grid = [[
6636            ## grid 1
6637              [2:----------------------------------------]|*6
6638              [3:----------------------------------------]|
6639            ## grid 2
6640              ^x                                       |
6641              a                                       |
6642              {0:~                                       }|*4
6643            ## grid 3
6644                                                      |
6645            ## grid 4
6646              {1:y                   }|
6647              {2:~                   }|
6648            ]],
6649              float_pos = expected_pos,
6650            }
6651          else
6652            screen:expect {
6653              grid = [[
6654            ## grid 1
6655              [2:----------------------------------------]|*6
6656              [3:----------------------------------------]|
6657            ## grid 2
6658              x                                       |
6659              ^a                                       |
6660              {0:~                                       }|*4
6661            ## grid 3
6662                                                      |
6663            ## grid 4
6664              {1:y                   }|
6665              {2:~                   }|
6666            ]],
6667              float_pos = expected_pos,
6668            }
6669          end
6670        else
6671          screen:expect([[
6672            x                                       |
6673            ^a                                       |
6674            {0:~    }{1:y                   }{0:               }|
6675            {0:~    }{2:~                   }{0:               }|
6676            {0:~                                       }|*2
6677                                                    |
6678          ]])
6679        end
6680
6681        if send_mouse_grid then
6682          api.nvim_input_mouse('left', 'press', '', 2, 0, 0)
6683        else
6684          api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
6685        end
6686        if multigrid then
6687          screen:expect {
6688            grid = [[
6689          ## grid 1
6690            [2:----------------------------------------]|*6
6691            [3:----------------------------------------]|
6692          ## grid 2
6693            ^x                                       |
6694            a                                       |
6695            {0:~                                       }|*4
6696          ## grid 3
6697                                                    |
6698          ## grid 4
6699            {1:y                   }|
6700            {2:~                   }|
6701          ]],
6702            float_pos = expected_pos,
6703            unchanged = true,
6704          }
6705        else
6706          screen:expect([[
6707            ^x                                       |
6708            a                                       |
6709            {0:~    }{1:y                   }{0:               }|
6710            {0:~    }{2:~                   }{0:               }|
6711            {0:~                                       }|*2
6712                                                    |
6713          ]])
6714        end
6715      end
6716
6717      it('focus by mouse (focusable=false)', function()
6718        api.nvim_win_set_config(win, { focusable = false })
6719        test_float_mouse_no_focus()
6720      end)
6721
6722      it('focus by mouse (focusable=true, mouse=false)', function()
6723        api.nvim_win_set_config(win, { mouse = false })
6724        test_float_mouse_no_focus()
6725      end)
6726
6727      it(':help (focusable=false, hide=true)', function()
6728        n.add_builddir_to_rtp()
6729        local w = curwin()
6730        for _, helpcmd in ipairs({
6731          'help',
6732          'helpgrep api-types',
6733          'lhelpgrep api-types',
6734        }) do
6735          command(helpcmd)
6736          local badwins = {
6737            api.nvim_open_win(0, false, { focusable = false, relative = 'editor', width = 1, height = 1, row = 0, col = 0 }),
6738            api.nvim_open_win(0, false, { hide = true, relative = 'editor', width = 1, height = 1, row = 0, col = 0 }),
6739          }
6740          command('helpclose')
6741          command(helpcmd)
6742          eq(false, tbl_contains(badwins, curwin()))
6743          command('helpclose')
6744          eq(w, curwin())
6745        end
6746      end)
6747
6748      it('j', function()
6749        feed('<c-w>ji') -- INSERT to trigger screen change
6750        if multigrid then
6751          screen:expect {
6752            grid = [[
6753          ## grid 1
6754            [2:----------------------------------------]|*6
6755            [3:----------------------------------------]|
6756          ## grid 2
6757            ^x                                       |
6758            {0:~                                       }|*5
6759          ## grid 3
6760            {3:-- INSERT --}                            |
6761          ## grid 4
6762            {1:y                   }|
6763            {2:~                   }|
6764          ]],
6765            float_pos = expected_pos,
6766          }
6767        else
6768          screen:expect([[
6769            ^x                                       |
6770            {0:~                                       }|
6771            {0:~    }{1:y                   }{0:               }|
6772            {0:~    }{2:~                   }{0:               }|
6773            {0:~                                       }|*2
6774            {3:-- INSERT --}                            |
6775          ]])
6776        end
6777
6778        feed('<esc><c-w>w')
6779        if multigrid then
6780          screen:expect {
6781            grid = [[
6782          ## grid 1
6783            [2:----------------------------------------]|*6
6784            [3:----------------------------------------]|
6785          ## grid 2
6786            x                                       |
6787            {0:~                                       }|*5
6788          ## grid 3
6789                                                    |
6790          ## grid 4
6791            {1:^y                   }|
6792            {2:~                   }|
6793          ]],
6794            float_pos = expected_pos,
6795          }
6796        else
6797          screen:expect([[
6798            x                                       |
6799            {0:~                                       }|
6800            {0:~    }{1:^y                   }{0:               }|
6801            {0:~    }{2:~                   }{0:               }|
6802            {0:~                                       }|*2
6803                                                    |
6804          ]])
6805        end
6806
6807        feed('<c-w>j')
6808        if multigrid then
6809          screen:expect {
6810            grid = [[
6811          ## grid 1
6812            [2:----------------------------------------]|*6
6813            [3:----------------------------------------]|
6814          ## grid 2
6815            ^x                                       |
6816            {0:~                                       }|*5
6817          ## grid 3
6818                                                    |
6819          ## grid 4
6820            {1:y                   }|
6821            {2:~                   }|
6822          ]],
6823            float_pos = expected_pos,
6824          }
6825        else
6826          screen:expect([[
6827            ^x                                       |
6828            {0:~                                       }|
6829            {0:~    }{1:y                   }{0:               }|
6830            {0:~    }{2:~                   }{0:               }|
6831            {0:~                                       }|*2
6832                                                    |
6833          ]])
6834        end
6835      end)
6836
6837      it('vertical resize + - _', function()
6838        feed('<c-w>w')
6839        if multigrid then
6840          screen:expect {
6841            grid = [[
6842          ## grid 1
6843            [2:----------------------------------------]|*6
6844            [3:----------------------------------------]|
6845          ## grid 2
6846            x                                       |
6847            {0:~                                       }|*5
6848          ## grid 3
6849                                                    |
6850          ## grid 4
6851            {1:^y                   }|
6852            {2:~                   }|
6853          ]],
6854            float_pos = expected_pos,
6855          }
6856        else
6857          screen:expect([[
6858            x                                       |
6859            {0:~                                       }|
6860            {0:~    }{1:^y                   }{0:               }|
6861            {0:~    }{2:~                   }{0:               }|
6862            {0:~                                       }|*2
6863                                                    |
6864          ]])
6865        end
6866
6867        feed('<c-w>+')
6868        if multigrid then
6869          screen:expect {
6870            grid = [[
6871          ## grid 1
6872            [2:----------------------------------------]|*6
6873            [3:----------------------------------------]|
6874          ## grid 2
6875            x                                       |
6876            {0:~                                       }|*5
6877          ## grid 3
6878                                                    |
6879          ## grid 4
6880            {1:^y                   }|
6881            {2:~                   }|*2
6882          ]],
6883            float_pos = expected_pos,
6884          }
6885        else
6886          screen:expect([[
6887            x                                       |
6888            {0:~                                       }|
6889            {0:~    }{1:^y                   }{0:               }|
6890            {0:~    }{2:~                   }{0:               }|*2
6891            {0:~                                       }|
6892                                                    |
6893          ]])
6894        end
6895
6896        feed('<c-w>2-')
6897        if multigrid then
6898          screen:expect {
6899            grid = [[
6900          ## grid 1
6901            [2:----------------------------------------]|*6
6902            [3:----------------------------------------]|
6903          ## grid 2
6904            x                                       |
6905            {0:~                                       }|*5
6906          ## grid 3
6907                                                    |
6908          ## grid 4
6909            {1:^y                   }|
6910          ]],
6911            float_pos = expected_pos,
6912          }
6913        else
6914          screen:expect([[
6915            x                                       |
6916            {0:~                                       }|
6917            {0:~    }{1:^y                   }{0:               }|
6918            {0:~                                       }|*3
6919                                                    |
6920          ]])
6921        end
6922
6923        feed('<c-w>4_')
6924        if multigrid then
6925          screen:expect {
6926            grid = [[
6927          ## grid 1
6928            [2:----------------------------------------]|*6
6929            [3:----------------------------------------]|
6930          ## grid 2
6931            x                                       |
6932            {0:~                                       }|*5
6933          ## grid 3
6934                                                    |
6935          ## grid 4
6936            {1:^y                   }|
6937            {2:~                   }|*3
6938          ]],
6939            float_pos = expected_pos,
6940          }
6941        else
6942          screen:expect([[
6943            x                                       |
6944            {0:~                                       }|
6945            {0:~    }{1:^y                   }{0:               }|
6946            {0:~    }{2:~                   }{0:               }|*3
6947                                                    |
6948          ]])
6949        end
6950
6951        feed('<c-w>_')
6952        if multigrid then
6953          screen:expect {
6954            grid = [[
6955          ## grid 1
6956            [2:----------------------------------------]|*6
6957            [3:----------------------------------------]|
6958          ## grid 2
6959            x                                       |
6960            {0:~                                       }|*5
6961          ## grid 3
6962                                                    |
6963          ## grid 4
6964            {1:^y                   }|
6965            {2:~                   }|*5
6966          ]],
6967            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 0, 5 } },
6968          }
6969        else
6970          screen:expect([[
6971            x    {1:^y                   }               |
6972            {0:~    }{2:~                   }{0:               }|*5
6973                                                    |
6974          ]])
6975        end
6976      end)
6977
6978      it('horizontal resize > < |', function()
6979        feed('<c-w>w')
6980        if multigrid then
6981          screen:expect {
6982            grid = [[
6983          ## grid 1
6984            [2:----------------------------------------]|*6
6985            [3:----------------------------------------]|
6986          ## grid 2
6987            x                                       |
6988            {0:~                                       }|*5
6989          ## grid 3
6990                                                    |
6991          ## grid 4
6992            {1:^y                   }|
6993            {2:~                   }|
6994          ]],
6995            float_pos = expected_pos,
6996          }
6997        else
6998          screen:expect([[
6999            x                                       |
7000            {0:~                                       }|
7001            {0:~    }{1:^y                   }{0:               }|
7002            {0:~    }{2:~                   }{0:               }|
7003            {0:~                                       }|*2
7004                                                    |
7005          ]])
7006        end
7007
7008        feed('<c-w>>')
7009        if multigrid then
7010          screen:expect {
7011            grid = [[
7012          ## grid 1
7013            [2:----------------------------------------]|*6
7014            [3:----------------------------------------]|
7015          ## grid 2
7016            x                                       |
7017            {0:~                                       }|*5
7018          ## grid 3
7019                                                    |
7020          ## grid 4
7021            {1:^y                    }|
7022            {2:~                    }|
7023          ]],
7024            float_pos = expected_pos,
7025          }
7026        else
7027          screen:expect([[
7028            x                                       |
7029            {0:~                                       }|
7030            {0:~    }{1:^y                    }{0:              }|
7031            {0:~    }{2:~                    }{0:              }|
7032            {0:~                                       }|*2
7033                                                    |
7034          ]])
7035        end
7036
7037        feed('<c-w>10<lt>')
7038        if multigrid then
7039          screen:expect {
7040            grid = [[
7041          ## grid 1
7042            [2:----------------------------------------]|*6
7043            [3:----------------------------------------]|
7044          ## grid 2
7045            x                                       |
7046            {0:~                                       }|*5
7047          ## grid 3
7048                                                    |
7049          ## grid 4
7050            {1:^y          }|
7051            {2:~          }|
7052          ]],
7053            float_pos = expected_pos,
7054          }
7055        else
7056          screen:expect([[
7057            x                                       |
7058            {0:~                                       }|
7059            {0:~    }{1:^y          }{0:                        }|
7060            {0:~    }{2:~          }{0:                        }|
7061            {0:~                                       }|*2
7062                                                    |
7063          ]])
7064        end
7065
7066        feed('<c-w>15|')
7067        if multigrid then
7068          screen:expect {
7069            grid = [[
7070          ## grid 1
7071            [2:----------------------------------------]|*6
7072            [3:----------------------------------------]|
7073          ## grid 2
7074            x                                       |
7075            {0:~                                       }|*5
7076          ## grid 3
7077                                                    |
7078          ## grid 4
7079            {1:^y              }|
7080            {2:~              }|
7081          ]],
7082            float_pos = expected_pos,
7083          }
7084        else
7085          screen:expect([[
7086            x                                       |
7087            {0:~                                       }|
7088            {0:~    }{1:^y              }{0:                    }|
7089            {0:~    }{2:~              }{0:                    }|
7090            {0:~                                       }|*2
7091                                                    |
7092          ]])
7093        end
7094
7095        feed('<c-w>|')
7096        if multigrid then
7097          screen:expect {
7098            grid = [[
7099          ## grid 1
7100            [2:----------------------------------------]|*6
7101            [3:----------------------------------------]|
7102          ## grid 2
7103            x                                       |
7104            {0:~                                       }|*5
7105          ## grid 3
7106                                                    |
7107          ## grid 4
7108            {1:^y                                       }|
7109            {2:~                                       }|
7110          ]],
7111            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 0 } },
7112          }
7113        else
7114          screen:expect([[
7115            x                                       |
7116            {0:~                                       }|
7117            {1:^y                                       }|
7118            {2:~                                       }|
7119            {0:~                                       }|*2
7120                                                    |
7121          ]])
7122        end
7123      end)
7124
7125      it('s :split (non-float)', function()
7126        feed('<c-w>s')
7127        if multigrid then
7128          screen:expect {
7129            grid = [[
7130          ## grid 1
7131            [5:----------------------------------------]|*2
7132            {4:[No Name] [+]                           }|
7133            [2:----------------------------------------]|*2
7134            {5:[No Name] [+]                           }|
7135            [3:----------------------------------------]|
7136          ## grid 2
7137            x                                       |
7138            {0:~                                       }|
7139          ## grid 3
7140                                                    |
7141          ## grid 4
7142            {1:y                   }|
7143            {2:~                   }|
7144          ## grid 5
7145            ^x                                       |
7146            {0:~                                       }|
7147          ]],
7148            float_pos = expected_pos,
7149          }
7150        else
7151          screen:expect([[
7152            ^x                                       |
7153            {0:~                                       }|
7154            {4:[No N}{1:y                   }{4:               }|
7155            x    {2:~                   }               |
7156            {0:~                                       }|
7157            {5:[No Name] [+]                           }|
7158                                                    |
7159          ]])
7160        end
7161
7162        feed('<c-w>w')
7163        if multigrid then
7164          screen:expect {
7165            grid = [[
7166          ## grid 1
7167            [5:----------------------------------------]|*2
7168            {5:[No Name] [+]                           }|
7169            [2:----------------------------------------]|*2
7170            {4:[No Name] [+]                           }|
7171            [3:----------------------------------------]|
7172          ## grid 2
7173            ^x                                       |
7174            {0:~                                       }|
7175          ## grid 3
7176                                                    |
7177          ## grid 4
7178            {1:y                   }|
7179            {2:~                   }|
7180          ## grid 5
7181            x                                       |
7182            {0:~                                       }|
7183          ]],
7184            float_pos = expected_pos,
7185          }
7186        else
7187          screen:expect([[
7188            x                                       |
7189            {0:~                                       }|
7190            {5:[No N}{1:y                   }{5:               }|
7191            ^x    {2:~                   }               |
7192            {0:~                                       }|
7193            {4:[No Name] [+]                           }|
7194                                                    |
7195          ]])
7196        end
7197
7198        feed('<c-w>w')
7199        if multigrid then
7200          screen:expect {
7201            grid = [[
7202          ## grid 1
7203            [5:----------------------------------------]|*2
7204            {5:[No Name] [+]                           }|
7205            [2:----------------------------------------]|*2
7206            {5:[No Name] [+]                           }|
7207            [3:----------------------------------------]|
7208          ## grid 2
7209            x                                       |
7210            {0:~                                       }|
7211          ## grid 3
7212                                                    |
7213          ## grid 4
7214            {1:^y                   }|
7215            {2:~                   }|
7216          ## grid 5
7217            x                                       |
7218            {0:~                                       }|
7219          ]],
7220            float_pos = expected_pos,
7221          }
7222        else
7223          screen:expect([[
7224            x                                       |
7225            {0:~                                       }|
7226            {5:[No N}{1:^y                   }{5:               }|
7227            x    {2:~                   }               |
7228            {0:~                                       }|
7229            {5:[No Name] [+]                           }|
7230                                                    |
7231          ]])
7232        end
7233
7234        feed('<c-w>w')
7235        if multigrid then
7236          screen:expect {
7237            grid = [[
7238          ## grid 1
7239            [5:----------------------------------------]|*2
7240            {4:[No Name] [+]                           }|
7241            [2:----------------------------------------]|*2
7242            {5:[No Name] [+]                           }|
7243            [3:----------------------------------------]|
7244          ## grid 2
7245            x                                       |
7246            {0:~                                       }|
7247          ## grid 3
7248                                                    |
7249          ## grid 4
7250            {1:y                   }|
7251            {2:~                   }|
7252          ## grid 5
7253            ^x                                       |
7254            {0:~                                       }|
7255          ]],
7256            float_pos = expected_pos,
7257          }
7258        else
7259          screen:expect([[
7260            ^x                                       |
7261            {0:~                                       }|
7262            {4:[No N}{1:y                   }{4:               }|
7263            x    {2:~                   }               |
7264            {0:~                                       }|
7265            {5:[No Name] [+]                           }|
7266                                                    |
7267          ]])
7268        end
7269      end)
7270
7271      it('s :split (float)', function()
7272        feed('<c-w>w<c-w>s')
7273        if multigrid then
7274          screen:expect {
7275            grid = [[
7276          ## grid 1
7277            [5:----------------------------------------]|*2
7278            {4:[No Name] [+]                           }|
7279            [2:----------------------------------------]|*2
7280            {5:[No Name] [+]                           }|
7281            [3:----------------------------------------]|
7282          ## grid 2
7283            x                                       |
7284            {0:~                                       }|
7285          ## grid 3
7286                                                    |
7287          ## grid 4
7288            {1:y                   }|
7289            {2:~                   }|
7290          ## grid 5
7291            ^y                                       |
7292            {0:~                                       }|
7293          ]],
7294            float_pos = expected_pos,
7295          }
7296        else
7297          screen:expect([[
7298            ^y                                       |
7299            {0:~                                       }|
7300            {4:[No N}{1:y                   }{4:               }|
7301            x    {2:~                   }               |
7302            {0:~                                       }|
7303            {5:[No Name] [+]                           }|
7304                                                    |
7305          ]])
7306        end
7307
7308        feed('<c-w>j')
7309        if multigrid then
7310          screen:expect {
7311            grid = [[
7312          ## grid 1
7313            [5:----------------------------------------]|*2
7314            {5:[No Name] [+]                           }|
7315            [2:----------------------------------------]|*2
7316            {4:[No Name] [+]                           }|
7317            [3:----------------------------------------]|
7318          ## grid 2
7319            ^x                                       |
7320            {0:~                                       }|
7321          ## grid 3
7322                                                    |
7323          ## grid 4
7324            {1:y                   }|
7325            {2:~                   }|
7326          ## grid 5
7327            y                                       |
7328            {0:~                                       }|
7329          ]],
7330            float_pos = expected_pos,
7331          }
7332        else
7333          screen:expect([[
7334            y                                       |
7335            {0:~                                       }|
7336            {5:[No N}{1:y                   }{5:               }|
7337            ^x    {2:~                   }               |
7338            {0:~                                       }|
7339            {4:[No Name] [+]                           }|
7340                                                    |
7341          ]])
7342        end
7343
7344        feed('<c-w>ji')
7345        if multigrid then
7346          screen:expect {
7347            grid = [[
7348          ## grid 1
7349            [5:----------------------------------------]|*2
7350            {5:[No Name] [+]                           }|
7351            [2:----------------------------------------]|*2
7352            {4:[No Name] [+]                           }|
7353            [3:----------------------------------------]|
7354          ## grid 2
7355            ^x                                       |
7356            {0:~                                       }|
7357          ## grid 3
7358            {3:-- INSERT --}                            |
7359          ## grid 4
7360            {1:y                   }|
7361            {2:~                   }|
7362          ## grid 5
7363            y                                       |
7364            {0:~                                       }|
7365          ]],
7366            float_pos = expected_pos,
7367          }
7368        else
7369          screen:expect([[
7370            y                                       |
7371            {0:~                                       }|
7372            {5:[No N}{1:y                   }{5:               }|
7373            ^x    {2:~                   }               |
7374            {0:~                                       }|
7375            {4:[No Name] [+]                           }|
7376            {3:-- INSERT --}                            |
7377          ]])
7378        end
7379      end)
7380
7381      it(':new (non-float)', function()
7382        feed(':new<cr>')
7383        if multigrid then
7384          screen:expect {
7385            grid = [[
7386          ## grid 1
7387            [5:----------------------------------------]|*2
7388            {4:[No Name]                               }|
7389            [2:----------------------------------------]|*2
7390            {5:[No Name] [+]                           }|
7391            [3:----------------------------------------]|
7392          ## grid 2
7393            x                                       |
7394            {0:~                                       }|
7395          ## grid 3
7396            :new                                    |
7397          ## grid 4
7398            {1:y                   }|
7399            {2:~                   }|
7400          ## grid 5
7401            ^                                        |
7402            {0:~                                       }|
7403          ]],
7404            float_pos = expected_pos,
7405          }
7406        else
7407          screen:expect([[
7408            ^                                        |
7409            {0:~                                       }|
7410            {4:[No N}{1:y                   }{4:               }|
7411            x    {2:~                   }               |
7412            {0:~                                       }|
7413            {5:[No Name] [+]                           }|
7414            :new                                    |
7415          ]])
7416        end
7417      end)
7418
7419      it(':new (float)', function()
7420        feed('<c-w>w:new<cr>')
7421        if multigrid then
7422          screen:expect {
7423            grid = [[
7424          ## grid 1
7425            [5:----------------------------------------]|*2
7426            {4:[No Name]                               }|
7427            [2:----------------------------------------]|*2
7428            {5:[No Name] [+]                           }|
7429            [3:----------------------------------------]|
7430          ## grid 2
7431            x                                       |
7432            {0:~                                       }|
7433          ## grid 3
7434            :new                                    |
7435          ## grid 4
7436            {1:y                   }|
7437            {2:~                   }|
7438          ## grid 5
7439            ^                                        |
7440            {0:~                                       }|
7441          ]],
7442            float_pos = expected_pos,
7443          }
7444        else
7445          screen:expect([[
7446            ^                                        |
7447            {0:~                                       }|
7448            {4:[No N}{1:y                   }{4:               }|
7449            x    {2:~                   }               |
7450            {0:~                                       }|
7451            {5:[No Name] [+]                           }|
7452            :new                                    |
7453          ]])
7454        end
7455      end)
7456
7457      it('v :vsplit (non-float)', function()
7458        feed('<c-w>v')
7459        if multigrid then
7460          screen:expect {
7461            grid = [[
7462          ## grid 1
7463            [5:--------------------]{5:│}[2:-------------------]|*5
7464            {4:[No Name] [+]        }{5:[No Name] [+]      }|
7465            [3:----------------------------------------]|
7466          ## grid 2
7467            x                  |
7468            {0:~                  }|*4
7469          ## grid 3
7470                                                    |
7471          ## grid 4
7472            {1:y                   }|
7473            {2:~                   }|
7474          ## grid 5
7475            ^x                   |
7476            {0:~                   }|*4
7477          ]],
7478            float_pos = expected_pos,
7479          }
7480        else
7481          screen:expect([[
7482            ^x                   {5:│}x                  |
7483            {0:~                   }{5:│}{0:~                  }|
7484            {0:~    }{1:y                   }{0:               }|
7485            {0:~    }{2:~                   }{0:               }|
7486            {0:~                   }{5:│}{0:~                  }|
7487            {4:[No Name] [+]        }{5:[No Name] [+]      }|
7488                                                    |
7489          ]])
7490        end
7491      end)
7492
7493      it(':vnew (non-float)', function()
7494        feed(':vnew<cr>')
7495        if multigrid then
7496          screen:expect {
7497            grid = [[
7498          ## grid 1
7499            [5:--------------------]{5:│}[2:-------------------]|*5
7500            {4:[No Name]            }{5:[No Name] [+]      }|
7501            [3:----------------------------------------]|
7502          ## grid 2
7503            x                  |
7504            {0:~                  }|*4
7505          ## grid 3
7506            :vnew                                   |
7507          ## grid 4
7508            {1:y                   }|
7509            {2:~                   }|
7510          ## grid 5
7511            ^                    |
7512            {0:~                   }|*4
7513          ]],
7514            float_pos = expected_pos,
7515          }
7516        else
7517          screen:expect([[
7518            ^                    {5:│}x                  |
7519            {0:~                   }{5:│}{0:~                  }|
7520            {0:~    }{1:y                   }{0:               }|
7521            {0:~    }{2:~                   }{0:               }|
7522            {0:~                   }{5:│}{0:~                  }|
7523            {4:[No Name]            }{5:[No Name] [+]      }|
7524            :vnew                                   |
7525          ]])
7526        end
7527      end)
7528
7529      it(':vnew (float)', function()
7530        feed('<c-w>w:vnew<cr>')
7531        if multigrid then
7532          screen:expect {
7533            grid = [[
7534          ## grid 1
7535            [5:--------------------]{5:│}[2:-------------------]|*5
7536            {4:[No Name]            }{5:[No Name] [+]      }|
7537            [3:----------------------------------------]|
7538          ## grid 2
7539            x                  |
7540            {0:~                  }|*4
7541          ## grid 3
7542            :vnew                                   |
7543          ## grid 4
7544            {1:y                   }|
7545            {2:~                   }|
7546          ## grid 5
7547            ^                    |
7548            {0:~                   }|*4
7549          ]],
7550            float_pos = expected_pos,
7551          }
7552        else
7553          screen:expect([[
7554            ^                    {5:│}x                  |
7555            {0:~                   }{5:│}{0:~                  }|
7556            {0:~    }{1:y                   }{0:               }|
7557            {0:~    }{2:~                   }{0:               }|
7558            {0:~                   }{5:│}{0:~                  }|
7559            {4:[No Name]            }{5:[No Name] [+]      }|
7560            :vnew                                   |
7561          ]])
7562        end
7563      end)
7564
7565      it('q (:quit) last non-float exits nvim', function()
7566        command('autocmd VimLeave    * call rpcrequest(1, "exit")')
7567        -- avoid unsaved change in other buffer
7568        feed('<c-w><c-w>:w Xtest_written2<cr><c-w><c-w>')
7569        -- quit in last non-float
7570        feed(':wq Xtest_written<cr>')
7571        local exited = false
7572        local function on_request(name, args)
7573          eq('exit', name)
7574          eq({}, args)
7575          exited = true
7576          return 0
7577        end
7578        local function on_setup()
7579          feed(':wq Xtest_written<cr>')
7580        end
7581        run(on_request, nil, on_setup)
7582        os.remove('Xtest_written')
7583        os.remove('Xtest_written2')
7584        eq(true, exited)
7585      end)
7586
7587      it(':quit two floats in a row', function()
7588        -- enter first float
7589        feed('<c-w><c-w>')
7590        -- enter second float
7591        api.nvim_open_win(0, true, { relative = 'editor', width = 20, height = 2, row = 4, col = 8 })
7592        if multigrid then
7593          screen:expect {
7594            grid = [[
7595          ## grid 1
7596            [2:----------------------------------------]|*6
7597            [3:----------------------------------------]|
7598          ## grid 2
7599            x                                       |
7600            {0:~                                       }|*5
7601          ## grid 3
7602                                                    |
7603          ## grid 4
7604            {1:y                   }|
7605            {2:~                   }|
7606          ## grid 5
7607            {1:^y                   }|
7608            {2:~                   }|
7609          ]],
7610            float_pos = {
7611              [5] = { 1002, 'NW', 1, 4, 8, true, 50, 2, 4, 8 },
7612              [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 },
7613            },
7614          }
7615        else
7616          screen:expect([[
7617            x                                       |
7618            {0:~                                       }|
7619            {0:~    }{1:y                   }{0:               }|
7620            {0:~    }{2:~                   }{0:               }|
7621            {0:~       }{1:^y                   }{0:            }|
7622            {0:~       }{2:~                   }{0:            }|
7623                                                    |
7624          ]])
7625        end
7626
7627        feed(':quit<cr>')
7628        if multigrid then
7629          screen:expect {
7630            grid = [[
7631          ## grid 1
7632            [2:----------------------------------------]|*6
7633            [3:----------------------------------------]|
7634          ## grid 2
7635            x                                       |
7636            {0:~                                       }|*5
7637          ## grid 3
7638            :quit                                   |
7639          ## grid 4
7640            {1:^y                   }|
7641            {2:~                   }|
7642          ]],
7643            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
7644          }
7645        else
7646          screen:expect([[
7647            x                                       |
7648            {0:~                                       }|
7649            {0:~    }{1:^y                   }{0:               }|
7650            {0:~    }{2:~                   }{0:               }|
7651            {0:~                                       }|*2
7652            :quit                                   |
7653          ]])
7654        end
7655
7656        feed(':quit<cr>')
7657        if multigrid then
7658          screen:expect([[
7659          ## grid 1
7660            [2:----------------------------------------]|*6
7661            [3:----------------------------------------]|
7662          ## grid 2
7663            ^x                                       |
7664            {0:~                                       }|*5
7665          ## grid 3
7666            :quit                                   |
7667          ]])
7668        else
7669          screen:expect([[
7670            ^x                                       |
7671            {0:~                                       }|*5
7672            :quit                                   |
7673          ]])
7674        end
7675
7676        assert_alive()
7677      end)
7678
7679      it('o (:only) non-float', function()
7680        feed('<c-w>o')
7681        if multigrid then
7682          screen:expect {
7683            grid = [[
7684          ## grid 1
7685            [2:----------------------------------------]|*6
7686            [3:----------------------------------------]|
7687          ## grid 2
7688            ^x                                       |
7689            {0:~                                       }|*5
7690          ## grid 3
7691                                                    |
7692          ]],
7693          }
7694        else
7695          screen:expect([[
7696            ^x                                       |
7697            {0:~                                       }|*5
7698                                                    |
7699          ]])
7700        end
7701      end)
7702
7703      it('o (:only) float fails', function()
7704        feed('<c-w>w<c-w>o')
7705        if multigrid then
7706          screen:expect {
7707            grid = [[
7708          ## grid 1
7709            [2:----------------------------------------]|*4
7710            [3:----------------------------------------]|*3
7711          ## grid 2
7712            x                                       |
7713            {0:~                                       }|*5
7714          ## grid 3
7715            {7:E5601: Cannot close window, only floatin}|
7716            {7:g window would remain}                   |
7717            {8:Press ENTER or type command to continue}^ |
7718          ## grid 4
7719            {1:y                   }|
7720            {2:~                   }|
7721          ]],
7722            float_pos = expected_pos,
7723          }
7724        else
7725          screen:expect([[
7726            x                                       |
7727            {0:~                                       }|
7728            {0:~    }{1:y                   }{0:               }|
7729            {4:                                        }|
7730            {7:E5601: Cannot close window, only floatin}|
7731            {7:g window would remain}                   |
7732            {8:Press ENTER or type command to continue}^ |
7733          ]])
7734        end
7735
7736        -- test message clear
7737        feed('<cr>')
7738        if multigrid then
7739          screen:expect {
7740            grid = [[
7741          ## grid 1
7742            [2:----------------------------------------]|*6
7743            [3:----------------------------------------]|
7744          ## grid 2
7745            x                                       |
7746            {0:~                                       }|*5
7747          ## grid 3
7748                                                    |
7749          ## grid 4
7750            {1:^y                   }|
7751            {2:~                   }|
7752          ]],
7753            float_pos = expected_pos,
7754          }
7755        else
7756          screen:expect([[
7757            x                                       |
7758            {0:~                                       }|
7759            {0:~    }{1:^y                   }{0:               }|
7760            {0:~    }{2:~                   }{0:               }|
7761            {0:~                                       }|*2
7762                                                    |
7763          ]])
7764        end
7765      end)
7766
7767      it('o (:only) non-float with split', function()
7768        feed('<c-w>s')
7769        if multigrid then
7770          screen:expect {
7771            grid = [[
7772          ## grid 1
7773            [5:----------------------------------------]|*2
7774            {4:[No Name] [+]                           }|
7775            [2:----------------------------------------]|*2
7776            {5:[No Name] [+]                           }|
7777            [3:----------------------------------------]|
7778          ## grid 2
7779            x                                       |
7780            {0:~                                       }|
7781          ## grid 3
7782                                                    |
7783          ## grid 4
7784            {1:y                   }|
7785            {2:~                   }|
7786          ## grid 5
7787            ^x                                       |
7788            {0:~                                       }|
7789        ]],
7790            float_pos = expected_pos,
7791          }
7792        else
7793          screen:expect([[
7794            ^x                                       |
7795            {0:~                                       }|
7796            {4:[No N}{1:y                   }{4:               }|
7797            x    {2:~                   }               |
7798            {0:~                                       }|
7799            {5:[No Name] [+]                           }|
7800                                                    |
7801          ]])
7802        end
7803
7804        feed('<c-w>o')
7805        if multigrid then
7806          screen:expect {
7807            grid = [[
7808          ## grid 1
7809            [5:----------------------------------------]|*6
7810            [3:----------------------------------------]|
7811          ## grid 3
7812                                                    |
7813          ## grid 5
7814            ^x                                       |
7815            {0:~                                       }|*5
7816          ]],
7817          }
7818        else
7819          screen:expect([[
7820            ^x                                       |
7821            {0:~                                       }|*5
7822                                                    |
7823          ]])
7824        end
7825      end)
7826
7827      it('o (:only) float with split', function()
7828        feed('<c-w>s<c-w>W')
7829        if multigrid then
7830          screen:expect {
7831            grid = [[
7832          ## grid 1
7833            [5:----------------------------------------]|*2
7834            {5:[No Name] [+]                           }|
7835            [2:----------------------------------------]|*2
7836            {5:[No Name] [+]                           }|
7837            [3:----------------------------------------]|
7838          ## grid 2
7839            x                                       |
7840            {0:~                                       }|
7841          ## grid 3
7842                                                    |
7843          ## grid 4
7844            {1:^y                   }|
7845            {2:~                   }|
7846          ## grid 5
7847            x                                       |
7848            {0:~                                       }|
7849          ]],
7850            float_pos = expected_pos,
7851          }
7852        else
7853          screen:expect([[
7854            x                                       |
7855            {0:~                                       }|
7856            {5:[No N}{1:^y                   }{5:               }|
7857            x    {2:~                   }               |
7858            {0:~                                       }|
7859            {5:[No Name] [+]                           }|
7860                                                    |
7861          ]])
7862        end
7863
7864        feed('<c-w>o')
7865        if multigrid then
7866          screen:expect {
7867            grid = [[
7868          ## grid 1
7869            [5:----------------------------------------]|*2
7870            {5:[No Name] [+]                           }|
7871            [2:----------------------------------------]|
7872            [3:----------------------------------------]|*3
7873          ## grid 2
7874            x                                       |
7875            {0:~                                       }|
7876          ## grid 3
7877            {7:E5601: Cannot close window, only floatin}|
7878            {7:g window would remain}                   |
7879            {8:Press ENTER or type command to continue}^ |
7880          ## grid 4
7881            {1:y                   }|
7882            {2:~                   }|
7883          ## grid 5
7884            x                                       |
7885            {0:~                                       }|
7886          ]],
7887            float_pos = expected_pos,
7888          }
7889        else
7890          screen:expect([[
7891            x                                       |
7892            {0:~                                       }|
7893            {5:[No N}{1:y                   }{5:               }|
7894            {4:                                        }|
7895            {7:E5601: Cannot close window, only floatin}|
7896            {7:g window would remain}                   |
7897            {8:Press ENTER or type command to continue}^ |
7898          ]])
7899        end
7900      end)
7901
7902      it('J (float)', function()
7903        feed('<c-w>w<c-w>J')
7904        if multigrid then
7905          screen:expect {
7906            grid = [[
7907          ## grid 1
7908            [2:----------------------------------------]|*2
7909            {5:[No Name] [+]                           }|
7910            [4:----------------------------------------]|*2
7911            {4:[No Name] [+]                           }|
7912            [3:----------------------------------------]|
7913          ## grid 2
7914            x                                       |
7915            {0:~                                       }|
7916          ## grid 3
7917                                                    |
7918          ## grid 4
7919            ^y                                       |
7920            {0:~                                       }|
7921          ]],
7922          }
7923        else
7924          screen:expect([[
7925            x                                       |
7926            {0:~                                       }|
7927            {5:[No Name] [+]                           }|
7928            ^y                                       |
7929            {0:~                                       }|
7930            {4:[No Name] [+]                           }|
7931                                                    |
7932          ]])
7933        end
7934
7935        if multigrid then
7936          api.nvim_win_set_config(0, { external = true, width = 30, height = 2 })
7937          expected_pos = { [4] = { external = true } }
7938          screen:expect {
7939            grid = [[
7940          ## grid 1
7941            [2:----------------------------------------]|*6
7942            [3:----------------------------------------]|
7943          ## grid 2
7944            x                                       |
7945            {0:~                                       }|*5
7946          ## grid 3
7947                                                    |
7948          ## grid 4
7949            ^y                             |
7950            {0:~                             }|
7951          ]],
7952            float_pos = expected_pos,
7953          }
7954        else
7955          eq("UI doesn't support external windows", pcall_err(api.nvim_win_set_config, 0, { external = true, width = 30, height = 2 }))
7956          return
7957        end
7958
7959        feed('<c-w>J')
7960        if multigrid then
7961          screen:expect([[
7962          ## grid 1
7963            [2:----------------------------------------]|*2
7964            {5:[No Name] [+]                           }|
7965            [4:----------------------------------------]|*2
7966            {4:[No Name] [+]                           }|
7967            [3:----------------------------------------]|
7968          ## grid 2
7969            x                                       |
7970            {0:~                                       }|
7971          ## grid 3
7972                                                    |
7973          ## grid 4
7974            ^y                                       |
7975            {0:~                                       }|
7976          ]])
7977        end
7978      end)
7979
7980      it('J (float with border)', function()
7981        api.nvim_win_set_config(win, { relative = 'editor', width = 20, height = 2, row = 2, col = 5, border = 'single' })
7982        if multigrid then
7983          screen:expect {
7984            grid = [[
7985          ## grid 1
7986            [2:----------------------------------------]|*6
7987            [3:----------------------------------------]|
7988          ## grid 2
7989            ^x                                       |
7990            {0:~                                       }|*5
7991          ## grid 3
7992                                                    |
7993          ## grid 4
7994            {33:┌────────────────────┐}|
7995            {33:│}{1:y                   }{33:│}|
7996            {33:│}{2:~                   }{33:│}|
7997            {33:└────────────────────┘}|
7998          ]],
7999            float_pos = expected_pos,
8000          }
8001        else
8002          screen:expect([[
8003            ^x                                       |
8004            {0:~                                       }|
8005            {0:~    }{33:┌────────────────────┐}{0:             }|
8006            {0:~    }{33:│}{1:y                   }{33:│}{0:             }|
8007            {0:~    }{33:│}{2:~                   }{33:│}{0:             }|
8008            {0:~    }{33:└────────────────────┘}{0:             }|
8009                                                    |
8010          ]])
8011        end
8012
8013        feed('<c-w>w<c-w>J')
8014        if multigrid then
8015          screen:expect {
8016            grid = [[
8017          ## grid 1
8018            [2:----------------------------------------]|*2
8019            {5:[No Name] [+]                           }|
8020            [4:----------------------------------------]|*2
8021            {4:[No Name] [+]                           }|
8022            [3:----------------------------------------]|
8023          ## grid 2
8024            x                                       |
8025            {0:~                                       }|
8026          ## grid 3
8027                                                    |
8028          ## grid 4
8029            ^y                                       |
8030            {0:~                                       }|
8031          ]],
8032          }
8033        else
8034          screen:expect([[
8035            x                                       |
8036            {0:~                                       }|
8037            {5:[No Name] [+]                           }|
8038            ^y                                       |
8039            {0:~                                       }|
8040            {4:[No Name] [+]                           }|
8041                                                    |
8042          ]])
8043        end
8044      end)
8045
8046      it('movements with nested split layout', function()
8047        command('set hidden')
8048        feed('<c-w>s<c-w>v<c-w>b<c-w>v')
8049        if multigrid then
8050          screen:expect {
8051            grid = [[
8052          ## grid 1
8053            [6:--------------------]{5:│}[5:-------------------]|*2
8054            {5:[No Name] [+]        [No Name] [+]      }|
8055            [7:--------------------]{5:│}[2:-------------------]|*2
8056            {4:[No Name] [+]        }{5:[No Name] [+]      }|
8057            [3:----------------------------------------]|
8058          ## grid 2
8059            x                  |
8060            {0:~                  }|
8061          ## grid 3
8062                                                    |
8063          ## grid 4
8064            {1:y                   }|
8065            {2:~                   }|
8066          ## grid 5
8067            x                  |
8068            {0:~                  }|
8069          ## grid 6
8070            x                   |
8071            {0:~                   }|
8072          ## grid 7
8073            ^x                   |
8074            {0:~                   }|
8075        ]],
8076            float_pos = expected_pos,
8077          }
8078        else
8079          screen:expect([[
8080            x                   {5:│}x                  |
8081            {0:~                   }{5:│}{0:~                  }|
8082            {5:[No N}{1:y                   }{5:Name] [+]      }|
8083            ^x    {2:~                   }               |
8084            {0:~                   }{5:│}{0:~                  }|
8085            {4:[No Name] [+]        }{5:[No Name] [+]      }|
8086                                                    |
8087          ]])
8088        end
8089
8090        -- verify that N<c-w>w works
8091        for i = 1, 5 do
8092          feed(i .. '<c-w>w')
8093          feed_command('enew')
8094          api.nvim_buf_set_lines(0, 0, -1, true, { tostring(i) })
8095        end
8096
8097        if multigrid then
8098          screen:expect {
8099            grid = [[
8100          ## grid 1
8101            [6:-------------------]{5:│}[5:--------------------]|*2
8102            {5:[No Name] [+]       [No Name] [+]       }|
8103            [7:-------------------]{5:│}[2:--------------------]|*2
8104            {5:[No Name] [+]       [No Name] [+]       }|
8105            [3:----------------------------------------]|
8106          ## grid 2
8107            4                   |
8108            {0:~                   }|
8109          ## grid 3
8110            :enew                                   |
8111          ## grid 4
8112            {1:^5                   }|
8113            {2:~                   }|
8114          ## grid 5
8115            2                   |
8116            {0:~                   }|
8117          ## grid 6
8118            1                  |
8119            {0:~                  }|
8120          ## grid 7
8121            3                  |
8122            {0:~                  }|
8123        ]],
8124            float_pos = expected_pos,
8125          }
8126        else
8127          screen:expect([[
8128            1                  {5:│}2                   |
8129            {0:~                  }{5:│}{0:~                   }|
8130            {5:[No N}{1:^5                   }{5:ame] [+]       }|
8131            3    {2:~                   }               |
8132            {0:~                  }{5:│}{0:~                   }|
8133            {5:[No Name] [+]       [No Name] [+]       }|
8134            :enew                                   |
8135          ]])
8136        end
8137
8138        local movements = {
8139          w = { 2, 3, 4, 5, 1 },
8140          W = { 5, 1, 2, 3, 4 },
8141          h = { 1, 1, 3, 3, 3 },
8142          j = { 3, 3, 3, 4, 4 },
8143          k = { 1, 2, 1, 1, 1 },
8144          l = { 2, 2, 4, 4, 4 },
8145          t = { 1, 1, 1, 1, 1 },
8146          b = { 4, 4, 4, 4, 4 },
8147        }
8148
8149        for k, v in pairs(movements) do
8150          for i = 1, 5 do
8151            feed(i .. '<c-w>w')
8152            feed('<c-w>' .. k)
8153            local nr = fn.winnr()
8154            eq(v[i], nr, 'when using <c-w>' .. k .. ' from window ' .. i)
8155          end
8156        end
8157
8158        for i = 1, 5 do
8159          feed(i .. '<c-w>w')
8160          for j = 1, 5 do
8161            if j ~= i then
8162              feed(j .. '<c-w>w')
8163              feed('<c-w>p')
8164              local nr = fn.winnr()
8165              eq(i, nr, 'when using <c-w>p to window ' .. i .. ' from window ' .. j)
8166            end
8167          end
8168        end
8169      end)
8170
8171      it(':tabnew and :tabnext', function()
8172        feed(':tabnew<cr>')
8173        if multigrid then
8174          -- grid is not freed, but float is marked as closed (should it rather be "invisible"?)
8175          screen:expect {
8176            grid = [[
8177          ## grid 1
8178            {9: }{10:2}{9:+ [No Name] }{3: [No Name] }{5:              }{9:X}|
8179            [5:----------------------------------------]|*5
8180            [3:----------------------------------------]|
8181          ## grid 2 (hidden)
8182            x                                       |
8183            {0:~                                       }|*5
8184          ## grid 3
8185            :tabnew                                 |
8186          ## grid 4 (hidden)
8187            {1:y                   }|
8188            {2:~                   }|
8189          ## grid 5
8190            ^                                        |
8191            {0:~                                       }|*4
8192          ]],
8193          }
8194        else
8195          screen:expect([[
8196            {9: }{10:2}{9:+ [No Name] }{3: [No Name] }{5:              }{9:X}|
8197            ^                                        |
8198            {0:~                                       }|*4
8199            :tabnew                                 |
8200          ]])
8201        end
8202
8203        feed(':tabnext<cr>')
8204        if multigrid then
8205          screen:expect {
8206            grid = [[
8207          ## grid 1
8208            {3: }{34:2}{3:+ [No Name] }{9: [No Name] }{5:              }{9:X}|
8209            [2:----------------------------------------]|*5
8210            [3:----------------------------------------]|
8211          ## grid 2
8212            ^x                                       |
8213            {0:~                                       }|*4
8214          ## grid 3
8215            :tabnext                                |
8216          ## grid 4
8217            {1:y                   }|
8218            {2:~                   }|
8219          ## grid 5 (hidden)
8220                                                    |
8221            {0:~                                       }|*4
8222        ]],
8223            float_pos = expected_pos,
8224          }
8225        else
8226          screen:expect([[
8227            {3: }{34:2}{3:+ [No Name] }{9: [No Name] }{5:              }{9:X}|
8228            ^x                                       |
8229            {0:~    }{1:y                   }{0:               }|
8230            {0:~    }{2:~                   }{0:               }|
8231            {0:~                                       }|*2
8232            :tabnext                                |
8233          ]])
8234        end
8235
8236        feed(':tabnext<cr>')
8237        if multigrid then
8238          screen:expect {
8239            grid = [[
8240          ## grid 1
8241            {9: }{10:2}{9:+ [No Name] }{3: [No Name] }{5:              }{9:X}|
8242            [5:----------------------------------------]|*5
8243            [3:----------------------------------------]|
8244          ## grid 2 (hidden)
8245            x                                       |
8246            {0:~                                       }|*4
8247          ## grid 3
8248            :tabnext                                |
8249          ## grid 4 (hidden)
8250            {1:y                   }|
8251            {2:~                   }|
8252          ## grid 5
8253            ^                                        |
8254            {0:~                                       }|*4
8255        ]],
8256          }
8257        else
8258          screen:expect([[
8259            {9: }{10:2}{9:+ [No Name] }{3: [No Name] }{5:              }{9:X}|
8260            ^                                        |
8261            {0:~                                       }|*4
8262            :tabnext                                |
8263          ]])
8264        end
8265      end)
8266
8267      it(':tabnew and :tabnext (external)', function()
8268        if multigrid then
8269          -- also test external window wider than main screen
8270          api.nvim_win_set_config(win, { external = true, width = 65, height = 4 })
8271          expected_pos = { [4] = { external = true } }
8272          feed(':tabnew<cr>')
8273          screen:expect {
8274            grid = [[
8275          ## grid 1
8276            {9: + [No Name] }{3: }{34:2}{3:+ [No Name] }{5:            }{9:X}|
8277            [5:----------------------------------------]|*5
8278            [3:----------------------------------------]|
8279          ## grid 2 (hidden)
8280            x                                       |
8281            {0:~                                       }|*5
8282          ## grid 3
8283            :tabnew                                 |
8284          ## grid 4
8285            y                                                                |
8286            {0:~                                                                }|*3
8287          ## grid 5
8288            ^                                        |
8289            {0:~                                       }|*4
8290        ]],
8291            float_pos = expected_pos,
8292          }
8293        else
8294          eq("UI doesn't support external windows", pcall_err(api.nvim_win_set_config, 0, { external = true, width = 65, height = 4 }))
8295        end
8296
8297        feed(':tabnext<cr>')
8298        if multigrid then
8299          screen:expect {
8300            grid = [[
8301          ## grid 1
8302            {3: }{34:2}{3:+ [No Name] }{9: [No Name] }{5:              }{9:X}|
8303            [2:----------------------------------------]|*5
8304            [3:----------------------------------------]|
8305          ## grid 2
8306            ^x                                       |
8307            {0:~                                       }|*4
8308          ## grid 3
8309            :tabnext                                |
8310          ## grid 4
8311            y                                                                |
8312            {0:~                                                                }|*3
8313          ## grid 5 (hidden)
8314                                                    |
8315            {0:~                                       }|*4
8316        ]],
8317            float_pos = expected_pos,
8318          }
8319        end
8320
8321        feed(':tabnext<cr>')
8322        if multigrid then
8323          screen:expect {
8324            grid = [[
8325          ## grid 1
8326            {9: + [No Name] }{3: }{34:2}{3:+ [No Name] }{5:            }{9:X}|
8327            [5:----------------------------------------]|*5
8328            [3:----------------------------------------]|
8329          ## grid 2 (hidden)
8330            x                                       |
8331            {0:~                                       }|*4
8332          ## grid 3
8333            :tabnext                                |
8334          ## grid 4
8335            y                                                                |
8336            {0:~                                                                }|*3
8337          ## grid 5
8338            ^                                        |
8339            {0:~                                       }|*4
8340        ]],
8341            float_pos = expected_pos,
8342          }
8343        end
8344      end)
8345    end)
8346
8347    it('left drag changes visual selection in float window', function()
8348      local buf = api.nvim_create_buf(false, false)
8349      api.nvim_buf_set_lines(buf, 0, -1, true, { 'foo', 'bar', 'baz' })
8350      api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 3, row = 2, col = 5 })
8351      if multigrid then
8352        screen:expect {
8353          grid = [[
8354        ## grid 1
8355          [2:----------------------------------------]|*6
8356          [3:----------------------------------------]|
8357        ## grid 2
8358          ^                                        |
8359          {0:~                                       }|*5
8360        ## grid 3
8361                                                  |
8362        ## grid 4
8363          {1:foo                 }|
8364          {1:bar                 }|
8365          {1:baz                 }|
8366        ]],
8367          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
8368          win_viewport = {
8369            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
8370            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
8371          },
8372        }
8373
8374        if send_mouse_grid then
8375          api.nvim_input_mouse('left', 'press', '', 4, 0, 0)
8376        else
8377          api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
8378        end
8379        screen:expect {
8380          grid = [[
8381        ## grid 1
8382          [2:----------------------------------------]|*6
8383          [3:----------------------------------------]|
8384        ## grid 2
8385                                                  |
8386          {0:~                                       }|*5
8387        ## grid 3
8388                                                  |
8389        ## grid 4
8390          {1:^foo                 }|
8391          {1:bar                 }|
8392          {1:baz                 }|
8393        ]],
8394          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
8395          win_viewport = {
8396            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
8397            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
8398          },
8399        }
8400
8401        if send_mouse_grid then
8402          api.nvim_input_mouse('left', 'drag', '', 4, 1, 2)
8403        else
8404          api.nvim_input_mouse('left', 'drag', '', 0, 3, 7)
8405        end
8406        screen:expect {
8407          grid = [[
8408        ## grid 1
8409          [2:----------------------------------------]|*6
8410          [3:----------------------------------------]|
8411        ## grid 2
8412                                                  |
8413          {0:~                                       }|*5
8414        ## grid 3
8415          {3:-- VISUAL --}                            |
8416        ## grid 4
8417          {27:foo}{1:                 }|
8418          {27:ba^r}{1:                 }|
8419          {1:baz                 }|
8420        ]],
8421          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
8422          win_viewport = {
8423            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
8424            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 3, sum_scroll_delta = 0 },
8425          },
8426        }
8427      else
8428        screen:expect {
8429          grid = [[
8430          ^                                        |
8431          {0:~                                       }|
8432          {0:~    }{1:foo                 }{0:               }|
8433          {0:~    }{1:bar                 }{0:               }|
8434          {0:~    }{1:baz                 }{0:               }|
8435          {0:~                                       }|
8436                                                  |
8437        ]],
8438        }
8439
8440        api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
8441        screen:expect {
8442          grid = [[
8443                                                  |
8444          {0:~                                       }|
8445          {0:~    }{1:^foo                 }{0:               }|
8446          {0:~    }{1:bar                 }{0:               }|
8447          {0:~    }{1:baz                 }{0:               }|
8448          {0:~                                       }|
8449                                                  |
8450        ]],
8451        }
8452
8453        api.nvim_input_mouse('left', 'drag', '', 0, 3, 7)
8454        screen:expect {
8455          grid = [[
8456                                                  |
8457          {0:~                                       }|
8458          {0:~    }{27:foo}{1:                 }{0:               }|
8459          {0:~    }{27:ba^r}{1:                 }{0:               }|
8460          {0:~    }{1:baz                 }{0:               }|
8461          {0:~                                       }|
8462          {3:-- VISUAL --}                            |
8463        ]],
8464        }
8465      end
8466    end)
8467
8468    it('left drag changes visual selection in float window with border', function()
8469      local buf = api.nvim_create_buf(false, false)
8470      api.nvim_buf_set_lines(buf, 0, -1, true, { 'foo', 'bar', 'baz' })
8471      api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 3, row = 0, col = 5, border = 'single' })
8472      if multigrid then
8473        screen:expect {
8474          grid = [[
8475        ## grid 1
8476          [2:----------------------------------------]|*6
8477          [3:----------------------------------------]|
8478        ## grid 2
8479          ^                                        |
8480          {0:~                                       }|*5
8481        ## grid 3
8482                                                  |
8483        ## grid 4
8484          {33:┌────────────────────┐}|
8485          {33:│}{1:foo                 }{33:│}|
8486          {33:│}{1:bar                 }{33:│}|
8487          {33:│}{1:baz                 }{33:│}|
8488          {33:└────────────────────┘}|
8489        ]],
8490          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
8491          win_viewport = {
8492            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
8493            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
8494          },
8495        }
8496
8497        if send_mouse_grid then
8498          api.nvim_input_mouse('left', 'press', '', 4, 1, 1)
8499        else
8500          api.nvim_input_mouse('left', 'press', '', 0, 1, 6)
8501        end
8502        screen:expect {
8503          grid = [[
8504        ## grid 1
8505          [2:----------------------------------------]|*6
8506          [3:----------------------------------------]|
8507        ## grid 2
8508                                                  |
8509          {0:~                                       }|*5
8510        ## grid 3
8511                                                  |
8512        ## grid 4
8513          {33:┌────────────────────┐}|
8514          {33:│}{1:^foo                 }{33:│}|
8515          {33:│}{1:bar                 }{33:│}|
8516          {33:│}{1:baz                 }{33:│}|
8517          {33:└────────────────────┘}|
8518        ]],
8519          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
8520          win_viewport = {
8521            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
8522            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
8523          },
8524        }
8525
8526        if send_mouse_grid then
8527          api.nvim_input_mouse('left', 'drag', '', 4, 2, 3)
8528        else
8529          api.nvim_input_mouse('left', 'drag', '', 0, 2, 8)
8530        end
8531        screen:expect {
8532          grid = [[
8533        ## grid 1
8534          [2:----------------------------------------]|*6
8535          [3:----------------------------------------]|
8536        ## grid 2
8537                                                  |
8538          {0:~                                       }|*5
8539        ## grid 3
8540          {3:-- VISUAL --}                            |
8541        ## grid 4
8542          {33:┌────────────────────┐}|
8543          {33:│}{27:foo}{1:                 }{33:│}|
8544          {33:│}{27:ba^r}{1:                 }{33:│}|
8545          {33:│}{1:baz                 }{33:│}|
8546          {33:└────────────────────┘}|
8547        ]],
8548          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
8549          win_viewport = {
8550            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
8551            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 3, sum_scroll_delta = 0 },
8552          },
8553        }
8554      else
8555        screen:expect {
8556          grid = [[
8557          ^     {33:┌────────────────────┐}             |
8558          {0:~    }{33:│}{1:foo                 }{33:│}{0:             }|
8559          {0:~    }{33:│}{1:bar                 }{33:│}{0:             }|
8560          {0:~    }{33:│}{1:baz                 }{33:│}{0:             }|
8561          {0:~    }{33:└────────────────────┘}{0:             }|
8562          {0:~                                       }|
8563                                                  |
8564        ]],
8565        }
8566
8567        api.nvim_input_mouse('left', 'press', '', 0, 1, 6)
8568        screen:expect {
8569          grid = [[
8570               {33:┌────────────────────┐}             |
8571          {0:~    }{33:│}{1:^foo                 }{33:│}{0:             }|
8572          {0:~    }{33:│}{1:bar                 }{33:│}{0:             }|
8573          {0:~    }{33:│}{1:baz                 }{33:│}{0:             }|
8574          {0:~    }{33:└────────────────────┘}{0:             }|
8575          {0:~                                       }|
8576                                                  |
8577        ]],
8578        }
8579
8580        api.nvim_input_mouse('left', 'drag', '', 0, 2, 8)
8581        screen:expect {
8582          grid = [[
8583               {33:┌────────────────────┐}             |
8584          {0:~    }{33:│}{27:foo}{1:                 }{33:│}{0:             }|
8585          {0:~    }{33:│}{27:ba^r}{1:                 }{33:│}{0:             }|
8586          {0:~    }{33:│}{1:baz                 }{33:│}{0:             }|
8587          {0:~    }{33:└────────────────────┘}{0:             }|
8588          {0:~                                       }|
8589          {3:-- VISUAL --}                            |
8590        ]],
8591        }
8592      end
8593    end)
8594
8595    it('left drag changes visual selection in float window with winbar', function()
8596      local buf = api.nvim_create_buf(false, false)
8597      api.nvim_buf_set_lines(buf, 0, -1, true, { 'foo', 'bar', 'baz' })
8598      local float_win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 4, row = 1, col = 5 })
8599      api.nvim_set_option_value('winbar', 'floaty bar', { win = float_win })
8600      if multigrid then
8601        screen:expect {
8602          grid = [[
8603        ## grid 1
8604          [2:----------------------------------------]|*6
8605          [3:----------------------------------------]|
8606        ## grid 2
8607          ^                                        |
8608          {0:~                                       }|*5
8609        ## grid 3
8610                                                  |
8611        ## grid 4
8612          {3:floaty bar          }|
8613          {1:foo                 }|
8614          {1:bar                 }|
8615          {1:baz                 }|
8616        ]],
8617          float_pos = { [4] = { 1001, 'NW', 1, 1, 5, true, 50, 1, 1, 5 } },
8618          win_viewport = {
8619            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
8620            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
8621          },
8622        }
8623
8624        if send_mouse_grid then
8625          api.nvim_input_mouse('left', 'press', '', 4, 1, 0)
8626        else
8627          api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
8628        end
8629        screen:expect {
8630          grid = [[
8631        ## grid 1
8632          [2:----------------------------------------]|*6
8633          [3:----------------------------------------]|
8634        ## grid 2
8635                                                  |
8636          {0:~                                       }|*5
8637        ## grid 3
8638                                                  |
8639        ## grid 4
8640          {3:floaty bar          }|
8641          {1:^foo                 }|
8642          {1:bar                 }|
8643          {1:baz                 }|
8644        ]],
8645          float_pos = { [4] = { 1001, 'NW', 1, 1, 5, true, 50, 1, 1, 5 } },
8646          win_viewport = {
8647            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
8648            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
8649          },
8650        }
8651
8652        if send_mouse_grid then
8653          api.nvim_input_mouse('left', 'drag', '', 4, 2, 2)
8654        else
8655          api.nvim_input_mouse('left', 'drag', '', 0, 3, 7)
8656        end
8657        screen:expect {
8658          grid = [[
8659        ## grid 1
8660          [2:----------------------------------------]|*6
8661          [3:----------------------------------------]|
8662        ## grid 2
8663                                                  |
8664          {0:~                                       }|*5
8665        ## grid 3
8666          {3:-- VISUAL --}                            |
8667        ## grid 4
8668          {3:floaty bar          }|
8669          {27:foo}{1:                 }|
8670          {27:ba^r}{1:                 }|
8671          {1:baz                 }|
8672        ]],
8673          float_pos = { [4] = { 1001, 'NW', 1, 1, 5, true, 50, 1, 1, 5 } },
8674          win_viewport = {
8675            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
8676            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 3, sum_scroll_delta = 0 },
8677          },
8678        }
8679      else
8680        screen:expect {
8681          grid = [[
8682          ^                                        |
8683          {0:~    }{3:floaty bar          }{0:               }|
8684          {0:~    }{1:foo                 }{0:               }|
8685          {0:~    }{1:bar                 }{0:               }|
8686          {0:~    }{1:baz                 }{0:               }|
8687          {0:~                                       }|
8688                                                  |
8689        ]],
8690        }
8691
8692        api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
8693        screen:expect {
8694          grid = [[
8695                                                  |
8696          {0:~    }{3:floaty bar          }{0:               }|
8697          {0:~    }{1:^foo                 }{0:               }|
8698          {0:~    }{1:bar                 }{0:               }|
8699          {0:~    }{1:baz                 }{0:               }|
8700          {0:~                                       }|
8701                                                  |
8702        ]],
8703        }
8704
8705        api.nvim_input_mouse('left', 'drag', '', 0, 3, 7)
8706        screen:expect {
8707          grid = [[
8708                                                  |
8709          {0:~    }{3:floaty bar          }{0:               }|
8710          {0:~    }{27:foo}{1:                 }{0:               }|
8711          {0:~    }{27:ba^r}{1:                 }{0:               }|
8712          {0:~    }{1:baz                 }{0:               }|
8713          {0:~                                       }|
8714          {3:-- VISUAL --}                            |
8715        ]],
8716        }
8717      end
8718    end)
8719
8720    it('left drag changes visual selection if float window is turned into a split', function()
8721      local buf = api.nvim_create_buf(false, false)
8722      api.nvim_buf_set_lines(buf, 0, -1, true, { 'foo', 'bar', 'baz' })
8723      api.nvim_open_win(buf, true, { relative = 'editor', width = 20, height = 3, row = 2, col = 5 })
8724      command('wincmd L')
8725      if multigrid then
8726        screen:expect([[
8727        ## grid 1
8728          [2:-------------------]{5:│}[4:--------------------]|*5
8729          {5:[No Name]           }{4:[No Name] [+]       }|
8730          [3:----------------------------------------]|
8731        ## grid 2
8732                             |
8733          {0:~                  }|*4
8734        ## grid 3
8735                                                  |
8736        ## grid 4
8737          ^foo                 |
8738          bar                 |
8739          baz                 |
8740          {0:~                   }|*2
8741        ]])
8742
8743        if send_mouse_grid then
8744          api.nvim_input_mouse('left', 'press', '', 4, 2, 2)
8745        else
8746          api.nvim_input_mouse('left', 'press', '', 0, 2, 22)
8747        end
8748        screen:expect([[
8749        ## grid 1
8750          [2:-------------------]{5:│}[4:--------------------]|*5
8751          {5:[No Name]           }{4:[No Name] [+]       }|
8752          [3:----------------------------------------]|
8753        ## grid 2
8754                             |
8755          {0:~                  }|*4
8756        ## grid 3
8757                                                  |
8758        ## grid 4
8759          foo                 |
8760          bar                 |
8761          ba^z                 |
8762          {0:~                   }|*2
8763        ]])
8764
8765        if send_mouse_grid then
8766          api.nvim_input_mouse('left', 'drag', '', 4, 1, 1)
8767        else
8768          api.nvim_input_mouse('left', 'drag', '', 0, 1, 21)
8769        end
8770        screen:expect([[
8771        ## grid 1
8772          [2:-------------------]{5:│}[4:--------------------]|*5
8773          {5:[No Name]           }{4:[No Name] [+]       }|
8774          [3:----------------------------------------]|
8775        ## grid 2
8776                             |
8777          {0:~                  }|*4
8778        ## grid 3
8779          {3:-- VISUAL --}                            |
8780        ## grid 4
8781          foo                 |
8782          b{27:^ar}                 |
8783          {27:baz}                 |
8784          {0:~                   }|*2
8785        ]])
8786      else
8787        screen:expect([[
8788                             {5:│}^foo                 |
8789          {0:~                  }{5:│}bar                 |
8790          {0:~                  }{5:│}baz                 |
8791          {0:~                  }{5:│}{0:~                   }|*2
8792          {5:[No Name]           }{4:[No Name] [+]       }|
8793                                                  |
8794        ]])
8795
8796        api.nvim_input_mouse('left', 'press', '', 0, 2, 22)
8797        screen:expect([[
8798                             {5:│}foo                 |
8799          {0:~                  }{5:│}bar                 |
8800          {0:~                  }{5:│}ba^z                 |
8801          {0:~                  }{5:│}{0:~                   }|*2
8802          {5:[No Name]           }{4:[No Name] [+]       }|
8803                                                  |
8804        ]])
8805
8806        api.nvim_input_mouse('left', 'drag', '', 0, 1, 21)
8807        screen:expect([[
8808                             {5:│}foo                 |
8809          {0:~                  }{5:│}b{27:^ar}                 |
8810          {0:~                  }{5:│}{27:baz}                 |
8811          {0:~                  }{5:│}{0:~                   }|*2
8812          {5:[No Name]           }{4:[No Name] [+]       }|
8813          {3:-- VISUAL --}                            |
8814        ]])
8815      end
8816    end)
8817
8818    it('left click sets correct curswant in float window with border', function()
8819      local buf = api.nvim_create_buf(false, false)
8820      api.nvim_buf_set_lines(buf, 0, -1, true, { '', '', '' })
8821      api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 3, row = 0, col = 5, border = 'single' })
8822      if multigrid then
8823        screen:expect {
8824          grid = [[
8825        ## grid 1
8826          [2:----------------------------------------]|*6
8827          [3:----------------------------------------]|
8828        ## grid 2
8829          ^                                        |
8830          {0:~                                       }|*5
8831        ## grid 3
8832                                                  |
8833        ## grid 4
8834          {33:┌────────────────────┐}|
8835          {33:│}{1:                    }{33:│}|*3
8836          {33:└────────────────────┘}|
8837        ]],
8838          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
8839          win_viewport = {
8840            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
8841            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
8842          },
8843        }
8844      else
8845        screen:expect {
8846          grid = [[
8847          ^     {33:┌────────────────────┐}             |
8848          {0:~    }{33:│}{1:                    }{33:│}{0:             }|*3
8849          {0:~    }{33:└────────────────────┘}{0:             }|
8850          {0:~                                       }|
8851                                                  |
8852        ]],
8853        }
8854      end
8855
8856      if send_mouse_grid then
8857        api.nvim_input_mouse('left', 'press', '', 4, 3, 1)
8858      else
8859        api.nvim_input_mouse('left', 'press', '', 0, 3, 6)
8860      end
8861      eq({ 0, 3, 1, 0, 1 }, fn.getcurpos())
8862
8863      if send_mouse_grid then
8864        api.nvim_input_mouse('left', 'press', '', 4, 3, 2)
8865      else
8866        api.nvim_input_mouse('left', 'press', '', 0, 3, 7)
8867      end
8868      eq({ 0, 3, 1, 0, 2 }, fn.getcurpos())
8869
8870      if send_mouse_grid then
8871        api.nvim_input_mouse('left', 'press', '', 4, 3, 10)
8872      else
8873        api.nvim_input_mouse('left', 'press', '', 0, 3, 15)
8874      end
8875      eq({ 0, 3, 1, 0, 10 }, fn.getcurpos())
8876
8877      command('setlocal foldcolumn=1')
8878      feed('zfkgg')
8879      if multigrid then
8880        screen:expect {
8881          grid = [[
8882        ## grid 1
8883          [2:----------------------------------------]|*6
8884          [3:----------------------------------------]|
8885        ## grid 2
8886                                                  |
8887          {0:~                                       }|*5
8888        ## grid 3
8889                                                  |
8890        ## grid 4
8891          {33:┌────────────────────┐}|
8892          {33:│}{19: }{1:^                   }{33:│}|
8893          {33:│}{19:+}{28:+--  2 lines: ·····}{33:│}|
8894          {33:│}{2:~                   }{33:│}|
8895          {33:└────────────────────┘}|
8896        ]],
8897          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
8898          win_viewport = {
8899            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
8900            [4] = { win = 1001, topline = 0, botline = 4, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
8901          },
8902        }
8903      else
8904        screen:expect {
8905          grid = [[
8906               {33:┌────────────────────┐}             |
8907          {0:~    }{33:│}{19: }{1:^                   }{33:│}{0:             }|
8908          {0:~    }{33:│}{19:+}{28:+--  2 lines: ·····}{33:│}{0:             }|
8909          {0:~    }{33:│}{2:~                   }{33:│}{0:             }|
8910          {0:~    }{33:└────────────────────┘}{0:             }|
8911          {0:~                                       }|
8912                                                  |
8913        ]],
8914        }
8915      end
8916
8917      if send_mouse_grid then
8918        api.nvim_input_mouse('left', 'press', '', 4, 2, 1)
8919      else
8920        api.nvim_input_mouse('left', 'press', '', 0, 2, 6)
8921      end
8922      if multigrid then
8923        screen:expect {
8924          grid = [[
8925        ## grid 1
8926          [2:----------------------------------------]|*6
8927          [3:----------------------------------------]|
8928        ## grid 2
8929                                                  |
8930          {0:~                                       }|*5
8931        ## grid 3
8932                                                  |
8933        ## grid 4
8934          {33:┌────────────────────┐}|
8935          {33:│}{19: }{1:^                   }{33:│}|
8936          {33:│}{19:-}{1:                   }{33:│}|
8937          {33:│}{19:│}{1:                   }{33:│}|
8938          {33:└────────────────────┘}|
8939        ]],
8940          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
8941          win_viewport = {
8942            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
8943            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
8944          },
8945        }
8946      else
8947        screen:expect {
8948          grid = [[
8949               {33:┌────────────────────┐}             |
8950          {0:~    }{33:│}{19: }{1:^                   }{33:│}{0:             }|
8951          {0:~    }{33:│}{19:-}{1:                   }{33:│}{0:             }|
8952          {0:~    }{33:│}{19:│}{1:                   }{33:│}{0:             }|
8953          {0:~    }{33:└────────────────────┘}{0:             }|
8954          {0:~                                       }|
8955                                                  |
8956        ]],
8957        }
8958      end
8959
8960      if send_mouse_grid then
8961        api.nvim_input_mouse('left', 'press', '', 4, 2, 2)
8962      else
8963        api.nvim_input_mouse('left', 'press', '', 0, 2, 7)
8964      end
8965      eq({ 0, 2, 1, 0, 1 }, fn.getcurpos())
8966
8967      if send_mouse_grid then
8968        api.nvim_input_mouse('left', 'press', '', 4, 2, 3)
8969      else
8970        api.nvim_input_mouse('left', 'press', '', 0, 2, 8)
8971      end
8972      eq({ 0, 2, 1, 0, 2 }, fn.getcurpos())
8973
8974      if send_mouse_grid then
8975        api.nvim_input_mouse('left', 'press', '', 4, 2, 11)
8976      else
8977        api.nvim_input_mouse('left', 'press', '', 0, 2, 16)
8978      end
8979      eq({ 0, 2, 1, 0, 10 }, fn.getcurpos())
8980    end)
8981
8982    it("'winblend' option", function()
8983      screen:try_resize(50, 9)
8984      screen:set_default_attr_ids({
8985        [1] = { background = Screen.colors.LightMagenta },
8986        [2] = { foreground = Screen.colors.Grey0, background = tonumber('0xffcfff') },
8987        [3] = { foreground = tonumber('0xb282b2'), background = tonumber('0xffcfff') },
8988        [4] = { foreground = Screen.colors.Red, background = Screen.colors.LightMagenta },
8989        [5] = { foreground = tonumber('0x990000'), background = tonumber('0xfff1ff') },
8990        [6] = { foreground = tonumber('0x332533'), background = tonumber('0xfff1ff') },
8991        [7] = { background = tonumber('0xffcfff'), bold = true, foreground = tonumber('0x0000d8') },
8992        [8] = { background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1 },
8993        [9] = { background = Screen.colors.LightMagenta, blend = 30 },
8994        [10] = { foreground = Screen.colors.Red, background = Screen.colors.LightMagenta, blend = 0 },
8995        [11] = { foreground = Screen.colors.Red, background = Screen.colors.LightMagenta, blend = 80 },
8996        [12] = { background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1, blend = 30 },
8997        [13] = { foreground = Screen.colors.Black, background = Screen.colors.LightGray, blend = 30 },
8998        [14] = { foreground = Screen.colors.Black, background = Screen.colors.Grey88 },
8999        [15] = { foreground = tonumber('0x939393'), background = Screen.colors.Grey88 },
9000        [16] = { background = Screen.colors.Grey90 },
9001        [17] = { blend = 100 },
9002        [18] = { background = Screen.colors.LightMagenta, blend = 100 },
9003        [19] = { background = Screen.colors.LightMagenta, bold = true, blend = 100, foreground = Screen.colors.Blue1 },
9004        [20] = { background = Screen.colors.White, foreground = Screen.colors.Gray0 },
9005        [21] = { background = Screen.colors.White, bold = true, foreground = tonumber('0x00007f') },
9006        [22] = { background = Screen.colors.Gray90, foreground = Screen.colors.Gray0 },
9007        [23] = { blend = 100, bold = true, foreground = Screen.colors.Magenta },
9008        [24] = { foreground = tonumber('0x7f007f'), bold = true, background = Screen.colors.White },
9009        [25] = { foreground = tonumber('0x7f007f'), bold = true, background = Screen.colors.Grey90 },
9010        [26] = { foreground = Screen.colors.Black },
9011        [27] = { bold = true, foreground = tonumber('0x7f007f') },
9012        [28] = { foreground = tonumber('0x990000') },
9013        [29] = { foreground = Screen.colors.Gray20 },
9014        [30] = { bold = true, foreground = tonumber('0x00007f') },
9015        [31] = { foreground = Screen.colors.Red, blend = 80 },
9016        [32] = { foreground = Screen.colors.Blue1, blend = 100, bold = true },
9017        [33] = { foreground = Screen.colors.Gray0, underline = true },
9018        [34] = { underline = true },
9019        [35] = { foreground = Screen.colors.Black, underline = true, special = Screen.colors.Red },
9020        [36] = { special = Screen.colors.Red, underline = true },
9021      })
9022      insert([[
9023        Lorem ipsum dolor sit amet, consectetur
9024        adipisicing elit, sed do eiusmod tempor
9025        incididunt ut labore et dolore magna aliqua.
9026        Ut enim ad minim veniam, quis nostrud
9027        exercitation ullamco laboris nisi ut aliquip ex
9028        ea commodo consequat. Duis aute irure dolor in
9029        reprehenderit in voluptate velit esse cillum
9030        dolore eu fugiat nulla pariatur. Excepteur sint
9031        occaecat cupidatat non proident, sunt in culpa
9032        qui officia deserunt mollit anim id est
9033        laborum.]])
9034      local curbufnr = api.nvim_get_current_buf()
9035      local buf = api.nvim_create_buf(false, false)
9036      local test_data = { 'test', '', 'popup    text' }
9037      api.nvim_buf_set_lines(buf, 0, -1, true, test_data)
9038      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 15, height = 3, row = 2, col = 5 })
9039      if multigrid then
9040        screen:expect {
9041          grid = [[
9042        ## grid 1
9043          [2:--------------------------------------------------]|*8
9044          [3:--------------------------------------------------]|
9045        ## grid 2
9046          Ut enim ad minim veniam, quis nostrud             |
9047          exercitation ullamco laboris nisi ut aliquip ex   |
9048          ea commodo consequat. Duis aute irure dolor in    |
9049          reprehenderit in voluptate velit esse cillum      |
9050          dolore eu fugiat nulla pariatur. Excepteur sint   |
9051          occaecat cupidatat non proident, sunt in culpa    |
9052          qui officia deserunt mollit anim id est           |
9053          laborum^.                                          |
9054        ## grid 3
9055                                                            |
9056        ## grid 4
9057          {1:test           }|
9058          {1:               }|
9059          {1:popup    text  }|
9060        ]],
9061          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
9062        }
9063      else
9064        screen:expect([[
9065          Ut enim ad minim veniam, quis nostrud             |
9066          exercitation ullamco laboris nisi ut aliquip ex   |
9067          ea co{1:test           }. Duis aute irure dolor in    |
9068          repre{1:               }uptate velit esse cillum      |
9069          dolor{1:popup    text  }la pariatur. Excepteur sint   |
9070          occaecat cupidatat non proident, sunt in culpa    |
9071          qui officia deserunt mollit anim id est           |
9072          laborum^.                                          |
9073                                                            |
9074        ]])
9075      end
9076
9077      api.nvim_set_option_value('winblend', 30, { win = win })
9078      if multigrid then
9079        screen:expect {
9080          grid = [[
9081        ## grid 1
9082          [2:--------------------------------------------------]|*8
9083          [3:--------------------------------------------------]|
9084        ## grid 2
9085          Ut enim ad minim veniam, quis nostrud             |
9086          exercitation ullamco laboris nisi ut aliquip ex   |
9087          ea commodo consequat. Duis aute irure dolor in    |
9088          reprehenderit in voluptate velit esse cillum      |
9089          dolore eu fugiat nulla pariatur. Excepteur sint   |
9090          occaecat cupidatat non proident, sunt in culpa    |
9091          qui officia deserunt mollit anim id est           |
9092          laborum^.                                          |
9093        ## grid 3
9094                                                            |
9095        ## grid 4
9096          {9:test           }|
9097          {9:               }|
9098          {9:popup    text  }|
9099        ]],
9100          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
9101          unchanged = true,
9102        }
9103      else
9104        screen:expect([[
9105          Ut enim ad minim veniam, quis nostrud             |
9106          exercitation ullamco laboris nisi ut aliquip ex   |
9107          ea co{2:test}{3:o consequat}. Duis aute irure dolor in    |
9108          repre{3:henderit in vol}uptate velit esse cillum      |
9109          dolor{2:popup}{3:fugi}{2:text}{3:ul}la pariatur. Excepteur sint   |
9110          occaecat cupidatat non proident, sunt in culpa    |
9111          qui officia deserunt mollit anim id est           |
9112          laborum^.                                          |
9113                                                            |
9114        ]])
9115      end
9116
9117      -- Treat for \u2800 (braille blank) as whitespace.
9118      local braille_blank = '\226\160\128'
9119      api.nvim_buf_set_lines(buf, 0, -1, true, { 'test' .. braille_blank, '', 'popup' .. braille_blank .. '   text' })
9120      if multigrid then
9121        screen:expect {
9122          grid = [[
9123        ## grid 1
9124          [2:--------------------------------------------------]|*8
9125          [3:--------------------------------------------------]|
9126        ## grid 2
9127          Ut enim ad minim veniam, quis nostrud             |
9128          exercitation ullamco laboris nisi ut aliquip ex   |
9129          ea commodo consequat. Duis aute irure dolor in    |
9130          reprehenderit in voluptate velit esse cillum      |
9131          dolore eu fugiat nulla pariatur. Excepteur sint   |
9132          occaecat cupidatat non proident, sunt in culpa    |
9133          qui officia deserunt mollit anim id est           |
9134          laborum^.                                          |
9135        ## grid 3
9136                                                            |
9137        ## grid 4
9138          {9:test]] .. braille_blank .. [[          }|
9139          {9:               }|
9140          {9:popup]] .. braille_blank .. [[   text  }|
9141        ]],
9142          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
9143          unchanged = true,
9144        }
9145      else
9146        screen:expect_unchanged()
9147      end
9148      api.nvim_buf_set_lines(buf, 0, -1, true, test_data)
9149
9150      -- Check that 'winblend' works with NormalNC highlight
9151      api.nvim_set_option_value('winhighlight', 'NormalNC:Visual', { win = win })
9152      if multigrid then
9153        screen:expect {
9154          grid = [[
9155        ## grid 1
9156          [2:--------------------------------------------------]|*8
9157          [3:--------------------------------------------------]|
9158        ## grid 2
9159          Ut enim ad minim veniam, quis nostrud             |
9160          exercitation ullamco laboris nisi ut aliquip ex   |
9161          ea commodo consequat. Duis aute irure dolor in    |
9162          reprehenderit in voluptate velit esse cillum      |
9163          dolore eu fugiat nulla pariatur. Excepteur sint   |
9164          occaecat cupidatat non proident, sunt in culpa    |
9165          qui officia deserunt mollit anim id est           |
9166          laborum^.                                          |
9167        ## grid 3
9168                                                            |
9169        ## grid 4
9170          {13:test           }|
9171          {13:               }|
9172          {13:popup    text  }|
9173        ]],
9174          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
9175        }
9176      else
9177        screen:expect([[
9178          Ut enim ad minim veniam, quis nostrud             |
9179          exercitation ullamco laboris nisi ut aliquip ex   |
9180          ea co{14:test}{15:o consequat}. Duis aute irure dolor in    |
9181          repre{15:henderit in vol}uptate velit esse cillum      |
9182          dolor{14:popup}{15:fugi}{14:text}{15:ul}la pariatur. Excepteur sint   |
9183          occaecat cupidatat non proident, sunt in culpa    |
9184          qui officia deserunt mollit anim id est           |
9185          laborum^.                                          |
9186                                                            |
9187        ]])
9188      end
9189
9190      -- Also test with global NormalNC highlight
9191      exec_lua(
9192        [[
9193        vim.api.nvim_set_option_value('winhighlight', '', {win = ...})
9194        vim.api.nvim_set_hl(0, 'NormalNC', {link = 'Visual'})
9195      ]],
9196        win
9197      )
9198      screen:expect_unchanged()
9199      command('hi clear NormalNC')
9200
9201      command('hi SpecialRegion guifg=Red blend=0')
9202      api.nvim_buf_add_highlight(buf, -1, 'SpecialRegion', 2, 0, -1)
9203      if multigrid then
9204        screen:expect {
9205          grid = [[
9206        ## grid 1
9207          [2:--------------------------------------------------]|*8
9208          [3:--------------------------------------------------]|
9209        ## grid 2
9210          Ut enim ad minim veniam, quis nostrud             |
9211          exercitation ullamco laboris nisi ut aliquip ex   |
9212          ea commodo consequat. Duis aute irure dolor in    |
9213          reprehenderit in voluptate velit esse cillum      |
9214          dolore eu fugiat nulla pariatur. Excepteur sint   |
9215          occaecat cupidatat non proident, sunt in culpa    |
9216          qui officia deserunt mollit anim id est           |
9217          laborum^.                                          |
9218        ## grid 3
9219                                                            |
9220        ## grid 4
9221          {9:test           }|
9222          {9:               }|
9223          {10:popup    text}{9:  }|
9224        ]],
9225          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
9226        }
9227      else
9228        screen:expect([[
9229          Ut enim ad minim veniam, quis nostrud             |
9230          exercitation ullamco laboris nisi ut aliquip ex   |
9231          ea co{2:test}{3:o consequat}. Duis aute irure dolor in    |
9232          repre{3:henderit in vol}uptate velit esse cillum      |
9233          dolor{10:popup    text}{3:ul}la pariatur. Excepteur sint   |
9234          occaecat cupidatat non proident, sunt in culpa    |
9235          qui officia deserunt mollit anim id est           |
9236          laborum^.                                          |
9237                                                            |
9238        ]])
9239      end
9240
9241      command('hi SpecialRegion guifg=Red blend=80')
9242      if multigrid then
9243        screen:expect {
9244          grid = [[
9245        ## grid 1
9246          [2:--------------------------------------------------]|*8
9247          [3:--------------------------------------------------]|
9248        ## grid 2
9249          Ut enim ad minim veniam, quis nostrud             |
9250          exercitation ullamco laboris nisi ut aliquip ex   |
9251          ea commodo consequat. Duis aute irure dolor in    |
9252          reprehenderit in voluptate velit esse cillum      |
9253          dolore eu fugiat nulla pariatur. Excepteur sint   |
9254          occaecat cupidatat non proident, sunt in culpa    |
9255          qui officia deserunt mollit anim id est           |
9256          laborum^.                                          |
9257        ## grid 3
9258                                                            |
9259        ## grid 4
9260          {9:test           }|
9261          {9:               }|
9262          {11:popup    text}{9:  }|
9263        ]],
9264          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
9265          unchanged = true,
9266        }
9267      else
9268        screen:expect([[
9269          Ut enim ad minim veniam, quis nostrud             |
9270          exercitation ullamco laboris nisi ut aliquip ex   |
9271          ea co{2:test}{3:o consequat}. Duis aute irure dolor in    |
9272          repre{3:henderit in vol}uptate velit esse cillum      |
9273          dolor{5:popup}{6:fugi}{5:text}{3:ul}la pariatur. Excepteur sint   |
9274          occaecat cupidatat non proident, sunt in culpa    |
9275          qui officia deserunt mollit anim id est           |
9276          laborum^.                                          |
9277                                                            |
9278        ]])
9279      end
9280
9281      -- Test scrolling by mouse
9282      if send_mouse_grid then
9283        api.nvim_input_mouse('wheel', 'down', '', 4, 2, 2)
9284      else
9285        api.nvim_input_mouse('wheel', 'down', '', 0, 4, 7)
9286      end
9287      if multigrid then
9288        screen:expect {
9289          grid = [[
9290        ## grid 1
9291          [2:--------------------------------------------------]|*8
9292          [3:--------------------------------------------------]|
9293        ## grid 2
9294          Ut enim ad minim veniam, quis nostrud             |
9295          exercitation ullamco laboris nisi ut aliquip ex   |
9296          ea commodo consequat. Duis aute irure dolor in    |
9297          reprehenderit in voluptate velit esse cillum      |
9298          dolore eu fugiat nulla pariatur. Excepteur sint   |
9299          occaecat cupidatat non proident, sunt in culpa    |
9300          qui officia deserunt mollit anim id est           |
9301          laborum^.                                          |
9302        ## grid 3
9303                                                            |
9304        ## grid 4
9305          {11:popup    text}{9:  }|
9306          {12:~              }|*2
9307        ]],
9308          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
9309        }
9310      else
9311        screen:expect([[
9312          Ut enim ad minim veniam, quis nostrud             |
9313          exercitation ullamco laboris nisi ut aliquip ex   |
9314          ea co{5:popup}{6: con}{5:text}{3:at}. Duis aute irure dolor in    |
9315          repre{7:~}{3:enderit in vol}uptate velit esse cillum      |
9316          dolor{7:~}{3: eu fugiat nul}la pariatur. Excepteur sint   |
9317          occaecat cupidatat non proident, sunt in culpa    |
9318          qui officia deserunt mollit anim id est           |
9319          laborum^.                                          |
9320                                                            |
9321        ]])
9322      end
9323
9324      -- Check that 'winblend' applies to border/title/footer
9325      api.nvim_win_set_config(win, { border = 'single', title = 'Title', footer = 'Footer' })
9326      api.nvim_set_option_value('winblend', 100, { win = win })
9327      api.nvim_set_option_value('cursorline', true, { win = 0 })
9328      -- 'winblend' with transparent background. #18576
9329      command('hi clear VertSplit | hi Normal guibg=NONE ctermbg=NONE')
9330      api.nvim_win_set_option(win, 'winhighlight', 'Normal:Normal')
9331      feed('k0')
9332      if multigrid then
9333        screen:expect({
9334          grid = [[
9335          ## grid 1
9336            [2:--------------------------------------------------]|*8
9337            [3:--------------------------------------------------]|
9338          ## grid 2
9339            Ut enim ad minim veniam, quis nostrud             |
9340            exercitation ullamco laboris nisi ut aliquip ex   |
9341            ea commodo consequat. Duis aute irure dolor in    |
9342            reprehenderit in voluptate velit esse cillum      |
9343            dolore eu fugiat nulla pariatur. Excepteur sint   |
9344            occaecat cupidatat non proident, sunt in culpa    |
9345            {16:^qui officia deserunt mollit anim id est           }|
9346            laborum.                                          |
9347          ## grid 3
9348                                                              |
9349          ## grid 4
9350            {17:┌}{23:Title}{17:──────────┐}|
9351            {17:│}{31:popup    text}{17:  │}|
9352            {17:│}{32:~              }{17:│}|*2
9353            {17:└}{23:Footer}{17:─────────┘}|
9354          ]],
9355          win_pos = { [2] = { height = 8, startcol = 0, startrow = 0, width = 50, win = 1000 } },
9356          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
9357          win_viewport = {
9358            [2] = { win = 1000, topline = 3, botline = 11, curline = 9, curcol = 0, linecount = 11, sum_scroll_delta = 3 },
9359            [4] = { win = 1001, topline = 2, botline = 4, curline = 2, curcol = 7, linecount = 3, sum_scroll_delta = 2 },
9360          },
9361          win_viewport_margins = {
9362            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
9363            [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 },
9364          },
9365        })
9366      else
9367        screen:expect([[
9368          Ut enim ad minim veniam, quis nostrud             |
9369          exercitation ullamco laboris nisi ut aliquip ex   |
9370          ea co{26:┌}{27:Title}{26:──────────┐}Duis aute irure dolor in    |
9371          repre{26:│}{28:popup}{29:it i}{28:text}{26:lu│}tate velit esse cillum      |
9372          dolor{26:│}{30:~}{26:eu fugiat null│} pariatur. Excepteur sint   |
9373          occae{26:│}{30:~}{26:t cupidatat no│} proident, sunt in culpa    |
9374          {16:^qui o}{22:└}{25:Footer}{22:─────────┘}{16:ollit anim id est           }|
9375          laborum.                                          |
9376                                                            |
9377        ]])
9378      end
9379
9380      -- winblend underline: without guisp follows the fg (#14453), with guisp keeps its sp (#34614).
9381      command('fclose | hi TestUnderLine gui=underline | hi TestUnderLineSp gui=underline guisp=Red')
9382      api.nvim_buf_add_highlight(curbufnr, -1, 'TestUnderLine', 3, 0, -1)
9383      api.nvim_buf_add_highlight(curbufnr, -1, 'TestUnderLineSp', 4, 0, -1)
9384      api.nvim_buf_set_lines(buf, 0, -1, false, { '', '' })
9385      api.nvim_open_win(buf, false, { relative = 'win', row = 0, col = 0, width = 50, height = 2 })
9386      if multigrid then
9387        screen:expect({
9388          grid = [[
9389          ## grid 1
9390            [2:--------------------------------------------------]|*8
9391            [3:--------------------------------------------------]|
9392          ## grid 2
9393            {34:Ut enim ad minim veniam, quis nostrud}             |
9394            {36:exercitation ullamco laboris nisi ut aliquip ex}   |
9395            ea commodo consequat. Duis aute irure dolor in    |
9396            reprehenderit in voluptate velit esse cillum      |
9397            dolore eu fugiat nulla pariatur. Excepteur sint   |
9398            occaecat cupidatat non proident, sunt in culpa    |
9399            {16:^qui officia deserunt mollit anim id est           }|
9400            laborum.                                          |
9401          ## grid 3
9402                                                              |
9403          ## grid 5
9404            {17:                                                  }|*2
9405          ]],
9406          win_pos = { [2] = { height = 8, startcol = 0, startrow = 0, width = 50, win = 1000 } },
9407          float_pos = { [5] = { 1002, 'NW', 2, 0, 0, true, 50, 1, 0, 0 } },
9408          win_viewport = {
9409            [2] = { win = 1000, topline = 3, botline = 11, curline = 9, curcol = 0, linecount = 11, sum_scroll_delta = 3 },
9410            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
9411          },
9412          win_viewport_margins = {
9413            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
9414            [5] = { bottom = 0, left = 0, right = 0, top = 0, win = 1002 },
9415          },
9416        })
9417      else
9418        screen:expect([[
9419          {33:Ut enim ad minim veniam, quis nostrud}{26:             }|
9420          {35:exercitation ullamco laboris nisi ut aliquip ex}{26:   }|
9421          ea commodo consequat. Duis aute irure dolor in    |
9422          reprehenderit in voluptate velit esse cillum      |
9423          dolore eu fugiat nulla pariatur. Excepteur sint   |
9424          occaecat cupidatat non proident, sunt in culpa    |
9425          {16:^qui officia deserunt mollit anim id est           }|
9426          laborum.                                          |
9427                                                            |
9428        ]])
9429      end
9430    end)
9431
9432    it('can overlap doublewidth chars', function()
9433      insert([[
9434        # TODO: 测试字典信息的准确性
9435        # FIXME: 测试字典信息的准确性]])
9436      local buf = api.nvim_create_buf(false, false)
9437      api.nvim_buf_set_lines(buf, 0, -1, true, { '口', '口' })
9438      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 5, height = 3, row = 0, col = 11, style = 'minimal' })
9439      if multigrid then
9440        screen:expect {
9441          grid = [[
9442        ## grid 1
9443          [2:----------------------------------------]|*6
9444          [3:----------------------------------------]|
9445        ## grid 2
9446          # TODO: 测试字典信息的准确性            |
9447          # FIXME: 测试字典信息的准确^性           |
9448          {0:~                                       }|*4
9449        ## grid 3
9450                                                  |
9451        ## grid 4
9452          {1:口   }|*2
9453          {1:     }|
9454        ]],
9455          float_pos = { [4] = { 1001, 'NW', 1, 0, 11, true, 50, 1, 0, 11 } },
9456        }
9457      else
9458        screen:expect([[
9459          # TODO: 测 {1:口   }信息的准确性            |
9460          # FIXME: 测{1:口   } 信息的准确^性           |
9461          {0:~          }{1:     }{0:                        }|
9462          {0:~                                       }|*3
9463                                                  |
9464        ]])
9465      end
9466
9467      api.nvim_win_close(win, false)
9468      if multigrid then
9469        screen:expect([[
9470        ## grid 1
9471          [2:----------------------------------------]|*6
9472          [3:----------------------------------------]|
9473        ## grid 2
9474          # TODO: 测试字典信息的准确性            |
9475          # FIXME: 测试字典信息的准确^性           |
9476          {0:~                                       }|*4
9477        ## grid 3
9478                                                  |
9479        ]])
9480      else
9481        screen:expect([[
9482          # TODO: 测试字典信息的准确性            |
9483          # FIXME: 测试字典信息的准确^性           |
9484          {0:~                                       }|*4
9485                                                  |
9486        ]])
9487      end
9488
9489      -- The interaction between 'winblend' and doublewidth chars in the background
9490      -- does not look very good. But check no chars get incorrectly placed
9491      -- at least. Also check invisible EndOfBuffer region blends correctly.
9492      api.nvim_buf_set_lines(buf, 0, -1, true, { ' x x  x   xx', '  x x  x   x' })
9493      win = api.nvim_open_win(buf, false, { relative = 'editor', width = 12, height = 3, row = 0, col = 11, style = 'minimal' })
9494      api.nvim_set_option_value('winblend', 30, { win = win })
9495      screen:set_default_attr_ids({
9496        [1] = { foreground = tonumber('0xb282b2'), background = tonumber('0xffcfff') },
9497        [2] = { foreground = Screen.colors.Grey0, background = tonumber('0xffcfff') },
9498        [3] = { bold = true, foreground = Screen.colors.Blue1 },
9499        [4] = { background = tonumber('0xffcfff'), bold = true, foreground = tonumber('0xb282ff') },
9500        [5] = { background = Screen.colors.LightMagenta, blend = 30 },
9501      })
9502      if multigrid then
9503        screen:expect {
9504          grid = [[
9505        ## grid 1
9506          [2:----------------------------------------]|*6
9507          [3:----------------------------------------]|
9508        ## grid 2
9509          # TODO: 测试字典信息的准确性            |
9510          # FIXME: 测试字典信息的准确^性           |
9511          {3:~                                       }|*4
9512        ## grid 3
9513                                                  |
9514        ## grid 5
9515          {5: x x  x   xx}|
9516          {5:  x x  x   x}|
9517          {5:            }|
9518        ]],
9519          float_pos = { [5] = { 1002, 'NW', 1, 0, 11, true, 50, 1, 0, 11 } },
9520        }
9521      else
9522        screen:expect([[
9523          # TODO: 测 {2: x x  x}{1:息}{2: xx} 确性            |
9524          # FIXME: 测{1:试}{2:x x  x}{1:息}{2: x}准确^性           |
9525          {3:~          }{4:            }{3:                 }|
9526          {3:~                                       }|*3
9527                                                  |
9528        ]])
9529      end
9530
9531      api.nvim_win_set_config(win, { relative = 'editor', row = 0, col = 12 })
9532      if multigrid then
9533        screen:expect {
9534          grid = [[
9535        ## grid 1
9536          [2:----------------------------------------]|*6
9537          [3:----------------------------------------]|
9538        ## grid 2
9539          # TODO: 测试字典信息的准确性            |
9540          # FIXME: 测试字典信息的准确^性           |
9541          {3:~                                       }|*4
9542        ## grid 3
9543                                                  |
9544        ## grid 5
9545          {5: x x  x   xx}|
9546          {5:  x x  x   x}|
9547          {5:            }|
9548        ]],
9549          float_pos = { [5] = { 1002, 'NW', 1, 0, 12, true, 50, 1, 0, 12 } },
9550        }
9551      else
9552        screen:expect([[
9553          # TODO: 测试{2: x x}{1:信}{2:x }{1:的}{2:xx}确性            |
9554          # FIXME: 测 {2:  x x}{1:信}{2:x }{1:的}{2:x} 确^性           |
9555          {3:~           }{4:            }{3:                }|
9556          {3:~                                       }|*3
9557                                                  |
9558        ]])
9559      end
9560    end)
9561
9562    it('correctly redraws when overlaid windows are resized #13991', function()
9563      n.source([[
9564        let popup_config = {"relative" : "editor",
9565                    \ "width" : 7,
9566                    \ "height" : 3,
9567                    \ "row" : 1,
9568                    \ "col" : 1,
9569                    \ "style" : "minimal"}
9570
9571        let border_config = {"relative" : "editor",
9572                    \ "width" : 9,
9573                    \ "height" : 5,
9574                    \ "row" : 0,
9575                    \ "col" : 0,
9576                    \ "style" : "minimal"}
9577
9578        let popup_buffer = nvim_create_buf(v:false, v:true)
9579        let border_buffer = nvim_create_buf(v:false, v:true)
9580        let popup_win = nvim_open_win(popup_buffer, v:true, popup_config)
9581        let border_win = nvim_open_win(border_buffer, v:false, border_config)
9582
9583        call nvim_buf_set_lines(popup_buffer, 0, -1, v:true,
9584                    \ ["long", "longer", "longest"])
9585
9586        call nvim_buf_set_lines(border_buffer, 0, -1, v:true,
9587                    \ ["---------", "-       -", "-       -"])
9588      ]])
9589
9590      if multigrid then
9591        screen:expect {
9592          grid = [[
9593		## grid 1
9594		  [2:----------------------------------------]|*6
9595		  [3:----------------------------------------]|
9596		## grid 2
9597		                                          |
9598		  {1:~                                       }|*5
9599		## grid 3
9600		                                          |
9601		## grid 4
9602		  {2:^long   }|
9603		  {2:longer }|
9604		  {2:longest}|
9605		## grid 5
9606		  {2:---------}|
9607		  {2:-       -}|*2
9608		  {2:         }|*2
9609		]],
9610          attr_ids = {
9611            [1] = { foreground = Screen.colors.Blue1, bold = true },
9612            [2] = { background = Screen.colors.LightMagenta },
9613          },
9614          float_pos = {
9615            [4] = { 1001, 'NW', 1, 1, 1, true, 50, 2, 1, 1 },
9616            [5] = { 1002, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
9617          },
9618        }
9619      else
9620        screen:expect([[
9621        {1:---------}                               |
9622        {1:-^long   -}{0:                               }|
9623        {1:-longer -}{0:                               }|
9624        {1: longest }{0:                               }|
9625        {1:         }{0:                               }|
9626        {0:~                                       }|
9627                                                |
9628        ]])
9629      end
9630
9631      n.source([[
9632        let new_popup_config = {"width" : 1, "height" : 3}
9633        let new_border_config = {"width" : 3, "height" : 5}
9634
9635        function! Resize()
9636            call nvim_win_set_config(g:popup_win, g:new_popup_config)
9637            call nvim_win_set_config(g:border_win, g:new_border_config)
9638
9639            call nvim_buf_set_lines(g:border_buffer, 0, -1, v:true,
9640                        \ ["---", "- -", "- -"])
9641        endfunction
9642
9643        nnoremap zz <cmd>call Resize()<cr>
9644      ]])
9645
9646      n.feed('zz')
9647      if multigrid then
9648        screen:expect {
9649          grid = [[
9650        ## grid 1
9651          [2:----------------------------------------]|*6
9652          [3:----------------------------------------]|
9653        ## grid 2
9654                                                  |
9655          {1:~                                       }|*5
9656        ## grid 3
9657                                                  |
9658        ## grid 4
9659          {2:^l}|
9660          {2:o}|
9661          {2:n}|
9662        ## grid 5
9663          {2:---}|
9664          {2:- -}|*2
9665          {2:   }|*2
9666        ]],
9667          attr_ids = {
9668            [1] = { foreground = Screen.colors.Blue1, bold = true },
9669            [2] = { background = Screen.colors.LightMagenta },
9670          },
9671          float_pos = {
9672            [4] = { 1001, 'NW', 1, 1, 1, true, 50, 2, 1, 1 },
9673            [5] = { 1002, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
9674          },
9675        }
9676      else
9677        screen:expect([[
9678        {1:---}                                     |
9679        {1:-^l-}{0:                                     }|
9680        {1:-o-}{0:                                     }|
9681        {1: n }{0:                                     }|
9682        {1:   }{0:                                     }|
9683        {0:~                                       }|
9684                                                |
9685        ]])
9686      end
9687    end)
9688
9689    it('correctly orders multiple opened floats (current last)', function()
9690      local buf = api.nvim_create_buf(false, false)
9691      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
9692      api.nvim_set_option_value('winhl', 'Normal:ErrorMsg,EndOfBuffer:ErrorMsg', { win = win })
9693
9694      if multigrid then
9695        screen:expect {
9696          grid = [[
9697        ## grid 1
9698          [2:----------------------------------------]|*6
9699          [3:----------------------------------------]|
9700        ## grid 2
9701          ^                                        |
9702          {0:~                                       }|*5
9703        ## grid 3
9704                                                  |
9705        ## grid 4
9706          {7:                    }|
9707          {7:~                   }|
9708        ]],
9709          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
9710          win_viewport = {
9711            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9712            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9713          },
9714        }
9715      else
9716        screen:expect {
9717          grid = [[
9718          ^                                        |
9719          {0:~                                       }|
9720          {0:~    }{7:                    }{0:               }|
9721          {0:~    }{7:~                   }{0:               }|
9722          {0:~                                       }|*2
9723                                                  |
9724        ]],
9725        }
9726      end
9727
9728      exec_lua [[
9729        local buf = vim.api.nvim_create_buf(false,false)
9730        local win = vim.api.nvim_open_win(buf, false, {relative='editor', width=16, height=2, row=3, col=8})
9731        vim.wo[win].winhl = "EndOfBuffer:Normal"
9732        buf = vim.api.nvim_create_buf(false,false)
9733        win = vim.api.nvim_open_win(buf, true, {relative='editor', width=12, height=2, row=4, col=10})
9734        vim.wo[win].winhl = "Normal:Search,EndOfBuffer:Search"
9735      ]]
9736
9737      if multigrid then
9738        screen:expect {
9739          grid = [[
9740        ## grid 1
9741          [2:----------------------------------------]|*6
9742          [3:----------------------------------------]|
9743        ## grid 2
9744                                                  |
9745          {0:~                                       }|*5
9746        ## grid 3
9747                                                  |
9748        ## grid 4
9749          {7:                    }|
9750          {7:~                   }|
9751        ## grid 5
9752          {1:                }|
9753          {1:~               }|
9754        ## grid 6
9755          {17:^            }|
9756          {17:~           }|
9757        ]],
9758          float_pos = {
9759            [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 },
9760            [5] = { 1002, 'NW', 1, 3, 8, true, 50, 2, 3, 8 },
9761            [6] = { 1003, 'NW', 1, 4, 10, true, 50, 3, 4, 10 },
9762          },
9763          win_viewport = {
9764            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9765            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9766            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9767            [6] = { win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9768          },
9769        }
9770      else
9771        screen:expect {
9772          grid = [[
9773                                                  |
9774          {0:~                                       }|
9775          {0:~    }{7:                    }{0:               }|
9776          {0:~    }{7:~  }{1:                }{7: }{0:               }|
9777          {0:~       }{1:~ }{17:^            }{1:  }{0:                }|
9778          {0:~         }{17:~           }{0:                  }|
9779                                                  |
9780        ]],
9781        }
9782      end
9783
9784      -- This should bring win into focus on top
9785      api.nvim_set_current_win(win)
9786      if multigrid then
9787        screen:expect({
9788          grid = [[
9789          ## grid 1
9790            [2:----------------------------------------]|*6
9791            [3:----------------------------------------]|
9792          ## grid 2
9793                                                    |
9794            {0:~                                       }|*5
9795          ## grid 3
9796                                                    |
9797          ## grid 4
9798            {7:^                    }|
9799            {7:~                   }|
9800          ## grid 5
9801            {1:                }|
9802            {1:~               }|
9803          ## grid 6
9804            {17:            }|
9805            {17:~           }|
9806          ]],
9807          win_pos = { [2] = { height = 6, startcol = 0, startrow = 0, width = 40, win = 1000 } },
9808          float_pos = {
9809            [4] = { 1001, 'NW', 1, 2, 5, true, 50, 3, 2, 5 },
9810            [5] = { 1002, 'NW', 1, 3, 8, true, 50, 1, 3, 8 },
9811            [6] = { 1003, 'NW', 1, 4, 10, true, 50, 2, 4, 10 },
9812          },
9813          win_viewport = {
9814            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9815            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9816            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9817            [6] = { win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9818          },
9819        })
9820      else
9821        screen:expect([[
9822                                                  |
9823          {0:~                                       }|
9824          {0:~    }{7:^                    }{0:               }|
9825          {0:~    }{7:~                   }{0:               }|
9826          {0:~       }{1:~ }{17:            }{1:  }{0:                }|
9827          {0:~         }{17:~           }{0:                  }|
9828                                                  |
9829        ]])
9830      end
9831    end)
9832
9833    it('correctly orders multiple opened floats (non-current last)', function()
9834      local buf = api.nvim_create_buf(false, false)
9835      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
9836      api.nvim_set_option_value('winhl', 'Normal:ErrorMsg,EndOfBuffer:ErrorMsg', { win = win })
9837
9838      if multigrid then
9839        screen:expect {
9840          grid = [[
9841        ## grid 1
9842          [2:----------------------------------------]|*6
9843          [3:----------------------------------------]|
9844        ## grid 2
9845          ^                                        |
9846          {0:~                                       }|*5
9847        ## grid 3
9848                                                  |
9849        ## grid 4
9850          {7:                    }|
9851          {7:~                   }|
9852        ]],
9853          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
9854          win_viewport = {
9855            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9856            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9857          },
9858        }
9859      else
9860        screen:expect {
9861          grid = [[
9862          ^                                        |
9863          {0:~                                       }|
9864          {0:~    }{7:                    }{0:               }|
9865          {0:~    }{7:~                   }{0:               }|
9866          {0:~                                       }|*2
9867                                                  |
9868        ]],
9869        }
9870      end
9871
9872      exec_lua [[
9873        local buf = vim.api.nvim_create_buf(false,false)
9874        local win = vim.api.nvim_open_win(buf, true, {relative='editor', width=12, height=2, row=4, col=10})
9875        vim.wo[win].winhl = "Normal:Search,EndOfBuffer:Search"
9876        buf = vim.api.nvim_create_buf(false,false)
9877        win = vim.api.nvim_open_win(buf, false, {relative='editor', width=16, height=2, row=3, col=8})
9878        vim.wo[win].winhl = "EndOfBuffer:Normal"
9879      ]]
9880
9881      if multigrid then
9882        screen:expect {
9883          grid = [[
9884        ## grid 1
9885          [2:----------------------------------------]|*6
9886          [3:----------------------------------------]|
9887        ## grid 2
9888                                                  |
9889          {0:~                                       }|*5
9890        ## grid 3
9891                                                  |
9892        ## grid 4
9893          {7:                    }|
9894          {7:~                   }|
9895        ## grid 5
9896          {17:^            }|
9897          {17:~           }|
9898        ## grid 6
9899          {1:                }|
9900          {1:~               }|
9901        ]],
9902          float_pos = {
9903            [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 },
9904            [5] = { 1002, 'NW', 1, 4, 10, true, 50, 3, 4, 10 },
9905            [6] = { 1003, 'NW', 1, 3, 8, true, 50, 2, 3, 8 },
9906          },
9907          win_viewport = {
9908            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9909            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9910            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9911            [6] = { win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9912          },
9913        }
9914      else
9915        screen:expect {
9916          grid = [[
9917                                                  |
9918          {0:~                                       }|
9919          {0:~    }{7:                    }{0:               }|
9920          {0:~    }{7:~  }{1:                }{7: }{0:               }|
9921          {0:~       }{1:~ }{17:^            }{1:  }{0:                }|
9922          {0:~         }{17:~           }{0:                  }|
9923                                                  |
9924        ]],
9925        }
9926      end
9927
9928      -- This should bring win into focus on top
9929      api.nvim_set_current_win(win)
9930      if multigrid then
9931        screen:expect({
9932          grid = [[
9933          ## grid 1
9934            [2:----------------------------------------]|*6
9935            [3:----------------------------------------]|
9936          ## grid 2
9937                                                    |
9938            {0:~                                       }|*5
9939          ## grid 3
9940                                                    |
9941          ## grid 4
9942            {7:^                    }|
9943            {7:~                   }|
9944          ## grid 5
9945            {17:            }|
9946            {17:~           }|
9947          ## grid 6
9948            {1:                }|
9949            {1:~               }|
9950          ]],
9951          win_pos = { [2] = { height = 6, startcol = 0, startrow = 0, width = 40, win = 1000 } },
9952          float_pos = {
9953            [4] = { 1001, 'NW', 1, 2, 5, true, 50, 3, 2, 5 },
9954            [5] = { 1002, 'NW', 1, 4, 10, true, 50, 2, 4, 10 },
9955            [6] = { 1003, 'NW', 1, 3, 8, true, 50, 1, 3, 8 },
9956          },
9957          win_viewport = {
9958            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9959            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9960            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9961            [6] = { win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
9962          },
9963        })
9964      else
9965        screen:expect([[
9966                                                  |
9967          {0:~                                       }|
9968          {0:~    }{7:^                    }{0:               }|
9969          {0:~    }{7:~                   }{0:               }|
9970          {0:~       }{1:~ }{17:            }{1:  }{0:                }|
9971          {0:~         }{17:~           }{0:                  }|
9972                                                  |
9973        ]])
9974      end
9975    end)
9976
9977    it('can use z-index', function()
9978      local buf = api.nvim_create_buf(false, false)
9979      local win1 = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 3, row = 1, col = 5, zindex = 30 })
9980      api.nvim_set_option_value('winhl', 'Normal:ErrorMsg,EndOfBuffer:ErrorMsg', { win = win1 })
9981      local win2 = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 3, row = 2, col = 6, zindex = 50 })
9982      api.nvim_set_option_value('winhl', 'Normal:Search,EndOfBuffer:Search', { win = win2 })
9983      local win3 = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 3, row = 3, col = 7, zindex = 40 })
9984      api.nvim_set_option_value('winhl', 'Normal:Question,EndOfBuffer:Question', { win = win3 })
9985
9986      if multigrid then
9987        screen:expect {
9988          grid = [[
9989        ## grid 1
9990          [2:----------------------------------------]|*6
9991          [3:----------------------------------------]|
9992        ## grid 2
9993          ^                                        |
9994          {0:~                                       }|*5
9995        ## grid 3
9996                                                  |
9997        ## grid 4
9998          {7:                    }|
9999          {7:~                   }|*2
10000        ## grid 5
10001          {17:                    }|
10002          {17:~                   }|*2
10003        ## grid 6
10004          {8:                    }|
10005          {8:~                   }|*2
10006        ]],
10007          float_pos = {
10008            [4] = { 1001, 'NW', 1, 1, 5, true, 30, 1, 1, 5 },
10009            [5] = { 1002, 'NW', 1, 2, 6, true, 50, 3, 2, 6 },
10010            [6] = { 1003, 'NW', 1, 3, 7, true, 40, 2, 3, 7 },
10011          },
10012          win_viewport = {
10013            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10014            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10015            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10016            [6] = { win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10017          },
10018        }
10019      else
10020        screen:expect {
10021          grid = [[
10022          ^                                        |
10023          {0:~    }{7:                    }{0:               }|
10024          {0:~    }{7:~}{17:                    }{0:              }|
10025          {0:~    }{7:~}{17:~                   }{8: }{0:             }|
10026          {0:~     }{17:~                   }{8: }{0:             }|
10027          {0:~      }{8:~                   }{0:             }|
10028                                                  |
10029        ]],
10030        }
10031      end
10032
10033      --
10034      -- Check that floats are positioned correctly after changing the zindexes.
10035      --
10036      command('fclose')
10037      exec_lua(
10038        [[
10039        local win1, win3 = ...
10040        vim.api.nvim_win_set_config(win1, { zindex = 400, title = 'win_400', title_pos = 'center', border = 'double' })
10041        vim.api.nvim_win_set_config(win3, { zindex = 300, title = 'win_300', title_pos = 'center', border = 'single' })
10042      ]],
10043        win1,
10044        win3
10045      )
10046      if multigrid then
10047        screen:expect({
10048          grid = [[
10049          ## grid 1
10050            [2:----------------------------------------]|*6
10051            [3:----------------------------------------]|
10052          ## grid 2
10053            ^                                        |
10054            {0:~                                       }|*5
10055          ## grid 3
10056                                                    |
10057          ## grid 4
10058            {35:╔══════}{36:win_400}{35:═══════╗}|
10059            {35:║}{7:                    }{35:║}|
10060            {35:║}{7:~                   }{35:║}|*2
10061            {35:╚════════════════════╝}|
10062          ## grid 6
10063            {37:┌──────}{34:win_300}{37:───────┐}|
10064            {37:│}{8:                    }{37:│}|
10065            {37:│}{8:~                   }{37:│}|*2
10066            {37:└────────────────────┘}|
10067          ]],
10068          float_pos = {
10069            [4] = { 1001, 'NW', 1, 1, 5, true, 400, 3, 1, 5 },
10070            [6] = { 1003, 'NW', 1, 3, 7, true, 300, 2, 2, 7 },
10071          },
10072          win_viewport = {
10073            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10074            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10075            [6] = { win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10076          },
10077          win_viewport_margins = {
10078            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
10079            [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 },
10080            [6] = { bottom = 1, left = 1, right = 1, top = 1, win = 1003 },
10081          },
10082        })
10083      else
10084        screen:expect({
10085          grid = [[
10086            ^                                        |
10087            {0:~    }{35:╔══════}{36:win_400}{35:═══════╗}{0:             }|
10088            {0:~    }{35:║}{7:                    }{35:║}{37:─┐}{0:           }|
10089            {0:~    }{35:║}{7:~                   }{35:║}{8: }{37:│}{0:           }|*2
10090            {0:~    }{35:╚════════════════════╝}{8: }{37:│}{0:           }|
10091                   {37:└────────────────────┘}           |
10092          ]],
10093        })
10094      end
10095      exec_lua(
10096        [[
10097        local win1, win3 = ...
10098        vim.api.nvim_win_set_config(win1, { zindex = 100, title='win_100' })
10099        vim.api.nvim_win_set_config(win3, { zindex = 150, title='win_150' })
10100      ]],
10101        win1,
10102        win3
10103      )
10104      if multigrid then
10105        screen:expect({
10106          grid = [[
10107          ## grid 1
10108            [2:----------------------------------------]|*6
10109            [3:----------------------------------------]|
10110          ## grid 2
10111            ^                                        |
10112            {0:~                                       }|*5
10113          ## grid 3
10114                                                    |
10115          ## grid 4
10116            {35:╔══════}{36:win_100}{35:═══════╗}|
10117            {35:║}{7:                    }{35:║}|
10118            {35:║}{7:~                   }{35:║}|*2
10119            {35:╚════════════════════╝}|
10120          ## grid 6
10121            {37:┌──────}{34:win_150}{37:───────┐}|
10122            {37:│}{8:                    }{37:│}|
10123            {37:│}{8:~                   }{37:│}|*2
10124            {37:└────────────────────┘}|
10125          ]],
10126          float_pos = {
10127            [4] = { 1001, 'NW', 1, 1, 5, true, 100, 1, 1, 5 },
10128            [6] = { 1003, 'NW', 1, 3, 7, true, 150, 2, 1, 7 },
10129          },
10130          win_viewport = {
10131            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10132            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10133            [6] = { win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10134          },
10135          win_viewport_margins = {
10136            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
10137            [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 },
10138            [6] = { bottom = 1, left = 1, right = 1, top = 1, win = 1003 },
10139          },
10140        })
10141      else
10142        screen:expect([[
10143          ^                                        |
10144          {0:~    }{35:╔═}{37:┌──────}{34:win_150}{37:───────┐}{0:           }|
10145          {0:~    }{35:║}{7: }{37:│}{8:                    }{37:│}{0:           }|
10146          {0:~    }{35:║}{7:~}{37:│}{8:~                   }{37:│}{0:           }|*2
10147          {0:~    }{35:╚═}{37:└────────────────────┘}{0:           }|
10148                                                  |
10149        ]])
10150      end
10151    end)
10152
10153    it('can use winbar', function()
10154      local buf = api.nvim_create_buf(false, false)
10155      local win1 = api.nvim_open_win(buf, false, { relative = 'editor', width = 15, height = 3, row = 1, col = 5 })
10156      api.nvim_set_option_value('winbar', 'floaty bar', { win = win1 })
10157
10158      if multigrid then
10159        screen:expect {
10160          grid = [[
10161        ## grid 1
10162          [2:----------------------------------------]|*6
10163          [3:----------------------------------------]|
10164        ## grid 2
10165          ^                                        |
10166          {0:~                                       }|*5
10167        ## grid 3
10168                                                  |
10169        ## grid 4
10170          {3:floaty bar     }|
10171          {1:               }|
10172          {2:~              }|
10173        ]],
10174          float_pos = { [4] = { 1001, 'NW', 1, 1, 5, true, 50, 1, 1, 5 } },
10175          win_viewport = {
10176            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10177            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10178          },
10179        }
10180      else
10181        screen:expect {
10182          grid = [[
10183          ^                                        |
10184          {0:~    }{3:floaty bar     }{0:                    }|
10185          {0:~    }{1:               }{0:                    }|
10186          {0:~    }{2:~              }{0:                    }|
10187          {0:~                                       }|*2
10188                                                  |
10189        ]],
10190        }
10191      end
10192
10193      -- resize and add a border
10194      api.nvim_win_set_config(win1, { relative = 'editor', width = 15, height = 4, row = 0, col = 4, border = 'single' })
10195
10196      if multigrid then
10197        screen:expect {
10198          grid = [[
10199        ## grid 1
10200          [2:----------------------------------------]|*6
10201          [3:----------------------------------------]|
10202        ## grid 2
10203          ^                                        |
10204          {0:~                                       }|*5
10205        ## grid 3
10206                                                  |
10207        ## grid 4
10208          {33:┌───────────────┐}|
10209          {33:│}{3:floaty bar     }{33:│}|
10210          {33:│}{1:               }{33:│}|
10211          {33:│}{2:~              }{33:│}|*2
10212          {33:└───────────────┘}|
10213        ]],
10214          float_pos = { [4] = { 1001, 'NW', 1, 0, 4, true, 50, 1, 0, 4 } },
10215          win_viewport = {
10216            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10217            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10218          },
10219          win_viewport_margins = {
10220            [2] = { win = 1000, top = 0, bottom = 0, left = 0, right = 0 },
10221            [4] = { win = 1001, top = 2, bottom = 1, left = 1, right = 1 },
10222          },
10223        }
10224      else
10225        screen:expect {
10226          grid = [[
10227          ^    {33:┌───────────────┐}                   |
10228          {0:~   }{33:│}{3:floaty bar     }{33:│}{0:                   }|
10229          {0:~   }{33:│}{1:               }{33:│}{0:                   }|
10230          {0:~   }{33:│}{2:~              }{33:│}{0:                   }|*2
10231          {0:~   }{33:└───────────────┘}{0:                   }|
10232                                                  |
10233        ]],
10234        }
10235      end
10236    end)
10237
10238    it('it can be resized with messages and cmdheight=0 #20106', function()
10239      screen:try_resize(40, 9)
10240      command 'set cmdheight=0'
10241      local buf = api.nvim_create_buf(false, true)
10242      local win = api.nvim_open_win(buf, false, {
10243        relative = 'editor',
10244        width = 40,
10245        height = 4,
10246        anchor = 'SW',
10247        row = 9,
10248        col = 0,
10249        style = 'minimal',
10250        border = 'single',
10251        noautocmd = true,
10252      })
10253
10254      if multigrid then
10255        screen:expect {
10256          grid = [[
10257        ## grid 1
10258          [2:----------------------------------------]|*9
10259        ## grid 2
10260          ^                                        |
10261          {0:~                                       }|*8
10262        ## grid 3
10263        ## grid 4
10264          {33:┌────────────────────────────────────────┐}|
10265          {33:│}{1:                                        }{33:│}|*4
10266          {33:└────────────────────────────────────────┘}|
10267        ]],
10268          float_pos = { [4] = { 1001, 'SW', 1, 9, 0, true, 50, 1, 3, 0 } },
10269          win_viewport = {
10270            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10271            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10272          },
10273        }
10274      else
10275        screen:expect {
10276          grid = [[
10277          ^                                        |
10278          {0:~                                       }|*2
10279          {33:┌──────────────────────────────────────┐}|
10280          {33:│}{1:                                      }{33:│}|*4
10281          {33:└──────────────────────────────────────┘}|
10282        ]],
10283        }
10284      end
10285
10286      exec_lua(
10287        [[
10288        local win = ...
10289        vim.api.nvim_win_set_height(win, 2)
10290        vim.api.nvim_echo({ { "" } }, false, {})
10291      ]],
10292        win
10293      )
10294
10295      if multigrid then
10296        screen:expect {
10297          grid = [[
10298        ## grid 1
10299          [2:----------------------------------------]|*9
10300        ## grid 2
10301          ^                                        |
10302          {0:~                                       }|*8
10303        ## grid 3
10304        ## grid 4
10305          {33:┌────────────────────────────────────────┐}|
10306          {33:│}{1:                                        }{33:│}|*2
10307          {33:└────────────────────────────────────────┘}|
10308        ]],
10309          float_pos = { [4] = { 1001, 'SW', 1, 9, 0, true, 50, 1, 5, 0 } },
10310          win_viewport = {
10311            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10312            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10313          },
10314        }
10315      else
10316        screen:expect {
10317          grid = [[
10318          ^                                        |
10319          {0:~                                       }|*4
10320          {33:┌──────────────────────────────────────┐}|
10321          {33:│}{1:                                      }{33:│}|*2
10322          {33:└──────────────────────────────────────┘}|
10323        ]],
10324        }
10325      end
10326
10327      api.nvim_win_close(win, true)
10328      if multigrid then
10329        screen:expect {
10330          grid = [[
10331        ## grid 1
10332          [2:----------------------------------------]|*9
10333        ## grid 2
10334          ^                                        |
10335          {0:~                                       }|*8
10336        ## grid 3
10337        ]],
10338          win_viewport = {
10339            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10340          },
10341        }
10342      else
10343        screen:expect {
10344          grid = [[
10345          ^                                        |
10346          {0:~                                       }|*8
10347        ]],
10348        }
10349      end
10350    end)
10351
10352    it('it can be resized with messages and cmdheight=1', function()
10353      screen:try_resize(40, 9)
10354      local buf = api.nvim_create_buf(false, true)
10355      local win = api.nvim_open_win(buf, false, {
10356        relative = 'editor',
10357        width = 40,
10358        height = 4,
10359        anchor = 'SW',
10360        row = 8,
10361        col = 0,
10362        style = 'minimal',
10363        border = 'single',
10364        noautocmd = true,
10365      })
10366
10367      if multigrid then
10368        screen:expect {
10369          grid = [[
10370        ## grid 1
10371          [2:----------------------------------------]|*8
10372          [3:----------------------------------------]|
10373        ## grid 2
10374          ^                                        |
10375          {0:~                                       }|*7
10376        ## grid 3
10377                                                  |
10378        ## grid 4
10379          {33:┌────────────────────────────────────────┐}|
10380          {33:│}{1:                                        }{33:│}|*4
10381          {33:└────────────────────────────────────────┘}|
10382        ]],
10383          float_pos = { [4] = { 1001, 'SW', 1, 8, 0, true, 50, 1, 2, 0 } },
10384          win_viewport = {
10385            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10386            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10387          },
10388        }
10389      else
10390        screen:expect {
10391          grid = [[
10392          ^                                        |
10393          {0:~                                       }|
10394          {33:┌──────────────────────────────────────┐}|
10395          {33:│}{1:                                      }{33:│}|*4
10396          {33:└──────────────────────────────────────┘}|
10397                                                  |
10398        ]],
10399        }
10400      end
10401
10402      exec_lua(
10403        [[
10404        -- echo prompt is blocking, so schedule
10405        local win = ...
10406        vim.schedule(function()
10407          vim.api.nvim_win_set_height(win, 2)
10408          vim.api.nvim_echo({ { "\n" } }, false, {})
10409        end)
10410      ]],
10411        win
10412      )
10413
10414      if multigrid then
10415        screen:expect {
10416          grid = [[
10417        ## grid 1
10418          [2:----------------------------------------]|*7
10419          [3:----------------------------------------]|*2
10420        ## grid 2
10421                                                  |
10422          {0:~                                       }|*7
10423        ## grid 3
10424                                                  |
10425          {8:Press ENTER or type command to continue}^ |
10426        ## grid 4
10427          {33:┌────────────────────────────────────────┐}|
10428          {33:│}{1:                                        }{33:│}|*4
10429          {33:└────────────────────────────────────────┘}|
10430        ]],
10431          float_pos = { [4] = { 1001, 'SW', 1, 8, 0, true, 50, 1, 4, 0 } },
10432          win_viewport = {
10433            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10434            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10435          },
10436        }
10437      else
10438        screen:expect {
10439          grid = [[
10440                                                  |
10441          {0:~                                       }|
10442          {33:┌──────────────────────────────────────┐}|
10443          {33:│}{1:                                      }{33:│}|*3
10444          {4:                                        }|
10445                                                  |
10446          {8:Press ENTER or type command to continue}^ |
10447        ]],
10448        }
10449      end
10450
10451      feed('<cr>')
10452      if multigrid then
10453        screen:expect {
10454          grid = [[
10455        ## grid 1
10456          [2:----------------------------------------]|*8
10457          [3:----------------------------------------]|
10458        ## grid 2
10459          ^                                        |
10460          {0:~                                       }|*7
10461        ## grid 3
10462                                                  |
10463        ## grid 4
10464          {33:┌────────────────────────────────────────┐}|
10465          {33:│}{1:                                        }{33:│}|*2
10466          {33:└────────────────────────────────────────┘}|
10467        ]],
10468          float_pos = { [4] = { 1001, 'SW', 1, 8, 0, true, 50, 1, 4, 0 } },
10469          win_viewport = {
10470            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10471            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10472          },
10473        }
10474      else
10475        screen:expect {
10476          grid = [[
10477          ^                                        |
10478          {0:~                                       }|*3
10479          {33:┌──────────────────────────────────────┐}|
10480          {33:│}{1:                                      }{33:│}|*2
10481          {33:└──────────────────────────────────────┘}|
10482                                                  |
10483        ]],
10484        }
10485      end
10486
10487      api.nvim_win_close(win, true)
10488      if multigrid then
10489        screen:expect {
10490          grid = [[
10491        ## grid 1
10492          [2:----------------------------------------]|*8
10493          [3:----------------------------------------]|
10494        ## grid 2
10495          ^                                        |
10496          {0:~                                       }|*7
10497        ## grid 3
10498                                                  |
10499        ]],
10500          win_viewport = {
10501            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10502          },
10503        }
10504      else
10505        screen:expect {
10506          grid = [[
10507          ^                                        |
10508          {0:~                                       }|*7
10509                                                  |
10510        ]],
10511        }
10512      end
10513    end)
10514
10515    describe('no crash after moving and closing float window #21547', function()
10516      local function test_float_move_close(cmd)
10517        local float_opts = { relative = 'editor', row = 1, col = 1, width = 10, height = 10 }
10518        api.nvim_open_win(api.nvim_create_buf(false, false), true, float_opts)
10519        if multigrid then
10520          screen:expect({ float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 0, 1 } } })
10521        end
10522        command(cmd)
10523        exec_lua([[
10524          vim.api.nvim_win_set_config(0, {relative = 'editor', row = 2, col = 2})
10525          vim.api.nvim_win_close(0, {})
10526          vim.api.nvim_echo({{''}}, false, {})
10527        ]])
10528        if multigrid then
10529          screen:expect({ float_pos = {} })
10530        end
10531        assert_alive()
10532      end
10533
10534      it('if WinClosed autocommand flushes UI', function()
10535        test_float_move_close('autocmd WinClosed * ++once redraw')
10536      end)
10537
10538      it('if closing buffer flushes UI', function()
10539        test_float_move_close('autocmd BufWinLeave * ++once redraw')
10540      end)
10541    end)
10542
10543    it('no crash when closing a floating window from a non-current tab', function()
10544      local buf = api.nvim_create_buf(false, true)
10545      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 5, height = 5, row = 0, col = 0 })
10546      local triggered = exec_lua(function()
10547        vim.cmd.tabnew()
10548        vim.api.nvim_win_call(win, vim.cmd.redraw)
10549        local triggered = false
10550        vim.api.nvim_create_autocmd('BufHidden', {
10551          once = true,
10552          buf = buf,
10553          callback = function()
10554            vim.api.nvim_win_call(win, vim.cmd.redraw)
10555            triggered = true
10556          end,
10557        })
10558        vim.api.nvim_win_close(win, true)
10559        return triggered
10560      end)
10561      eq(true, triggered)
10562    end)
10563
10564    it(':sleep cursor placement #22639', function()
10565      local float_opts = { relative = 'editor', row = 1, col = 1, width = 4, height = 3 }
10566      local win = api.nvim_open_win(api.nvim_create_buf(false, false), true, float_opts)
10567      feed('iab<CR>cd<Esc>')
10568      feed(':sleep 100')
10569      if multigrid then
10570        screen:expect {
10571          grid = [[
10572        ## grid 1
10573          [2:----------------------------------------]|*6
10574          [3:----------------------------------------]|
10575        ## grid 2
10576                                                  |
10577          {0:~                                       }|*5
10578        ## grid 3
10579          :sleep 100^                              |
10580        ## grid 4
10581          {1:ab  }|
10582          {1:cd  }|
10583          {2:~   }|
10584        ]],
10585          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
10586          win_viewport = {
10587            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10588            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0 },
10589          },
10590        }
10591      else
10592        screen:expect {
10593          grid = [[
10594                                                  |
10595          {0:~}{1:ab  }{0:                                   }|
10596          {0:~}{1:cd  }{0:                                   }|
10597          {0:~}{2:~   }{0:                                   }|
10598          {0:~                                       }|*2
10599          :sleep 100^                              |
10600        ]],
10601        }
10602      end
10603
10604      feed('<CR>')
10605      if multigrid then
10606        screen:expect {
10607          grid = [[
10608        ## grid 1
10609          [2:----------------------------------------]|*6
10610          [3:----------------------------------------]|
10611        ## grid 2
10612                                                  |
10613          {0:~                                       }|*5
10614        ## grid 3
10615          :sleep 100                              |
10616        ## grid 4
10617          {1:ab  }|
10618          {1:c^d  }|
10619          {2:~   }|
10620        ]],
10621          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
10622          win_viewport = {
10623            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10624            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0 },
10625          },
10626        }
10627      else
10628        screen:expect {
10629          grid = [[
10630                                                  |
10631          {0:~}{1:ab  }{0:                                   }|
10632          {0:~}{1:c^d  }{0:                                   }|
10633          {0:~}{2:~   }{0:                                   }|
10634          {0:~                                       }|*2
10635          :sleep 100                              |
10636        ]],
10637        }
10638      end
10639      feed('<C-C>')
10640      screen:expect_unchanged()
10641
10642      api.nvim_win_set_config(win, { border = 'single' })
10643      feed(':sleep 100')
10644      if multigrid then
10645        screen:expect {
10646          grid = [[
10647        ## grid 1
10648          [2:----------------------------------------]|*6
10649          [3:----------------------------------------]|
10650        ## grid 2
10651                                                  |
10652          {0:~                                       }|*5
10653        ## grid 3
10654          :sleep 100^                              |
10655        ## grid 4
10656          {33:┌────┐}|
10657          {33:│}{1:ab  }{33:│}|
10658          {33:│}{1:cd  }{33:│}|
10659          {33:│}{2:~   }{33:│}|
10660          {33:└────┘}|
10661        ]],
10662          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
10663          win_viewport = {
10664            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10665            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0 },
10666          },
10667        }
10668      else
10669        screen:expect {
10670          grid = [[
10671                                                  |
10672          {0:~}{33:┌────┐}{0:                                 }|
10673          {0:~}{33:│}{1:ab  }{33:│}{0:                                 }|
10674          {0:~}{33:│}{1:cd  }{33:│}{0:                                 }|
10675          {0:~}{33:│}{2:~   }{33:│}{0:                                 }|
10676          {0:~}{33:└────┘}{0:                                 }|
10677          :sleep 100^                              |
10678        ]],
10679        }
10680      end
10681
10682      feed('<CR>')
10683      if multigrid then
10684        screen:expect {
10685          grid = [[
10686        ## grid 1
10687          [2:----------------------------------------]|*6
10688          [3:----------------------------------------]|
10689        ## grid 2
10690                                                  |
10691          {0:~                                       }|*5
10692        ## grid 3
10693          :sleep 100                              |
10694        ## grid 4
10695          {33:┌────┐}|
10696          {33:│}{1:ab  }{33:│}|
10697          {33:│}{1:c^d  }{33:│}|
10698          {33:│}{2:~   }{33:│}|
10699          {33:└────┘}|
10700        ]],
10701          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
10702          win_viewport = {
10703            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10704            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0 },
10705          },
10706        }
10707      else
10708        screen:expect {
10709          grid = [[
10710                                                  |
10711          {0:~}{33:┌────┐}{0:                                 }|
10712          {0:~}{33:│}{1:ab  }{33:│}{0:                                 }|
10713          {0:~}{33:│}{1:c^d  }{33:│}{0:                                 }|
10714          {0:~}{33:│}{2:~   }{33:│}{0:                                 }|
10715          {0:~}{33:└────┘}{0:                                 }|
10716          :sleep 100                              |
10717        ]],
10718        }
10719      end
10720      feed('<C-C>')
10721      screen:expect_unchanged()
10722
10723      command('setlocal winbar=foo')
10724      feed(':sleep 100')
10725      if multigrid then
10726        screen:expect {
10727          grid = [[
10728        ## grid 1
10729          [2:----------------------------------------]|*6
10730          [3:----------------------------------------]|
10731        ## grid 2
10732                                                  |
10733          {0:~                                       }|*5
10734        ## grid 3
10735          :sleep 100^                              |
10736        ## grid 4
10737          {33:┌────┐}|
10738          {33:│}{3:foo }{33:│}|
10739          {33:│}{1:ab  }{33:│}|
10740          {33:│}{1:cd  }{33:│}|
10741          {33:└────┘}|
10742        ]],
10743          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
10744          win_viewport = {
10745            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10746            [4] = { win = 1001, topline = 0, botline = 2, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0 },
10747          },
10748        }
10749      else
10750        screen:expect {
10751          grid = [[
10752                                                  |
10753          {0:~}{33:┌────┐}{0:                                 }|
10754          {0:~}{33:│}{3:foo }{33:│}{0:                                 }|
10755          {0:~}{33:│}{1:ab  }{33:│}{0:                                 }|
10756          {0:~}{33:│}{1:cd  }{33:│}{0:                                 }|
10757          {0:~}{33:└────┘}{0:                                 }|
10758          :sleep 100^                              |
10759        ]],
10760        }
10761      end
10762
10763      feed('<CR>')
10764      if multigrid then
10765        screen:expect {
10766          grid = [[
10767        ## grid 1
10768          [2:----------------------------------------]|*6
10769          [3:----------------------------------------]|
10770        ## grid 2
10771                                                  |
10772          {0:~                                       }|*5
10773        ## grid 3
10774          :sleep 100                              |
10775        ## grid 4
10776          {33:┌────┐}|
10777          {33:│}{3:foo }{33:│}|
10778          {33:│}{1:ab  }{33:│}|
10779          {33:│}{1:c^d  }{33:│}|
10780          {33:└────┘}|
10781        ]],
10782          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
10783          win_viewport = {
10784            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10785            [4] = { win = 1001, topline = 0, botline = 2, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0 },
10786          },
10787        }
10788      else
10789        screen:expect {
10790          grid = [[
10791                                                  |
10792          {0:~}{33:┌────┐}{0:                                 }|
10793          {0:~}{33:│}{3:foo }{33:│}{0:                                 }|
10794          {0:~}{33:│}{1:ab  }{33:│}{0:                                 }|
10795          {0:~}{33:│}{1:c^d  }{33:│}{0:                                 }|
10796          {0:~}{33:└────┘}{0:                                 }|
10797          :sleep 100                              |
10798        ]],
10799        }
10800      end
10801      feed('<C-C>')
10802      screen:expect_unchanged()
10803    end)
10804
10805    it('with rightleft and border #22640', function()
10806      local float_opts = { relative = 'editor', width = 5, height = 3, row = 1, col = 1, border = 'single' }
10807      api.nvim_open_win(api.nvim_create_buf(false, false), true, float_opts)
10808      command('setlocal rightleft')
10809      feed('iabc<CR>def<Esc>')
10810      if multigrid then
10811        screen:expect {
10812          grid = [[
10813        ## grid 1
10814          [2:----------------------------------------]|*6
10815          [3:----------------------------------------]|
10816        ## grid 2
10817                                                  |
10818          {0:~                                       }|*5
10819        ## grid 3
10820                                                  |
10821        ## grid 4
10822          {33:┌─────┐}|
10823          {33:│}{1:  cba}{33:│}|
10824          {33:│}{1:  ^fed}{33:│}|
10825          {33:│}{2:    ~}{33:│}|
10826          {33:└─────┘}|
10827        ]],
10828          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
10829          win_viewport = {
10830            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10831            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 2, sum_scroll_delta = 0 },
10832          },
10833        }
10834      else
10835        screen:expect {
10836          grid = [[
10837                                                  |
10838          {0:~}{33:┌─────┐}{0:                                }|
10839          {0:~}{33:│}{1:  cba}{33:│}{0:                                }|
10840          {0:~}{33:│}{1:  ^fed}{33:│}{0:                                }|
10841          {0:~}{33:│}{2:    ~}{33:│}{0:                                }|
10842          {0:~}{33:└─────┘}{0:                                }|
10843                                                  |
10844        ]],
10845        }
10846      end
10847    end)
10848
10849    it('float window with hide option', function()
10850      local cwin = api.nvim_get_current_win()
10851      local buf = api.nvim_create_buf(false, false)
10852      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 10, height = 2, row = 2, col = 5, hide = true })
10853      local expected_pos = {
10854        [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 },
10855      }
10856
10857      if multigrid then
10858        screen:expect {
10859          grid = [[
10860        ## grid 1
10861          [2:----------------------------------------]|*6
10862          [3:----------------------------------------]|
10863        ## grid 2
10864          ^                                        |
10865          {0:~                                       }|*5
10866        ## grid 3
10867                                                  |
10868
10869        ## grid 4 (hidden)
10870          {1:          }|
10871          {2:~         }|
10872        ]],
10873          float_pos = {},
10874        }
10875      else
10876        screen:expect([[
10877          ^                                        |
10878          {0:~                                       }|*5
10879                                                  |
10880        ]])
10881      end
10882
10883      api.nvim_win_set_config(win, { hide = false })
10884      if multigrid then
10885        screen:expect {
10886          grid = [[
10887        ## grid 1
10888          [2:----------------------------------------]|*6
10889          [3:----------------------------------------]|
10890        ## grid 2
10891          ^                                        |
10892          {0:~                                       }|*5
10893        ## grid 3
10894                                                  |
10895
10896        ## grid 4
10897          {1:          }|
10898          {2:~         }|
10899        ]],
10900          float_pos = expected_pos,
10901        }
10902      else
10903        screen:expect([[
10904          ^                                        |
10905          {0:~                                       }|
10906          {0:~    }{1:          }{0:                         }|
10907          {0:~    }{2:~         }{0:                         }|
10908          {0:~                                       }|*2
10909                                                  |
10910        ]])
10911      end
10912
10913      api.nvim_win_set_config(win, { hide = true })
10914      if multigrid then
10915        screen:expect {
10916          grid = [[
10917        ## grid 1
10918          [2:----------------------------------------]|*6
10919          [3:----------------------------------------]|
10920        ## grid 2
10921          ^                                        |
10922          {0:~                                       }|*5
10923        ## grid 3
10924                                                  |
10925
10926        ## grid 4 (hidden)
10927          {1:          }|
10928          {2:~         }|
10929        ]],
10930          float_pos = {},
10931        }
10932      else
10933        screen:expect([[
10934          ^                                        |
10935          {0:~                                       }|*5
10936                                                  |
10937        ]])
10938      end
10939
10940      --
10941      -- Cursor visibility:
10942      --
10943      -- Cursor is not visible in a hide=true floating window.
10944      api.nvim_set_current_win(win)
10945      if multigrid then
10946        screen:expect({
10947          grid = [[
10948          ## grid 1
10949            [2:----------------------------------------]|*6
10950            [3:----------------------------------------]|
10951          ## grid 2
10952                                                    |
10953            {0:~                                       }|*5
10954          ## grid 3
10955                                                    |
10956          ## grid 4 (hidden)
10957            {1:          }|
10958            {2:~         }|
10959          ]],
10960          win_viewport = {
10961            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10962            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10963          },
10964          win_viewport_margins = {
10965            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
10966            [4] = { bottom = 0, left = 0, right = 0, top = 0, win = 1001 },
10967          },
10968        })
10969      else
10970        screen:expect({
10971          grid = [[
10972                                                    |
10973            {0:~                                       }|*5
10974                                                    |
10975          ]],
10976        })
10977      end
10978
10979      -- Show cursor if cmdline is entered while curwin is a hide=true floating window.
10980      feed(':')
10981      if multigrid then
10982        screen:expect({
10983          grid = [[
10984          ## grid 1
10985            [2:----------------------------------------]|*6
10986            [3:----------------------------------------]|
10987          ## grid 2
10988                                                    |
10989            {0:~                                       }|*5
10990          ## grid 3
10991            :^                                       |
10992          ## grid 4 (hidden)
10993            {1:          }|
10994            {2:~         }|
10995          ]],
10996          win_viewport = {
10997            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10998            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
10999          },
11000          win_viewport_margins = {
11001            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
11002            [4] = { bottom = 0, left = 0, right = 0, top = 0, win = 1001 },
11003          },
11004        })
11005      else
11006        screen:expect({
11007          grid = [[
11008                                                    |
11009            {0:~                                       }|*5
11010            :^                                       |
11011          ]],
11012        })
11013      end
11014
11015      command('set keymap=dvorak')
11016      feed('<C-^>')
11017      screen:expect_unchanged()
11018
11019      feed('<C-^>')
11020      command('set keymap&')
11021      screen:expect_unchanged()
11022
11023      feed('<ESC>')
11024
11025      -- Show cursor after switching to a normal window (hide=false).
11026      api.nvim_set_current_win(cwin)
11027      if multigrid then
11028        screen:expect({
11029          grid = [[
11030          ## grid 1
11031            [2:----------------------------------------]|*6
11032            [3:----------------------------------------]|
11033          ## grid 2
11034            ^                                        |
11035            {0:~                                       }|*5
11036          ## grid 3
11037                                                    |
11038          ## grid 4 (hidden)
11039            {1:          }|
11040            {2:~         }|
11041          ]],
11042          win_viewport = {
11043            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
11044            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
11045          },
11046          win_viewport_margins = {
11047            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
11048            [4] = { bottom = 0, left = 0, right = 0, top = 0, win = 1001 },
11049          },
11050        })
11051      else
11052        screen:expect({
11053          grid = [[
11054            ^                                        |
11055            {0:~                                       }|*5
11056                                                    |
11057          ]],
11058        })
11059      end
11060      api.nvim_set_current_win(win)
11061      local win1 = api.nvim_open_win(buf, false, { relative = 'editor', width = 4, height = 4, row = 1, col = 2 })
11062      api.nvim_set_current_win(win1)
11063      if multigrid then
11064        screen:expect({
11065          grid = [[
11066        ## grid 1
11067          [2:----------------------------------------]|*6
11068          [3:----------------------------------------]|
11069        ## grid 2
11070                                                  |
11071          {0:~                                       }|*5
11072        ## grid 3
11073                                                  |
11074        ## grid 4 (hidden)
11075          {1:          }|
11076          {2:~         }|
11077        ## grid 5
11078          {1:^    }|
11079          {2:~   }|*3
11080        ]],
11081          float_pos = { [5] = { 1002, 'NW', 1, 1, 2, true, 50, 1, 1, 2 } },
11082          win_viewport = {
11083            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
11084            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
11085            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
11086          },
11087          win_viewport_margins = {
11088            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
11089            [4] = { bottom = 0, left = 0, right = 0, top = 0, win = 1001 },
11090            [5] = { bottom = 0, left = 0, right = 0, top = 0, win = 1002 },
11091          },
11092        })
11093      else
11094        screen:expect({
11095          grid = [[
11096                                                    |
11097            {0:~ }{1:^    }{0:                                  }|
11098            {0:~ }{2:~   }{0:                                  }|*3
11099            {0:~                                       }|
11100                                                    |
11101          ]],
11102        })
11103      end
11104      api.nvim_win_close(win1, true)
11105
11106      -- check window jump with hide
11107      feed('<C-W><C-W>')
11108      -- should keep on current window
11109      eq(cwin, api.nvim_get_current_win())
11110      api.nvim_win_set_config(win, { hide = false })
11111      api.nvim_set_current_win(win)
11112      local win3 = api.nvim_open_win(buf, true, { relative = 'editor', width = 4, height = 4, row = 2, col = 5, hide = false })
11113      api.nvim_win_set_config(win, { hide = true })
11114      feed('<C-W>w')
11115      -- should goto the first window with prev
11116      eq(cwin, api.nvim_get_current_win())
11117      -- windo
11118      command('windo set winheight=6')
11119      eq(win3, api.nvim_get_current_win())
11120      eq(6, api.nvim_win_get_height(win3))
11121      eq(2, api.nvim_win_get_height(win))
11122    end)
11123
11124    it(':fclose command #9663', function()
11125      local buf_a = api.nvim_create_buf(false, false)
11126      local buf_b = api.nvim_create_buf(false, false)
11127      local buf_c = api.nvim_create_buf(false, false)
11128      local buf_d = api.nvim_create_buf(false, false)
11129      local config_a = { relative = 'editor', width = 11, height = 11, row = 5, col = 5, border = 'single', zindex = 50 }
11130      local config_b = { relative = 'editor', width = 8, height = 8, row = 7, col = 7, border = 'single', zindex = 70 }
11131      local config_c = { relative = 'editor', width = 4, height = 4, row = 9, col = 9, border = 'single', zindex = 90 }
11132      local config_d = { relative = 'editor', width = 2, height = 2, row = 10, col = 10, border = 'single', zindex = 100 }
11133      api.nvim_open_win(buf_a, false, config_a)
11134      api.nvim_open_win(buf_b, false, config_b)
11135      api.nvim_open_win(buf_c, false, config_c)
11136      api.nvim_open_win(buf_d, false, config_d)
11137      local expected_pos = {
11138        [4] = { 1001, 'NW', 1, 5, 5, true, 50, 1, 0, 5 },
11139        [5] = { 1002, 'NW', 1, 7, 7, true, 70, 2, 0, 7 },
11140        [6] = { 1003, 'NW', 1, 9, 9, true, 90, 3, 0, 9 },
11141        [7] = { 1004, 'NW', 1, 10, 10, true, 100, 4, 2, 10 },
11142      }
11143      if multigrid then
11144        screen:expect {
11145          grid = [[
11146        ## grid 1
11147          [2:----------------------------------------]|*6
11148          [3:----------------------------------------]|
11149        ## grid 2
11150          ^                                        |
11151          {0:~                                       }|*5
11152        ## grid 3
11153                                                  |
11154        ## grid 4
11155          {33:┌───────────┐}|
11156          {33:│}{1:           }{33:│}|
11157          {33:│}{2:~          }{33:│}|*10
11158          {33:└───────────┘}|
11159        ## grid 5
11160          {33:┌────────┐}|
11161          {33:│}{1:        }{33:│}|
11162          {33:│}{2:~       }{33:│}|*7
11163          {33:└────────┘}|
11164        ## grid 6
11165          {33:┌────┐}|
11166          {33:│}{1:    }{33:│}|
11167          {33:│}{2:~   }{33:│}|*3
11168          {33:└────┘}|
11169        ## grid 7
11170          {33:┌──┐}|
11171          {33:│}{1:  }{33:│}|
11172          {33:│}{2:~ }{33:│}|
11173          {33:└──┘}|
11174        ]],
11175          float_pos = expected_pos,
11176        }
11177      else
11178        screen:expect([[
11179          ^     {33:┌─┌─┌────┐─┐┐}                      |
11180          {0:~    }{33:│}{1: }{33:│}{1: }{33:│}{1:    }{33:│}{1: }{33:││}{0:                      }|
11181          {0:~    }{33:│}{2:~}{33:│}{2:~}{33:│┌──┐│}{2: }{33:││}{0:                      }|
11182          {0:~    }{33:│}{2:~}{33:│}{2:~}{33:││}{1:  }{33:││}{2: }{33:││}{0:                      }|
11183          {0:~    }{33:│}{2:~}{33:│}{2:~}{33:││}{2:~ }{33:││}{2: }{33:││}{0:                      }|
11184          {0:~    }{33:└─└─└└──┘┘─┘┘}{0:                      }|
11185                                                  |
11186        ]])
11187      end
11188      -- close the window with the highest zindex value
11189      command('fclose')
11190      expected_pos[7] = nil
11191      if multigrid then
11192        screen:expect {
11193          grid = [[
11194        ## grid 1
11195          [2:----------------------------------------]|*6
11196          [3:----------------------------------------]|
11197        ## grid 2
11198          ^                                        |
11199          {0:~                                       }|*5
11200        ## grid 3
11201                                                  |
11202
11203        ## grid 4
11204          {33:┌───────────┐}|
11205          {33:│}{1:           }{33:│}|
11206          {33:│}{2:~          }{33:│}|*10
11207          {33:└───────────┘}|
11208        ## grid 5
11209          {33:┌────────┐}|
11210          {33:│}{1:        }{33:│}|
11211          {33:│}{2:~       }{33:│}|*7
11212          {33:└────────┘}|
11213        ## grid 6
11214          {33:┌────┐}|
11215          {33:│}{1:    }{33:│}|
11216          {33:│}{2:~   }{33:│}|*3
11217          {33:└────┘}|
11218        ]],
11219          float_pos = expected_pos,
11220        }
11221      else
11222        screen:expect([[
11223          ^     {33:┌─┌─┌────┐─┐┐}                      |
11224          {0:~    }{33:│}{1: }{33:│}{1: }{33:│}{1:    }{33:│}{1: }{33:││}{0:                      }|
11225          {0:~    }{33:│}{2:~}{33:│}{2:~}{33:│}{2:~   }{33:│}{2: }{33:││}{0:                      }|*3
11226          {0:~    }{33:└─└─└────┘─┘┘}{0:                      }|
11227                                                  |
11228        ]])
11229      end
11230      -- with range
11231      command('1fclose')
11232      expected_pos[6] = nil
11233      if multigrid then
11234        screen:expect {
11235          grid = [[
11236        ## grid 1
11237          [2:----------------------------------------]|*6
11238          [3:----------------------------------------]|
11239        ## grid 2
11240          ^                                        |
11241          {0:~                                       }|*5
11242        ## grid 3
11243                                                  |
11244
11245        ## grid 4
11246          {33:┌───────────┐}|
11247          {33:│}{1:           }{33:│}|
11248          {33:│}{2:~          }{33:│}|*10
11249          {33:└───────────┘}|
11250        ## grid 5
11251          {33:┌────────┐}|
11252          {33:│}{1:        }{33:│}|
11253          {33:│}{2:~       }{33:│}|*7
11254          {33:└────────┘}|
11255        ]],
11256          float_pos = expected_pos,
11257        }
11258      else
11259        screen:expect([[
11260          ^     {33:┌─┌────────┐┐}                      |
11261          {0:~    }{33:│}{1: }{33:│}{1:        }{33:││}{0:                      }|
11262          {0:~    }{33:│}{2:~}{33:│}{2:~       }{33:││}{0:                      }|*3
11263          {0:~    }{33:└─└────────┘┘}{0:                      }|
11264                                                  |
11265        ]])
11266      end
11267      -- with bang
11268      command('fclose!')
11269      if multigrid then
11270        screen:expect {
11271          grid = [[
11272        ## grid 1
11273          [2:----------------------------------------]|*6
11274          [3:----------------------------------------]|
11275        ## grid 2
11276          ^                                        |
11277          {0:~                                       }|*5
11278        ## grid 3
11279                                                  |
11280
11281        ]],
11282          float_pos = {},
11283        }
11284      else
11285        screen:expect([[
11286          ^                                        |
11287          {0:~                                       }|*5
11288                                                  |
11289        ]])
11290      end
11291      -- allow use with trailing bar
11292      eq('hello', n.exec_capture('fclose | echo "hello"'))
11293    end)
11294
11295    it('correctly placed in or above message area', function()
11296      local float_opts = { relative = 'editor', width = 5, height = 1, row = 100, col = 1, border = 'single' }
11297      api.nvim_set_option_value('cmdheight', 3, {})
11298      command("echo 'cmdline'")
11299      local win = api.nvim_open_win(api.nvim_create_buf(false, false), true, float_opts)
11300      -- Not hidden behind message area but placed above it.
11301      if multigrid then
11302        screen:expect {
11303          grid = [[
11304          ## grid 1
11305            [2:----------------------------------------]|*4
11306            [3:----------------------------------------]|*3
11307          ## grid 2
11308                                                    |
11309            {0:~                                       }|*3
11310          ## grid 3
11311            cmdline                                 |
11312                                                    |*2
11313          ## grid 4
11314            {33:┌─────┐}|
11315            {33:│}{1:^     }{33:│}|
11316            {33:└─────┘}|
11317          ]],
11318          float_pos = { [4] = { 1001, 'NW', 1, 100, 1, true, 50, 1, 1, 1 } },
11319          win_viewport = {
11320            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
11321            [4] = { win = 1001, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
11322          },
11323        }
11324      else
11325        screen:expect {
11326          grid = [[
11327                                                  |
11328          {0:~}{33:┌─────┐}{0:                                }|
11329          {0:~}{33:│}{1:^     }{33:│}{0:                                }|
11330          {0:~}{33:└─────┘}{0:                                }|
11331          cmdline                                 |
11332                                                  |*2
11333        ]],
11334        }
11335      end
11336      -- Not placed above message area and visible on top of it.
11337      api.nvim_win_set_config(win, { zindex = 300 })
11338      if multigrid then
11339        screen:expect {
11340          grid = [[
11341        ## grid 1
11342          [2:----------------------------------------]|*4
11343          [3:----------------------------------------]|*3
11344        ## grid 2
11345                                                  |
11346          {0:~                                       }|*3
11347        ## grid 3
11348          cmdline                                 |
11349                                                  |*2
11350        ## grid 4
11351          {33:┌─────┐}|
11352          {33:│}{1:^     }{33:│}|
11353          {33:└─────┘}|
11354        ]],
11355          float_pos = { [4] = { 1001, 'NW', 1, 100, 1, true, 300, 2, 4, 1 } },
11356          win_viewport = {
11357            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
11358            [4] = { win = 1001, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
11359          },
11360        }
11361      else
11362        screen:expect {
11363          grid = [[
11364                                                  |
11365          {0:~                                       }|*3
11366          c{33:┌─────┐}                                |
11367           {33:│}{1:^     }{33:│}                                |
11368           {33:└─────┘}                                |
11369        ]],
11370        }
11371      end
11372    end)
11373
11374    it('attempt to turn into split with no room', function()
11375      eq('Vim(split):E36: Not enough room', pcall_err(command, 'execute "split |"->repeat(&lines)'))
11376      command('vsplit | wincmd | | wincmd p')
11377      api.nvim_open_win(0, true, { relative = 'editor', row = 0, col = 0, width = 5, height = 5 })
11378      local config = api.nvim_win_get_config(0)
11379      eq('editor', config.relative)
11380
11381      local layout = fn.winlayout()
11382      local restcmd = fn.winrestcmd()
11383      eq('Vim(wincmd):E36: Not enough room', pcall_err(command, 'wincmd K'))
11384      eq('Vim(wincmd):E36: Not enough room', pcall_err(command, 'wincmd J'))
11385      eq(layout, fn.winlayout())
11386      eq(restcmd, fn.winrestcmd())
11387      eq(config, api.nvim_win_get_config(0))
11388    end)
11389
11390    it('error when relative to itself', function()
11391      local buf = api.nvim_create_buf(false, true)
11392      local config = { relative = 'win', width = 5, height = 2, row = 3, col = 3 }
11393      local winid = api.nvim_open_win(buf, false, config)
11394      api.nvim_set_current_win(winid)
11395      eq('floating window cannot be relative to itself', pcall_err(api.nvim_win_set_config, winid, config))
11396      eq('floating window cannot be relative to itself', pcall_err(api.nvim_win_set_config, winid, { win = winid }))
11397      -- Don't assume win=0 if no win given for existing relative=win float; so no error.
11398      api.nvim_win_set_config(winid, { width = 7 })
11399      eq(7, api.nvim_win_get_config(winid).width)
11400      -- Don't expect the error when configuring to something other than relative=win, as win=self
11401      -- is fine in those cases. (though maybe pointless) Other errors might be expected, though.
11402      eq('Cannot split a floating window', pcall_err(api.nvim_win_set_config, winid, { split = 'above', win = winid }))
11403      eq('win', api.nvim_win_get_config(winid).relative)
11404      api.nvim_win_set_config(winid, { relative = 'editor', win = winid, row = 3, col = 3 })
11405      eq('editor', api.nvim_win_get_config(winid).relative)
11406      -- An error when configuring split into relative=win float.
11407      command('split')
11408      eq('floating window cannot be relative to itself', pcall_err(api.nvim_win_set_config, 0, config))
11409    end)
11410
11411    it('bufpos out of range', function()
11412      local buf = api.nvim_create_buf(false, true)
11413      api.nvim_buf_set_lines(0, 0, -1, false, {})
11414      local config = { relative = 'win', width = 5, height = 2, row = 0, col = 0, bufpos = { 3, 3 } }
11415      api.nvim_open_win(buf, false, config)
11416      if multigrid then
11417        screen:expect({
11418          grid = [[
11419          ## grid 1
11420            [2:----------------------------------------]|*6
11421            [3:----------------------------------------]|
11422          ## grid 2
11423            ^                                        |
11424            {0:~                                       }|*5
11425          ## grid 3
11426                                                    |
11427          ## grid 4
11428            {1:     }|
11429            {2:~    }|
11430          ]],
11431          float_pos = { [4] = { 1001, 'NW', 2, 0, 0, true, 50, 1, 0, 0 } },
11432          win_viewport = {
11433            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
11434            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
11435          },
11436        })
11437      else
11438        screen:expect({
11439          grid = [[
11440            {1:^     }                                   |
11441            {2:~    }{0:                                   }|
11442            {0:~                                       }|*4
11443                                                    |
11444          ]],
11445        })
11446      end
11447    end)
11448
11449    it("1-line float does not inherit 'winbar' #19464", function()
11450      local res = exec_lua([[
11451        local win = vim.api.nvim_get_current_win()
11452        vim.wo[win].winbar = '%f'
11453        local grp = vim.api.nvim_create_augroup('asdf', { clear = true })
11454        vim.api.nvim_create_autocmd('WinEnter', {
11455          group = grp,
11456          pattern = '*',
11457          desc = 'winbar crash?',
11458          callback = function()
11459            vim.wo[win].winbar = '%f'
11460          end,
11461        })
11462
11463        local buf = vim.api.nvim_create_buf(false, true)
11464        local float_winid = vim.api.nvim_open_win(buf, true, {
11465          relative = 'win',
11466          win = win,
11467          border = 'single',
11468          col = 1,
11469          row = 1,
11470          height = 1,
11471          width = 40,
11472        })
11473        return {vim.wo[win].winbar, vim.wo[float_winid].winbar}
11474      ]])
11475      eq({ '%f', '' }, res)
11476    end)
11477
11478    it('winborder option', function()
11479      local buf = api.nvim_create_buf(false, false)
11480      local config = { relative = 'editor', width = 4, height = 4, row = 2, col = 2 }
11481      command('set winborder=single')
11482      local winid = api.nvim_open_win(buf, true, config)
11483      eq('┌', api.nvim_win_get_config(winid).border[1])
11484      command('fclose')
11485
11486      command('set winborder=double')
11487      winid = api.nvim_open_win(buf, true, config)
11488      eq('╔', api.nvim_win_get_config(winid).border[1])
11489      command('fclose!')
11490
11491      command('set winborder=none')
11492      winid = api.nvim_open_win(buf, true, config)
11493      eq('none', api.nvim_win_get_config(winid).border)
11494      command('fclose!')
11495
11496      -- respect config.border
11497      command('set winborder=rounded')
11498      config.border = 'single'
11499      winid = api.nvim_open_win(buf, false, config)
11500      eq('┌', api.nvim_win_get_config(winid).border[1])
11501
11502      -- don't use winborder when reconfig a floating window
11503      -- still show a single border
11504      config.border = nil
11505      api.nvim_win_set_config(winid, config)
11506      eq('┌', api.nvim_win_get_config(winid).border[1])
11507      command('fclose!')
11508
11509      command('set winborder=bold')
11510      winid = api.nvim_open_win(buf, false, config)
11511      eq('┏', api.nvim_win_get_config(winid).border[1])
11512
11513      command([[set winborder=+,-,+,\|,+,-,+,\|]])
11514      winid = api.nvim_open_win(buf, false, config)
11515      eq('+', api.nvim_win_get_config(winid).border[1])
11516
11517      command([[set winborder=●,○,●,○,●,○,●,○]])
11518      winid = api.nvim_open_win(buf, false, config)
11519      eq('●', api.nvim_win_get_config(winid).border[1])
11520
11521      -- Single-space border char.
11522      command([[lua vim.opt.winborder=",,, ,,,, "]])
11523      winid = api.nvim_open_win(buf, false, config)
11524      eq({ '', '', '', ' ', '', '', '', ' ' }, api.nvim_win_get_config(winid).border)
11525
11526      -- Trailing comma hides the last side
11527      command([[set winborder=+,-,+,\|,+,-,+,]])
11528      winid = api.nvim_open_win(buf, false, config)
11529      eq({ '+', '-', '+', '|', '+', '-', '+', '' }, api.nvim_win_get_config(winid).border)
11530      command('fclose!')
11531
11532      eq('Vim(set):E474: Invalid argument: winborder=,,', pcall_err(command, 'set winborder=,,'))
11533      eq('Vim(set):E474: Invalid argument: winborder=custom', pcall_err(command, 'set winborder=custom'))
11534    end)
11535
11536    it('cursor shape when the cursor is covered by a floating window', function()
11537      local normal_win = api.nvim_get_current_win()
11538      api.nvim_buf_set_lines(0, 0, -1, true, { 'one', 'two' })
11539      api.nvim_win_set_cursor(0, { 2, 2 })
11540      local buf = api.nvim_create_buf(false, false)
11541      api.nvim_buf_set_lines(buf, 0, 0, true, { 'the only line' })
11542      local win = api.nvim_open_win(buf, false, { relative = 'editor', row = 0, col = 0, height = 2, width = 20 })
11543      if multigrid then
11544        screen:expect({
11545          grid = [[
11546          ## grid 1
11547            [2:----------------------------------------]|*6
11548            [3:----------------------------------------]|
11549          ## grid 2
11550            one                                     |
11551            tw^o                                     |
11552            {0:~                                       }|*4
11553          ## grid 3
11554                                                    |
11555          ## grid 4
11556            {1:the only line       }|
11557            {1:                    }|
11558          ]],
11559          win_pos = {
11560            [2] = { height = 6, startcol = 0, startrow = 0, width = 40, win = 1000 },
11561          },
11562          float_pos = {
11563            [4] = { 1001, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
11564          },
11565          mode = 'normal',
11566        })
11567      else
11568        screen:expect {
11569          grid = [[
11570          {1:the only line       }                    |
11571          {1:  ^                  }                    |
11572          {0:~                                       }|*4
11573                                                  |
11574        ]],
11575          mode = 'replace',
11576        }
11577      end
11578      api.nvim_buf_set_lines(0, 0, -1, true, { 'one', 'two', 'three' })
11579      feed('<Down>')
11580      if multigrid then
11581        screen:expect({
11582          grid = [[
11583          ## grid 1
11584            [2:----------------------------------------]|*6
11585            [3:----------------------------------------]|
11586          ## grid 2
11587            one                                     |
11588            two                                     |
11589            th^ree                                   |
11590            {0:~                                       }|*3
11591          ## grid 3
11592                                                    |
11593          ## grid 4
11594            {1:the only line       }|
11595            {1:                    }|
11596          ]],
11597          win_pos = {
11598            [2] = { height = 6, startcol = 0, startrow = 0, width = 40, win = 1000 },
11599          },
11600          float_pos = {
11601            [4] = { 1001, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
11602          },
11603          mode = 'normal',
11604        })
11605      else
11606        screen:expect { mode = 'normal' }
11607      end
11608      -- Cursor shape on a lower z-index floating window
11609      buf = api.nvim_create_buf(false, false)
11610      api.nvim_buf_set_lines(buf, 0, 0, true, { 'highest' })
11611      local high_win = api.nvim_open_win(buf, false, { relative = 'editor', row = 0, col = 0, height = 2, width = 7, zindex = 150 })
11612      api.nvim_set_current_win(win)
11613      api.nvim_win_set_cursor(win, { 2, 1 })
11614      if multigrid then
11615        screen:expect({
11616          grid = [[
11617          ## grid 1
11618            [2:----------------------------------------]|*6
11619            [3:----------------------------------------]|
11620          ## grid 2
11621            one                                     |
11622            two                                     |
11623            three                                   |
11624            {0:~                                       }|*3
11625          ## grid 3
11626                                                    |
11627          ## grid 4
11628            {1:the only line       }|
11629            {1:^                    }|
11630          ## grid 5
11631            {1:highest}|
11632            {1:       }|
11633          ]],
11634          win_pos = {
11635            [2] = { height = 6, startcol = 0, startrow = 0, width = 40, win = 1000 },
11636          },
11637          float_pos = {
11638            [5] = { 1002, 'NW', 1, 0, 0, true, 150, 2, 0, 0 },
11639            [4] = { 1001, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
11640          },
11641          mode = 'normal',
11642        })
11643      else
11644        screen:expect { mode = 'replace' }
11645      end
11646
11647      api.nvim_set_current_win(high_win)
11648      if multigrid then
11649        screen:expect({
11650          grid = [[
11651          ## grid 1
11652            [2:----------------------------------------]|*6
11653            [3:----------------------------------------]|
11654          ## grid 2
11655            one                                     |
11656            two                                     |
11657            three                                   |
11658            {0:~                                       }|*3
11659          ## grid 3
11660                                                    |
11661          ## grid 4
11662            {1:the only line       }|
11663            {1:                    }|
11664          ## grid 5
11665            {1:^highest}|
11666            {1:       }|
11667          ]],
11668          win_pos = {
11669            [2] = { height = 6, startcol = 0, startrow = 0, width = 40, win = 1000 },
11670          },
11671          float_pos = {
11672            [5] = { 1002, 'NW', 1, 0, 0, true, 150, 2, 0, 0 },
11673            [4] = { 1001, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
11674          },
11675          mode = 'normal',
11676        })
11677      else
11678        screen:expect {
11679          grid = [[
11680          {1:^highesty line       }                    |
11681          {1:                    }                    |
11682          three                                   |
11683          {0:~                                       }|*3
11684                                                  |
11685        ]],
11686          mode = 'normal',
11687        }
11688      end
11689
11690      buf = api.nvim_create_buf(false, false)
11691      api.nvim_buf_set_lines(buf, 0, 0, true, { 'another' })
11692      api.nvim_open_win(buf, true, { relative = 'editor', row = 0, col = 0, height = 2, width = 7, zindex = 160 })
11693      if multigrid then
11694        screen:expect({
11695          grid = [[
11696          ## grid 1
11697            [2:----------------------------------------]|*6
11698            [3:----------------------------------------]|
11699          ## grid 2
11700            one                                     |
11701            two                                     |
11702            three                                   |
11703            {0:~                                       }|*3
11704          ## grid 3
11705                                                    |
11706          ## grid 4
11707            {1:the only line       }|
11708            {1:                    }|
11709          ## grid 5
11710            {1:highest}|
11711            {1:       }|
11712          ## grid 6
11713            {1:^another}|
11714            {1:       }|
11715          ]],
11716          win_pos = {
11717            [2] = { height = 6, startcol = 0, startrow = 0, width = 40, win = 1000 },
11718          },
11719          float_pos = {
11720            [4] = { 1001, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
11721            [5] = { 1002, 'NW', 1, 0, 0, true, 150, 2, 0, 0 },
11722            [6] = { 1003, 'NW', 1, 0, 0, true, 160, 3, 0, 0 },
11723          },
11724          mode = 'normal',
11725        })
11726      else
11727        screen:expect {
11728          grid = [[
11729          {1:^anothery line       }                    |
11730          {1:                    }                    |
11731          three                                   |
11732          {0:~                                       }|*3
11733                                                  |
11734        ]],
11735          mode = 'normal',
11736        }
11737      end
11738      api.nvim_set_current_win(normal_win)
11739      command('only')
11740      screen:try_resize(50, 20)
11741      buf = api.nvim_create_buf(false, false)
11742      api.nvim_buf_set_lines(buf, 0, -1, true, { 'x' })
11743      local float_win = api.nvim_open_win(buf, true, {
11744        relative = 'editor',
11745        width = 5,
11746        height = 5,
11747        row = 8,
11748        col = 9,
11749        border = 'single',
11750      })
11751      local buf2 = api.nvim_create_buf(false, false)
11752      local float_win_above = api.nvim_open_win(buf2, false, {
11753        relative = 'editor',
11754        width = 10,
11755        height = 10,
11756        row = 0,
11757        col = 0,
11758        zindex = 100,
11759      })
11760      if multigrid then
11761        screen:expect({
11762          grid = [[
11763          ## grid 1
11764            [2:--------------------------------------------------]|*19
11765            [3:--------------------------------------------------]|
11766          ## grid 2
11767            one                                               |
11768            two                                               |
11769            three                                             |
11770            {0:~                                                 }|*16
11771          ## grid 3
11772                                                              |
11773          ## grid 7
11774            {33:┌─────┐}|
11775            {33:│}{1:^x    }{33:│}|
11776            {33:│}{2:~    }{33:│}|*4
11777            {33:└─────┘}|
11778          ## grid 8
11779            {1:          }|
11780            {2:~         }|*9
11781          ]],
11782          win_pos = {
11783            [2] = { height = 19, startcol = 0, startrow = 0, width = 50, win = 1000 },
11784          },
11785          float_pos = {
11786            [7] = { 1004, 'NW', 1, 8, 9, true, 50, 1, 8, 9 },
11787            [8] = { 1005, 'NW', 1, 0, 0, true, 100, 2, 0, 0 },
11788          },
11789          mode = 'normal',
11790        })
11791      else
11792        screen:expect {
11793          grid = [[
11794          {1:          }                                        |
11795          {2:~         }                                        |*2
11796          {2:~         }{0:                                        }|*5
11797          {2:~         }{33:─────┐}{0:                                  }|
11798          {2:~         }{1:^x    }{33:│}{0:                                  }|
11799          {0:~        }{33:│}{2:~    }{33:│}{0:                                  }|*4
11800          {0:~        }{33:└─────┘}{0:                                  }|
11801          {0:~                                                 }|*4
11802                                                            |
11803        ]],
11804          mode = 'normal',
11805        }
11806      end
11807      -- Move window
11808      api.nvim_win_set_config(float_win, { relative = 'editor', row = 9, col = 8 })
11809      if multigrid then
11810        screen:expect({
11811          grid = [[
11812          ## grid 1
11813            [2:--------------------------------------------------]|*19
11814            [3:--------------------------------------------------]|
11815          ## grid 2
11816            one                                               |
11817            two                                               |
11818            three                                             |
11819            {0:~                                                 }|*16
11820          ## grid 3
11821                                                              |
11822          ## grid 7
11823            {33:┌─────┐}|
11824            {33:│}{1:^x    }{33:│}|
11825            {33:│}{2:~    }{33:│}|*4
11826            {33:└─────┘}|
11827          ## grid 8
11828            {1:          }|
11829            {2:~         }|*9
11830          ]],
11831          win_pos = {
11832            [2] = { height = 19, startcol = 0, startrow = 0, width = 50, win = 1000 },
11833          },
11834          float_pos = {
11835            [7] = { 1004, 'NW', 1, 9, 8, true, 50, 1, 9, 8 },
11836            [8] = { 1005, 'NW', 1, 0, 0, true, 100, 2, 0, 0 },
11837          },
11838          mode = 'normal',
11839        })
11840      else
11841        screen:expect {
11842          grid = [[
11843          {1:          }                                        |
11844          {2:~         }                                        |*2
11845          {2:~         }{0:                                        }|*6
11846          {2:~         }{33:────┐}{0:                                   }|
11847          {0:~       }{33:│}{1:^x    }{33:│}{0:                                   }|
11848          {0:~       }{33:│}{2:~    }{33:│}{0:                                   }|*4
11849          {0:~       }{33:└─────┘}{0:                                   }|
11850          {0:~                                                 }|*3
11851                                                            |
11852        ]],
11853          mode = 'normal',
11854        }
11855      end
11856
11857      -- rightleft
11858      api.nvim_win_set_config(float_win, { relative = 'editor', row = 8, col = 8 })
11859      command('set rightleft')
11860      if multigrid then
11861        screen:expect({
11862          grid = [[
11863          ## grid 1
11864            [2:--------------------------------------------------]|*19
11865            [3:--------------------------------------------------]|
11866          ## grid 2
11867            one                                               |
11868            two                                               |
11869            three                                             |
11870            {0:~                                                 }|*16
11871          ## grid 3
11872                                                              |
11873          ## grid 7
11874            {33:┌─────┐}|
11875            {33:│}{1:    ^x}{33:│}|
11876            {33:│}{2:    ~}{33:│}|*4
11877            {33:└─────┘}|
11878          ## grid 8
11879            {1:          }|
11880            {2:~         }|*9
11881          ]],
11882          win_pos = {
11883            [2] = { height = 19, startcol = 0, startrow = 0, width = 50, win = 1000 },
11884          },
11885          float_pos = {
11886            [7] = { 1004, 'NW', 1, 8, 8, true, 50, 1, 8, 8 },
11887            [8] = { 1005, 'NW', 1, 0, 0, true, 100, 2, 0, 0 },
11888          },
11889          mode = 'normal',
11890        })
11891      else
11892        screen:expect {
11893          grid = [[
11894          {1:          }                                        |
11895          {2:~         }                                        |*2
11896          {2:~         }{0:                                        }|*5
11897          {2:~         }{33:────┐}{0:                                   }|
11898          {2:~         }{1:   ^x}{33:│}{0:                                   }|
11899          {0:~       }{33:│}{2:    ~}{33:│}{0:                                   }|*4
11900          {0:~       }{33:└─────┘}{0:                                   }|
11901          {0:~                                                 }|*4
11902                                                            |
11903        ]],
11904          mode = 'normal',
11905        }
11906      end
11907
11908      command('set virtualedit=all')
11909      fn.setpos('.', { 0, 1, 1, 4 })
11910      if multigrid then
11911        screen:expect({
11912          grid = [[
11913          ## grid 1
11914            [2:--------------------------------------------------]|*19
11915            [3:--------------------------------------------------]|
11916          ## grid 2
11917            one                                               |
11918            two                                               |
11919            three                                             |
11920            {0:~                                                 }|*16
11921          ## grid 3
11922                                                              |
11923          ## grid 7
11924            {33:┌─────┐}|
11925            {33:│}{1:^    x}{33:│}|
11926            {33:│}{2:    ~}{33:│}|*4
11927            {33:└─────┘}|
11928          ## grid 8
11929            {1:          }|
11930            {2:~         }|*9
11931          ]],
11932          win_pos = {
11933            [2] = { height = 19, startcol = 0, startrow = 0, width = 50, win = 1000 },
11934          },
11935          float_pos = {
11936            [7] = { 1004, 'NW', 1, 8, 8, true, 50, 1, 8, 8 },
11937            [8] = { 1005, 'NW', 1, 0, 0, true, 100, 2, 0, 0 },
11938          },
11939          mode = 'normal',
11940        })
11941      else
11942        screen:expect { mode = 'replace' }
11943      end
11944      -- Not obscured when zindex doesn't exceed the zindex of the current grid + 50 (#37703).
11945      api.nvim_win_set_config(float_win_above, { zindex = 99 })
11946      if not multigrid then
11947        screen:expect { mode = 'normal' }
11948      end
11949
11950      -- Not obscured by a hidden floatwin.
11951      api.nvim_win_set_config(float_win_above, { hide = true, zindex = 100 })
11952      if multigrid then
11953        screen:expect({
11954          grid = [[
11955          ## grid 1
11956            [2:--------------------------------------------------]|*19
11957            [3:--------------------------------------------------]|
11958          ## grid 2
11959            one                                               |
11960            two                                               |
11961            three                                             |
11962            {0:~                                                 }|*16
11963          ## grid 3
11964                                                              |
11965          ## grid 7
11966            {33:┌─────┐}|
11967            {33:│}{1:^    x}{33:│}|
11968            {33:│}{2:    ~}{33:│}|*4
11969            {33:└─────┘}|
11970          ## grid 8 (hidden)
11971            {1:          }|
11972            {2:~         }|*9
11973          ]],
11974          float_pos = {
11975            [7] = { 1004, 'NW', 1, 8, 8, true, 50, 1, 8, 8 },
11976          },
11977          mode = 'normal',
11978        })
11979      else
11980        screen:expect({
11981          grid = [[
11982            one                                               |
11983            two                                               |
11984            three                                             |
11985            {0:~                                                 }|*5
11986            {0:~       }{33:┌─────┐}{0:                                   }|
11987            {0:~       }{33:│}{1:^    x}{33:│}{0:                                   }|
11988            {0:~       }{33:│}{2:    ~}{33:│}{0:                                   }|*4
11989            {0:~       }{33:└─────┘}{0:                                   }|
11990            {0:~                                                 }|*4
11991                                                              |
11992          ]],
11993          mode = 'normal',
11994        })
11995      end
11996
11997      -- Not obscured in the command-line if curwin's cursor is obscured.
11998      api.nvim_win_set_config(float_win_above, { hide = false })
11999      feed(':')
12000      if multigrid then
12001        screen:expect({
12002          grid = [[
12003          ## grid 1
12004            [2:--------------------------------------------------]|*19
12005            [3:--------------------------------------------------]|
12006          ## grid 2
12007            one                                               |
12008            two                                               |
12009            three                                             |
12010            {0:~                                                 }|*16
12011          ## grid 3
12012            :^                                                 |
12013          ## grid 7
12014            {33:┌─────┐}|
12015            {33:│}{1:    x}{33:│}|
12016            {33:│}{2:    ~}{33:│}|*4
12017            {33:└─────┘}|
12018          ## grid 8
12019            {1:          }|
12020            {2:~         }|*9
12021          ]],
12022          float_pos = {
12023            [7] = { 1004, 'NW', 1, 8, 8, true, 50, 1, 8, 8 },
12024            [8] = { 1005, 'NW', 1, 0, 0, true, 100, 2, 0, 0 },
12025          },
12026          mode = 'cmdline_normal',
12027        })
12028      else
12029        screen:expect { mode = 'cmdline_normal' }
12030      end
12031    end)
12032
12033    it("window is not enlarged behind 'cmdheight'", function()
12034      local opts = { relative = 'editor', width = 10, height = 4, row = 0, col = 0, zindex = 199 }
12035      opts.border = 'single'
12036      api.nvim_open_win(0, true, opts)
12037      opts.zindex, opts.col = 200, 12
12038      local above = api.nvim_open_win(0, false, opts)
12039      command('echo "cmdline" | wincmd +')
12040      if multigrid then
12041        screen:expect({
12042          grid = [[
12043          ## grid 1
12044            [2:----------------------------------------]|*6
12045            [3:----------------------------------------]|
12046          ## grid 2
12047                                                    |
12048            {0:~                                       }|*5
12049          ## grid 3
12050            cmdline                                 |
12051          ## grid 4
12052            {33:┌──────────┐}|
12053            {33:│}{1:^          }{33:│}|
12054            {33:│}{2:~         }{33:│}|*4
12055            {33:└──────────┘}|
12056          ## grid 5
12057            {33:┌──────────┐}|
12058            {33:│}{1:          }{33:│}|
12059            {33:│}{2:~         }{33:│}|*3
12060            {33:└──────────┘}|
12061          ]],
12062          float_pos = {
12063            [5] = { 1002, 'NW', 1, 0, 12, true, 200, 3, 0, 12 },
12064            [4] = { 1001, 'NW', 1, 0, 0, true, 199, 1, 0, 0 },
12065          },
12066        })
12067      else
12068        screen:expect([[
12069          {33:┌──────────┐┌──────────┐}                |
12070          {33:│}{1:^          }{33:││}{1:          }{33:│}{0:                }|
12071          {33:│}{2:~         }{33:││}{2:~         }{33:│}{0:                }|*3
12072          {33:└──────────┘└──────────┘}{0:                }|
12073          cmdline                                 |
12074        ]])
12075      end
12076      api.nvim_set_current_win(above)
12077      command('wincmd +')
12078      if multigrid then
12079        screen:expect({
12080          grid = [[
12081          ## grid 1
12082            [2:----------------------------------------]|*6
12083            [3:----------------------------------------]|
12084          ## grid 2
12085                                                    |
12086            {0:~                                       }|*5
12087          ## grid 3
12088            cmdline                                 |
12089          ## grid 4
12090            {33:┌──────────┐}|
12091            {33:│}{1:          }{33:│}|
12092            {33:│}{2:~         }{33:│}|*4
12093            {33:└──────────┘}|
12094          ## grid 5
12095            {33:┌──────────┐}|
12096            {33:│}{1:^          }{33:│}|
12097            {33:│}{2:~         }{33:│}|*4
12098            {33:└──────────┘}|
12099          ]],
12100          float_pos = {
12101            [5] = { 1002, 'NW', 1, 0, 12, true, 200, 3, 0, 12 },
12102            [4] = { 1001, 'NW', 1, 0, 0, true, 199, 1, 0, 0 },
12103          },
12104        })
12105      else
12106        screen:expect([[
12107          {33:┌──────────┐┌──────────┐}                |
12108          {33:│}{1:          }{33:││}{1:^          }{33:│}{0:                }|
12109          {33:│}{2:~         }{33:││}{2:~         }{33:│}{0:                }|*3
12110          {33:└──────────┘│}{2:~         }{33:│}{0:                }|
12111          cmdline     {33:└──────────┘}                |
12112        ]])
12113      end
12114    end)
12115
12116    it('redrawn after moving tabpages via nvim_win_set_config()', function()
12117      local tab1_win = api.nvim_get_current_win()
12118      fn.setline(1, 'hello')
12119      command('tab split')
12120      local tab2_win = api.nvim_get_current_win()
12121      -- Schedule an UPD_NOT_VALID redraw, but in one event move the float out of curtab before it's
12122      -- handled. Do not flush before then.
12123      local float = exec_lua(function()
12124        local float = vim.api.nvim_open_win(0, true, { relative = 'editor', width = 10, height = 5, row = 1, col = 1 })
12125        vim.api.nvim__redraw({ valid = false, flush = false })
12126        vim.api.nvim_win_set_config(float, { win = tab1_win })
12127        return float
12128      end)
12129
12130      if multigrid then
12131        screen:expect({
12132          grid = [[
12133          ## grid 1
12134            {9: }{10:2}{9:+ [No Name] }{3: + [No Name] }{5:            }{9:X}|
12135            [4:----------------------------------------]|*5
12136            [3:----------------------------------------]|
12137          ## grid 2 (hidden)
12138            hello                                   |
12139            {0:~                                       }|*5
12140          ## grid 3
12141                                                    |
12142          ## grid 4
12143            ^hello                                   |
12144            {0:~                                       }|*4
12145          ]],
12146        })
12147      else
12148        screen:expect([[
12149          {9: }{10:2}{9:+ [No Name] }{3: + [No Name] }{5:            }{9:X}|
12150          ^hello                                   |
12151          {0:~                                       }|*4
12152                                                  |
12153        ]])
12154      end
12155
12156      -- Importantly, want tabline redrawn and float's hl attribs to be correct here.
12157      api.nvim_win_set_config(float, { win = 0 })
12158      if multigrid then
12159        screen:expect({
12160          grid = [[
12161          ## grid 1
12162            {9: + [No Name] }{3: }{34:2}{3:+ [No Name] }{5:            }{9:X}|
12163            [4:----------------------------------------]|*5
12164            [3:----------------------------------------]|
12165          ## grid 2 (hidden)
12166            hello                                   |
12167            {0:~                                       }|*5
12168          ## grid 3
12169                                                    |
12170          ## grid 4
12171            ^hello                                   |
12172            {0:~                                       }|*4
12173          ## grid 5
12174            {1:hello     }|
12175            {2:~         }|*4
12176          ]],
12177          float_pos = {
12178            [5] = { 1002, 'NW', 1, 1, 1, true, 50, 1, 1, 1 },
12179          },
12180        })
12181      else
12182        screen:expect([[
12183          {9: + [No Name] }{3: }{34:2}{3:+ [No Name] }{5:            }{9:X}|
12184          ^h{1:hello     }                             |
12185          {0:~}{2:~         }{0:                             }|*4
12186                                                  |
12187        ]])
12188      end
12189
12190      -- Autocommand runs within the first tabpage, but won't refresh grids when switching to it due
12191      -- to switch_win_noblock having no_display set.
12192      command(
12193        ('autocmd OptionSet rightleft ++once call nvim_win_set_config(%d, #{relative: "win", win: %d, row: 0, col: 0})'):format(
12194          float,
12195          tab1_win
12196        )
12197      )
12198      api.nvim_set_option_value('rightleft', true, { win = tab1_win })
12199      -- Stale grids should not have caused issues with removing the float's grid.
12200      if multigrid then
12201        screen:expect({
12202          grid = [[
12203          ## grid 1
12204            {9: }{10:2}{9:+ [No Name] }{3: + [No Name] }{5:            }{9:X}|
12205            [4:----------------------------------------]|*5
12206            [3:----------------------------------------]|
12207          ## grid 2 (hidden)
12208            hello                                   |
12209            {0:~                                       }|*5
12210          ## grid 3
12211                                                    |
12212          ## grid 4
12213            ^hello                                   |
12214            {0:~                                       }|*4
12215          ## grid 5 (hidden)
12216            {1:hello     }|
12217            {2:~         }|*4
12218          ]],
12219        })
12220      else
12221        screen:expect([[
12222          {9: }{10:2}{9:+ [No Name] }{3: + [No Name] }{5:            }{9:X}|
12223          ^hello                                   |
12224          {0:~                                       }|*4
12225                                                  |
12226        ]])
12227      end
12228
12229      command('tabfirst')
12230      if multigrid then
12231        screen:expect({
12232          grid = [[
12233          ## grid 1
12234            {3: }{34:2}{3:+ [No Name] }{9: + [No Name] }{5:            }{9:X}|
12235            [2:----------------------------------------]|*5
12236            [3:----------------------------------------]|
12237          ## grid 2
12238                                               olle^h|
12239            {0:                                       ~}|*4
12240          ## grid 3
12241                                                    |
12242          ## grid 4 (hidden)
12243            hello                                   |
12244            {0:~                                       }|*4
12245          ## grid 5
12246            {1:hello     }|
12247            {2:~         }|*4
12248          ]],
12249          float_pos = {
12250            [5] = { 1002, 'NW', 2, 0, 0, true, 50, 1, 1, 0 },
12251          },
12252        })
12253      else
12254        screen:expect([[
12255          {3: }{34:2}{3:+ [No Name] }{9: + [No Name] }{5:            }{9:X}|
12256          {1:hello     }                         olle^h|
12257          {2:~         }{0:                             ~}|*4
12258                                                  |
12259        ]])
12260      end
12261
12262      -- Check tablines are redrawn even when moving floats between two non-current tabpages.
12263      command('tabnew')
12264      local tab3_win = api.nvim_get_current_win()
12265      if multigrid then
12266        screen:expect({
12267          grid = [[
12268          ## grid 1
12269            {9: }{10:2}{9:+ No Name] }{3: [No Name] }{9: + [No Name] }{5:  }{9:X}|
12270            [6:----------------------------------------]|*5
12271            [3:----------------------------------------]|
12272          ## grid 2 (hidden)
12273                                               olleh|
12274            {0:                                       ~}|*4
12275          ## grid 3
12276                                                    |
12277          ## grid 4 (hidden)
12278            hello                                   |
12279            {0:~                                       }|*4
12280          ## grid 5 (hidden)
12281            {1:hello     }|
12282            {2:~         }|*4
12283          ## grid 6
12284                                                   ^ |
12285            {0:                                       ~}|*4
12286          ]],
12287        })
12288      else
12289        screen:expect([[
12290          {9: }{10:2}{9:+ No Name] }{3: [No Name] }{9: + [No Name] }{5:  }{9:X}|
12291                                                 ^ |
12292          {0:                                       ~}|*4
12293                                                  |
12294        ]])
12295      end
12296
12297      api.nvim_win_set_config(float, { win = tab2_win })
12298      if multigrid then
12299        screen:expect({
12300          grid = [[
12301          ## grid 1
12302            {9: + [No Name] }{3: [No Name] }{9: }{10:2}{9:+ No Name] }{5:  }{9:X}|
12303            [6:----------------------------------------]|*5
12304            [3:----------------------------------------]|
12305          ## grid 2 (hidden)
12306                                               olleh|
12307            {0:                                       ~}|*4
12308          ## grid 3
12309                                                    |
12310          ## grid 4 (hidden)
12311            hello                                   |
12312            {0:~                                       }|*4
12313          ## grid 5 (hidden)
12314            {1:hello     }|
12315            {2:~         }|*4
12316          ## grid 6
12317                                                   ^ |
12318            {0:                                       ~}|*4
12319          ]],
12320        })
12321      else
12322        screen:expect([[
12323          {9: + [No Name] }{3: [No Name] }{9: }{10:2}{9:+ No Name] }{5:  }{9:X}|
12324                                                 ^ |
12325          {0:                                       ~}|*4
12326                                                  |
12327        ]])
12328      end
12329
12330      -- Try converting a split to a float, then moving it to another tabpage in one call.
12331      command('set norightleft | new')
12332      fn.setline(1, 'floaty mcfloatface')
12333      api.nvim_win_set_config(0, { relative = 'editor', win = tab1_win, row = 3, col = 3, width = 15, height = 5 })
12334      if multigrid then
12335        screen:expect({
12336          grid = [[
12337          ## grid 1
12338            {9: }{10:2}{9:+ No Name] }{3: [No Name] }{9: }{10:2}{9:+ No Name] }{5:  }{9:X}|
12339            [6:----------------------------------------]|*5
12340            [3:----------------------------------------]|
12341          ## grid 2 (hidden)
12342                                               olleh|
12343            {0:                                       ~}|*4
12344          ## grid 3
12345                                                    |
12346          ## grid 4 (hidden)
12347            hello                                   |
12348            {0:~                                       }|*4
12349          ## grid 5 (hidden)
12350            {1:hello     }|
12351            {2:~         }|*4
12352          ## grid 6
12353            ^                                        |
12354            {0:~                                       }|*4
12355          ## grid 7 (hidden)
12356            floaty mcfloatface                      |
12357            {0:~                                       }|
12358          ]],
12359        })
12360      else
12361        screen:expect([[
12362          {9: }{10:2}{9:+ No Name] }{3: [No Name] }{9: }{10:2}{9:+ No Name] }{5:  }{9:X}|
12363          ^                                        |
12364          {0:~                                       }|*4
12365                                                  |
12366        ]])
12367      end
12368
12369      command('tabfirst')
12370      if multigrid then
12371        screen:expect({
12372          grid = [[
12373          ## grid 1
12374            {3: }{34:2}{3:+ No Name] }{9: [No Name]  }{10:2}{9:+ No Name] }{5:  }{9:X}|
12375            [2:----------------------------------------]|*5
12376            [3:----------------------------------------]|
12377          ## grid 2
12378                                               olle^h|
12379            {0:                                       ~}|*4
12380          ## grid 3
12381                                                    |
12382          ## grid 4 (hidden)
12383            hello                                   |
12384            {0:~                                       }|*4
12385          ## grid 5 (hidden)
12386            {1:hello     }|
12387            {2:~         }|*4
12388          ## grid 6 (hidden)
12389                                                    |
12390            {0:~                                       }|*4
12391          ## grid 7
12392            {1:floaty mcfloatf}|
12393            {1:ace            }|
12394            {2:~              }|*3
12395          ]],
12396          float_pos = {
12397            [7] = { 1004, 'NW', 1, 3, 3, true, 50, 1, 1, 3 },
12398          },
12399        })
12400      else
12401        screen:expect([[
12402          {3: }{34:2}{3:+ No Name] }{9: [No Name]  }{10:2}{9:+ No Name] }{5:  }{9:X}|
12403             {1:floaty mcfloatf}                 olle^h|
12404          {0:   }{1:ace            }{0:                     ~}|
12405          {0:   }{2:~              }{0:                     ~}|*3
12406                                                  |
12407        ]])
12408      end
12409
12410      -- Works when doing the same between two non-current tabpages.
12411      local float2 = api.nvim_open_win(0, false, { split = 'below', win = tab3_win })
12412      api.nvim_win_set_config(float2, { relative = 'win', win = tab2_win, row = 2, col = 7, width = 4, height = 4, border = 'single' })
12413      if multigrid then
12414        screen:expect({
12415          grid = [[
12416          ## grid 1
12417            {3: }{34:2}{3:+ No Name] }{9: [No Name]  }{10:3}{9:+ No Name] }{5:  }{9:X}|
12418            [2:----------------------------------------]|*5
12419            [3:----------------------------------------]|
12420          ## grid 2
12421                                               olle^h|
12422            {0:                                       ~}|*4
12423          ## grid 3
12424                                                    |
12425          ## grid 4 (hidden)
12426            hello                                   |
12427            {0:~                                       }|*4
12428          ## grid 5 (hidden)
12429            {1:hello     }|
12430            {2:~         }|*4
12431          ## grid 6 (hidden)
12432                                                    |
12433            {0:~                                       }|*4
12434          ## grid 7
12435            {1:floaty mcfloatf}|
12436            {1:ace            }|
12437            {2:~              }|*3
12438          ]],
12439          float_pos = {
12440            [7] = { 1004, 'NW', 1, 3, 3, true, 50, 1, 1, 3 },
12441          },
12442        })
12443      else
12444        screen:expect([[
12445          {3: }{34:2}{3:+ No Name] }{9: [No Name]  }{10:3}{9:+ No Name] }{5:  }{9:X}|
12446             {1:floaty mcfloatf}                 olle^h|
12447          {0:   }{1:ace            }{0:                     ~}|
12448          {0:   }{2:~              }{0:                     ~}|*3
12449                                                  |
12450        ]])
12451      end
12452
12453      command('tabnext')
12454      if multigrid then
12455        screen:expect({
12456          grid = [[
12457          ## grid 1
12458            {9: }{10:2}{9:+ No Name] }{3: [No Name] }{9: }{10:3}{9:+ No Name] }{5:  }{9:X}|
12459            [6:----------------------------------------]|*5
12460            [3:----------------------------------------]|
12461          ## grid 2 (hidden)
12462                                               olleh|
12463            {0:                                       ~}|*4
12464          ## grid 3
12465                                                    |
12466          ## grid 4 (hidden)
12467            hello                                   |
12468            {0:~                                       }|*4
12469          ## grid 5 (hidden)
12470            {1:hello     }|
12471            {2:~         }|*4
12472          ## grid 6
12473            ^                                        |
12474            {0:~                                       }|*4
12475          ## grid 7 (hidden)
12476            {1:floaty mcfloatf}|
12477            {1:ace            }|
12478            {2:~              }|*3
12479          ]],
12480        })
12481      else
12482        screen:expect([[
12483          {9: }{10:2}{9:+ No Name] }{3: [No Name] }{9: }{10:3}{9:+ No Name] }{5:  }{9:X}|
12484          ^                                        |
12485          {0:~                                       }|*4
12486                                                  |
12487        ]])
12488      end
12489
12490      command('tabnext')
12491      if multigrid then
12492        screen:expect({
12493          grid = [[
12494          ## grid 1
12495            {9: }{10:2}{9:+ No Name]  [No Name] }{3: }{34:3}{3:+ No Name] }{5:  }{9:X}|
12496            [4:----------------------------------------]|*5
12497            [3:----------------------------------------]|
12498          ## grid 2 (hidden)
12499                                               olleh|
12500            {0:                                       ~}|*4
12501          ## grid 3
12502                                                    |
12503          ## grid 4
12504            ^hello                                   |
12505            {0:~                                       }|*4
12506          ## grid 5
12507            {1:hello     }|
12508            {2:~         }|*4
12509          ## grid 6 (hidden)
12510                                                    |
12511            {0:~                                       }|*4
12512          ## grid 7 (hidden)
12513            {1:floaty mcfloatf}|
12514            {1:ace            }|
12515            {2:~              }|*3
12516          ## grid 8
12517            {33:┌────┐}|
12518            {33:│}{1:lleh}{33:│}|
12519            {33:│}{1:   o}{33:│}|
12520            {33:│}{2:   ~}{33:│}|*2
12521            {33:└────┘}|
12522          ]],
12523          float_pos = {
12524            [5] = { 1002, 'NW', 4, 0, 0, true, 50, 1, 1, 0 },
12525            [8] = { 1005, 'NW', 4, 2, 7, true, 50, 2, 0, 7 },
12526          },
12527        })
12528      else
12529        screen:expect([[
12530          {9: }{10:2}{9:+ No }{33:┌────┐}{9: [No Name] }{3: }{34:3}{3:+ No Name] }{5:  }{9:X}|
12531          {1:^hello  }{33:│}{1:lleh}{33:│}                           |
12532          {2:~      }{33:│}{1:   o}{33:│}{0:                           }|
12533          {2:~      }{33:│}{2:   ~}{33:│}{0:                           }|*2
12534          {2:~      }{33:└────┘}{0:                           }|
12535                                                  |
12536        ]])
12537      end
12538
12539      -- Used relative=win on two floats relative to this window.
12540      -- Split it to the right to ensure both follow.
12541      command('topleft vsplit')
12542      if multigrid then
12543        screen:expect({
12544          grid = [[
12545          ## grid 1
12546            {9: }{10:2}{9:+ No Name]  [No Name] }{3: }{34:4}{3:+ No Name] }{5:  }{9:X}|
12547            [9:--------------------]{5:│}[4:-------------------]|*4
12548            {4:[No Name] [+]        }{5:[No Name] [+]      }|
12549            [3:----------------------------------------]|
12550          ## grid 2 (hidden)
12551                                               olleh|
12552            {0:                                       ~}|*4
12553          ## grid 3
12554                                                    |
12555          ## grid 4
12556            hello              |
12557            {0:~                  }|*3
12558          ## grid 5
12559            {1:hello     }|
12560            {2:~         }|*4
12561          ## grid 6 (hidden)
12562                                                    |
12563            {0:~                                       }|*4
12564          ## grid 7 (hidden)
12565            {1:floaty mcfloatf}|
12566            {1:ace            }|
12567            {2:~              }|*3
12568          ## grid 8
12569            {33:┌────┐}|
12570            {33:│}{1:lleh}{33:│}|
12571            {33:│}{1:   o}{33:│}|
12572            {33:│}{2:   ~}{33:│}|*2
12573            {33:└────┘}|
12574          ## grid 9
12575            ^hello               |
12576            {0:~                   }|*3
12577          ]],
12578          float_pos = {
12579            [5] = { 1002, 'NW', 4, 0, 0, true, 50, 1, 1, 21 },
12580            [8] = { 1005, 'NW', 4, 2, 7, true, 50, 2, 0, 28 },
12581          },
12582        })
12583      else
12584        screen:expect([[
12585          {9: }{10:2}{9:+ No Name]  [No Name] }{3: }{34:4}{3:+ }{33:┌────┐}{3:e] }{5:  }{9:X}|
12586          ^hello               {5:│}{1:hello  }{33:│}{1:lleh}{33:│}      |
12587          {0:~                   }{5:│}{2:~      }{33:│}{1:   o}{33:│}{0:      }|
12588          {0:~                   }{5:│}{2:~      }{33:│}{2:   ~}{33:│}{0:      }|*2
12589          {4:[No Name] [+]        }{2:~      }{33:└────┘}{5:      }|
12590                                                  |
12591        ]])
12592      end
12593    end)
12594  end
12595
12596  describe('with ext_multigrid and actual mouse grid', function()
12597    with_ext_multigrid(true, true)
12598  end)
12599
12600  describe('with ext_multigrid and mouse grid 0', function()
12601    with_ext_multigrid(true, false)
12602  end)
12603
12604  describe('without ext_multigrid', function()
12605    with_ext_multigrid(false, false)
12606  end)
12607end)