neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

float_spec.lua (465985B)


      1 local t = require('test.testutil')
      2 local n = require('test.functional.testnvim')()
      3 local Screen = require('test.functional.ui.screen')
      4 local os = require('os')
      5 
      6 local clear, feed = n.clear, n.feed
      7 local assert_alive = n.assert_alive
      8 local command, feed_command = n.command, n.feed_command
      9 local eval = n.eval
     10 local eq = t.eq
     11 local neq = t.neq
     12 local matches = t.matches
     13 local expect = n.expect
     14 local exec = n.exec
     15 local exec_lua = n.exec_lua
     16 local insert = n.insert
     17 local api = n.api
     18 local fn = n.fn
     19 local run = n.run
     20 local pcall_err = t.pcall_err
     21 local tbl_contains = vim.tbl_contains
     22 local curbuf = n.api.nvim_get_current_buf
     23 local curwin = n.api.nvim_get_current_win
     24 local curtab = n.api.nvim_get_current_tabpage
     25 local NIL = vim.NIL
     26 
     27 describe('float window', function()
     28  before_each(function()
     29    clear()
     30    command('hi VertSplit gui=reverse')
     31  end)
     32 
     33  it('behavior', function()
     34    -- Create three windows and test that ":wincmd <direction>" changes to the
     35    -- first window, if the previous window is invalid.
     36    command('split')
     37    api.nvim_open_win(0, true, { width = 10, height = 10, relative = 'editor', row = 0, col = 0 })
     38    eq(1002, fn.win_getid())
     39    eq('editor', api.nvim_win_get_config(1002).relative)
     40    command([[
     41      call nvim_win_close(1001, v:false)
     42      wincmd j
     43    ]])
     44    eq(1000, fn.win_getid())
     45  end)
     46 
     47  it('win_execute() should work', function()
     48    local buf = api.nvim_create_buf(false, false)
     49    api.nvim_buf_set_lines(buf, 0, -1, true, { 'the floatwin', 'abc', 'def' })
     50    local win = api.nvim_open_win(buf, false, { relative = 'win', width = 16, height = 1, row = 0, col = 10 })
     51    local line = fn.win_execute(win, 'echo getline(1)')
     52    eq('\nthe floatwin', line)
     53    eq('\n1', fn.win_execute(win, 'echo line(".",' .. win .. ')'))
     54    eq('\n3', fn.win_execute(win, 'echo line("$",' .. win .. ')'))
     55    eq('\n0', fn.win_execute(win, 'echo line("$", 123456)'))
     56    fn.win_execute(win, 'bwipe!')
     57  end)
     58 
     59  it("win_execute() call commands that are not allowed when 'hidden' is not set", function()
     60    command('set nohidden')
     61    local buf = api.nvim_create_buf(false, false)
     62    api.nvim_buf_set_lines(buf, 0, -1, true, { 'the floatwin' })
     63    local win = api.nvim_open_win(buf, true, { relative = 'win', width = 16, height = 1, row = 0, col = 10 })
     64    eq('Vim(close):E37: No write since last change (add ! to override)', pcall_err(fn.win_execute, win, 'close'))
     65    eq('Vim(bdelete):E89: No write since last change for buffer 2 (add ! to override)', pcall_err(fn.win_execute, win, 'bdelete'))
     66    fn.win_execute(win, 'bwipe!')
     67  end)
     68 
     69  it('closed immediately by autocmd #11383', function()
     70    eq(
     71      'Window was closed immediately',
     72      pcall_err(
     73        exec_lua,
     74        [[
     75        local api = vim.api
     76        local function crashes(contents)
     77          local buf = api.nvim_create_buf(false, true)
     78          local floatwin = api.nvim_open_win(buf, true, {
     79            relative = 'cursor';
     80            style = 'minimal';
     81            row = 0; col = 0;
     82            height = #contents;
     83            width = 10;
     84          })
     85          api.nvim_buf_set_lines(buf, 0, -1, true, contents)
     86          local winnr = vim.fn.win_id2win(floatwin)
     87          api.nvim_command('wincmd p')
     88          api.nvim_command('autocmd BufEnter * ++once '..winnr..'wincmd c')
     89          return buf, floatwin
     90        end
     91        crashes{'foo'}
     92        crashes{'bar'}
     93    ]]
     94      )
     95    )
     96    assert_alive()
     97  end)
     98 
     99  it('closed immediately by autocmd after win_enter #15548', function()
    100    eq(
    101      'Window was closed immediately',
    102      pcall_err(
    103        exec_lua,
    104        [[
    105        vim.cmd "autocmd BufLeave * ++once quit!"
    106        local buf = vim.api.nvim_create_buf(true, true)
    107        vim.api.nvim_open_win(buf, true, {
    108          relative = "win",
    109          row = 0, col = 0,
    110          width = 1, height = 1,
    111          noautocmd = false,
    112        })
    113    ]]
    114      )
    115    )
    116    assert_alive()
    117  end)
    118 
    119  it('open with WinNew autocmd', function()
    120    local new_triggered_before_enter, new_curwin, win = unpack(exec_lua([[
    121      local enter_triggered = false
    122      local new_triggered_before_enter = false
    123      local new_curwin
    124      local buf = vim.api.nvim_create_buf(true, true)
    125      vim.api.nvim_create_autocmd('WinEnter', {
    126        callback = function()
    127          enter_triggered = true
    128        end
    129      })
    130      vim.api.nvim_create_autocmd('WinNew', {
    131        callback = function()
    132          new_triggered_before_enter = not enter_triggered
    133          new_curwin = vim.api.nvim_get_current_win()
    134        end
    135      })
    136      local opts = { relative = "win", row = 0, col = 0, width = 1, height = 1, noautocmd = false }
    137      local win = vim.api.nvim_open_win(buf, true, opts)
    138      return {new_triggered_before_enter, new_curwin, win}
    139    ]]))
    140    eq(true, new_triggered_before_enter)
    141    eq(win, new_curwin)
    142  end)
    143 
    144  it('opened with correct height', function()
    145    local height = exec_lua([[
    146      vim.go.winheight = 20
    147      local bufnr = vim.api.nvim_create_buf(false, true)
    148      local opts = { height = 10, col = 5, row = 1, relative = 'editor', style = 'minimal', width = 15 }
    149      local win_id = vim.api.nvim_open_win(bufnr, true, opts)
    150      return vim.api.nvim_win_get_height(win_id)
    151    ]])
    152    eq(10, height)
    153  end)
    154 
    155  it('opened with correct width', function()
    156    local width = exec_lua([[
    157      vim.go.winwidth = 20
    158      local bufnr = vim.api.nvim_create_buf(false, true)
    159      local opts = { height = 10, col = 5, row = 1, relative = 'editor', style = 'minimal', width = 10 }
    160      local win_id = vim.api.nvim_open_win(bufnr, true, opts)
    161      return vim.api.nvim_win_get_width(win_id)
    162    ]])
    163    eq(10, width)
    164  end)
    165 
    166  it('opened with correct position', function()
    167    local pos = exec_lua([[
    168      local bufnr = vim.api.nvim_create_buf(false, true)
    169      local opts = { width = 10, height = 10, col = 7, row = 9, relative = 'editor', style = 'minimal' }
    170      local win_id = vim.api.nvim_open_win(bufnr, false, opts)
    171      return vim.api.nvim_win_get_position(win_id)
    172    ]])
    173    eq({ 9, 7 }, { pos[1], pos[2] })
    174  end)
    175 
    176  it('opened with correct position relative to the mouse', function()
    177    api.nvim_input_mouse('left', 'press', '', 0, 10, 10)
    178    local pos = exec_lua([[
    179      local bufnr = vim.api.nvim_create_buf(false, true)
    180      local opts = { width = 10, height = 10, col = 1, row = 2, relative = 'mouse', style = 'minimal' }
    181      local win_id = vim.api.nvim_open_win(bufnr, false, opts)
    182      return vim.api.nvim_win_get_position(win_id)
    183    ]])
    184    eq({ 12, 11 }, { pos[1], pos[2] })
    185  end)
    186 
    187  it('opened with correct position relative to the cursor', function()
    188    local pos = exec_lua([[
    189      local bufnr = vim.api.nvim_create_buf(false, true)
    190      local opts = { width = 10, height = 10, col = 7, row = 9, relative = 'cursor', style = 'minimal' }
    191      local win_id = vim.api.nvim_open_win(bufnr, false, opts)
    192      return vim.api.nvim_win_get_position(win_id)
    193    ]])
    194    eq({ 9, 7 }, { pos[1], pos[2] })
    195  end)
    196 
    197  it('opened with correct position relative to another window', function()
    198    local pos = exec_lua([[
    199      local bufnr = vim.api.nvim_create_buf(false, true)
    200      local par_opts = { width = 50, height = 50, col = 7, row = 9, relative = 'editor', style = 'minimal' }
    201      local par_win_id = vim.api.nvim_open_win(bufnr, false, par_opts)
    202      local opts = { width = 10, height = 10, col = 7, row = 9, relative = 'win', style = 'minimal', win = par_win_id }
    203      local win_id = vim.api.nvim_open_win(bufnr, false, opts)
    204      return vim.api.nvim_win_get_position(win_id)
    205    ]])
    206    eq({ 18, 14 }, { pos[1], pos[2] })
    207  end)
    208 
    209  it('opened with correct position relative to another relative window', function()
    210    local pos = exec_lua([[
    211      local bufnr = vim.api.nvim_create_buf(false, true)
    212      local root_opts = { width = 50, height = 50, col = 7, row = 9, relative = 'editor', style = 'minimal' }
    213      local root_win_id = vim.api.nvim_open_win(bufnr, false, root_opts)
    214      local par_opts = { width = 20, height = 20, col = 2, row = 3, relative = 'win', win = root_win_id, style = 'minimal' }
    215      local par_win_id = vim.api.nvim_open_win(bufnr, false, par_opts)
    216      local opts = { width = 10, height = 10, col = 3, row = 2, relative = 'win', win = par_win_id, style = 'minimal' }
    217      local win_id = vim.api.nvim_open_win(bufnr, false, opts)
    218      return vim.api.nvim_win_get_position(win_id)
    219    ]])
    220 
    221    eq({ 14, 12 }, { pos[1], pos[2] })
    222  end)
    223 
    224  it('error message when invalid field specified for split', function()
    225    local bufnr = api.nvim_create_buf(false, true)
    226    eq("non-float cannot have 'row'", pcall_err(api.nvim_open_win, bufnr, true, { split = 'right', row = 10 }))
    227    eq("non-float cannot have 'col'", pcall_err(api.nvim_open_win, bufnr, true, { split = 'right', col = 10 }))
    228    eq("non-float cannot have 'bufpos'", pcall_err(api.nvim_open_win, bufnr, true, { split = 'right', bufpos = { 0, 0 } }))
    229    local winid = api.nvim_open_win(bufnr, true, { split = 'right' })
    230    eq("non-float cannot have 'row'", pcall_err(api.nvim_win_set_config, winid, { split = 'right', row = 10 }))
    231    eq("non-float cannot have 'col'", pcall_err(api.nvim_win_set_config, winid, { split = 'right', col = 10 }))
    232    eq("non-float cannot have 'bufpos'", pcall_err(api.nvim_win_set_config, winid, { split = 'right', bufpos = { 0, 0 } }))
    233  end)
    234 
    235  it('error message when reconfig missing relative field', function()
    236    local bufnr = api.nvim_create_buf(false, true)
    237    local opts = { width = 10, height = 10, col = 5, row = 5, relative = 'editor', style = 'minimal' }
    238    local winid = api.nvim_open_win(bufnr, true, opts)
    239    eq(
    240      "Missing 'relative' field when reconfiguring floating window 1001",
    241      pcall_err(api.nvim_win_set_config, winid, { width = 3, height = 3, row = 10, col = 10 })
    242    )
    243  end)
    244 
    245  it('no error message when reconfig relative field on closed win', function()
    246    command('split')
    247    local winid = api.nvim_open_win(0, false, { relative = 'win', width = 1, height = 1, col = 1, row = 1 })
    248    eq(1001, api.nvim_win_get_config(winid).win)
    249    -- But unrelated config doesn't clear parent win #34286
    250    api.nvim_win_set_config(winid, { title = 'foo' })
    251    eq(1001, api.nvim_win_get_config(winid).win)
    252    command('close')
    253    api.nvim_win_set_config(winid, { title = 'bar' })
    254    api.nvim_win_set_config(winid, { relative = 'editor', row = 1, col = 1 })
    255    eq(nil, api.nvim_win_get_config(winid).win)
    256  end)
    257 
    258  it('is not operated on by windo when non-focusable #15374', function()
    259    command([[
    260      let winids = []
    261      windo call add(winids, win_getid())
    262    ]])
    263    local windo_count_before = eval('len(winids)')
    264    local winid = exec_lua([[
    265      local bufnr = vim.api.nvim_create_buf(false, true)
    266      local opts = { relative = 'editor', focusable = false, height = 5, width = 5, col = 5, row = 5 }
    267      return vim.api.nvim_open_win(bufnr, false, opts)
    268    ]])
    269    command([[
    270      let winids = []
    271      windo call add(winids, win_getid())
    272    ]])
    273    local windo_count_after = eval('len(winids)')
    274    eq(windo_count_before, windo_count_after)
    275    eq(false, tbl_contains(eval('winids'), winid))
    276  end)
    277 
    278  it('is operated on by windo when focusable', function()
    279    command([[
    280      let winids = []
    281      windo call add(winids, win_getid())
    282    ]])
    283    local windo_count_before = eval('len(winids)')
    284    local winid = exec_lua([[
    285      local bufnr = vim.api.nvim_create_buf(false, true)
    286      local opts = { relative = 'editor', focusable = true, height = 5, width = 5, col = 5, row = 5 }
    287      return vim.api.nvim_open_win(bufnr, false, opts)
    288    ]])
    289    command([[
    290      let winids = []
    291      windo call add(winids, win_getid())
    292    ]])
    293    local windo_count_after = eval('len(winids)')
    294    eq(windo_count_before + 1, windo_count_after)
    295    eq(true, tbl_contains(eval('winids'), winid))
    296  end)
    297 
    298  it('is not active after windo when non-focusable #15374', function()
    299    local winid = exec_lua([[
    300      local bufnr = vim.api.nvim_create_buf(false, true)
    301      local opts = { relative = 'editor', focusable = false, height = 5, width = 5, col = 5, row = 5 }
    302      return vim.api.nvim_open_win(bufnr, false, opts)
    303    ]])
    304    command('windo echo')
    305    neq(winid, eval('win_getid()'))
    306  end)
    307 
    308  it('is active after windo when focusable', function()
    309    local winid = exec_lua([[
    310      local bufnr = vim.api.nvim_create_buf(false, true)
    311      local opts = { relative = 'editor', focusable = true, height = 5, width = 5, col = 5, row = 5 }
    312      return vim.api.nvim_open_win(bufnr, false, opts)
    313    ]])
    314    command('windo echo')
    315    eq(winid, eval('win_getid()'))
    316  end)
    317 
    318  it('is not active after closing window when non-focusable #28454', function()
    319    command('copen')
    320    local winid = exec_lua([[
    321      local bufnr = vim.api.nvim_create_buf(false, true)
    322      local opts = { relative = 'editor', focusable = false, height = 5, width = 5, col = 5, row = 5 }
    323      return vim.api.nvim_open_win(bufnr, false, opts)
    324    ]])
    325    command('wincmd t')
    326    command('wincmd q')
    327    neq(winid, curwin())
    328  end)
    329 
    330  it('supports windo with focusable and non-focusable floats', function()
    331    local winids = exec_lua([[
    332      local result = {vim.api.nvim_get_current_win()}
    333      local bufnr = vim.api.nvim_create_buf(false, true)
    334      local opts = { relative = 'editor', focusable = false, height = 5, width = 5, col = 5, row = 5 }
    335      vim.api.nvim_open_win(bufnr, false, opts)
    336      opts.focusable = true
    337      table.insert(result, vim.api.nvim_open_win(bufnr, false, opts))
    338      opts.focusable = false
    339      vim.api.nvim_open_win(bufnr, false, opts)
    340      opts.focusable = true
    341      table.insert(result, vim.api.nvim_open_win(bufnr, false, opts))
    342      opts.focusable = false
    343      vim.api.nvim_open_win(bufnr, false, opts)
    344      return result
    345    ]])
    346    table.sort(winids)
    347    command([[
    348      let winids = []
    349      windo call add(winids, win_getid())
    350      call sort(winids)
    351    ]])
    352    eq(winids, eval('winids'))
    353  end)
    354 
    355  it('open does not trigger BufEnter #15300', function()
    356    local res = exec_lua [[
    357      local times = {}
    358      local buf = vim.api.nvim_create_buf(fasle, true)
    359      vim.api.nvim_create_autocmd('BufEnter', {
    360        callback = function(opt)
    361          if opt.buf == buf then
    362            times[#times + 1] = 1
    363          end
    364        end
    365      })
    366      local win_id
    367      local fconfig = { relative = 'editor', row = 10, col = 10, width = 10, height = 10 }
    368      --enter is false doesn't trigger
    369      win_id = vim.api.nvim_open_win(buf, false, fconfig)
    370      vim.api.nvim_win_close(win_id, true)
    371      times[#times + 1] = #times == 0 and true or nil
    372 
    373      --enter is true trigger
    374      win_id = vim.api.nvim_open_win(buf, true, fconfig)
    375      vim.api.nvim_win_close(win_id, true)
    376      times[#times + 1] = #times == 2 and true or nil
    377 
    378      --enter is true and fconfig.noautocmd is true doesn't trigger
    379      fconfig.noautocmd = true
    380      win_id = vim.api.nvim_open_win(buf, true, fconfig)
    381      vim.api.nvim_win_close(win_id, true)
    382      times[#times + 1] = #times == 2 and true or nil
    383 
    384      return times
    385    ]]
    386    eq({ true, 1, true }, res)
    387  end)
    388 
    389  it('no crash with bufpos and non-existent window', function()
    390    command('new')
    391    local closed_win = api.nvim_get_current_win()
    392    command('close')
    393    local buf = api.nvim_create_buf(false, false)
    394    eq(
    395      'Invalid window id: ' .. closed_win,
    396      pcall_err(api.nvim_open_win, buf, true, { relative = 'win', win = closed_win, width = 1, height = 1, bufpos = { 0, 0 } })
    397    )
    398    assert_alive()
    399  end)
    400 
    401  it("no segfault when setting minimal style after clearing local 'fillchars' #19510", function()
    402    local float_opts = { relative = 'editor', row = 1, col = 1, width = 1, height = 1 }
    403    local float_win = api.nvim_open_win(0, true, float_opts)
    404    api.nvim_set_option_value('fillchars', NIL, { win = float_win })
    405    float_opts.style = 'minimal'
    406    api.nvim_win_set_config(float_win, float_opts)
    407    assert_alive()
    408  end)
    409 
    410  it("should re-apply 'style' when present and not leak to normal windows", function()
    411    local buf = api.nvim_create_buf(true, false)
    412    local float_opts = { style = 'minimal', relative = 'editor', row = 1, col = 1, width = 1, height = 1 }
    413    local float_win = api.nvim_open_win(buf, true, float_opts)
    414    api.nvim_set_option_value('number', true, { win = float_win })
    415    float_opts.row = 2
    416    api.nvim_win_set_config(float_win, float_opts)
    417    eq(false, api.nvim_get_option_value('number', { win = float_win }))
    418    -- closing the float should not leak minimal style options to normal windows
    419    api.nvim_win_close(float_win, true)
    420    api.nvim_set_option_value('number', true, { win = 0 })
    421    command('bnext')
    422    eq(true, api.nvim_get_option_value('number', { win = 0 }))
    423  end)
    424 
    425  it("should not re-apply 'style' when missing", function()
    426    local float_opts = { style = 'minimal', relative = 'editor', row = 1, col = 1, width = 1, height = 1 }
    427    local float_win = api.nvim_open_win(0, true, float_opts)
    428    api.nvim_set_option_value('number', true, { win = float_win })
    429    float_opts.row = 2
    430    float_opts.style = nil
    431    api.nvim_win_set_config(float_win, float_opts)
    432    eq(true, api.nvim_get_option_value('number', { win = float_win }))
    433  end)
    434 
    435  it("'scroll' is computed correctly when opening float with splitkeep=screen #20684", function()
    436    api.nvim_set_option_value('splitkeep', 'screen', {})
    437    local float_opts = { relative = 'editor', row = 1, col = 1, width = 10, height = 10 }
    438    local float_win = api.nvim_open_win(0, true, float_opts)
    439    eq(5, api.nvim_get_option_value('scroll', { win = float_win }))
    440  end)
    441 
    442  it("lines('w$') after nvim_win_set_height with 'splitkeep=screen' #36056", function()
    443    api.nvim_set_option_value('splitkeep', 'screen', {})
    444    local buf = api.nvim_create_buf(false, true)
    445    local win = api.nvim_open_win(buf, false, { width = 5, height = 1, col = 0, row = 0, relative = 'cursor' })
    446    api.nvim_buf_set_lines(buf, 0, -1, true, { ('1'):rep(10), ('2'):rep(10) })
    447    local line = exec_lua(function()
    448      vim.api.nvim_win_set_height(win, vim.api.nvim_win_get_height(win) + 3)
    449      return vim.fn.line('w$', win)
    450    end)
    451    eq(2, line)
    452  end)
    453 
    454  it(':unhide works when there are floating windows', function()
    455    local float_opts = { relative = 'editor', row = 1, col = 1, width = 5, height = 5 }
    456    local w0 = curwin()
    457    api.nvim_open_win(0, false, float_opts)
    458    api.nvim_open_win(0, false, float_opts)
    459    eq(3, #api.nvim_list_wins())
    460    command('unhide')
    461    eq({ w0 }, api.nvim_list_wins())
    462  end)
    463 
    464  it(':all works when there are floating windows', function()
    465    command('args Xa.txt')
    466    local float_opts = { relative = 'editor', row = 1, col = 1, width = 5, height = 5 }
    467    local w0 = curwin()
    468    api.nvim_open_win(0, false, float_opts)
    469    api.nvim_open_win(0, false, float_opts)
    470    eq(3, #api.nvim_list_wins())
    471    command('all')
    472    eq({ w0 }, api.nvim_list_wins())
    473  end)
    474 
    475  it('win_splitmove() can move float into a split', function()
    476    command('split')
    477    eq({ 'col', { { 'leaf', 1001 }, { 'leaf', 1000 } } }, fn.winlayout())
    478 
    479    local win1 = api.nvim_open_win(0, true, { relative = 'editor', row = 1, col = 1, width = 5, height = 5 })
    480    fn.win_splitmove(win1, 1001, { vertical = true })
    481    eq({ 'col', { { 'row', { { 'leaf', win1 }, { 'leaf', 1001 } } }, { 'leaf', 1000 } } }, fn.winlayout())
    482    eq('', api.nvim_win_get_config(win1).relative)
    483 
    484    -- Should be unable to create a split relative to a float, though.
    485    local win2 = api.nvim_open_win(0, true, { relative = 'editor', row = 1, col = 1, width = 5, height = 5 })
    486    eq('Vim:E957: Invalid window number', pcall_err(fn.win_splitmove, win1, win2, { vertical = true }))
    487  end)
    488 
    489  it('tp_curwin updated if external window is moved into split', function()
    490    local _ = Screen.new(20, 7, { ext_multigrid = true })
    491 
    492    command('tabnew')
    493    local external_win = api.nvim_open_win(0, true, { external = true, width = 5, height = 5 })
    494    eq(external_win, api.nvim_get_current_win())
    495    eq(2, fn.tabpagenr())
    496    command('tabfirst')
    497    api.nvim_set_current_win(external_win)
    498    eq(external_win, api.nvim_get_current_win())
    499    eq(1, fn.tabpagenr())
    500 
    501    command('wincmd J')
    502    eq(external_win, api.nvim_get_current_win())
    503    eq(false, api.nvim_win_get_config(external_win).external)
    504    command('tabnext')
    505    eq(2, fn.tabpagenr())
    506    neq(external_win, api.nvim_get_current_win())
    507  end)
    508 
    509  it('no crash with relative="win" after %bdelete #30569', function()
    510    exec([[
    511      botright vsplit
    512      %bdelete
    513    ]])
    514    api.nvim_open_win(0, false, { relative = 'win', win = 0, row = 0, col = 5, width = 5, height = 5 })
    515    assert_alive()
    516  end)
    517 
    518  describe('with only one tabpage,', function()
    519    local float_opts = { relative = 'editor', row = 1, col = 1, width = 1, height = 1 }
    520    local old_buf, old_win
    521    before_each(function()
    522      insert('foo')
    523      old_buf = curbuf()
    524      old_win = curwin()
    525    end)
    526    describe('closing the last non-floating window gives E444', function()
    527      before_each(function()
    528        api.nvim_open_win(old_buf, true, float_opts)
    529      end)
    530      it('if called from non-floating window', function()
    531        api.nvim_set_current_win(old_win)
    532        eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, old_win, false))
    533        -- Start with many tab pages, but make autocommands from closing floats leave us with just
    534        -- one (where we're now the last window).
    535        command('tabnew | autocmd WinClosed * ++once tabonly')
    536        api.nvim_open_win(0, false, float_opts)
    537        eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, 0, true))
    538      end)
    539      it('if called from floating window', function()
    540        eq('Vim:E444: Cannot close last window', pcall_err(api.nvim_win_close, old_win, false))
    541      end)
    542    end)
    543    describe("deleting the last non-floating window's buffer", function()
    544      describe('leaves one window with an empty buffer when there is only one buffer', function()
    545        local same_buf_float
    546        before_each(function()
    547          same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
    548        end)
    549        after_each(function()
    550          eq(old_win, curwin())
    551          expect('')
    552          eq(1, #api.nvim_list_wins())
    553        end)
    554        it('if called from non-floating window', function()
    555          api.nvim_buf_delete(old_buf, { force = true })
    556        end)
    557        it('if called from floating window', function()
    558          api.nvim_set_current_win(same_buf_float)
    559          command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()')
    560          command('autocmd WinEnter * let g:win_enter = nvim_get_current_win()')
    561          api.nvim_buf_delete(old_buf, { force = true })
    562          eq(same_buf_float, eval('g:win_leave'))
    563          eq(old_win, eval('g:win_enter'))
    564        end)
    565      end)
    566      describe('closes other windows with that buffer when there are other buffers', function()
    567        local same_buf_float, other_buf, other_buf_float
    568        before_each(function()
    569          same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
    570          other_buf = api.nvim_create_buf(true, false)
    571          other_buf_float = api.nvim_open_win(other_buf, true, float_opts)
    572          insert('bar')
    573          api.nvim_set_current_win(old_win)
    574        end)
    575        after_each(function()
    576          eq(other_buf, curbuf())
    577          expect('bar')
    578          eq(2, #api.nvim_list_wins())
    579        end)
    580        it('if called from non-floating window', function()
    581          api.nvim_buf_delete(old_buf, { force = true })
    582          eq(old_win, curwin())
    583        end)
    584        it('if called from floating window with the same buffer', function()
    585          api.nvim_set_current_win(same_buf_float)
    586          command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()')
    587          command('autocmd WinEnter * let g:win_enter = nvim_get_current_win()')
    588          api.nvim_buf_delete(old_buf, { force = true })
    589          eq(same_buf_float, eval('g:win_leave'))
    590          eq(old_win, eval('g:win_enter'))
    591          eq(old_win, curwin())
    592        end)
    593        -- TODO: this case is too hard to deal with
    594        pending('if called from floating window with another buffer', function()
    595          api.nvim_set_current_win(other_buf_float)
    596          api.nvim_buf_delete(old_buf, { force = true })
    597        end)
    598      end)
    599      describe('creates an empty buffer when there is only one listed buffer', function()
    600        local same_buf_float, unlisted_buf_float
    601        before_each(function()
    602          same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
    603          local unlisted_buf = api.nvim_create_buf(true, false)
    604          unlisted_buf_float = api.nvim_open_win(unlisted_buf, true, float_opts)
    605          insert('unlisted')
    606          command('set nobuflisted')
    607          api.nvim_set_current_win(old_win)
    608        end)
    609        after_each(function()
    610          expect('')
    611          eq(2, #api.nvim_list_wins())
    612        end)
    613        it('if called from non-floating window', function()
    614          api.nvim_buf_delete(old_buf, { force = true })
    615          eq(old_win, curwin())
    616        end)
    617        it('if called from floating window with the same buffer', function()
    618          api.nvim_set_current_win(same_buf_float)
    619          command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()')
    620          command('autocmd WinEnter * let g:win_enter = nvim_get_current_win()')
    621          api.nvim_buf_delete(old_buf, { force = true })
    622          eq(same_buf_float, eval('g:win_leave'))
    623          eq(old_win, eval('g:win_enter'))
    624          eq(old_win, curwin())
    625        end)
    626        -- TODO: this case is too hard to deal with
    627        pending('if called from floating window with an unlisted buffer', function()
    628          api.nvim_set_current_win(unlisted_buf_float)
    629          api.nvim_buf_delete(old_buf, { force = true })
    630        end)
    631      end)
    632    end)
    633    describe('with splits, deleting the last listed buffer creates an empty buffer', function()
    634      describe('when a non-floating window has an unlisted buffer', function()
    635        local same_buf_float
    636        before_each(function()
    637          command('botright vnew')
    638          insert('unlisted')
    639          command('set nobuflisted')
    640          api.nvim_set_current_win(old_win)
    641          same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
    642        end)
    643        after_each(function()
    644          expect('')
    645          eq(2, #api.nvim_list_wins())
    646        end)
    647        it('if called from non-floating window with the deleted buffer', function()
    648          api.nvim_buf_delete(old_buf, { force = true })
    649          eq(old_win, curwin())
    650        end)
    651        it('if called from floating window with the deleted buffer', function()
    652          api.nvim_set_current_win(same_buf_float)
    653          api.nvim_buf_delete(old_buf, { force = true })
    654          eq(same_buf_float, curwin())
    655        end)
    656      end)
    657    end)
    658  end)
    659 
    660  describe('with multiple tabpages but only one listed buffer,', function()
    661    local float_opts = { relative = 'editor', row = 1, col = 1, width = 1, height = 1 }
    662    local unlisted_buf, old_buf, old_win
    663    before_each(function()
    664      insert('unlisted')
    665      command('set nobuflisted')
    666      unlisted_buf = curbuf()
    667      command('tabnew')
    668      insert('foo')
    669      old_buf = curbuf()
    670      old_win = curwin()
    671    end)
    672    describe('without splits, deleting the last listed buffer creates an empty buffer', function()
    673      local same_buf_float
    674      before_each(function()
    675        api.nvim_set_current_win(old_win)
    676        same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
    677      end)
    678      after_each(function()
    679        expect('')
    680        eq(2, #api.nvim_list_wins())
    681        eq(2, #api.nvim_list_tabpages())
    682      end)
    683      it('if called from non-floating window', function()
    684        api.nvim_buf_delete(old_buf, { force = true })
    685        eq(old_win, curwin())
    686      end)
    687      it('if called from non-floating window in another tabpage', function()
    688        command('tab split')
    689        eq(3, #api.nvim_list_tabpages())
    690        api.nvim_buf_delete(old_buf, { force = true })
    691      end)
    692      it('if called from floating window with the same buffer', function()
    693        api.nvim_set_current_win(same_buf_float)
    694        command('autocmd WinLeave * let g:win_leave = nvim_get_current_win()')
    695        command('autocmd WinEnter * let g:win_enter = nvim_get_current_win()')
    696        api.nvim_buf_delete(old_buf, { force = true })
    697        eq(same_buf_float, eval('g:win_leave'))
    698        eq(old_win, eval('g:win_enter'))
    699        eq(old_win, curwin())
    700      end)
    701    end)
    702    describe('with splits, deleting the last listed buffer creates an empty buffer', function()
    703      local same_buf_float
    704      before_each(function()
    705        command('botright vsplit')
    706        api.nvim_set_current_buf(unlisted_buf)
    707        api.nvim_set_current_win(old_win)
    708        same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
    709      end)
    710      after_each(function()
    711        expect('')
    712        eq(3, #api.nvim_list_wins())
    713        eq(2, #api.nvim_list_tabpages())
    714      end)
    715      it('if called from non-floating window with the deleted buffer', function()
    716        api.nvim_buf_delete(old_buf, { force = true })
    717        eq(old_win, curwin())
    718      end)
    719      it('if called from floating window with the deleted buffer', function()
    720        api.nvim_set_current_win(same_buf_float)
    721        api.nvim_buf_delete(old_buf, { force = true })
    722        eq(same_buf_float, curwin())
    723      end)
    724    end)
    725  end)
    726 
    727  describe('with multiple tabpages and multiple listed buffers,', function()
    728    local float_opts = { relative = 'editor', row = 1, col = 1, width = 1, height = 1 }
    729    local old_tabpage, old_buf, old_win
    730    before_each(function()
    731      old_tabpage = curtab()
    732      insert('oldtab')
    733      command('tabnew')
    734      old_buf = curbuf()
    735      old_win = curwin()
    736    end)
    737    describe('closing the last non-floating window', function()
    738      describe('closes the tabpage when all floating windows are closeable', function()
    739        local same_buf_float
    740        before_each(function()
    741          same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
    742        end)
    743        after_each(function()
    744          eq(old_tabpage, curtab())
    745          expect('oldtab')
    746          eq(1, #api.nvim_list_tabpages())
    747        end)
    748        it('if called from non-floating window', function()
    749          api.nvim_win_close(old_win, false)
    750        end)
    751        it('if called from floating window', function()
    752          api.nvim_set_current_win(same_buf_float)
    753          api.nvim_win_close(old_win, false)
    754        end)
    755      end)
    756      describe('gives E5601 when there are non-closeable floating windows', function()
    757        local other_buf_float
    758        before_each(function()
    759          command('set nohidden')
    760          local other_buf = api.nvim_create_buf(true, false)
    761          other_buf_float = api.nvim_open_win(other_buf, true, float_opts)
    762          insert('foo')
    763          api.nvim_set_current_win(old_win)
    764        end)
    765        it('if called from non-floating window', function()
    766          eq('Vim:E5601: Cannot close window, only floating window would remain', pcall_err(api.nvim_win_close, old_win, false))
    767        end)
    768        it('if called from floating window', function()
    769          api.nvim_set_current_win(other_buf_float)
    770          eq('Vim:E5601: Cannot close window, only floating window would remain', pcall_err(api.nvim_win_close, old_win, false))
    771        end)
    772      end)
    773    end)
    774    describe("deleting the last non-floating window's buffer", function()
    775      describe('closes the tabpage when all floating windows are closeable', function()
    776        local same_buf_float, other_buf, other_buf_float
    777        before_each(function()
    778          same_buf_float = api.nvim_open_win(old_buf, false, float_opts)
    779          other_buf = api.nvim_create_buf(true, false)
    780          other_buf_float = api.nvim_open_win(other_buf, true, float_opts)
    781          api.nvim_set_current_win(old_win)
    782        end)
    783        after_each(function()
    784          eq(old_tabpage, curtab())
    785          expect('oldtab')
    786          eq(1, #api.nvim_list_tabpages())
    787        end)
    788        it('if called from non-floating window', function()
    789          api.nvim_buf_delete(old_buf, { force = false })
    790        end)
    791        it('if called from floating window with the same buffer', function()
    792          api.nvim_set_current_win(same_buf_float)
    793          api.nvim_buf_delete(old_buf, { force = false })
    794        end)
    795        -- TODO: this case is too hard to deal with
    796        pending('if called from floating window with another buffer', function()
    797          api.nvim_set_current_win(other_buf_float)
    798          api.nvim_buf_delete(old_buf, { force = false })
    799        end)
    800      end)
    801      -- TODO: what to do when there are non-closeable floating windows?
    802    end)
    803  end)
    804 
    805  describe(':close on non-float with floating windows', function()
    806    -- XXX: it isn't really clear whether this should quit Nvim, as if the autocommand
    807    -- here is BufUnload then it does quit Nvim.
    808    -- But with BufWinLeave, this doesn't quit Nvim if there are no floating windows,
    809    -- so it shouldn't quit Nvim if there are floating windows.
    810    it('does not quit Nvim if BufWinLeave makes it the only non-float', function()
    811      exec([[
    812        let g:buf = bufnr()
    813        new
    814        let s:midwin = win_getid()
    815        new
    816        setlocal bufhidden=wipe
    817        call nvim_win_set_config(s:midwin,
    818              \ #{relative: 'editor', row: 5, col: 5, width: 5, height: 5})
    819        autocmd BufWinLeave * ++once exe g:buf .. 'bwipe!'
    820      ]])
    821      eq('Vim(close):E855: Autocommands caused command to abort', pcall_err(command, 'close'))
    822      assert_alive()
    823    end)
    824 
    825    it('does not crash if BufUnload makes it the only non-float in tabpage', function()
    826      exec([[
    827        tabnew
    828        let g:buf = bufnr()
    829        new
    830        let s:midwin = win_getid()
    831        new
    832        setlocal bufhidden=wipe
    833        call nvim_win_set_config(s:midwin,
    834              \ #{relative: 'editor', row: 5, col: 5, width: 5, height: 5})
    835        autocmd BufUnload * ++once exe g:buf .. 'bwipe!'
    836      ]])
    837      eq('Vim(close):E5601: Cannot close window, only floating window would remain', pcall_err(command, 'close'))
    838      assert_alive()
    839    end)
    840 
    841    describe('does not crash if WinClosed makes it the only non-float', function()
    842      before_each(function()
    843        exec([[
    844          let g:buf = bufnr()
    845          new
    846          setlocal bufhidden=wipe
    847          autocmd WinClosed * ++once exe g:buf .. 'bwipe!'
    848        ]])
    849      end)
    850 
    851      local opts = { relative = 'editor', row = 5, col = 5, width = 5, height = 5 }
    852      local floatwin
    853 
    854      describe('and there is a float window with the same buffer', function()
    855        before_each(function()
    856          floatwin = api.nvim_open_win(0, false, opts)
    857        end)
    858 
    859        it('with multiple tabpages', function()
    860          command('tabnew | tabprev')
    861          eq('Vim(close):E5601: Cannot close window, only floating window would remain', pcall_err(command, 'close'))
    862          api.nvim_win_close(floatwin, true)
    863          assert_alive()
    864        end)
    865 
    866        it('with only one tabpage', function()
    867          command('close')
    868          api.nvim_win_close(floatwin, true)
    869          assert_alive()
    870        end)
    871      end)
    872 
    873      describe('and there is a float with a different buffer', function()
    874        before_each(function()
    875          floatwin = api.nvim_open_win(api.nvim_create_buf(true, false), false, opts)
    876        end)
    877 
    878        it('with multiple tabpages', function()
    879          command('tabnew | tabprev')
    880          eq('Vim(close):E855: Autocommands caused command to abort', pcall_err(command, 'close'))
    881          assert_alive()
    882        end)
    883 
    884        it('with only one tabpage', function()
    885          eq('Vim(close):E855: Autocommands caused command to abort', pcall_err(command, 'close'))
    886          assert_alive()
    887        end)
    888      end)
    889    end)
    890 
    891    it('does not crash if WinClosed from floating window closes it', function()
    892      exec([[
    893        tabnew
    894        new
    895        let s:win = win_getid()
    896        call nvim_win_set_config(s:win,
    897              \ #{relative: 'editor', row: 5, col: 5, width: 5, height: 5})
    898        wincmd t
    899        exe $"autocmd WinClosed {s:win} 1close"
    900      ]])
    901      command('close')
    902      assert_alive()
    903    end)
    904  end)
    905 
    906  it('placed relative to tabline and laststatus', function()
    907    local screen = Screen.new(20, 10)
    908    screen:add_extra_attr_ids({ [100] = { bold = true, foreground = Screen.colors.Magenta } })
    909    command('set showtabline=1 laststatus=1')
    910    api.nvim_open_win(0, false, { relative = 'laststatus', border = 'single', anchor = 'SE', width = 5, height = 1, row = 0, col = 1000 })
    911    local tabwin = api.nvim_open_win(0, false, { relative = 'tabline', border = 'single', width = 5, height = 1, row = 0, col = 1000 })
    912    screen:expect([[
    913      ^             {2:┌─────┐}|
    914      {1:~            }{2:│}{4:     }{2:│}|
    915      {1:~            }{2:└─────┘}|
    916      {1:~                   }|*3
    917      {1:~            }{2:┌─────┐}|
    918      {1:~            }{2:│}{4:     }{2:│}|
    919      {1:~            }{2:└─────┘}|
    920                          |
    921    ]])
    922    command('tabnew | tabnext')
    923    screen:expect([[
    924      {5: }{100:3}{5:  Name] }{24: No Name]X}|
    925      ^             {2:┌─────┐}|
    926      {1:~            }{2:│}{4:     }{2:│}|
    927      {1:~            }{2:└─────┘}|
    928      {1:~                   }|*2
    929      {1:~            }{2:┌─────┐}|
    930      {1:~            }{2:│}{4:     }{2:│}|
    931      {1:~            }{2:└─────┘}|
    932                          |
    933    ]])
    934    command('vsplit')
    935    screen:expect([[
    936      {5: }{100:4}{5:  Name] }{24: No Name]X}|
    937      ^             {2:┌─────┐}|
    938      {1:~            }{2:│}{4:     }{2:│}|
    939      {1:~            }{2:└─────┘}|
    940      {1:~                 }{2:│}{1:~}|
    941      {1:~            }{2:┌─────┐}|
    942      {1:~            }{2:│}{4:     }{2:│}|
    943      {1:~            }{2:└─────┘}|
    944      {3:[No Name]          }{2:<}|
    945                          |
    946    ]])
    947    command('quit')
    948    api.nvim_win_set_config(tabwin, { relative = 'tabline', border = 'single', width = 5, height = 1, row = 1, col = 0 })
    949    screen:expect([[
    950      {5: }{100:3}{5:  Name] }{24: No Name]X}|
    951      ^                    |
    952      {2:┌─────┐}{1:             }|
    953      {2:│}{4:     }{2:│}{1:             }|
    954      {2:└─────┘}{1:             }|
    955      {1:~                   }|
    956      {1:~            }{2:┌─────┐}|
    957      {1:~            }{2:│}{4:     }{2:│}|
    958      {1:~            }{2:└─────┘}|
    959                          |
    960    ]])
    961    command('tabonly')
    962    screen:expect([[
    963      ^                    |
    964      {2:┌─────┐}{1:             }|
    965      {2:│}{4:     }{2:│}{1:             }|
    966      {2:└─────┘}{1:             }|
    967      {1:~                   }|*2
    968      {1:~            }{2:┌─────┐}|
    969      {1:~            }{2:│}{4:     }{2:│}|
    970      {1:~            }{2:└─────┘}|
    971                          |
    972    ]])
    973  end)
    974 
    975  it('non-visible/focusable are not assigned a window number', function()
    976    command('tabnew')
    977    local tp = api.nvim_get_current_tabpage()
    978    local split_win = api.nvim_get_current_win()
    979    local float_buf = api.nvim_create_buf(true, true)
    980    local win = api.nvim_open_win(float_buf, false, { relative = 'editor', width = 2, height = 2, row = 2, col = 2, focusable = false })
    981    api.nvim_open_win(0, false, { relative = 'editor', width = 2, height = 2, row = 2, col = 2, hide = true })
    982    api.nvim_open_win(0, false, { relative = 'editor', width = 2, height = 2, row = 2, col = 2 })
    983 
    984    eq(2, fn.winnr('$'))
    985    eq(0, fn.win_id2win(win))
    986    eq(0, fn.getwininfo(win)[1].winnr)
    987    eq({ 0, 0 }, fn.win_id2tabwin(win))
    988    eq(2, fn.tabpagewinnr(2, '$'))
    989    eq(0, fn.win_getid(3))
    990    eq(0, fn.win_getid(3, 2))
    991    eq(-1, fn.bufwinnr(float_buf))
    992    eq(win, fn.bufwinid(float_buf)) -- bufwinid unaffected.
    993    eq(nil, fn.winrestcmd():match('3resize'))
    994 
    995    -- Unless it is the current window.
    996    api.nvim_set_current_win(win)
    997    eq(3, fn.winnr('$'))
    998    eq(3, fn.winnr())
    999    eq(3, fn.win_id2win(win))
   1000    eq(3, fn.getwininfo(win)[1].winnr)
   1001    eq({ 2, 3 }, fn.win_id2tabwin(win))
   1002    eq(3, fn.tabpagewinnr(2, '$'))
   1003    eq(3, fn.tabpagewinnr(2))
   1004    eq(win, fn.win_getid(3))
   1005    eq(win, fn.win_getid(3, 2))
   1006    eq(3, fn.bufwinnr(float_buf))
   1007    matches('3resize', fn.winrestcmd())
   1008 
   1009    -- When switching tabpages it should still have a winnr, as it's current in the other tabpage.
   1010    command('tabfirst')
   1011    eq({ 2, 3 }, fn.win_id2tabwin(win))
   1012    eq(3, fn.getwininfo(win)[1].winnr)
   1013    eq(win, fn.win_getid(3, 2))
   1014    eq(3, fn.tabpagewinnr(2, '$'))
   1015    eq(3, fn.tabpagewinnr(2))
   1016 
   1017    -- ...but not if it's non-current in that tabpage.
   1018    api.nvim_tabpage_set_win(tp, split_win)
   1019    eq({ 0, 0 }, fn.win_id2tabwin(win))
   1020    eq(0, fn.getwininfo(win)[1].winnr)
   1021    eq(0, fn.win_getid(3, 2))
   1022    eq(2, fn.tabpagewinnr(2, '$'))
   1023    eq(1, fn.tabpagewinnr(2))
   1024  end)
   1025 
   1026  it('non-visible/focusable is not a valid previous window', function()
   1027    local win = api.nvim_open_win(0, true, { relative = 'editor', width = 2, height = 2, row = 2, col = 2, focusable = false })
   1028    command('wincmd p')
   1029    command('wincmd p')
   1030    neq(win, api.nvim_get_current_win())
   1031    api.nvim_win_set_config(win, { focusable = true, hide = true })
   1032    command('wincmd p')
   1033    neq(win, api.nvim_get_current_win())
   1034    api.nvim_win_set_config(win, { hide = false })
   1035    command('wincmd p')
   1036    eq(win, api.nvim_get_current_win())
   1037  end)
   1038 
   1039  it('no crash for unallocated relative window grid', function()
   1040    local win = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, height = 1, width = 1 })
   1041    exec_lua(function()
   1042      vim.api.nvim_create_autocmd('CmdwinEnter', {
   1043        callback = function()
   1044          vim.api.nvim_win_set_config(win, { relative = 'win', win = 0, row = 0, col = 0 })
   1045          vim.api.nvim__redraw({ flush = true })
   1046        end,
   1047      })
   1048    end)
   1049    feed('q:')
   1050    assert_alive()
   1051  end)
   1052 
   1053  it("no error for zero height with 'winminheight'", function()
   1054    local win = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, height = 1, width = 1 })
   1055    api.nvim_set_option_value('winminheight', 0, {})
   1056    api.nvim_win_set_height(win, 0)
   1057    api.nvim_win_set_config(win, api.nvim_win_get_config(win))
   1058  end)
   1059 
   1060  it(':fclose does not crash from nasty autocommands', function()
   1061    local w1 = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, width = 5, height = 5, zindex = 6 })
   1062    local w2 = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, width = 5, height = 5, zindex = 5 })
   1063    local w3 = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, width = 5, height = 5, zindex = 4 })
   1064    local w4 = api.nvim_open_win(0, true, { relative = 'editor', row = 0, col = 0, width = 5, height = 5, zindex = 3 })
   1065    exec_lua(function()
   1066      vim.api.nvim_create_autocmd('WinClosed', {
   1067        once = true,
   1068        callback = function()
   1069          vim.api.nvim_win_close(w2, true)
   1070        end,
   1071      })
   1072    end)
   1073    -- We close just the first three floats with highest zindex, so w4 remains open.
   1074    -- (despite w2 being closed early by the autocommand rather than directly by :fclose)
   1075    command('3fclose')
   1076    eq(false, api.nvim_win_is_valid(w1))
   1077    eq(false, api.nvim_win_is_valid(w2))
   1078    eq(false, api.nvim_win_is_valid(w3))
   1079    eq(true, api.nvim_win_is_valid(w4))
   1080 
   1081    -- Try switching tab pages and moving windows between tab pages via nvim_win_set_config.
   1082    -- Simplest if :fclose skips windows in non-current tabpages.
   1083    local w5 = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, width = 5, height = 5, zindex = 2 })
   1084    command('tabnew | tabprevious')
   1085    command('autocmd WinEnter * ++once tabnext')
   1086    eq(w4, api.nvim_get_current_win())
   1087    local tp1 = api.nvim_get_current_tabpage()
   1088    command('fclose!')
   1089    eq(false, api.nvim_win_is_valid(w4))
   1090    eq(true, api.nvim_win_is_valid(w5))
   1091    neq(tp1, api.nvim_get_current_tabpage())
   1092 
   1093    local w_tp2 = api.nvim_get_current_win()
   1094    api.nvim_set_current_tabpage(tp1)
   1095    local w6 = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, width = 5, height = 5, zindex = 1 })
   1096    exec_lua(function()
   1097      vim.api.nvim_create_autocmd('WinClosed', {
   1098        once = true,
   1099        callback = function()
   1100          vim.api.nvim_win_set_config(w6, { win = w_tp2, split = 'below' })
   1101        end,
   1102      })
   1103    end)
   1104    command('fclose!')
   1105    eq(false, api.nvim_win_is_valid(w5))
   1106    eq(true, api.nvim_win_is_valid(w6))
   1107    neq(tp1, api.nvim_win_get_tabpage(w6))
   1108  end)
   1109 
   1110  local function with_ext_multigrid(multigrid, send_mouse_grid)
   1111    local screen, attrs
   1112    before_each(function()
   1113      screen = Screen.new(40, 7, { ext_multigrid = multigrid })
   1114      attrs = {
   1115        [0] = { bold = true, foreground = Screen.colors.Blue },
   1116        [1] = { background = Screen.colors.LightMagenta },
   1117        [2] = { background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1 },
   1118        [3] = { bold = true },
   1119        [4] = { bold = true, reverse = true },
   1120        [5] = { reverse = true },
   1121        [6] = { background = Screen.colors.LightMagenta, bold = true, reverse = true },
   1122        [7] = { foreground = Screen.colors.White, background = Screen.colors.Red },
   1123        [8] = { bold = true, foreground = Screen.colors.SeaGreen4 },
   1124        [9] = { background = Screen.colors.LightGrey, underline = true },
   1125        [10] = { background = Screen.colors.LightGrey, underline = true, bold = true, foreground = Screen.colors.Magenta },
   1126        [11] = { bold = true, foreground = Screen.colors.Magenta },
   1127        [12] = { background = Screen.colors.Red, bold = true, foreground = Screen.colors.Blue1 },
   1128        [13] = { background = Screen.colors.WebGray },
   1129        [14] = { foreground = Screen.colors.Brown },
   1130        [15] = { background = Screen.colors.Grey20 },
   1131        [16] = { background = Screen.colors.Grey20, bold = true, foreground = Screen.colors.Blue1 },
   1132        [17] = { background = Screen.colors.Yellow },
   1133        [18] = { foreground = Screen.colors.Brown, background = Screen.colors.Grey20 },
   1134        [19] = { foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray },
   1135        [20] = { bold = true, foreground = Screen.colors.Brown },
   1136        [21] = { background = Screen.colors.Gray90 },
   1137        [22] = { background = Screen.colors.LightRed },
   1138        [23] = { foreground = Screen.colors.Black, background = Screen.colors.White },
   1139        [24] = { foreground = Screen.colors.Black, background = Screen.colors.Grey80 },
   1140        [25] = { blend = 100, background = Screen.colors.Gray0 },
   1141        [26] = { blend = 80, background = Screen.colors.Gray0 },
   1142        [27] = { foreground = Screen.colors.Black, background = Screen.colors.LightGrey },
   1143        [28] = { foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey },
   1144        [29] = { background = Screen.colors.Yellow1, foreground = Screen.colors.Blue4 },
   1145        [30] = { background = Screen.colors.Grey, foreground = Screen.colors.Blue4, bold = true },
   1146        [31] = { foreground = Screen.colors.Grey0 },
   1147        [32] = { background = Screen.colors.LightMagenta, foreground = Screen.colors.Brown },
   1148      }
   1149      screen:set_default_attr_ids(attrs)
   1150    end)
   1151 
   1152    it('can be created and reconfigured', function()
   1153      local buf = api.nvim_create_buf(false, false)
   1154      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
   1155      local expected_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } }
   1156 
   1157      if multigrid then
   1158        screen:expect {
   1159          grid = [[
   1160        ## grid 1
   1161          [2:----------------------------------------]|*6
   1162          [3:----------------------------------------]|
   1163        ## grid 2
   1164          ^                                        |
   1165          {0:~                                       }|*5
   1166        ## grid 3
   1167                                                  |
   1168        ## grid 4
   1169          {1:                    }|
   1170          {2:~                   }|
   1171        ]],
   1172          float_pos = expected_pos,
   1173        }
   1174      else
   1175        screen:expect([[
   1176          ^                                        |
   1177          {0:~                                       }|
   1178          {0:~    }{1:                    }{0:               }|
   1179          {0:~    }{2:~                   }{0:               }|
   1180          {0:~                                       }|*2
   1181                                                  |
   1182          ]])
   1183      end
   1184 
   1185      api.nvim_win_set_config(win, { relative = 'editor', row = 0, col = 10 })
   1186      expected_pos[4][4] = 0
   1187      expected_pos[4][5] = 10
   1188      expected_pos[4][9] = 0
   1189      expected_pos[4][10] = 10
   1190      if multigrid then
   1191        screen:expect {
   1192          grid = [[
   1193        ## grid 1
   1194          [2:----------------------------------------]|*6
   1195          [3:----------------------------------------]|
   1196        ## grid 2
   1197          ^                                        |
   1198          {0:~                                       }|*5
   1199        ## grid 3
   1200                                                  |
   1201        ## grid 4
   1202          {1:                    }|
   1203          {2:~                   }|
   1204        ]],
   1205          float_pos = expected_pos,
   1206        }
   1207      else
   1208        screen:expect([[
   1209          ^          {1:                    }          |
   1210          {0:~         }{2:~                   }{0:          }|
   1211          {0:~                                       }|*4
   1212                                                  |
   1213        ]])
   1214      end
   1215 
   1216      api.nvim_win_close(win, false)
   1217      if multigrid then
   1218        screen:expect([[
   1219        ## grid 1
   1220          [2:----------------------------------------]|*6
   1221          [3:----------------------------------------]|
   1222        ## grid 2
   1223          ^                                        |
   1224          {0:~                                       }|*5
   1225        ## grid 3
   1226                                                  |
   1227        ]])
   1228      else
   1229        screen:expect([[
   1230          ^                                        |
   1231          {0:~                                       }|*5
   1232                                                  |
   1233        ]])
   1234      end
   1235    end)
   1236 
   1237    it('window position fixed', function()
   1238      command('rightbelow 20vsplit')
   1239      local buf = api.nvim_create_buf(false, false)
   1240      local win = api.nvim_open_win(buf, false, {
   1241        relative = 'win',
   1242        width = 15,
   1243        height = 2,
   1244        row = 2,
   1245        col = 10,
   1246        anchor = 'NW',
   1247        fixed = true,
   1248      })
   1249 
   1250      if multigrid then
   1251        screen:expect {
   1252          grid = [[
   1253        ## grid 1
   1254          [2:-------------------]{5:│}[4:--------------------]|*5
   1255          {5:[No Name]           }{4:[No Name]           }|
   1256          [3:----------------------------------------]|
   1257        ## grid 2
   1258                             |
   1259          {0:~                  }|*4
   1260        ## grid 3
   1261                                                  |
   1262        ## grid 4
   1263          ^                    |
   1264          {0:~                   }|*4
   1265        ## grid 5
   1266          {1:               }|
   1267          {2:~              }|
   1268        ]],
   1269          float_pos = { [5] = { 1002, 'NW', 4, 2, 10, true, 50, 1, 2, 30 } },
   1270        }
   1271      else
   1272        screen:expect([[
   1273                             {5:}^                    |
   1274          {0:~                  }{5:}{0:~                   }|
   1275          {0:~                  }{5:}{0:~         }{1:          }|
   1276          {0:~                  }{5:}{0:~         }{2:~         }|
   1277          {0:~                  }{5:}{0:~                   }|
   1278          {5:[No Name]           }{4:[No Name]           }|
   1279                                                  |
   1280        ]])
   1281      end
   1282 
   1283      api.nvim_win_set_config(win, { fixed = false })
   1284 
   1285      if multigrid then
   1286        screen:expect {
   1287          grid = [[
   1288        ## grid 1
   1289          [2:-------------------]{5:│}[4:--------------------]|*5
   1290          {5:[No Name]           }{4:[No Name]           }|
   1291          [3:----------------------------------------]|
   1292        ## grid 2
   1293                             |
   1294          {0:~                  }|*4
   1295        ## grid 3
   1296                                                  |
   1297        ## grid 4
   1298          ^                    |
   1299          {0:~                   }|*4
   1300        ## grid 5
   1301          {1:               }|
   1302          {2:~              }|
   1303        ]],
   1304          float_pos = { [5] = { 1002, 'NW', 4, 2, 10, true, 50, 1, 2, 25 } },
   1305        }
   1306      else
   1307        screen:expect([[
   1308                             {5:}^                    |
   1309          {0:~                  }{5:}{0:~                   }|
   1310          {0:~                  }{5:}{0:~    }{1:               }|
   1311          {0:~                  }{5:}{0:~    }{2:~              }|
   1312          {0:~                  }{5:}{0:~                   }|
   1313          {5:[No Name]           }{4:[No Name]           }|
   1314                                                  |
   1315        ]])
   1316      end
   1317    end)
   1318 
   1319    it('draws correctly with redrawdebug=compositor', function()
   1320      -- NB: we do not test that it produces the "correct" debug info
   1321      -- (as it is intermediate only, and is allowed to change by internal
   1322      -- refactors). Only check that it doesn't cause permanent glitches,
   1323      -- or something.
   1324      command('set redrawdebug=compositor')
   1325      command('set wd=1')
   1326      local buf = api.nvim_create_buf(false, false)
   1327      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
   1328      local expected_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } }
   1329 
   1330      if multigrid then
   1331        screen:expect {
   1332          grid = [[
   1333        ## grid 1
   1334          [2:----------------------------------------]|*6
   1335          [3:----------------------------------------]|
   1336        ## grid 2
   1337          ^                                        |
   1338          {0:~                                       }|*5
   1339        ## grid 3
   1340                                                  |
   1341        ## grid 4
   1342          {1:                    }|
   1343          {2:~                   }|
   1344        ]],
   1345          float_pos = expected_pos,
   1346        }
   1347      else
   1348        screen:expect([[
   1349          ^                                        |
   1350          {0:~                                       }|
   1351          {0:~    }{1:                    }{0:               }|
   1352          {0:~    }{2:~                   }{0:               }|
   1353          {0:~                                       }|*2
   1354                                                  |
   1355          ]])
   1356      end
   1357 
   1358      api.nvim_win_set_config(win, { relative = 'editor', row = 0, col = 10 })
   1359      expected_pos[4][4] = 0
   1360      expected_pos[4][5] = 10
   1361      expected_pos[4][9] = 0
   1362      expected_pos[4][10] = 10
   1363      if multigrid then
   1364        screen:expect {
   1365          grid = [[
   1366        ## grid 1
   1367          [2:----------------------------------------]|*6
   1368          [3:----------------------------------------]|
   1369        ## grid 2
   1370          ^                                        |
   1371          {0:~                                       }|*5
   1372        ## grid 3
   1373                                                  |
   1374        ## grid 4
   1375          {1:                    }|
   1376          {2:~                   }|
   1377        ]],
   1378          float_pos = expected_pos,
   1379        }
   1380      else
   1381        screen:expect([[
   1382          ^          {1:                    }          |
   1383          {0:~         }{2:~                   }{0:          }|
   1384          {0:~                                       }|*4
   1385                                                  |
   1386        ]])
   1387      end
   1388 
   1389      api.nvim_win_close(win, false)
   1390      if multigrid then
   1391        screen:expect([[
   1392        ## grid 1
   1393          [2:----------------------------------------]|*6
   1394          [3:----------------------------------------]|
   1395        ## grid 2
   1396          ^                                        |
   1397          {0:~                                       }|*5
   1398        ## grid 3
   1399                                                  |
   1400        ]])
   1401      else
   1402        screen:expect([[
   1403          ^                                        |
   1404          {0:~                                       }|*5
   1405                                                  |
   1406        ]])
   1407      end
   1408    end)
   1409 
   1410    it('return their configuration', function()
   1411      local buf = api.nvim_create_buf(false, false)
   1412      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 3, col = 5, zindex = 60 })
   1413      local expected = {
   1414        anchor = 'NW',
   1415        border = 'none',
   1416        col = 5,
   1417        external = false,
   1418        focusable = true,
   1419        mouse = true,
   1420        height = 2,
   1421        relative = 'editor',
   1422        row = 3,
   1423        width = 20,
   1424        zindex = 60,
   1425        hide = false,
   1426      }
   1427      eq(expected, api.nvim_win_get_config(win))
   1428      eq(
   1429        true,
   1430        exec_lua(
   1431          [[
   1432        local expected, win = ...
   1433        local actual = vim.api.nvim_win_get_config(win)
   1434        for k,v in pairs(expected) do
   1435          if v ~= actual[k] then
   1436            error(k)
   1437          end
   1438        end
   1439        return true]],
   1440          expected,
   1441          win
   1442        )
   1443      )
   1444 
   1445      eq(
   1446        { external = false, focusable = true, mouse = true, hide = false, relative = '', split = 'left', width = 40, height = 6 },
   1447        api.nvim_win_get_config(0)
   1448      )
   1449 
   1450      if multigrid then
   1451        api.nvim_win_set_config(win, { external = true, width = 10, height = 1 })
   1452        eq(
   1453          { external = true, focusable = true, mouse = true, width = 10, height = 1, relative = '', hide = false, border = 'none' },
   1454          api.nvim_win_get_config(win)
   1455        )
   1456      end
   1457    end)
   1458 
   1459    it('defaults to NormalFloat highlight and inherited options', function()
   1460      command('set number')
   1461      command('hi NormalFloat guibg=#333333 guifg=NONE')
   1462      feed('ix<cr>y<cr><esc>gg')
   1463      local win = api.nvim_open_win(0, false, { relative = 'editor', width = 20, height = 4, row = 4, col = 10 })
   1464      if multigrid then
   1465        screen:expect {
   1466          grid = [[
   1467        ## grid 1
   1468          [2:----------------------------------------]|*6
   1469          [3:----------------------------------------]|
   1470        ## grid 2
   1471          {14:  1 }^x                                   |
   1472          {14:  2 }y                                   |
   1473          {14:  3 }                                    |
   1474          {0:~                                       }|*3
   1475        ## grid 3
   1476                                                  |
   1477        ## grid 4
   1478          {18:  1 }{15:x               }|
   1479          {18:  2 }{15:y               }|
   1480          {18:  3 }{15:                }|
   1481          {16:~                   }|
   1482        ]],
   1483          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
   1484        }
   1485      else
   1486        screen:expect([[
   1487          {14:  1 }^x                                   |
   1488          {14:  2 }y                                   |
   1489          {14:  3 }      {18:  1 }{15:x               }          |
   1490          {0:~         }{18:  2 }{15:y               }{0:          }|
   1491          {0:~         }{18:  3 }{15:                }{0:          }|
   1492          {0:~         }{16:~                   }{0:          }|
   1493                                                  |
   1494        ]])
   1495      end
   1496 
   1497      local buf = api.nvim_create_buf(false, true)
   1498      api.nvim_win_set_buf(win, buf)
   1499      if multigrid then
   1500        screen:expect {
   1501          grid = [[
   1502        ## grid 1
   1503          [2:----------------------------------------]|*6
   1504          [3:----------------------------------------]|
   1505        ## grid 2
   1506          {14:  1 }^x                                   |
   1507          {14:  2 }y                                   |
   1508          {14:  3 }                                    |
   1509          {0:~                                       }|*3
   1510        ## grid 3
   1511                                                  |
   1512        ## grid 4
   1513          {18:  1 }{15:                }|
   1514          {16:~                   }|*3
   1515        ]],
   1516          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
   1517        }
   1518      else
   1519        screen:expect([[
   1520          {14:  1 }^x                                   |
   1521          {14:  2 }y                                   |
   1522          {14:  3 }      {18:  1 }{15:                }          |
   1523          {0:~         }{16:~                   }{0:          }|*3
   1524                                                  |
   1525        ]])
   1526      end
   1527 
   1528      --
   1529      -- floating windows inherit NormalFloat from global-ns.
   1530      --
   1531      command('fclose')
   1532      command('hi NormalFloat guibg=LightRed')
   1533      api.nvim_open_win(0, false, { relative = 'win', row = 3, col = 3, width = 12, height = 3, style = 'minimal' })
   1534      api.nvim_set_hl_ns(api.nvim_create_namespace('test1'))
   1535      if multigrid then
   1536        screen:expect({
   1537          grid = [[
   1538          ## grid 1
   1539            [2:----------------------------------------]|*6
   1540            [3:----------------------------------------]|
   1541          ## grid 2
   1542            {14:  1 }^x                                   |
   1543            {14:  2 }y                                   |
   1544            {14:  3 }                                    |
   1545            {0:~                                       }|*3
   1546          ## grid 3
   1547                                                    |
   1548          ## grid 5
   1549            {22:x           }|
   1550            {22:y           }|
   1551            {22:            }|
   1552          ]],
   1553          float_pos = { [5] = { 1002, 'NW', 2, 3, 3, true, 50, 1, 3, 3 } },
   1554          win_viewport = {
   1555            [2] = { win = 1000, topline = 0, botline = 4, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
   1556            [5] = { win = 1002, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
   1557          },
   1558          win_viewport_margins = {
   1559            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
   1560            [5] = { bottom = 0, left = 0, right = 0, top = 0, win = 1002 },
   1561          },
   1562        })
   1563      else
   1564        screen:expect({
   1565          grid = [[
   1566            {14:  1 }^x                                   |
   1567            {14:  2 }y                                   |
   1568            {14:  3 }                                    |
   1569            {0:~  }{22:x           }{0:                         }|
   1570            {0:~  }{22:y           }{0:                         }|
   1571            {0:~  }{22:            }{0:                         }|
   1572                                                    |
   1573          ]],
   1574        })
   1575      end
   1576    end)
   1577 
   1578    it("can use 'minimal' style", function()
   1579      command('set number')
   1580      command('set signcolumn=yes')
   1581      command('set colorcolumn=1')
   1582      command('set cursorline')
   1583      command('set foldcolumn=1')
   1584      command('hi NormalFloat guibg=#333333 guifg=NONE')
   1585      feed('ix<cr>y<cr><esc>gg')
   1586      local win = api.nvim_open_win(0, false, { relative = 'editor', width = 20, height = 4, row = 4, col = 10, style = 'minimal' })
   1587      if multigrid then
   1588        screen:expect {
   1589          grid = [[
   1590        ## grid 1
   1591          [2:----------------------------------------]|*6
   1592          [3:----------------------------------------]|
   1593        ## grid 2
   1594          {19:   }{20:  1 }{22:^x}{21:                                }|
   1595          {19:   }{14:  2 }{22:y}                                |
   1596          {19:   }{14:  3 }{22: }                                |
   1597          {0:~                                       }|*3
   1598        ## grid 3
   1599                                                  |
   1600        ## grid 4
   1601          {15:x                   }|
   1602          {15:y                   }|
   1603          {15:                    }|*2
   1604        ]],
   1605          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
   1606        }
   1607      else
   1608        screen:expect {
   1609          grid = [[
   1610          {19:   }{20:  1 }{22:^x}{21:                                }|
   1611          {19:   }{14:  2 }{22:y}                                |
   1612          {19:   }{14:  3 }{22: }  {15:x                   }          |
   1613          {0:~         }{15:y                   }{0:          }|
   1614          {0:~         }{15:                    }{0:          }|*2
   1615                                                  |
   1616        ]],
   1617        }
   1618      end
   1619 
   1620      --  signcolumn=yes still works if there actually are signs
   1621      command('sign define piet1 text=𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄ texthl=Search')
   1622      command('sign place 1 line=1 name=piet1 buffer=1')
   1623      if multigrid then
   1624        screen:expect {
   1625          grid = [[
   1626        ## grid 1
   1627          [2:----------------------------------------]|*6
   1628          [3:----------------------------------------]|
   1629        ## grid 2
   1630          {19: }{29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{20:  1 }{22:^x}{21:                                }|
   1631          {19:   }{14:  2 }{22:y}                                |
   1632          {19:   }{14:  3 }{22: }                                |
   1633          {0:~                                       }|*3
   1634        ## grid 3
   1635                                                  |
   1636        ## grid 4
   1637          {29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{15:x                 }|
   1638          {19:  }{15:y                 }|
   1639          {19:  }{15:                  }|
   1640          {15:                    }|
   1641        ]],
   1642          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
   1643        }
   1644      else
   1645        screen:expect([[
   1646          {19: }{29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{20:  1 }{22:^x}{21:                                }|
   1647          {19:   }{14:  2 }{22:y}                                |
   1648          {19:   }{14:  3 }{22: }  {29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{15:x                 }          |
   1649          {0:~         }{19:  }{15:y                 }{0:          }|
   1650          {0:~         }{19:  }{15:                  }{0:          }|
   1651          {0:~         }{15:                    }{0:          }|
   1652                                                  |
   1653        ]])
   1654      end
   1655      command('sign unplace 1 buffer=1')
   1656 
   1657      local buf = api.nvim_create_buf(false, true)
   1658      api.nvim_win_set_buf(win, buf)
   1659      if multigrid then
   1660        screen:expect {
   1661          grid = [[
   1662        ## grid 1
   1663          [2:----------------------------------------]|*6
   1664          [3:----------------------------------------]|
   1665        ## grid 2
   1666          {19:   }{20:  1 }{22:^x}{21:                                }|
   1667          {19:   }{14:  2 }{22:y}                                |
   1668          {19:   }{14:  3 }{22: }                                |
   1669          {0:~                                       }|*3
   1670        ## grid 3
   1671                                                  |
   1672        ## grid 4
   1673          {15:                    }|*4
   1674        ]],
   1675          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
   1676        }
   1677      else
   1678        screen:expect([[
   1679          {19:   }{20:  1 }{22:^x}{21:                                }|
   1680          {19:   }{14:  2 }{22:y}                                |
   1681          {19:   }{14:  3 }{22: }  {15:                    }          |
   1682          {0:~         }{15:                    }{0:          }|*3
   1683                                                  |
   1684        ]])
   1685      end
   1686    end)
   1687 
   1688    it("would not break 'minimal' style with signcolumn=auto:[min]-[max]", function()
   1689      command('set number')
   1690      command('set signcolumn=auto:1-3')
   1691      command('set colorcolumn=1')
   1692      command('set cursorline')
   1693      command('set foldcolumn=1')
   1694      command('hi NormalFloat guibg=#333333 guifg=NONE')
   1695      feed('ix<cr>y<cr><esc>gg')
   1696      local win = api.nvim_open_win(0, false, { relative = 'editor', width = 20, height = 4, row = 4, col = 10, style = 'minimal' })
   1697      if multigrid then
   1698        screen:expect {
   1699          grid = [[
   1700        ## grid 1
   1701          [2:----------------------------------------]|*6
   1702          [3:----------------------------------------]|
   1703        ## grid 2
   1704          {19:   }{20:  1 }{22:^x}{21:                                }|
   1705          {19:   }{14:  2 }{22:y}                                |
   1706          {19:   }{14:  3 }{22: }                                |
   1707          {0:~                                       }|*3
   1708        ## grid 3
   1709                                                  |
   1710        ## grid 4
   1711          {15:x                   }|
   1712          {15:y                   }|
   1713          {15:                    }|*2
   1714        ]],
   1715          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
   1716        }
   1717      else
   1718        screen:expect {
   1719          grid = [[
   1720          {19:   }{20:  1 }{22:^x}{21:                                }|
   1721          {19:   }{14:  2 }{22:y}                                |
   1722          {19:   }{14:  3 }{22: }  {15:x                   }          |
   1723          {0:~         }{15:y                   }{0:          }|
   1724          {0:~         }{15:                    }{0:          }|*2
   1725                                                  |
   1726        ]],
   1727        }
   1728      end
   1729 
   1730      command('sign define piet1 text=𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄ texthl=Search')
   1731      command('sign place 1 line=1 name=piet1 buffer=1')
   1732      --  signcolumn=auto:1-3 still works if there actually are signs
   1733      if multigrid then
   1734        screen:expect {
   1735          grid = [[
   1736        ## grid 1
   1737          [2:----------------------------------------]|*6
   1738          [3:----------------------------------------]|
   1739        ## grid 2
   1740          {19: }{29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{20:  1 }{22:^x}{21:                                }|
   1741          {19:   }{14:  2 }{22:y}                                |
   1742          {19:   }{14:  3 }{22: }                                |
   1743          {0:~                                       }|*3
   1744        ## grid 3
   1745                                                  |
   1746        ## grid 4
   1747          {29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{15:x                 }|
   1748          {19:  }{15:y                 }|
   1749          {19:  }{15:                  }|
   1750          {15:                    }|
   1751        ]],
   1752          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
   1753        }
   1754      else
   1755        screen:expect([[
   1756          {19: }{29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{20:  1 }{22:^x}{21:                                }|
   1757          {19:   }{14:  2 }{22:y}                                |
   1758          {19:   }{14:  3 }{22: }  {29:𐌢̀́̂̃̅̄𐌢̀́̂̃̅̄}{15:x                 }          |
   1759          {0:~         }{19:  }{15:y                 }{0:          }|
   1760          {0:~         }{19:  }{15:                  }{0:          }|
   1761          {0:~         }{15:                    }{0:          }|
   1762                                                  |
   1763        ]])
   1764      end
   1765      command('sign unplace 1 buffer=1')
   1766 
   1767      local buf = api.nvim_create_buf(false, true)
   1768      api.nvim_win_set_buf(win, buf)
   1769      if multigrid then
   1770        screen:expect {
   1771          grid = [[
   1772        ## grid 1
   1773          [2:----------------------------------------]|*6
   1774          [3:----------------------------------------]|
   1775        ## grid 2
   1776          {19:   }{20:  1 }{22:^x}{21:                                }|
   1777          {19:   }{14:  2 }{22:y}                                |
   1778          {19:   }{14:  3 }{22: }                                |
   1779          {0:~                                       }|*3
   1780        ## grid 3
   1781                                                  |
   1782        ## grid 4
   1783          {15:                    }|*4
   1784        ]],
   1785          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
   1786        }
   1787      else
   1788        screen:expect([[
   1789          {19:   }{20:  1 }{22:^x}{21:                                }|
   1790          {19:   }{14:  2 }{22:y}                                |
   1791          {19:   }{14:  3 }{22: }  {15:                    }          |
   1792          {0:~         }{15:                    }{0:          }|*3
   1793                                                  |
   1794        ]])
   1795      end
   1796    end)
   1797 
   1798    it("would not break 'minimal' style with statuscolumn set", function()
   1799      command('set number')
   1800      command('set signcolumn=yes')
   1801      command('set colorcolumn=1')
   1802      command('set cursorline')
   1803      command('set foldcolumn=1')
   1804      command('set statuscolumn=%l%s%C')
   1805      command('hi NormalFloat guibg=#333333 guifg=NONE')
   1806      feed('ix<cr>y<cr><esc>gg')
   1807      api.nvim_open_win(0, false, { relative = 'editor', width = 20, height = 4, row = 4, col = 10, style = 'minimal' })
   1808      if multigrid then
   1809        screen:expect({
   1810          grid = [[
   1811          ## grid 1
   1812            [2:----------------------------------------]|*6
   1813            [3:----------------------------------------]|
   1814          ## grid 2
   1815            {20:   1}{19:   }{22:^x}{21:                                }|
   1816            {14:   2}{19:   }{22:y}                                |
   1817            {14:   3}{19:   }{22: }                                |
   1818            {0:~                                       }|*3
   1819          ## grid 3
   1820                                                    |
   1821          ## grid 4
   1822            {15:x                   }|
   1823            {15:y                   }|
   1824            {15:                    }|*2
   1825          ]],
   1826          float_pos = { [4] = { 1001, 'NW', 1, 4, 10, true, 50, 1, 2, 10 } },
   1827        })
   1828      else
   1829        screen:expect([[
   1830          {20:   1}{19:   }{22:^x}{21:                                }|
   1831          {14:   2}{19:   }{22:y}                                |
   1832          {14:   3}{19:   }{22: }  {15:x                   }          |
   1833          {0:~         }{15:y                   }{0:          }|
   1834          {0:~         }{15:                    }{0:          }|*2
   1835                                                  |
   1836        ]])
   1837      end
   1838    end)
   1839 
   1840    it('can have border', function()
   1841      local buf = api.nvim_create_buf(false, false)
   1842      api.nvim_buf_set_lines(buf, 0, -1, true, { ' halloj! ', ' BORDAA  ' })
   1843      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 9, height = 2, row = 2, col = 5, border = 'double' })
   1844      eq('╔', api.nvim_win_get_config(win).border[1])
   1845 
   1846      api.nvim_win_set_config(win, { border = 'single' })
   1847      eq('┌', api.nvim_win_get_config(win).border[1])
   1848 
   1849      api.nvim_win_set_config(win, { border = 'rounded' })
   1850      eq('╭', api.nvim_win_get_config(win).border[1])
   1851 
   1852      api.nvim_win_set_config(win, { border = 'solid' })
   1853      eq(' ', api.nvim_win_get_config(win).border[1])
   1854 
   1855      -- support: ascii char, UTF-8 char, composed char, highlight per char
   1856      api.nvim_win_set_config(win, { border = { 'x', { 'å', 'ErrorMsg' }, { '\\' }, { 'n̈̊', 'Search' } } })
   1857      eq(
   1858        { 'x', { 'å', 'ErrorMsg' }, '\\', { 'n̈̊', 'Search' }, 'x', { 'å', 'ErrorMsg' }, '\\', { 'n̈̊', 'Search' } },
   1859        api.nvim_win_get_config(win).border
   1860      )
   1861      if multigrid then
   1862        screen:expect {
   1863          grid = [[
   1864        ## grid 1
   1865          [2:----------------------------------------]|*6
   1866          [3:----------------------------------------]|
   1867        ## grid 2
   1868          ^                                        |
   1869          {0:~                                       }|*5
   1870        ## grid 3
   1871                                                  |
   1872        ## grid 4
   1873          {5:x}{7:ååååååååå}{5:\}|
   1874          {17:n̈̊}{1: halloj! }{17:n̈̊}|
   1875          {17:n̈̊}{1: BORDAA  }{17:n̈̊}|
   1876          {5:\}{7:ååååååååå}{5:x}|
   1877        ]],
   1878          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   1879          win_viewport = {
   1880            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   1881            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   1882          },
   1883        }
   1884      else
   1885        screen:expect {
   1886          grid = [[
   1887          ^                                        |
   1888          {0:~                                       }|
   1889          {0:~    }{5:x}{7:ååååååååå}{5:\}{0:                        }|
   1890          {0:~    }{17:n̈̊}{1: halloj! }{17:n̈̊}{0:                        }|
   1891          {0:~    }{17:n̈̊}{1: BORDAA  }{17:n̈̊}{0:                        }|
   1892          {0:~    }{5:\}{7:ååååååååå}{5:x}{0:                        }|
   1893                                                  |
   1894        ]],
   1895        }
   1896      end
   1897 
   1898      api.nvim_win_set_config(win, { border = 'none' })
   1899      eq('none', api.nvim_win_get_config(win).border)
   1900 
   1901      api.nvim_win_set_config(win, { border = { '', '', '', '>', '', '', '', '<' } })
   1902      eq({ '', '', '', '>', '', '', '', '<' }, api.nvim_win_get_config(win).border)
   1903      if multigrid then
   1904        screen:expect {
   1905          grid = [[
   1906        ## grid 1
   1907          [2:----------------------------------------]|*6
   1908          [3:----------------------------------------]|
   1909        ## grid 2
   1910          ^                                        |
   1911          {0:~                                       }|*5
   1912        ## grid 3
   1913                                                  |
   1914        ## grid 4
   1915          {5:<}{1: halloj! }{5:>}|
   1916          {5:<}{1: BORDAA  }{5:>}|
   1917        ]],
   1918          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   1919          win_viewport = {
   1920            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   1921            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   1922          },
   1923          win_viewport_margins = {
   1924            [2] = { win = 1000, top = 0, bottom = 0, left = 0, right = 0 },
   1925            [4] = { win = 1001, top = 0, bottom = 0, left = 1, right = 1 },
   1926          },
   1927        }
   1928      else
   1929        screen:expect {
   1930          grid = [[
   1931          ^                                        |
   1932          {0:~                                       }|
   1933          {0:~    }{5:<}{1: halloj! }{5:>}{0:                        }|
   1934          {0:~    }{5:<}{1: BORDAA  }{5:>}{0:                        }|
   1935          {0:~                                       }|*2
   1936                                                  |
   1937        ]],
   1938        }
   1939      end
   1940 
   1941      api.nvim_win_set_config(win, { border = { '', '_', '', '', '', '-', '', '' } })
   1942      eq({ '', '_', '', '', '', '-', '', '' }, api.nvim_win_get_config(win).border)
   1943      if multigrid then
   1944        screen:expect {
   1945          grid = [[
   1946        ## grid 1
   1947          [2:----------------------------------------]|*6
   1948          [3:----------------------------------------]|
   1949        ## grid 2
   1950          ^                                        |
   1951          {0:~                                       }|*5
   1952        ## grid 3
   1953                                                  |
   1954        ## grid 4
   1955          {5:_________}|
   1956          {1: halloj! }|
   1957          {1: BORDAA  }|
   1958          {5:---------}|
   1959        ]],
   1960          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   1961          win_viewport = {
   1962            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   1963            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   1964          },
   1965          win_viewport_margins = {
   1966            [2] = { win = 1000, top = 0, bottom = 0, left = 0, right = 0 },
   1967            [4] = { win = 1001, top = 1, bottom = 1, left = 0, right = 0 },
   1968          },
   1969        }
   1970      else
   1971        screen:expect {
   1972          grid = [[
   1973          ^                                        |
   1974          {0:~                                       }|
   1975          {0:~    }{5:_________}{0:                          }|
   1976          {0:~    }{1: halloj! }{0:                          }|
   1977          {0:~    }{1: BORDAA  }{0:                          }|
   1978          {0:~    }{5:---------}{0:                          }|
   1979                                                  |
   1980        ]],
   1981        }
   1982      end
   1983 
   1984      insert [[
   1985        neeed some dummy
   1986        background text
   1987        to show the effect
   1988        of color blending
   1989        of border shadow
   1990      ]]
   1991 
   1992      api.nvim_win_set_config(win, { border = 'shadow' })
   1993      if multigrid then
   1994        screen:expect {
   1995          grid = [[
   1996        ## grid 1
   1997          [2:----------------------------------------]|*6
   1998          [3:----------------------------------------]|
   1999        ## grid 2
   2000          neeed some dummy                        |
   2001          background text                         |
   2002          to show the effect                      |
   2003          of color blending                       |
   2004          of border shadow                        |
   2005          ^                                        |
   2006        ## grid 3
   2007                                                  |
   2008        ## grid 4
   2009          {1: halloj! }{25: }|
   2010          {1: BORDAA  }{26: }|
   2011          {25: }{26:         }|
   2012        ]],
   2013          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2014          win_viewport = {
   2015            [2] = { win = 1000, topline = 0, botline = 6, curline = 5, curcol = 0, linecount = 6, sum_scroll_delta = 0 },
   2016            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2017          },
   2018          win_viewport_margins = {
   2019            [2] = { win = 1000, top = 0, bottom = 0, left = 0, right = 0 },
   2020            [4] = { win = 1001, top = 0, bottom = 1, left = 0, right = 1 },
   2021          },
   2022        }
   2023      else
   2024        screen:expect {
   2025          grid = [[
   2026          neeed some dummy                        |
   2027          background text                         |
   2028          to sh{1: halloj! }{31:f}ect                      |
   2029          of co{1: BORDAA  }{24:i}ng                       |
   2030          of bo{31:r}{24:der shado}w                        |
   2031          ^                                        |
   2032                                                  |
   2033        ]],
   2034        }
   2035      end
   2036    end)
   2037 
   2038    it('validates title title_pos', function()
   2039      local buf = api.nvim_create_buf(false, false)
   2040      eq(
   2041        'title_pos requires title to be set',
   2042        pcall_err(api.nvim_open_win, buf, false, {
   2043          relative = 'editor',
   2044          width = 9,
   2045          height = 2,
   2046          row = 2,
   2047          col = 5,
   2048          border = 'single',
   2049          title_pos = 'left',
   2050        })
   2051      )
   2052    end)
   2053 
   2054    it('validate title_pos in nvim_win_get_config', function()
   2055      local title_pos = exec_lua([[
   2056        local bufnr = vim.api.nvim_create_buf(false, false)
   2057        local opts = {
   2058          relative = 'editor',
   2059          col = 2,
   2060          row = 5,
   2061          height = 2,
   2062          width = 9,
   2063          border = 'double',
   2064          title = 'Test',
   2065          title_pos = 'center'
   2066        }
   2067 
   2068        local win_id = vim.api.nvim_open_win(bufnr, true, opts)
   2069        return vim.api.nvim_win_get_config(win_id).title_pos
   2070      ]])
   2071 
   2072      eq('center', title_pos)
   2073    end)
   2074 
   2075    it('validates footer footer_pos', function()
   2076      local buf = api.nvim_create_buf(false, false)
   2077      eq(
   2078        'footer_pos requires footer to be set',
   2079        pcall_err(api.nvim_open_win, buf, false, {
   2080          relative = 'editor',
   2081          width = 9,
   2082          height = 2,
   2083          row = 2,
   2084          col = 5,
   2085          border = 'single',
   2086          footer_pos = 'left',
   2087        })
   2088      )
   2089    end)
   2090 
   2091    it('validate footer_pos in nvim_win_get_config', function()
   2092      local footer_pos = exec_lua([[
   2093        local bufnr = vim.api.nvim_create_buf(false, false)
   2094        local opts = {
   2095          relative = 'editor',
   2096          col = 2,
   2097          row = 5,
   2098          height = 2,
   2099          width = 9,
   2100          border = 'double',
   2101          footer = 'Test',
   2102          footer_pos = 'center'
   2103        }
   2104 
   2105        local win_id = vim.api.nvim_open_win(bufnr, true, opts)
   2106        return vim.api.nvim_win_get_config(win_id).footer_pos
   2107      ]])
   2108 
   2109      eq('center', footer_pos)
   2110    end)
   2111 
   2112    it('truncates title longer than window width #25746 #23602', function()
   2113      local buf = api.nvim_create_buf(false, false)
   2114      api.nvim_buf_set_lines(buf, 0, -1, true, { ' halloj! ', ' BORDAA  ' })
   2115      local config = {
   2116        relative = 'editor',
   2117        width = 9,
   2118        height = 2,
   2119        row = 2,
   2120        col = 5,
   2121        border = 'double',
   2122        title = 'abcdefghijklmnopqrstuvwxyz',
   2123        title_pos = 'center',
   2124        footer = 'abcdefghi', -- exactly fits window width #36872
   2125      }
   2126      local win = api.nvim_open_win(buf, false, config)
   2127      if multigrid then
   2128        screen:expect {
   2129          grid = [[
   2130        ## grid 1
   2131          [2:----------------------------------------]|*6
   2132          [3:----------------------------------------]|
   2133        ## grid 2
   2134          ^                                        |
   2135          {0:~                                       }|*5
   2136        ## grid 3
   2137                                                  |
   2138        ## grid 4
   2139          {5:╔}{11:<stuvwxyz}{5:╗}|
   2140          {5:║}{1: halloj! }{5:║}|
   2141          {5:║}{1: BORDAA  }{5:║}|
   2142          {5:╚}{11:abcdefghi}{5:╝}|
   2143        ]],
   2144          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2145          win_viewport = {
   2146            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2147            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2148          },
   2149        }
   2150      else
   2151        screen:expect {
   2152          grid = [[
   2153          ^                                        |
   2154          {0:~                                       }|
   2155          {0:~    }{5:╔}{11:<stuvwxyz}{5:╗}{0:                        }|
   2156          {0:~    }{5:║}{1: halloj! }{5:║}{0:                        }|
   2157          {0:~    }{5:║}{1: BORDAA  }{5:║}{0:                        }|
   2158          {0:~    }{5:╚}{11:abcdefghi}{5:╝}{0:                        }|
   2159                                                  |
   2160        ]],
   2161        }
   2162      end
   2163      config.title = { { 'abcd' }, { 'stuvw' }, { 'xyz' } }
   2164      api.nvim_win_set_config(win, config)
   2165      screen:expect_unchanged()
   2166      api.nvim_win_close(win, false)
   2167      assert_alive()
   2168    end)
   2169 
   2170    it('no border with title and footer', function()
   2171      local buf = api.nvim_create_buf(false, false)
   2172      api.nvim_buf_set_lines(buf, 0, -1, true, { 'Hello' })
   2173      api.nvim_open_win(buf, false, {
   2174        relative = 'editor',
   2175        width = 9,
   2176        height = 2,
   2177        row = 2,
   2178        col = 5,
   2179        title = 'Title',
   2180        footer = 'Footer',
   2181      })
   2182 
   2183      if multigrid then
   2184        screen:expect({
   2185          grid = [[
   2186          ## grid 1
   2187            [2:----------------------------------------]|*6
   2188            [3:----------------------------------------]|
   2189          ## grid 2
   2190            ^                                        |
   2191            {0:~                                       }|*5
   2192          ## grid 3
   2193                                                    |
   2194          ## grid 4
   2195            {1:Hello    }|
   2196            {2:~        }|
   2197          ]],
   2198          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2199          win_viewport = {
   2200            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2201            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2202          },
   2203        })
   2204      else
   2205        screen:expect([[
   2206          ^                                        |
   2207          {0:~                                       }|
   2208          {0:~    }{1:Hello    }{0:                          }|
   2209          {0:~    }{2:~        }{0:                          }|
   2210          {0:~                                       }|*2
   2211                                                  |
   2212        ]])
   2213      end
   2214    end)
   2215 
   2216    it('border with title', function()
   2217      local buf = api.nvim_create_buf(false, false)
   2218      api.nvim_buf_set_lines(buf, 0, -1, true, { ' halloj! ', ' BORDAA  ' })
   2219      local win = api.nvim_open_win(buf, false, {
   2220        relative = 'editor',
   2221        width = 9,
   2222        height = 2,
   2223        row = 2,
   2224        col = 5,
   2225        border = 'double',
   2226        title = 'Left',
   2227        title_pos = 'left',
   2228      })
   2229 
   2230      if multigrid then
   2231        screen:expect {
   2232          grid = [[
   2233        ## grid 1
   2234          [2:----------------------------------------]|*6
   2235          [3:----------------------------------------]|
   2236        ## grid 2
   2237          ^                                        |
   2238          {0:~                                       }|*5
   2239        ## grid 3
   2240                                                  |
   2241        ## grid 4
   2242          {5:╔}{11:Left}{5:═════╗}|
   2243          {5:║}{1: halloj! }{5:║}|
   2244          {5:║}{1: BORDAA  }{5:║}|
   2245          {5:╚═════════╝}|
   2246        ]],
   2247          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2248          win_viewport = {
   2249            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2250            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2251          },
   2252        }
   2253      else
   2254        screen:expect {
   2255          grid = [[
   2256          ^                                        |
   2257          {0:~                                       }|
   2258          {0:~    }{5:╔}{11:Left}{5:═════╗}{0:                        }|
   2259          {0:~    }{5:║}{1: halloj! }{5:║}{0:                        }|
   2260          {0:~    }{5:║}{1: BORDAA  }{5:║}{0:                        }|
   2261          {0:~    }{5:╚═════════╝}{0:                        }|
   2262                                                  |
   2263        ]],
   2264        }
   2265      end
   2266 
   2267      api.nvim_win_set_config(win, { title = 'Center', title_pos = 'center' })
   2268      if multigrid then
   2269        screen:expect {
   2270          grid = [[
   2271        ## grid 1
   2272          [2:----------------------------------------]|*6
   2273          [3:----------------------------------------]|
   2274        ## grid 2
   2275          ^                                        |
   2276          {0:~                                       }|*5
   2277        ## grid 3
   2278                                                  |
   2279        ## grid 4
   2280          {5:╔═}{11:Center}{5:══╗}|
   2281          {5:║}{1: halloj! }{5:║}|
   2282          {5:║}{1: BORDAA  }{5:║}|
   2283          {5:╚═════════╝}|
   2284        ]],
   2285          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2286          win_viewport = {
   2287            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2288            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2289          },
   2290        }
   2291      else
   2292        screen:expect {
   2293          grid = [[
   2294          ^                                        |
   2295          {0:~                                       }|
   2296          {0:~    }{5:╔═}{11:Center}{5:══╗}{0:                        }|
   2297          {0:~    }{5:║}{1: halloj! }{5:║}{0:                        }|
   2298          {0:~    }{5:║}{1: BORDAA  }{5:║}{0:                        }|
   2299          {0:~    }{5:╚═════════╝}{0:                        }|
   2300                                                  |
   2301        ]],
   2302        }
   2303      end
   2304 
   2305      api.nvim_win_set_config(win, { title = 'Right', title_pos = 'right' })
   2306      if multigrid then
   2307        screen:expect {
   2308          grid = [[
   2309        ## grid 1
   2310          [2:----------------------------------------]|*6
   2311          [3:----------------------------------------]|
   2312        ## grid 2
   2313          ^                                        |
   2314          {0:~                                       }|*5
   2315        ## grid 3
   2316                                                  |
   2317        ## grid 4
   2318          {5:╔════}{11:Right}{5:╗}|
   2319          {5:║}{1: halloj! }{5:║}|
   2320          {5:║}{1: BORDAA  }{5:║}|
   2321          {5:╚═════════╝}|
   2322        ]],
   2323          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2324          win_viewport = {
   2325            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2326            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2327          },
   2328        }
   2329      else
   2330        screen:expect {
   2331          grid = [[
   2332          ^                                        |
   2333          {0:~                                       }|
   2334          {0:~    }{5:╔════}{11:Right}{5:╗}{0:                        }|
   2335          {0:~    }{5:║}{1: halloj! }{5:║}{0:                        }|
   2336          {0:~    }{5:║}{1: BORDAA  }{5:║}{0:                        }|
   2337          {0:~    }{5:╚═════════╝}{0:                        }|
   2338                                                  |
   2339        ]],
   2340        }
   2341      end
   2342 
   2343      api.nvim_win_set_config(win, { title = { { '🦄' }, { 'BB' } }, title_pos = 'right' })
   2344      if multigrid then
   2345        screen:expect {
   2346          grid = [[
   2347        ## grid 1
   2348          [2:----------------------------------------]|*6
   2349          [3:----------------------------------------]|
   2350        ## grid 2
   2351          ^                                        |
   2352          {0:~                                       }|*5
   2353        ## grid 3
   2354                                                  |
   2355        ## grid 4
   2356          {5:╔═════}{11:🦄BB}{5:╗}|
   2357          {5:║}{1: halloj! }{5:║}|
   2358          {5:║}{1: BORDAA  }{5:║}|
   2359          {5:╚═════════╝}|
   2360        ]],
   2361          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2362          win_viewport = {
   2363            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2364            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2365          },
   2366        }
   2367      else
   2368        screen:expect {
   2369          grid = [[
   2370          ^                                        |
   2371          {0:~                                       }|
   2372          {0:~    }{5:╔═════}{11:🦄BB}{5:╗}{0:                        }|
   2373          {0:~    }{5:║}{1: halloj! }{5:║}{0:                        }|
   2374          {0:~    }{5:║}{1: BORDAA  }{5:║}{0:                        }|
   2375          {0:~    }{5:╚═════════╝}{0:                        }|
   2376                                                  |
   2377        ]],
   2378        }
   2379      end
   2380 
   2381      -- reuse before title pos
   2382      api.nvim_win_set_config(win, { title = 'new' })
   2383      if multigrid then
   2384        screen:expect({
   2385          grid = [[
   2386          ## grid 1
   2387            [2:----------------------------------------]|*6
   2388            [3:----------------------------------------]|
   2389          ## grid 2
   2390            ^                                        |
   2391            {0:~                                       }|*5
   2392          ## grid 3
   2393                                                    |
   2394          ## grid 4
   2395            {5:╔══════}{11:new}{5:╗}|
   2396            {5:║}{1: halloj! }{5:║}|
   2397            {5:║}{1: BORDAA  }{5:║}|
   2398            {5:╚═════════╝}|
   2399          ]],
   2400          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2401          win_viewport = {
   2402            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2403            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2404          },
   2405          win_viewport_margins = {
   2406            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
   2407            [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 },
   2408          },
   2409        })
   2410      else
   2411        screen:expect([[
   2412          ^                                        |
   2413          {0:~                                       }|
   2414          {0:~    }{5:╔══════}{11:new}{5:}{0:                        }|
   2415          {0:~    }{5:}{1: halloj! }{5:}{0:                        }|
   2416          {0:~    }{5:}{1: BORDAA  }{5:}{0:                        }|
   2417          {0:~    }{5:╚═════════╝}{0:                        }|
   2418                                                  |
   2419        ]])
   2420      end
   2421    end)
   2422 
   2423    it('border with footer', function()
   2424      local buf = api.nvim_create_buf(false, false)
   2425      api.nvim_buf_set_lines(buf, 0, -1, true, { ' halloj! ', ' BORDAA  ' })
   2426      local win = api.nvim_open_win(buf, false, {
   2427        relative = 'editor',
   2428        width = 9,
   2429        height = 2,
   2430        row = 2,
   2431        col = 5,
   2432        border = 'double',
   2433        footer = 'Left',
   2434        footer_pos = 'left',
   2435      })
   2436 
   2437      if multigrid then
   2438        screen:expect {
   2439          grid = [[
   2440        ## grid 1
   2441          [2:----------------------------------------]|*6
   2442          [3:----------------------------------------]|
   2443        ## grid 2
   2444          ^                                        |
   2445          {0:~                                       }|*5
   2446        ## grid 3
   2447                                                  |
   2448        ## grid 4
   2449          {5:╔═════════╗}|
   2450          {5:║}{1: halloj! }{5:║}|
   2451          {5:║}{1: BORDAA  }{5:║}|
   2452          {5:╚}{11:Left}{5:═════╝}|
   2453        ]],
   2454          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2455          win_viewport = {
   2456            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2457            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2458          },
   2459        }
   2460      else
   2461        screen:expect {
   2462          grid = [[
   2463          ^                                        |
   2464          {0:~                                       }|
   2465          {0:~    }{5:╔═════════╗}{0:                        }|
   2466          {0:~    }{5:║}{1: halloj! }{5:║}{0:                        }|
   2467          {0:~    }{5:║}{1: BORDAA  }{5:║}{0:                        }|
   2468          {0:~    }{5:╚}{11:Left}{5:═════╝}{0:                        }|
   2469                                                  |
   2470        ]],
   2471        }
   2472      end
   2473 
   2474      api.nvim_win_set_config(win, { footer = 'Center', footer_pos = 'center' })
   2475      if multigrid then
   2476        screen:expect {
   2477          grid = [[
   2478        ## grid 1
   2479          [2:----------------------------------------]|*6
   2480          [3:----------------------------------------]|
   2481        ## grid 2
   2482          ^                                        |
   2483          {0:~                                       }|*5
   2484        ## grid 3
   2485                                                  |
   2486        ## grid 4
   2487          {5:╔═════════╗}|
   2488          {5:║}{1: halloj! }{5:║}|
   2489          {5:║}{1: BORDAA  }{5:║}|
   2490          {5:╚═}{11:Center}{5:══╝}|
   2491        ]],
   2492          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2493          win_viewport = {
   2494            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2495            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2496          },
   2497        }
   2498      else
   2499        screen:expect {
   2500          grid = [[
   2501          ^                                        |
   2502          {0:~                                       }|
   2503          {0:~    }{5:╔═════════╗}{0:                        }|
   2504          {0:~    }{5:║}{1: halloj! }{5:║}{0:                        }|
   2505          {0:~    }{5:║}{1: BORDAA  }{5:║}{0:                        }|
   2506          {0:~    }{5:╚═}{11:Center}{5:══╝}{0:                        }|
   2507                                                  |
   2508        ]],
   2509        }
   2510      end
   2511 
   2512      api.nvim_win_set_config(win, { footer = 'Right', footer_pos = 'right' })
   2513      if multigrid then
   2514        screen:expect {
   2515          grid = [[
   2516        ## grid 1
   2517          [2:----------------------------------------]|*6
   2518          [3:----------------------------------------]|
   2519        ## grid 2
   2520          ^                                        |
   2521          {0:~                                       }|*5
   2522        ## grid 3
   2523                                                  |
   2524        ## grid 4
   2525          {5:╔═════════╗}|
   2526          {5:║}{1: halloj! }{5:║}|
   2527          {5:║}{1: BORDAA  }{5:║}|
   2528          {5:╚════}{11:Right}{5:╝}|
   2529        ]],
   2530          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2531          win_viewport = {
   2532            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2533            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2534          },
   2535        }
   2536      else
   2537        screen:expect {
   2538          grid = [[
   2539          ^                                        |
   2540          {0:~                                       }|
   2541          {0:~    }{5:╔═════════╗}{0:                        }|
   2542          {0:~    }{5:║}{1: halloj! }{5:║}{0:                        }|
   2543          {0:~    }{5:║}{1: BORDAA  }{5:║}{0:                        }|
   2544          {0:~    }{5:╚════}{11:Right}{5:╝}{0:                        }|
   2545                                                  |
   2546        ]],
   2547        }
   2548      end
   2549 
   2550      api.nvim_win_set_config(win, { footer = { { '🦄' }, { 'BB' } }, footer_pos = 'right' })
   2551      if multigrid then
   2552        screen:expect {
   2553          grid = [[
   2554        ## grid 1
   2555          [2:----------------------------------------]|*6
   2556          [3:----------------------------------------]|
   2557        ## grid 2
   2558          ^                                        |
   2559          {0:~                                       }|*5
   2560        ## grid 3
   2561                                                  |
   2562        ## grid 4
   2563          {5:╔═════════╗}|
   2564          {5:║}{1: halloj! }{5:║}|
   2565          {5:║}{1: BORDAA  }{5:║}|
   2566          {5:╚═════}{11:🦄BB}{5:╝}|
   2567        ]],
   2568          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2569          win_viewport = {
   2570            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2571            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2572          },
   2573        }
   2574      else
   2575        screen:expect {
   2576          grid = [[
   2577          ^                                        |
   2578          {0:~                                       }|
   2579          {0:~    }{5:╔═════════╗}{0:                        }|
   2580          {0:~    }{5:║}{1: halloj! }{5:║}{0:                        }|
   2581          {0:~    }{5:║}{1: BORDAA  }{5:║}{0:                        }|
   2582          {0:~    }{5:╚═════}{11:🦄BB}{5:╝}{0:                        }|
   2583                                                  |
   2584        ]],
   2585        }
   2586      end
   2587 
   2588      -- reuse before footer pos
   2589      api.nvim_win_set_config(win, { footer = 'new' })
   2590      if multigrid then
   2591        screen:expect({
   2592          grid = [[
   2593          ## grid 1
   2594            [2:----------------------------------------]|*6
   2595            [3:----------------------------------------]|
   2596          ## grid 2
   2597            ^                                        |
   2598            {0:~                                       }|*5
   2599          ## grid 3
   2600                                                    |
   2601          ## grid 4
   2602            {5:╔═════════╗}|
   2603            {5:║}{1: halloj! }{5:║}|
   2604            {5:║}{1: BORDAA  }{5:║}|
   2605            {5:╚══════}{11:new}{5:╝}|
   2606          ]],
   2607          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2608          win_viewport = {
   2609            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2610            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2611          },
   2612          win_viewport_margins = {
   2613            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
   2614            [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 },
   2615          },
   2616        })
   2617      else
   2618        screen:expect([[
   2619          ^                                        |
   2620          {0:~                                       }|
   2621          {0:~    }{5:╔═════════╗}{0:                        }|
   2622          {0:~    }{5:}{1: halloj! }{5:}{0:                        }|
   2623          {0:~    }{5:}{1: BORDAA  }{5:}{0:                        }|
   2624          {0:~    }{5:╚══════}{11:new}{5:}{0:                        }|
   2625                                                  |
   2626        ]])
   2627      end
   2628    end)
   2629 
   2630    it('border with title and footer', function()
   2631      local buf = api.nvim_create_buf(false, false)
   2632      api.nvim_buf_set_lines(buf, 0, -1, true, { ' halloj! ', ' BORDAA  ' })
   2633      local win = api.nvim_open_win(buf, false, {
   2634        relative = 'editor',
   2635        width = 9,
   2636        height = 2,
   2637        row = 2,
   2638        col = 5,
   2639        border = 'double',
   2640        title = 'Left',
   2641        title_pos = 'left',
   2642        footer = 'Right',
   2643        footer_pos = 'right',
   2644      })
   2645 
   2646      if multigrid then
   2647        screen:expect {
   2648          grid = [[
   2649        ## grid 1
   2650          [2:----------------------------------------]|*6
   2651          [3:----------------------------------------]|
   2652        ## grid 2
   2653          ^                                        |
   2654          {0:~                                       }|*5
   2655        ## grid 3
   2656                                                  |
   2657        ## grid 4
   2658          {5:╔}{11:Left}{5:═════╗}|
   2659          {5:║}{1: halloj! }{5:║}|
   2660          {5:║}{1: BORDAA  }{5:║}|
   2661          {5:╚════}{11:Right}{5:╝}|
   2662        ]],
   2663          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2664          win_viewport = {
   2665            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2666            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2667          },
   2668        }
   2669      else
   2670        screen:expect {
   2671          grid = [[
   2672          ^                                        |
   2673          {0:~                                       }|
   2674          {0:~    }{5:╔}{11:Left}{5:═════╗}{0:                        }|
   2675          {0:~    }{5:║}{1: halloj! }{5:║}{0:                        }|
   2676          {0:~    }{5:║}{1: BORDAA  }{5:║}{0:                        }|
   2677          {0:~    }{5:╚════}{11:Right}{5:╝}{0:                        }|
   2678                                                  |
   2679        ]],
   2680        }
   2681      end
   2682 
   2683      api.nvim_win_set_config(win, { title = 'Center', title_pos = 'center', footer = 'Center', footer_pos = 'center' })
   2684      if multigrid then
   2685        screen:expect {
   2686          grid = [[
   2687        ## grid 1
   2688          [2:----------------------------------------]|*6
   2689          [3:----------------------------------------]|
   2690        ## grid 2
   2691          ^                                        |
   2692          {0:~                                       }|*5
   2693        ## grid 3
   2694                                                  |
   2695        ## grid 4
   2696          {5:╔═}{11:Center}{5:══╗}|
   2697          {5:║}{1: halloj! }{5:║}|
   2698          {5:║}{1: BORDAA  }{5:║}|
   2699          {5:╚═}{11:Center}{5:══╝}|
   2700        ]],
   2701          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2702          win_viewport = {
   2703            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2704            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2705          },
   2706        }
   2707      else
   2708        screen:expect {
   2709          grid = [[
   2710          ^                                        |
   2711          {0:~                                       }|
   2712          {0:~    }{5:╔═}{11:Center}{5:══╗}{0:                        }|
   2713          {0:~    }{5:║}{1: halloj! }{5:║}{0:                        }|
   2714          {0:~    }{5:║}{1: BORDAA  }{5:║}{0:                        }|
   2715          {0:~    }{5:╚═}{11:Center}{5:══╝}{0:                        }|
   2716                                                  |
   2717        ]],
   2718        }
   2719      end
   2720 
   2721      api.nvim_win_set_config(win, { title = 'Right', title_pos = 'right', footer = 'Left', footer_pos = 'left' })
   2722      if multigrid then
   2723        screen:expect {
   2724          grid = [[
   2725        ## grid 1
   2726          [2:----------------------------------------]|*6
   2727          [3:----------------------------------------]|
   2728        ## grid 2
   2729          ^                                        |
   2730          {0:~                                       }|*5
   2731        ## grid 3
   2732                                                  |
   2733        ## grid 4
   2734          {5:╔════}{11:Right}{5:╗}|
   2735          {5:║}{1: halloj! }{5:║}|
   2736          {5:║}{1: BORDAA  }{5:║}|
   2737          {5:╚}{11:Left}{5:═════╝}|
   2738        ]],
   2739          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2740          win_viewport = {
   2741            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2742            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2743          },
   2744        }
   2745      else
   2746        screen:expect {
   2747          grid = [[
   2748          ^                                        |
   2749          {0:~                                       }|
   2750          {0:~    }{5:╔════}{11:Right}{5:╗}{0:                        }|
   2751          {0:~    }{5:║}{1: halloj! }{5:║}{0:                        }|
   2752          {0:~    }{5:║}{1: BORDAA  }{5:║}{0:                        }|
   2753          {0:~    }{5:╚}{11:Left}{5:═════╝}{0:                        }|
   2754                                                  |
   2755        ]],
   2756        }
   2757      end
   2758 
   2759      command('hi B0 guibg=Red guifg=Black')
   2760      command('hi B1 guifg=White')
   2761 
   2762      api.nvim_win_set_config(win, {
   2763        title = { { '🦄' }, { 'BB', { 'B0', 'B1' } } },
   2764        title_pos = 'right',
   2765        footer = { { '🦄' }, { 'BB', { 'B0', 'B1' } } },
   2766        footer_pos = 'right',
   2767      })
   2768      if multigrid then
   2769        screen:expect {
   2770          grid = [[
   2771        ## grid 1
   2772          [2:----------------------------------------]|*6
   2773          [3:----------------------------------------]|
   2774        ## grid 2
   2775          ^                                        |
   2776          {0:~                                       }|*5
   2777        ## grid 3
   2778                                                  |
   2779        ## grid 4
   2780          {5:╔═════}{11:🦄}{7:BB}{5:╗}|
   2781          {5:║}{1: halloj! }{5:║}|
   2782          {5:║}{1: BORDAA  }{5:║}|
   2783          {5:╚═════}{11:🦄}{7:BB}{5:╝}|
   2784        ]],
   2785          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2786          win_viewport = {
   2787            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2788            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2789          },
   2790        }
   2791      else
   2792        screen:expect {
   2793          grid = [[
   2794          ^                                        |
   2795          {0:~                                       }|
   2796          {0:~    }{5:╔═════}{11:🦄}{7:BB}{5:╗}{0:                        }|
   2797          {0:~    }{5:║}{1: halloj! }{5:║}{0:                        }|
   2798          {0:~    }{5:║}{1: BORDAA  }{5:║}{0:                        }|
   2799          {0:~    }{5:╚═════}{11:🦄}{7:BB}{5:╝}{0:                        }|
   2800                                                  |
   2801        ]],
   2802        }
   2803      end
   2804      eq({ { '🦄' }, { 'BB', { 'B0', 'B1' } } }, api.nvim_win_get_config(win).title)
   2805      eq({ { '🦄' }, { 'BB', { 'B0', 'B1' } } }, api.nvim_win_get_config(win).footer)
   2806 
   2807      api.nvim_win_set_config(win, {
   2808        title = { { '🦄', '' }, { 'BB', { 'B0', 'B1', '' } } },
   2809        title_pos = 'left',
   2810        footer = { { '🦄', '' }, { 'BB', { 'B0', 'B1', '' } } },
   2811        footer_pos = 'left',
   2812      })
   2813      if multigrid then
   2814        screen:expect {
   2815          grid = [[
   2816        ## grid 1
   2817          [2:----------------------------------------]|*6
   2818          [3:----------------------------------------]|
   2819        ## grid 2
   2820          ^                                        |
   2821          {0:~                                       }|*5
   2822        ## grid 3
   2823                                                  |
   2824        ## grid 4
   2825          {5:╔}🦄{7:BB}{5:═════╗}|
   2826          {5:║}{1: halloj! }{5:║}|
   2827          {5:║}{1: BORDAA  }{5:║}|
   2828          {5:╚}🦄{7:BB}{5:═════╝}|
   2829        ]],
   2830          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   2831          win_viewport = {
   2832            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2833            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2834          },
   2835        }
   2836      else
   2837        screen:expect {
   2838          grid = [[
   2839          ^                                        |
   2840          {0:~                                       }|
   2841          {0:~    }{5:╔}🦄{7:BB}{5:═════╗}{0:                        }|
   2842          {0:~    }{5:║}{1: halloj! }{5:║}{0:                        }|
   2843          {0:~    }{5:║}{1: BORDAA  }{5:║}{0:                        }|
   2844          {0:~    }{5:╚}🦄{7:BB}{5:═════╝}{0:                        }|
   2845                                                  |
   2846        ]],
   2847        }
   2848      end
   2849      eq({ { '🦄', '' }, { 'BB', { 'B0', 'B1', '' } } }, api.nvim_win_get_config(win).title)
   2850      eq({ { '🦄', '' }, { 'BB', { 'B0', 'B1', '' } } }, api.nvim_win_get_config(win).footer)
   2851 
   2852      -- making it a split should not leak memory
   2853      api.nvim_win_set_config(win, { vertical = true })
   2854      if multigrid then
   2855        screen:expect {
   2856          grid = [[
   2857        ## grid 1
   2858          [4:--------------------]{5:│}[2:-------------------]|*5
   2859          {5:[No Name] [+]        }{4:[No Name]          }|
   2860          [3:----------------------------------------]|
   2861        ## grid 2
   2862          ^                   |
   2863          {0:~                  }|*4
   2864        ## grid 3
   2865                                                  |
   2866        ## grid 4
   2867           halloj!            |
   2868           BORDAA             |
   2869          {0:~                   }|*3
   2870        ]],
   2871          win_viewport = {
   2872            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2873            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   2874          },
   2875        }
   2876      else
   2877        screen:expect {
   2878          grid = [[
   2879           halloj!            {5:│}^                   |
   2880           BORDAA             {5:│}{0:~                  }|
   2881          {0:~                   }{5:│}{0:~                  }|*3
   2882          {5:[No Name] [+]        }{4:[No Name]          }|
   2883                                                  |
   2884        ]],
   2885        }
   2886      end
   2887    end)
   2888 
   2889    it('terminates border on edge of viewport when window extends past viewport', function()
   2890      local buf = api.nvim_create_buf(false, false)
   2891      api.nvim_open_win(buf, false, { relative = 'editor', width = 40, height = 7, row = 0, col = 0, border = 'single', zindex = 201 })
   2892      if multigrid then
   2893        screen:expect {
   2894          grid = [[
   2895        ## grid 1
   2896          [2:----------------------------------------]|*6
   2897          [3:----------------------------------------]|
   2898        ## grid 2
   2899          ^                                        |
   2900          {0:~                                       }|*5
   2901        ## grid 3
   2902                                                  |
   2903        ## grid 4
   2904          {5:┌────────────────────────────────────────┐}|
   2905          {5:│}{1:                                        }{5:│}|
   2906          {5:│}{2:~                                       }{5:│}|*6
   2907          {5:└────────────────────────────────────────┘}|
   2908        ]],
   2909          float_pos = { [4] = { 1001, 'NW', 1, 0, 0, true, 201, 2, 0, 0 } },
   2910          win_viewport = {
   2911            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2912            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2913          },
   2914        }
   2915      else
   2916        screen:expect {
   2917          grid = [[
   2918          {5:^┌──────────────────────────────────────┐}|
   2919          {5:│}{1:                                      }{5:│}|
   2920          {5:│}{2:~                                     }{5:│}|*4
   2921          {5:└──────────────────────────────────────┘}|
   2922        ]],
   2923        }
   2924      end
   2925    end)
   2926 
   2927    it('with border show popupmenu', function()
   2928      screen:try_resize(40, 10)
   2929      local buf = api.nvim_create_buf(false, false)
   2930      api.nvim_buf_set_lines(buf, 0, -1, true, {
   2931        'aaa aab ',
   2932        'abb acc ',
   2933        '',
   2934      })
   2935      api.nvim_open_win(buf, true, { relative = 'editor', width = 9, height = 3, row = 0, col = 5, border = 'double' })
   2936      feed 'G'
   2937 
   2938      if multigrid then
   2939        screen:expect {
   2940          grid = [[
   2941        ## grid 1
   2942          [2:----------------------------------------]|*9
   2943          [3:----------------------------------------]|
   2944        ## grid 2
   2945                                                  |
   2946          {0:~                                       }|*8
   2947        ## grid 3
   2948                                                  |
   2949        ## grid 4
   2950          {5:╔═════════╗}|
   2951          {5:║}{1:aaa aab  }{5:║}|
   2952          {5:║}{1:abb acc  }{5:║}|
   2953          {5:║}{1:^         }{5:║}|
   2954          {5:╚═════════╝}|
   2955        ]],
   2956          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
   2957          win_viewport = {
   2958            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   2959            [4] = { win = 1001, topline = 0, botline = 3, curline = 2, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
   2960          },
   2961        }
   2962      else
   2963        screen:expect {
   2964          grid = [[
   2965               {5:╔═════════╗}                        |
   2966          {0:~    }{5:║}{1:aaa aab  }{5:║}{0:                        }|
   2967          {0:~    }{5:║}{1:abb acc  }{5:║}{0:                        }|
   2968          {0:~    }{5:║}{1:^         }{5:║}{0:                        }|
   2969          {0:~    }{5:╚═════════╝}{0:                        }|
   2970          {0:~                                       }|*4
   2971                                                  |
   2972        ]],
   2973        }
   2974      end
   2975 
   2976      feed 'i<c-x><c-p>'
   2977      if multigrid then
   2978        screen:expect {
   2979          grid = [[
   2980        ## grid 1
   2981          [2:----------------------------------------]|*9
   2982          [3:----------------------------------------]|
   2983        ## grid 2
   2984                                                  |
   2985          {0:~                                       }|*8
   2986        ## grid 3
   2987          {3:-- }{8:match 1 of 4}                         |
   2988        ## grid 4
   2989          {5:╔═════════╗}|
   2990          {5:║}{1:aaa aab  }{5:║}|
   2991          {5:║}{1:abb acc  }{5:║}|
   2992          {5:║}{1:acc^      }{5:║}|
   2993          {5:╚═════════╝}|
   2994        ## grid 5
   2995          {1: aaa            }|
   2996          {1: aab            }|
   2997          {1: abb            }|
   2998          {13: acc            }|
   2999        ]],
   3000          float_pos = {
   3001            [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 },
   3002            [5] = { -1, 'NW', 4, 4, 0, false, 100, 2, 4, 5 },
   3003          },
   3004          win_viewport = {
   3005            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3006            [4] = { win = 1001, topline = 0, botline = 3, curline = 2, curcol = 3, linecount = 3, sum_scroll_delta = 0 },
   3007          },
   3008        }
   3009      else
   3010        screen:expect {
   3011          grid = [[
   3012               {5:╔═════════╗}                        |
   3013          {0:~    }{5:║}{1:aaa aab  }{5:║}{0:                        }|
   3014          {0:~    }{5:║}{1:abb acc  }{5:║}{0:                        }|
   3015          {0:~    }{5:║}{1:acc^      }{5:║}{0:                        }|
   3016          {0:~    }{1: aaa            }{0:                   }|
   3017          {0:~    }{1: aab            }{0:                   }|
   3018          {0:~    }{1: abb            }{0:                   }|
   3019          {0:~    }{13: acc            }{0:                   }|
   3020          {0:~                                       }|
   3021          {3:-- }{8:match 1 of 4}                         |
   3022        ]],
   3023        }
   3024      end
   3025 
   3026      feed '<esc>'
   3027      if multigrid then
   3028        screen:expect {
   3029          grid = [[
   3030        ## grid 1
   3031          [2:----------------------------------------]|*9
   3032          [3:----------------------------------------]|
   3033        ## grid 2
   3034                                                  |
   3035          {0:~                                       }|*8
   3036        ## grid 3
   3037                                                  |
   3038        ## grid 4
   3039          {5:╔═════════╗}|
   3040          {5:║}{1:aaa aab  }{5:║}|
   3041          {5:║}{1:abb acc  }{5:║}|
   3042          {5:║}{1:ac^c      }{5:║}|
   3043          {5:╚═════════╝}|
   3044        ]],
   3045          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
   3046          win_viewport = {
   3047            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3048            [4] = { win = 1001, topline = 0, botline = 3, curline = 2, curcol = 2, linecount = 3, sum_scroll_delta = 0 },
   3049          },
   3050        }
   3051      else
   3052        screen:expect {
   3053          grid = [[
   3054               {5:╔═════════╗}                        |
   3055          {0:~    }{5:║}{1:aaa aab  }{5:║}{0:                        }|
   3056          {0:~    }{5:║}{1:abb acc  }{5:║}{0:                        }|
   3057          {0:~    }{5:║}{1:ac^c      }{5:║}{0:                        }|
   3058          {0:~    }{5:╚═════════╝}{0:                        }|
   3059          {0:~                                       }|*4
   3060                                                  |
   3061        ]],
   3062        }
   3063      end
   3064 
   3065      exec([[
   3066        nnoremenu Test.foo :
   3067        nnoremenu Test.bar :
   3068        nnoremenu Test.baz :
   3069      ]])
   3070      feed ':popup Test<CR>'
   3071      if multigrid then
   3072        screen:expect {
   3073          grid = [[
   3074        ## grid 1
   3075          [2:----------------------------------------]|*9
   3076          [3:----------------------------------------]|
   3077        ## grid 2
   3078                                                  |
   3079          {0:~                                       }|*8
   3080        ## grid 3
   3081          :popup Test                             |
   3082        ## grid 4
   3083          {5:╔═════════╗}|
   3084          {5:║}{1:aaa aab  }{5:║}|
   3085          {5:║}{1:abb acc  }{5:║}|
   3086          {5:║}{1:ac^c      }{5:║}|
   3087          {5:╚═════════╝}|
   3088        ## grid 5
   3089          {1: foo }|
   3090          {1: bar }|
   3091          {1: baz }|
   3092        ]],
   3093          float_pos = {
   3094            [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 },
   3095            [5] = { -1, 'NW', 4, 4, 2, false, 250, 3, 4, 7 },
   3096          },
   3097          win_viewport = {
   3098            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3099            [4] = { win = 1001, topline = 0, botline = 3, curline = 2, curcol = 2, linecount = 3, sum_scroll_delta = 0 },
   3100          },
   3101        }
   3102      else
   3103        screen:expect {
   3104          grid = [[
   3105               {5:╔═════════╗}                        |
   3106          {0:~    }{5:║}{1:aaa aab  }{5:║}{0:                        }|
   3107          {0:~    }{5:║}{1:abb acc  }{5:║}{0:                        }|
   3108          {0:~    }{5:║}{1:ac^c      }{5:║}{0:                        }|
   3109          {0:~    }{5:╚═}{1: foo }{5:═══╝}{0:                        }|
   3110          {0:~      }{1: bar }{0:                            }|
   3111          {0:~      }{1: baz }{0:                            }|
   3112          {0:~                                       }|*2
   3113          :popup Test                             |
   3114        ]],
   3115        }
   3116      end
   3117    end)
   3118 
   3119    it("doesn't wrap with vertical border", function()
   3120      screen:try_resize(40, 10)
   3121      local buf = api.nvim_create_buf(false, false)
   3122      api.nvim_open_win(buf, false, { relative = 'editor', width = 9, height = 3, row = 0, col = 5, border = 'double' })
   3123      -- make sure text is drawn after border
   3124      if multigrid then
   3125        screen:expect {
   3126          grid = [[
   3127          ## grid 1
   3128            [2:----------------------------------------]|*9
   3129            [3:----------------------------------------]|
   3130          ## grid 2
   3131            ^                                        |
   3132            {0:~                                       }|*8
   3133          ## grid 3
   3134                                                    |
   3135          ## grid 4
   3136            {5:╔═════════╗}|
   3137            {5:║}{1:         }{5:║}|
   3138            {5:║}{2:~        }{5:║}|*2
   3139            {5:╚═════════╝}|
   3140          ]],
   3141          win_pos = { [2] = { height = 9, startcol = 0, startrow = 0, width = 40, win = 1000 } },
   3142          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
   3143          win_viewport = {
   3144            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3145            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3146          },
   3147          win_viewport_margins = {
   3148            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
   3149            [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 },
   3150          },
   3151        }
   3152      else
   3153        screen:expect([[
   3154          ^     {5:╔═════════╗}                        |
   3155          {0:~    }{5:}{1:         }{5:}{0:                        }|
   3156          {0:~    }{5:}{2:~        }{5:}{0:                        }|*2
   3157          {0:~    }{5:╚═════════╝}{0:                        }|
   3158          {0:~                                       }|*4
   3159                                                  |
   3160        ]])
   3161      end
   3162      api.nvim_buf_set_lines(buf, 0, -1, true, { 'aaa long line', 'abb acc ' })
   3163      if multigrid then
   3164        screen:expect {
   3165          grid = [[
   3166          ## grid 1
   3167            [2:----------------------------------------]|*9
   3168            [3:----------------------------------------]|
   3169          ## grid 2
   3170            ^                                        |
   3171            {0:~                                       }|*8
   3172          ## grid 3
   3173                                                    |
   3174          ## grid 4
   3175            {5:╔═════════╗}|
   3176            {5:║}{1:aaa long }{5:║}|
   3177            {5:║}{1:line     }{5:║}|
   3178            {5:║}{1:abb acc  }{5:║}|
   3179            {5:╚═════════╝}|
   3180          ]],
   3181          win_pos = { [2] = { height = 9, startcol = 0, startrow = 0, width = 40, win = 1000 } },
   3182          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
   3183          win_viewport = {
   3184            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3185            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   3186          },
   3187          win_viewport_margins = {
   3188            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
   3189            [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 },
   3190          },
   3191          condition = function()
   3192            for i = 1, 5 do
   3193              eq(false, screen._grids[4].rows[i].wrap, i)
   3194            end
   3195          end,
   3196        }
   3197      else
   3198        screen:expect([[
   3199          ^     {5:╔═════════╗}                        |
   3200          {0:~    }{5:}{1:aaa long }{5:}{0:                        }|
   3201          {0:~    }{5:}{1:line     }{5:}{0:                        }|
   3202          {0:~    }{5:}{1:abb acc  }{5:}{0:                        }|
   3203          {0:~    }{5:╚═════════╝}{0:                        }|
   3204          {0:~                                       }|*4
   3205                                                  |
   3206        ]])
   3207      end
   3208    end)
   3209 
   3210    it('does wrap without vertical border', function()
   3211      screen:try_resize(40, 10)
   3212      local buf = api.nvim_create_buf(false, false)
   3213      api.nvim_buf_set_lines(buf, 0, -1, true, { 'aaa long line', 'abb acc ' })
   3214      api.nvim_open_win(buf, false, { relative = 'editor', width = 9, height = 3, row = 0, col = 5 })
   3215      if multigrid then
   3216        screen:expect {
   3217          grid = [[
   3218          ## grid 1
   3219            [2:----------------------------------------]|*9
   3220            [3:----------------------------------------]|
   3221          ## grid 2
   3222            ^                                        |
   3223            {0:~                                       }|*8
   3224          ## grid 3
   3225                                                    |
   3226          ## grid 4
   3227            {1:aaa long }|
   3228            {1:line     }|
   3229            {1:abb acc  }|
   3230          ]],
   3231          win_pos = { [2] = { height = 9, startcol = 0, startrow = 0, width = 40, win = 1000 } },
   3232          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
   3233          win_viewport = {
   3234            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3235            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   3236          },
   3237          win_viewport_margins = {
   3238            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
   3239            [4] = { bottom = 0, left = 0, right = 0, top = 0, win = 1001 },
   3240          },
   3241          condition = function()
   3242            for i = 1, 3 do
   3243              eq(i == 1, screen._grids[4].rows[i].wrap, i)
   3244            end
   3245          end,
   3246        }
   3247      else
   3248        screen:expect([[
   3249          ^     {1:aaa long }                          |
   3250          {0:~    }{1:line     }{0:                          }|
   3251          {0:~    }{1:abb acc  }{0:                          }|
   3252          {0:~                                       }|*6
   3253                                                  |
   3254        ]])
   3255      end
   3256    end)
   3257 
   3258    it('border is drawn properly when number column is too wide #35431', function()
   3259      local buf = api.nvim_create_buf(false, false)
   3260      local opts = { relative = 'editor', row = 1, col = 1, width = 3, height = 3, border = 'rounded' }
   3261      local win = api.nvim_open_win(buf, false, opts)
   3262      api.nvim_set_option_value('number', true, { win = win })
   3263      if multigrid then
   3264        screen:expect({
   3265          grid = [[
   3266        ## grid 1
   3267          [2:----------------------------------------]|*6
   3268          [3:----------------------------------------]|
   3269        ## grid 2
   3270          ^                                        |
   3271          {0:~                                       }|*5
   3272        ## grid 3
   3273                                                  |
   3274        ## grid 4
   3275          {5:╭───╮}|
   3276          {5:│}{32:  1}{5:│}|
   3277          {5:│}{32:   }{5:│}|*2
   3278          {5:╰───╯}|
   3279        ]],
   3280          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
   3281        })
   3282      else
   3283        screen:expect([[
   3284          ^                                        |
   3285          {0:~}{5:╭───╮}{0:                                  }|
   3286          {0:~}{5:}{32:  1}{5:}{0:                                  }|
   3287          {0:~}{5:}{32:   }{5:}{0:                                  }|*2
   3288          {0:~}{5:╰───╯}{0:                                  }|
   3289                                                  |
   3290        ]])
   3291      end
   3292    end)
   3293 
   3294    it('show ruler of current floating window', function()
   3295      command 'set ruler'
   3296      local buf = api.nvim_create_buf(false, false)
   3297      api.nvim_buf_set_lines(buf, 0, -1, true, { 'aaa aab ', 'abb acc ' })
   3298      api.nvim_open_win(buf, true, { relative = 'editor', width = 9, height = 3, row = 0, col = 5 })
   3299      feed 'gg'
   3300 
   3301      if multigrid then
   3302        screen:expect {
   3303          grid = [[
   3304        ## grid 1
   3305          [2:----------------------------------------]|*6
   3306          [3:----------------------------------------]|
   3307        ## grid 2
   3308                                                  |
   3309          {0:~                                       }|*5
   3310        ## grid 3
   3311                                1,1           All |
   3312        ## grid 4
   3313          {1:^aaa aab  }|
   3314          {1:abb acc  }|
   3315          {2:~        }|
   3316        ]],
   3317          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
   3318          win_viewport = {
   3319            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3320            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   3321          },
   3322        }
   3323      else
   3324        screen:expect {
   3325          grid = [[
   3326               {1:^aaa aab  }                          |
   3327          {0:~    }{1:abb acc  }{0:                          }|
   3328          {0:~    }{2:~        }{0:                          }|
   3329          {0:~                                       }|*3
   3330                                1,1           All |
   3331        ]],
   3332        }
   3333      end
   3334 
   3335      feed 'w'
   3336      if multigrid then
   3337        screen:expect {
   3338          grid = [[
   3339        ## grid 1
   3340          [2:----------------------------------------]|*6
   3341          [3:----------------------------------------]|
   3342        ## grid 2
   3343                                                  |
   3344          {0:~                                       }|*5
   3345        ## grid 3
   3346                                1,5           All |
   3347        ## grid 4
   3348          {1:aaa ^aab  }|
   3349          {1:abb acc  }|
   3350          {2:~        }|
   3351        ]],
   3352          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
   3353          win_viewport = {
   3354            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3355            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 4, linecount = 2, sum_scroll_delta = 0 },
   3356          },
   3357        }
   3358      else
   3359        screen:expect {
   3360          grid = [[
   3361               {1:aaa ^aab  }                          |
   3362          {0:~    }{1:abb acc  }{0:                          }|
   3363          {0:~    }{2:~        }{0:                          }|
   3364          {0:~                                       }|*3
   3365                                1,5           All |
   3366        ]],
   3367        }
   3368      end
   3369    end)
   3370 
   3371    it("correct ruler position in current float with 'rulerformat' set", function()
   3372      command 'set ruler rulerformat=fish:<><'
   3373      api.nvim_open_win(0, true, { relative = 'editor', width = 9, height = 3, row = 0, col = 5 })
   3374      if multigrid then
   3375        screen:expect {
   3376          grid = [[
   3377        ## grid 1
   3378          [2:----------------------------------------]|*6
   3379          [3:----------------------------------------]|
   3380        ## grid 2
   3381                                                  |
   3382          {0:~                                       }|*5
   3383        ## grid 3
   3384                                fish:<><          |
   3385        ## grid 4
   3386          {1:^         }|
   3387          {2:~        }|*2
   3388        ]],
   3389          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
   3390          win_viewport = {
   3391            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3392            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3393          },
   3394        }
   3395      else
   3396        screen:expect {
   3397          grid = [[
   3398               {1:^         }                          |
   3399          {0:~    }{2:~        }{0:                          }|*2
   3400          {0:~                                       }|*3
   3401                                fish:<><          |
   3402        ]],
   3403        }
   3404      end
   3405    end)
   3406 
   3407    it('does not show ruler of not-last current float during ins-completion', function()
   3408      screen:try_resize(50, 9)
   3409      command 'set ruler showmode'
   3410      api.nvim_open_win(0, false, { relative = 'editor', width = 3, height = 3, row = 0, col = 0 })
   3411      api.nvim_open_win(0, false, { relative = 'editor', width = 3, height = 3, row = 0, col = 5 })
   3412      feed '<c-w>w'
   3413      neq('', api.nvim_win_get_config(0).relative)
   3414      neq(fn.winnr '$', fn.winnr())
   3415      if multigrid then
   3416        screen:expect {
   3417          grid = [[
   3418        ## grid 1
   3419          [2:--------------------------------------------------]|*8
   3420          [3:--------------------------------------------------]|
   3421        ## grid 2
   3422                                                            |
   3423          {0:~                                                 }|*7
   3424        ## grid 3
   3425                                          0,0-1         All |
   3426        ## grid 4
   3427          {1:   }|
   3428          {2:~  }|*2
   3429        ## grid 5
   3430          {1:^   }|
   3431          {2:~  }|*2
   3432        ]],
   3433          float_pos = {
   3434            [4] = { 1001, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
   3435            [5] = { 1002, 'NW', 1, 0, 5, true, 50, 2, 0, 5 },
   3436          },
   3437          win_viewport = {
   3438            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3439            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3440            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3441          },
   3442        }
   3443      else
   3444        screen:expect {
   3445          grid = [[
   3446          {1:   }  {1:^   }                                          |
   3447          {2:~  }{0:  }{2:~  }{0:                                          }|*2
   3448          {0:~                                                 }|*5
   3449                                          0,0-1         All |
   3450        ]],
   3451        }
   3452      end
   3453      feed 'i<c-x>'
   3454      if multigrid then
   3455        screen:expect {
   3456          grid = [[
   3457        ## grid 1
   3458          [2:--------------------------------------------------]|*8
   3459          [3:--------------------------------------------------]|
   3460        ## grid 2
   3461                                                            |
   3462          {0:~                                                 }|*7
   3463        ## grid 3
   3464          {3:-- ^X mode (^]^D^E^F^I^K^L^N^O^P^Rs^U^V^Y)}        |
   3465        ## grid 4
   3466          {1:   }|
   3467          {2:~  }|*2
   3468        ## grid 5
   3469          {1:^   }|
   3470          {2:~  }|*2
   3471        ]],
   3472          float_pos = {
   3473            [4] = { 1001, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
   3474            [5] = { 1002, 'NW', 1, 0, 5, true, 50, 2, 0, 5 },
   3475          },
   3476          win_viewport = {
   3477            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3478            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3479            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3480          },
   3481        }
   3482      else
   3483        screen:expect {
   3484          grid = [[
   3485          {1:   }  {1:^   }                                          |
   3486          {2:~  }{0:  }{2:~  }{0:                                          }|*2
   3487          {0:~                                                 }|*5
   3488          {3:-- ^X mode (^]^D^E^F^I^K^L^N^O^P^Rs^U^V^Y)}        |
   3489        ]],
   3490        }
   3491      end
   3492    end)
   3493 
   3494    it('can have minimum size', function()
   3495      insert('the background text')
   3496      local buf = api.nvim_create_buf(false, true)
   3497      api.nvim_buf_set_lines(buf, 0, -1, true, { 'x' })
   3498      local win = api.nvim_open_win(buf, false, { relative = 'win', width = 1, height = 1, row = 0, col = 4, focusable = false })
   3499      if multigrid then
   3500        screen:expect {
   3501          grid = [[
   3502        ## grid 1
   3503          [2:----------------------------------------]|*6
   3504          [3:----------------------------------------]|
   3505        ## grid 2
   3506          the background tex^t                     |
   3507          {0:~                                       }|*5
   3508        ## grid 3
   3509                                                  |
   3510        ## grid 4
   3511          {1:x}|
   3512        ]],
   3513          float_pos = { [4] = { 1001, 'NW', 2, 0, 4, false, 50, 1, 0, 4 } },
   3514        }
   3515      else
   3516        screen:expect([[
   3517          the {1:x}ackground tex^t                     |
   3518          {0:~                                       }|*5
   3519                                                  |
   3520        ]])
   3521      end
   3522 
   3523      api.nvim_win_set_config(win, { relative = 'win', row = 0, col = 15 })
   3524      if multigrid then
   3525        screen:expect {
   3526          grid = [[
   3527        ## grid 1
   3528          [2:----------------------------------------]|*6
   3529          [3:----------------------------------------]|
   3530        ## grid 2
   3531          the background tex^t                     |
   3532          {0:~                                       }|*5
   3533        ## grid 3
   3534                                                  |
   3535        ## grid 4
   3536          {1:x}|
   3537        ]],
   3538          float_pos = { [4] = { 1001, 'NW', 2, 0, 15, false, 50, 1, 0, 15 } },
   3539        }
   3540      else
   3541        screen:expect([[
   3542          the background {1:x}ex^t                     |
   3543          {0:~                                       }|*5
   3544                                                  |
   3545        ]])
   3546      end
   3547 
   3548      api.nvim_win_close(win, false)
   3549      if multigrid then
   3550        screen:expect([[
   3551        ## grid 1
   3552          [2:----------------------------------------]|*6
   3553          [3:----------------------------------------]|
   3554        ## grid 2
   3555          the background tex^t                     |
   3556          {0:~                                       }|*5
   3557        ## grid 3
   3558                                                  |
   3559        ]])
   3560      else
   3561        screen:expect([[
   3562          the background tex^t                     |
   3563          {0:~                                       }|*5
   3564                                                  |
   3565        ]])
   3566      end
   3567    end)
   3568 
   3569    describe('no crash when rearranging windows', function()
   3570      local function test_rearrange_windows(cmd)
   3571        command('set laststatus=2')
   3572        screen:try_resize(40, 13)
   3573 
   3574        command('args X1 X2 X3 X4 X5 X6')
   3575        command('sargument 2')
   3576        command('sargument 3')
   3577        local w3 = curwin()
   3578        command('sargument 4')
   3579        local w4 = curwin()
   3580        command('sargument 5')
   3581        command('sargument 6')
   3582 
   3583        local float_opts = { relative = 'editor', row = 6, col = 0, width = 40, height = 1 }
   3584        api.nvim_win_set_config(w3, float_opts)
   3585        api.nvim_win_set_config(w4, float_opts)
   3586        command('wincmd =')
   3587        if multigrid then
   3588          screen:expect {
   3589            grid = [[
   3590          ## grid 1
   3591            [8:----------------------------------------]|*2
   3592            {4:X6                                      }|
   3593            [7:----------------------------------------]|*2
   3594            {5:X5                                      }|
   3595            [4:----------------------------------------]|*2
   3596            {5:X2                                      }|
   3597            [2:----------------------------------------]|*2
   3598            {5:X1                                      }|
   3599            [3:----------------------------------------]|
   3600          ## grid 2
   3601                                                    |
   3602            {0:~                                       }|
   3603          ## grid 3
   3604                                                    |
   3605          ## grid 4
   3606                                                    |
   3607            {0:~                                       }|
   3608          ## grid 5
   3609            {1:                                        }|
   3610          ## grid 6
   3611            {1:                                        }|
   3612          ## grid 7
   3613                                                    |
   3614            {0:~                                       }|
   3615          ## grid 8
   3616            ^                                        |
   3617            {0:~                                       }|
   3618          ]],
   3619            float_pos = {
   3620              [5] = { 1002, 'NW', 1, 6, 0, true, 50, 1, 6, 0 },
   3621              [6] = { 1003, 'NW', 1, 6, 0, true, 50, 2, 6, 0 },
   3622            },
   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 = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3626              [5] = { win = 1002, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3627              [6] = { win = 1003, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3628              [7] = { win = 1004, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3629              [8] = { win = 1005, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3630            },
   3631          }
   3632        else
   3633          screen:expect {
   3634            grid = [[
   3635            ^                                        |
   3636            {0:~                                       }|
   3637            {4:X6                                      }|
   3638                                                    |
   3639            {0:~                                       }|
   3640            {5:X5                                      }|
   3641            {1:                                        }|
   3642            {0:~                                       }|
   3643            {5:X2                                      }|
   3644                                                    |
   3645            {0:~                                       }|
   3646            {5:X1                                      }|
   3647                                                    |
   3648          ]],
   3649          }
   3650        end
   3651 
   3652        command(cmd)
   3653        if multigrid then
   3654          screen:expect {
   3655            grid = [[
   3656          ## grid 1
   3657            [2:----------------------------------------]|
   3658            {4:X1                                      }|
   3659            [4:----------------------------------------]|
   3660            {5:X2                                      }|
   3661            [9:----------------------------------------]|
   3662            {5:X3                                      }|
   3663            [10:----------------------------------------]|
   3664            {5:X4                                      }|
   3665            [7:----------------------------------------]|
   3666            {5:X5                                      }|
   3667            [8:----------------------------------------]|
   3668            {5:X6                                      }|
   3669            [3:----------------------------------------]|
   3670          ## grid 2
   3671            ^                                        |
   3672          ## grid 3
   3673                                                    |
   3674          ## grid 4
   3675                                                    |
   3676          ## grid 7
   3677                                                    |
   3678          ## grid 8
   3679                                                    |
   3680          ## grid 9
   3681                                                    |
   3682          ## grid 10
   3683                                                    |
   3684          ]],
   3685            win_viewport = {
   3686              [2] = { win = 1000, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3687              [4] = { win = 1001, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3688              [7] = { win = 1004, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3689              [8] = { win = 1005, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3690              [9] = { win = 1006, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3691              [10] = { win = 1007, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   3692            },
   3693          }
   3694        else
   3695          screen:expect {
   3696            grid = [[
   3697            ^                                        |
   3698            {4:X1                                      }|
   3699                                                    |
   3700            {5:X2                                      }|
   3701                                                    |
   3702            {5:X3                                      }|
   3703                                                    |
   3704            {5:X4                                      }|
   3705                                                    |
   3706            {5:X5                                      }|
   3707                                                    |
   3708            {5:X6                                      }|
   3709                                                    |
   3710          ]],
   3711          }
   3712        end
   3713      end
   3714 
   3715      it('using :unhide', function()
   3716        test_rearrange_windows('unhide')
   3717      end)
   3718 
   3719      it('using :all', function()
   3720        test_rearrange_windows('all')
   3721      end)
   3722    end)
   3723 
   3724    it('API has proper error messages', function()
   3725      local buf = api.nvim_create_buf(false, false)
   3726      eq("Invalid key: 'bork'", pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, bork = true }))
   3727      eq(
   3728        "'win' key is only valid with relative='win' and relative=''",
   3729        pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, win = 0 })
   3730      )
   3731      eq(
   3732        "floating windows cannot have 'vertical'",
   3733        pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, vertical = true })
   3734      )
   3735      eq(
   3736        "floating windows cannot have 'split'",
   3737        pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, split = 'left' })
   3738      )
   3739      eq(
   3740        "Only one of 'relative' and 'external' must be used",
   3741        pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, external = true })
   3742      )
   3743      eq(
   3744        "Invalid value of 'relative' key",
   3745        pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'shell', row = 0, col = 0 })
   3746      )
   3747      eq(
   3748        "Invalid value of 'anchor' key",
   3749        pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor', row = 0, col = 0, anchor = 'bottom' })
   3750      )
   3751      eq(
   3752        "'relative' requires 'row'/'col' or 'bufpos'",
   3753        pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 2, relative = 'editor' })
   3754      )
   3755      eq(
   3756        "'width' key must be a positive Integer",
   3757        pcall_err(api.nvim_open_win, buf, false, { width = -1, height = 2, relative = 'editor', row = 0, col = 0 })
   3758      )
   3759      eq(
   3760        "'height' key must be a positive Integer",
   3761        pcall_err(api.nvim_open_win, buf, false, { width = 20, height = -1, relative = 'editor', row = 0, col = 0 })
   3762      )
   3763      eq(
   3764        "'height' key must be a positive Integer",
   3765        pcall_err(api.nvim_open_win, buf, false, { width = 20, height = 0, relative = 'editor', row = 0, col = 0 })
   3766      )
   3767      eq("Must specify 'width'", pcall_err(api.nvim_open_win, buf, false, { relative = 'editor', row = 0, col = 0 }))
   3768      eq("Must specify 'height'", pcall_err(api.nvim_open_win, buf, false, { relative = 'editor', row = 0, col = 0, width = 2 }))
   3769    end)
   3770 
   3771    it('can be placed relative window or cursor', function()
   3772      screen:try_resize(40, 9)
   3773      api.nvim_buf_set_lines(0, 0, -1, true, { 'just some', 'example text' })
   3774      feed('gge')
   3775      local oldwin = api.nvim_get_current_win()
   3776      command('below split')
   3777      if multigrid then
   3778        screen:expect([[
   3779        ## grid 1
   3780          [2:----------------------------------------]|*3
   3781          {5:[No Name] [+]                           }|
   3782          [4:----------------------------------------]|*3
   3783          {4:[No Name] [+]                           }|
   3784          [3:----------------------------------------]|
   3785        ## grid 2
   3786          just some                               |
   3787          example text                            |
   3788          {0:~                                       }|
   3789        ## grid 3
   3790                                                  |
   3791        ## grid 4
   3792          jus^t some                               |
   3793          example text                            |
   3794          {0:~                                       }|
   3795        ]])
   3796      else
   3797        screen:expect([[
   3798          just some                               |
   3799          example text                            |
   3800          {0:~                                       }|
   3801          {5:[No Name] [+]                           }|
   3802          jus^t some                               |
   3803          example text                            |
   3804          {0:~                                       }|
   3805          {4:[No Name] [+]                           }|
   3806                                                  |
   3807        ]])
   3808      end
   3809 
   3810      local buf = api.nvim_create_buf(false, false)
   3811      -- no 'win' arg, relative default window
   3812      local win = api.nvim_open_win(buf, false, { relative = 'win', width = 20, height = 2, row = 0, col = 10 })
   3813      if multigrid then
   3814        screen:expect {
   3815          grid = [[
   3816        ## grid 1
   3817          [2:----------------------------------------]|*3
   3818          {5:[No Name] [+]                           }|
   3819          [4:----------------------------------------]|*3
   3820          {4:[No Name] [+]                           }|
   3821          [3:----------------------------------------]|
   3822        ## grid 2
   3823          just some                               |
   3824          example text                            |
   3825          {0:~                                       }|
   3826        ## grid 3
   3827                                                  |
   3828        ## grid 4
   3829          jus^t some                               |
   3830          example text                            |
   3831          {0:~                                       }|
   3832        ## grid 5
   3833          {1:                    }|
   3834          {2:~                   }|
   3835        ]],
   3836          float_pos = { [5] = { 1002, 'NW', 4, 0, 10, true, 50, 1, 4, 10 } },
   3837        }
   3838      else
   3839        screen:expect([[
   3840          just some                               |
   3841          example text                            |
   3842          {0:~                                       }|
   3843          {5:[No Name] [+]                           }|
   3844          jus^t some {1:                    }          |
   3845          example te{2:~                   }          |
   3846          {0:~                                       }|
   3847          {4:[No Name] [+]                           }|
   3848                                                  |
   3849        ]])
   3850      end
   3851 
   3852      api.nvim_win_set_config(win, { relative = 'cursor', row = 1, col = -2 })
   3853      if multigrid then
   3854        screen:expect {
   3855          grid = [[
   3856        ## grid 1
   3857          [2:----------------------------------------]|*3
   3858          {5:[No Name] [+]                           }|
   3859          [4:----------------------------------------]|*3
   3860          {4:[No Name] [+]                           }|
   3861          [3:----------------------------------------]|
   3862        ## grid 2
   3863          just some                               |
   3864          example text                            |
   3865          {0:~                                       }|
   3866        ## grid 3
   3867                                                  |
   3868        ## grid 4
   3869          jus^t some                               |
   3870          example text                            |
   3871          {0:~                                       }|
   3872        ## grid 5
   3873          {1:                    }|
   3874          {2:~                   }|
   3875        ]],
   3876          float_pos = { [5] = { 1002, 'NW', 4, 1, 1, true, 50, 1, 5, 1 } },
   3877        }
   3878      else
   3879        screen:expect([[
   3880          just some                               |
   3881          example text                            |
   3882          {0:~                                       }|
   3883          {5:[No Name] [+]                           }|
   3884          jus^t some                               |
   3885          e{1:                    }                   |
   3886          {0:~}{2:~                   }{0:                   }|
   3887          {4:[No Name] [+]                           }|
   3888                                                  |
   3889        ]])
   3890      end
   3891 
   3892      api.nvim_win_set_config(win, { relative = 'cursor', row = 0, col = 0, anchor = 'SW' })
   3893      if multigrid then
   3894        screen:expect {
   3895          grid = [[
   3896        ## grid 1
   3897          [2:----------------------------------------]|*3
   3898          {5:[No Name] [+]                           }|
   3899          [4:----------------------------------------]|*3
   3900          {4:[No Name] [+]                           }|
   3901          [3:----------------------------------------]|
   3902        ## grid 2
   3903          just some                               |
   3904          example text                            |
   3905          {0:~                                       }|
   3906        ## grid 3
   3907                                                  |
   3908        ## grid 4
   3909          jus^t some                               |
   3910          example text                            |
   3911          {0:~                                       }|
   3912        ## grid 5
   3913          {1:                    }|
   3914          {2:~                   }|
   3915        ]],
   3916          float_pos = { [5] = { 1002, 'SW', 4, 0, 3, true, 50, 1, 2, 3 } },
   3917        }
   3918      else
   3919        screen:expect([[
   3920          just some                               |
   3921          example text                            |
   3922          {0:~  }{1:                    }{0:                 }|
   3923          {5:[No}{2:~                   }{5:                 }|
   3924          jus^t some                               |
   3925          example text                            |
   3926          {0:~                                       }|
   3927          {4:[No Name] [+]                           }|
   3928                                                  |
   3929        ]])
   3930      end
   3931 
   3932      api.nvim_win_set_config(win, { relative = 'win', win = oldwin, row = 1, col = 10, anchor = 'NW' })
   3933      if multigrid then
   3934        screen:expect {
   3935          grid = [[
   3936        ## grid 1
   3937          [2:----------------------------------------]|*3
   3938          {5:[No Name] [+]                           }|
   3939          [4:----------------------------------------]|*3
   3940          {4:[No Name] [+]                           }|
   3941          [3:----------------------------------------]|
   3942        ## grid 2
   3943          just some                               |
   3944          example text                            |
   3945          {0:~                                       }|
   3946        ## grid 3
   3947                                                  |
   3948        ## grid 4
   3949          jus^t some                               |
   3950          example text                            |
   3951          {0:~                                       }|
   3952        ## grid 5
   3953          {1:                    }|
   3954          {2:~                   }|
   3955        ]],
   3956          float_pos = { [5] = { 1002, 'NW', 2, 1, 10, true, 50, 1, 1, 10 } },
   3957        }
   3958      else
   3959        screen:expect([[
   3960          just some                               |
   3961          example te{1:                    }          |
   3962          {0:~         }{2:~                   }{0:          }|
   3963          {5:[No Name] [+]                           }|
   3964          jus^t some                               |
   3965          example text                            |
   3966          {0:~                                       }|
   3967          {4:[No Name] [+]                           }|
   3968                                                  |
   3969        ]])
   3970      end
   3971 
   3972      api.nvim_win_set_config(win, { relative = 'win', win = oldwin, row = 3, col = 39, anchor = 'SE' })
   3973      if multigrid then
   3974        screen:expect {
   3975          grid = [[
   3976        ## grid 1
   3977          [2:----------------------------------------]|*3
   3978          {5:[No Name] [+]                           }|
   3979          [4:----------------------------------------]|*3
   3980          {4:[No Name] [+]                           }|
   3981          [3:----------------------------------------]|
   3982        ## grid 2
   3983          just some                               |
   3984          example text                            |
   3985          {0:~                                       }|
   3986        ## grid 3
   3987                                                  |
   3988        ## grid 4
   3989          jus^t some                               |
   3990          example text                            |
   3991          {0:~                                       }|
   3992        ## grid 5
   3993          {1:                    }|
   3994          {2:~                   }|
   3995        ]],
   3996          float_pos = { [5] = { 1002, 'SE', 2, 3, 39, true, 50, 1, 1, 19 } },
   3997        }
   3998      else
   3999        screen:expect([[
   4000          just some                               |
   4001          example text       {1:                    } |
   4002          {0:~                  }{2:~                   }{0: }|
   4003          {5:[No Name] [+]                           }|
   4004          jus^t some                               |
   4005          example text                            |
   4006          {0:~                                       }|
   4007          {4:[No Name] [+]                           }|
   4008                                                  |
   4009        ]])
   4010      end
   4011 
   4012      api.nvim_win_set_config(win, { relative = 'win', win = 0, row = 0, col = 50, anchor = 'NE' })
   4013      if multigrid then
   4014        screen:expect {
   4015          grid = [[
   4016        ## grid 1
   4017          [2:----------------------------------------]|*3
   4018          {5:[No Name] [+]                           }|
   4019          [4:----------------------------------------]|*3
   4020          {4:[No Name] [+]                           }|
   4021          [3:----------------------------------------]|
   4022        ## grid 2
   4023          just some                               |
   4024          example text                            |
   4025          {0:~                                       }|
   4026        ## grid 3
   4027                                                  |
   4028        ## grid 4
   4029          jus^t some                               |
   4030          example text                            |
   4031          {0:~                                       }|
   4032        ## grid 5
   4033          {1:                    }|
   4034          {2:~                   }|
   4035        ]],
   4036          float_pos = { [5] = { 1002, 'NE', 4, 0, 50, true, 50, 1, 4, 20 } },
   4037          win_viewport = {
   4038            [2] = { topline = 0, botline = 3, curline = 0, curcol = 3, linecount = 2, sum_scroll_delta = 0, win = 1000 },
   4039            [4] = { topline = 0, botline = 3, curline = 0, curcol = 3, linecount = 2, sum_scroll_delta = 0, win = 1001 },
   4040            [5] = { topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0, win = 1002 },
   4041          },
   4042        }
   4043      else
   4044        screen:expect([[
   4045          just some                               |
   4046          example text                            |
   4047          {0:~                                       }|
   4048          {5:[No Name] [+]                           }|
   4049          jus^t some           {1:                    }|
   4050          example text        {2:~                   }|
   4051          {0:~                                       }|
   4052          {4:[No Name] [+]                           }|
   4053                                                  |
   4054        ]])
   4055      end
   4056    end)
   4057 
   4058    it('always anchor to corner including border', function()
   4059      screen:try_resize(40, 13)
   4060      api.nvim_buf_set_lines(0, 0, -1, true, { 'just some example text', 'some more example text' })
   4061      feed('ggeee')
   4062      command('below split')
   4063      if multigrid then
   4064        screen:expect([[
   4065        ## grid 1
   4066          [2:----------------------------------------]|*5
   4067          {5:[No Name] [+]                           }|
   4068          [4:----------------------------------------]|*5
   4069          {4:[No Name] [+]                           }|
   4070          [3:----------------------------------------]|
   4071        ## grid 2
   4072          just some example text                  |
   4073          some more example text                  |
   4074          {0:~                                       }|*3
   4075        ## grid 3
   4076                                                  |
   4077        ## grid 4
   4078          just some exampl^e text                  |
   4079          some more example text                  |
   4080          {0:~                                       }|*3
   4081        ]])
   4082      else
   4083        screen:expect([[
   4084          just some example text                  |
   4085          some more example text                  |
   4086          {0:~                                       }|*3
   4087          {5:[No Name] [+]                           }|
   4088          just some exampl^e text                  |
   4089          some more example text                  |
   4090          {0:~                                       }|*3
   4091          {4:[No Name] [+]                           }|
   4092                                                  |
   4093        ]])
   4094      end
   4095 
   4096      local buf = api.nvim_create_buf(false, false)
   4097      api.nvim_buf_set_lines(buf, 0, -1, true, { ' halloj! ', ' BORDAA  ' })
   4098      local win = api.nvim_open_win(buf, false, { relative = 'cursor', width = 9, height = 2, row = 1, col = -2, border = 'double' })
   4099 
   4100      if multigrid then
   4101        screen:expect {
   4102          grid = [[
   4103        ## grid 1
   4104          [2:----------------------------------------]|*5
   4105          {5:[No Name] [+]                           }|
   4106          [4:----------------------------------------]|*5
   4107          {4:[No Name] [+]                           }|
   4108          [3:----------------------------------------]|
   4109        ## grid 2
   4110          just some example text                  |
   4111          some more example text                  |
   4112          {0:~                                       }|*3
   4113        ## grid 3
   4114                                                  |
   4115        ## grid 4
   4116          just some exampl^e text                  |
   4117          some more example text                  |
   4118          {0:~                                       }|*3
   4119        ## grid 5
   4120          {5:╔═════════╗}|
   4121          {5:║}{1: halloj! }{5:║}|
   4122          {5:║}{1: BORDAA  }{5:║}|
   4123          {5:╚═════════╝}|
   4124        ]],
   4125          float_pos = { [5] = { 1002, 'NW', 4, 1, 14, true, 50, 1, 7, 14 } },
   4126        }
   4127      else
   4128        screen:expect([[
   4129          just some example text                  |
   4130          some more example text                  |
   4131          {0:~                                       }|*3
   4132          {5:[No Name] [+]                           }|
   4133          just some exampl^e text                  |
   4134          some more exam{5:╔═════════╗}               |
   4135          {0:~             }{5:}{1: halloj! }{5:}{0:               }|
   4136          {0:~             }{5:}{1: BORDAA  }{5:}{0:               }|
   4137          {0:~             }{5:╚═════════╝}{0:               }|
   4138          {4:[No Name] [+]                           }|
   4139                                                  |
   4140        ]])
   4141      end
   4142 
   4143      api.nvim_win_set_config(win, { relative = 'cursor', row = 0, col = -2, anchor = 'NE' })
   4144      if multigrid then
   4145        screen:expect {
   4146          grid = [[
   4147        ## grid 1
   4148          [2:----------------------------------------]|*5
   4149          {5:[No Name] [+]                           }|
   4150          [4:----------------------------------------]|*5
   4151          {4:[No Name] [+]                           }|
   4152          [3:----------------------------------------]|
   4153        ## grid 2
   4154          just some example text                  |
   4155          some more example text                  |
   4156          {0:~                                       }|*3
   4157        ## grid 3
   4158                                                  |
   4159        ## grid 4
   4160          just some exampl^e text                  |
   4161          some more example text                  |
   4162          {0:~                                       }|*3
   4163        ## grid 5
   4164          {5:╔═════════╗}|
   4165          {5:║}{1: halloj! }{5:║}|
   4166          {5:║}{1: BORDAA  }{5:║}|
   4167          {5:╚═════════╝}|
   4168        ]],
   4169          float_pos = { [5] = { 1002, 'NE', 4, 0, 14, true, 50, 1, 6, 3 } },
   4170        }
   4171      else
   4172        screen:expect([[
   4173          just some example text                  |
   4174          some more example text                  |
   4175          {0:~                                       }|*3
   4176          {5:[No Name] [+]                           }|
   4177          jus{5:╔═════════╗}pl^e text                  |
   4178          som{5:}{1: halloj! }{5:}ple text                  |
   4179          {0:~  }{5:}{1: BORDAA  }{5:}{0:                          }|
   4180          {0:~  }{5:╚═════════╝}{0:                          }|
   4181          {0:~                                       }|
   4182          {4:[No Name] [+]                           }|
   4183                                                  |
   4184        ]])
   4185      end
   4186 
   4187      api.nvim_win_set_config(win, { relative = 'cursor', row = 1, col = -2, anchor = 'SE' })
   4188      if multigrid then
   4189        screen:expect {
   4190          grid = [[
   4191        ## grid 1
   4192          [2:----------------------------------------]|*5
   4193          {5:[No Name] [+]                           }|
   4194          [4:----------------------------------------]|*5
   4195          {4:[No Name] [+]                           }|
   4196          [3:----------------------------------------]|
   4197        ## grid 2
   4198          just some example text                  |
   4199          some more example text                  |
   4200          {0:~                                       }|*3
   4201        ## grid 3
   4202                                                  |
   4203        ## grid 4
   4204          just some exampl^e text                  |
   4205          some more example text                  |
   4206          {0:~                                       }|*3
   4207        ## grid 5
   4208          {5:╔═════════╗}|
   4209          {5:║}{1: halloj! }{5:║}|
   4210          {5:║}{1: BORDAA  }{5:║}|
   4211          {5:╚═════════╝}|
   4212        ]],
   4213          float_pos = { [5] = { 1002, 'SE', 4, 1, 14, true, 50, 1, 3, 3 } },
   4214        }
   4215      else
   4216        screen:expect([[
   4217          just some example text                  |
   4218          some more example text                  |
   4219          {0:~                                       }|
   4220          {0:~  }{5:╔═════════╗}{0:                          }|
   4221          {0:~  }{5:}{1: halloj! }{5:}{0:                          }|
   4222          {5:[No}{1: BORDAA  }{5:                          }|
   4223          jus{5:╚═════════╝}pl^e text                  |
   4224          some more example text                  |
   4225          {0:~                                       }|*3
   4226          {4:[No Name] [+]                           }|
   4227                                                  |
   4228        ]])
   4229      end
   4230 
   4231      api.nvim_win_set_config(win, { relative = 'cursor', row = 0, col = -2, anchor = 'SW' })
   4232      if multigrid then
   4233        screen:expect {
   4234          grid = [[
   4235        ## grid 1
   4236          [2:----------------------------------------]|*5
   4237          {5:[No Name] [+]                           }|
   4238          [4:----------------------------------------]|*5
   4239          {4:[No Name] [+]                           }|
   4240          [3:----------------------------------------]|
   4241        ## grid 2
   4242          just some example text                  |
   4243          some more example text                  |
   4244          {0:~                                       }|*3
   4245        ## grid 3
   4246                                                  |
   4247        ## grid 4
   4248          just some exampl^e text                  |
   4249          some more example text                  |
   4250          {0:~                                       }|*3
   4251        ## grid 5
   4252          {5:╔═════════╗}|
   4253          {5:║}{1: halloj! }{5:║}|
   4254          {5:║}{1: BORDAA  }{5:║}|
   4255          {5:╚═════════╝}|
   4256        ]],
   4257          float_pos = { [5] = { 1002, 'SW', 4, 0, 14, true, 50, 1, 2, 14 } },
   4258        }
   4259      else
   4260        screen:expect([[
   4261          just some example text                  |
   4262          some more example text                  |
   4263          {0:~             }{5:╔═════════╗}{0:               }|
   4264          {0:~             }{5:}{1: halloj! }{5:}{0:               }|
   4265          {0:~             }{5:}{1: BORDAA  }{5:}{0:               }|
   4266          {5:[No Name] [+] ╚═════════╝               }|
   4267          just some exampl^e text                  |
   4268          some more example text                  |
   4269          {0:~                                       }|*3
   4270          {4:[No Name] [+]                           }|
   4271                                                  |
   4272        ]])
   4273      end
   4274    end)
   4275 
   4276    it('anchored to another floating window updated in the same call #14735', function()
   4277      feed('i<CR><CR><CR><Esc>')
   4278 
   4279      exec([[
   4280        let b1 = nvim_create_buf(v:true, v:false)
   4281        let b2 = nvim_create_buf(v:true, v:false)
   4282        let b3 = nvim_create_buf(v:true, v:false)
   4283        let b4 = nvim_create_buf(v:true, v:false)
   4284        let b5 = nvim_create_buf(v:true, v:false)
   4285        let b6 = nvim_create_buf(v:true, v:false)
   4286        let b7 = nvim_create_buf(v:true, v:false)
   4287        let b8 = nvim_create_buf(v:true, v:false)
   4288        call setbufline(b1, 1, '1')
   4289        call setbufline(b2, 1, '2')
   4290        call setbufline(b3, 1, '3')
   4291        call setbufline(b4, 1, '4')
   4292        call setbufline(b5, 1, '5')
   4293        call setbufline(b6, 1, '6')
   4294        call setbufline(b7, 1, '7')
   4295        call setbufline(b8, 1, '8')
   4296        let o1 = #{relative: 'editor', row: 1, col: 10, width: 5, height: 1}
   4297        let w1 = nvim_open_win(b1, v:false, o1)
   4298        let o2 = extendnew(o1, #{col: 30})
   4299        let w2 = nvim_open_win(b2, v:false, o2)
   4300        let o3 = extendnew(o1, #{relative: 'win', win: w1, anchor: 'NE', col: 0})
   4301        let w3 = nvim_open_win(b3, v:false, o3)
   4302        let o4 = extendnew(o3, #{win: w2})
   4303        let w4 = nvim_open_win(b4, v:false, o4)
   4304        let o5 = extendnew(o3, #{win: w3, anchor: 'SE', row: 0})
   4305        let w5 = nvim_open_win(b5, v:false, o5)
   4306        let o6 = extendnew(o5, #{win: w4})
   4307        let w6 = nvim_open_win(b6, v:false, o6)
   4308        let o7 = extendnew(o5, #{win: w5, anchor: 'SW', col: 5})
   4309        let w7 = nvim_open_win(b7, v:false, o7)
   4310        let o8 = extendnew(o7, #{win: w6})
   4311        let w8 = nvim_open_win(b8, v:false, o8)
   4312      ]])
   4313      if multigrid then
   4314        screen:expect {
   4315          grid = [[
   4316        ## grid 1
   4317          [2:----------------------------------------]|*6
   4318          [3:----------------------------------------]|
   4319        ## grid 2
   4320                                                  |*3
   4321          ^                                        |
   4322          {0:~                                       }|*2
   4323        ## grid 3
   4324                                                  |
   4325        ## grid 5
   4326          {1:1    }|
   4327        ## grid 6
   4328          {1:2    }|
   4329        ## grid 7
   4330          {1:3    }|
   4331        ## grid 8
   4332          {1:4    }|
   4333        ## grid 9
   4334          {1:5    }|
   4335        ## grid 10
   4336          {1:6    }|
   4337        ## grid 11
   4338          {1:7    }|
   4339        ## grid 12
   4340          {1:8    }|
   4341        ]],
   4342          float_pos = {
   4343            [5] = { 1002, 'NW', 1, 1, 10, true, 50, 5, 1, 10 },
   4344            [6] = { 1003, 'NW', 1, 1, 30, true, 50, 1, 1, 30 },
   4345            [7] = { 1004, 'NE', 5, 1, 0, true, 50, 6, 2, 5 },
   4346            [8] = { 1005, 'NE', 6, 1, 0, true, 50, 2, 2, 25 },
   4347            [9] = { 1006, 'SE', 7, 0, 0, true, 50, 7, 1, 0 },
   4348            [10] = { 1007, 'SE', 8, 0, 0, true, 50, 3, 1, 20 },
   4349            [11] = { 1008, 'SW', 9, 0, 5, true, 50, 8, 0, 5 },
   4350            [12] = { 1009, 'SW', 10, 0, 5, true, 50, 4, 0, 25 },
   4351          },
   4352        }
   4353      else
   4354        screen:expect([[
   4355               {1:7    }               {1:8    }          |
   4356          {1:5    }     {1:1    }     {1:6    }     {1:2    }     |
   4357               {1:3    }               {1:4    }          |
   4358          ^                                        |
   4359          {0:~                                       }|*2
   4360                                                  |
   4361        ]])
   4362      end
   4363 
   4364      -- Reconfigure in different directions
   4365      exec([[
   4366        let o1 = extendnew(o1, #{anchor: 'NW'})
   4367        call nvim_win_set_config(w8, o1)
   4368        let o2 = extendnew(o2, #{anchor: 'NW'})
   4369        call nvim_win_set_config(w4, o2)
   4370        let o3 = extendnew(o3, #{win: w8})
   4371        call nvim_win_set_config(w2, o3)
   4372        let o4 = extendnew(o4, #{win: w4})
   4373        call nvim_win_set_config(w1, o4)
   4374        let o5 = extendnew(o5, #{win: w2})
   4375        call nvim_win_set_config(w6, o5)
   4376        let o6 = extendnew(o6, #{win: w1})
   4377        call nvim_win_set_config(w3, o6)
   4378        let o7 = extendnew(o7, #{win: w6})
   4379        call nvim_win_set_config(w5, o7)
   4380        let o8 = extendnew(o8, #{win: w3})
   4381        call nvim_win_set_config(w7, o8)
   4382      ]])
   4383      if multigrid then
   4384        screen:expect {
   4385          grid = [[
   4386        ## grid 1
   4387          [2:----------------------------------------]|*6
   4388          [3:----------------------------------------]|
   4389        ## grid 2
   4390                                                  |*3
   4391          ^                                        |
   4392          {0:~                                       }|*2
   4393        ## grid 3
   4394                                                  |
   4395        ## grid 5
   4396          {1:1    }|
   4397        ## grid 6
   4398          {1:2    }|
   4399        ## grid 7
   4400          {1:3    }|
   4401        ## grid 8
   4402          {1:4    }|
   4403        ## grid 9
   4404          {1:5    }|
   4405        ## grid 10
   4406          {1:6    }|
   4407        ## grid 11
   4408          {1:7    }|
   4409        ## grid 12
   4410          {1:8    }|
   4411        ]],
   4412          float_pos = {
   4413            [5] = { 1002, 'NE', 8, 1, 0, true, 50, 5, 2, 25 },
   4414            [6] = { 1003, 'NE', 12, 1, 0, true, 50, 1, 2, 5 },
   4415            [7] = { 1004, 'SE', 5, 0, 0, true, 50, 6, 1, 20 },
   4416            [8] = { 1005, 'NW', 1, 1, 30, true, 50, 2, 1, 30 },
   4417            [9] = { 1006, 'SW', 10, 0, 5, true, 50, 7, 0, 5 },
   4418            [10] = { 1007, 'SE', 6, 0, 0, true, 50, 3, 1, 0 },
   4419            [11] = { 1008, 'SW', 7, 0, 5, true, 50, 8, 0, 25 },
   4420            [12] = { 1009, 'NW', 1, 1, 10, true, 50, 4, 1, 10 },
   4421          },
   4422        }
   4423      else
   4424        screen:expect([[
   4425               {1:5    }               {1:7    }          |
   4426          {1:6    }     {1:8    }     {1:3    }     {1:4    }     |
   4427               {1:2    }               {1:1    }          |
   4428          ^                                        |
   4429          {0:~                                       }|*2
   4430                                                  |
   4431        ]])
   4432      end
   4433 
   4434      -- Not clear how cycles should behave, but they should not hang or crash
   4435      exec([[
   4436        let o1 = extendnew(o1, #{relative: 'win', win: w7})
   4437        call nvim_win_set_config(w1, o1)
   4438        let o2 = extendnew(o2, #{relative: 'win', win: w8})
   4439        call nvim_win_set_config(w2, o2)
   4440        let o3 = extendnew(o3, #{win: w1})
   4441        call nvim_win_set_config(w3, o3)
   4442        let o4 = extendnew(o4, #{win: w2})
   4443        call nvim_win_set_config(w4, o4)
   4444        let o5 = extendnew(o5, #{win: w3})
   4445        call nvim_win_set_config(w5, o5)
   4446        let o6 = extendnew(o6, #{win: w4})
   4447        call nvim_win_set_config(w6, o6)
   4448        let o7 = extendnew(o7, #{win: w5})
   4449        call nvim_win_set_config(w7, o7)
   4450        let o8 = extendnew(o8, #{win: w6})
   4451        call nvim_win_set_config(w8, o8)
   4452        redraw
   4453      ]])
   4454    end)
   4455 
   4456    it('can be placed relative text in a window', function()
   4457      screen:try_resize(30, 5)
   4458      local firstwin = api.nvim_get_current_win()
   4459      api.nvim_buf_set_lines(0, 0, -1, true, { 'just some', 'example text that is wider than the window', '', '', 'more text' })
   4460      if multigrid then
   4461        screen:expect {
   4462          grid = [[
   4463        ## grid 1
   4464          [2:------------------------------]|*4
   4465          [3:------------------------------]|
   4466        ## grid 2
   4467          ^just some                     |
   4468          example text that is wider tha|
   4469          n the window                  |
   4470                                        |
   4471        ## grid 3
   4472                                        |
   4473        ]],
   4474        }
   4475      else
   4476        screen:expect {
   4477          grid = [[
   4478          ^just some                     |
   4479          example text that is wider tha|
   4480          n the window                  |
   4481                                        |*2
   4482        ]],
   4483        }
   4484      end
   4485 
   4486      local buf = api.nvim_create_buf(false, false)
   4487      api.nvim_buf_set_lines(buf, 0, -1, true, { 'some info!' })
   4488 
   4489      local win = api.nvim_open_win(buf, false, { relative = 'win', width = 12, height = 1, bufpos = { 1, 32 } })
   4490      if multigrid then
   4491        screen:expect {
   4492          grid = [[
   4493        ## grid 1
   4494          [2:------------------------------]|*4
   4495          [3:------------------------------]|
   4496        ## grid 2
   4497          ^just some                     |
   4498          example text that is wider tha|
   4499          n the window                  |
   4500                                        |
   4501        ## grid 3
   4502                                        |
   4503        ## grid 4
   4504          {1:some info!  }|
   4505        ]],
   4506          float_pos = { [4] = { 1001, 'NW', 2, 3, 2, true, 50, 1, 3, 2 } },
   4507        }
   4508      else
   4509        screen:expect {
   4510          grid = [[
   4511          ^just some                     |
   4512          example text that is wider tha|
   4513          n the window                  |
   4514            {1:some info!  }                |
   4515                                        |
   4516        ]],
   4517        }
   4518      end
   4519      eq({
   4520        relative = 'win',
   4521        width = 12,
   4522        height = 1,
   4523        bufpos = { 1, 32 },
   4524        anchor = 'NW',
   4525        border = 'none',
   4526        hide = false,
   4527        external = false,
   4528        col = 0,
   4529        row = 1,
   4530        win = firstwin,
   4531        focusable = true,
   4532        mouse = true,
   4533        zindex = 50,
   4534      }, api.nvim_win_get_config(win))
   4535 
   4536      feed('<c-e>')
   4537      if multigrid then
   4538        screen:expect {
   4539          grid = [[
   4540        ## grid 1
   4541          [2:------------------------------]|*4
   4542          [3:------------------------------]|
   4543        ## grid 2
   4544          ^example text that is wider tha|
   4545          n the window                  |
   4546                                        |*2
   4547        ## grid 3
   4548                                        |
   4549        ## grid 4
   4550          {1:some info!  }|
   4551        ]],
   4552          float_pos = { [4] = { 1001, 'NW', 2, 2, 2, true, 50, 1, 2, 2 } },
   4553        }
   4554      else
   4555        screen:expect {
   4556          grid = [[
   4557          ^example text that is wider tha|
   4558          n the window                  |
   4559            {1:some info!  }                |
   4560                                        |*2
   4561        ]],
   4562        }
   4563      end
   4564 
   4565      screen:try_resize(45, 5)
   4566      if multigrid then
   4567        screen:expect {
   4568          grid = [[
   4569        ## grid 1
   4570          [2:---------------------------------------------]|*4
   4571          [3:---------------------------------------------]|
   4572        ## grid 2
   4573          ^example text that is wider than the window   |
   4574                                                       |*2
   4575          more text                                    |
   4576        ## grid 3
   4577                                                       |
   4578        ## grid 4
   4579          {1:some info!  }|
   4580        ]],
   4581          float_pos = { [4] = { 1001, 'NW', 2, 1, 32, true, 50, 1, 1, 32 } },
   4582        }
   4583      else
   4584        -- note: appears misaligned due to cursor
   4585        screen:expect {
   4586          grid = [[
   4587          ^example text that is wider than the window   |
   4588                                          {1:some info!  } |
   4589                                                       |
   4590          more text                                    |
   4591                                                       |
   4592        ]],
   4593        }
   4594      end
   4595 
   4596      screen:try_resize(25, 10)
   4597      if multigrid then
   4598        screen:expect {
   4599          grid = [[
   4600        ## grid 1
   4601          [2:-------------------------]|*9
   4602          [3:-------------------------]|
   4603        ## grid 2
   4604          ^example text that is wide|
   4605          r than the window        |
   4606                                   |*2
   4607          more text                |
   4608          {0:~                        }|*4
   4609        ## grid 3
   4610                                   |
   4611        ## grid 4
   4612          {1:some info!  }|
   4613        ]],
   4614          float_pos = { [4] = { 1001, 'NW', 2, 2, 7, true, 50, 1, 2, 7 } },
   4615        }
   4616      else
   4617        screen:expect {
   4618          grid = [[
   4619          ^example text that is wide|
   4620          r than the window        |
   4621                 {1:some info!  }      |
   4622                                   |
   4623          more text                |
   4624          {0:~                        }|*4
   4625                                   |
   4626        ]],
   4627        }
   4628      end
   4629 
   4630      api.nvim_win_set_config(win, { relative = 'win', bufpos = { 1, 32 }, anchor = 'SW' })
   4631      if multigrid then
   4632        screen:expect {
   4633          grid = [[
   4634        ## grid 1
   4635          [2:-------------------------]|*9
   4636          [3:-------------------------]|
   4637        ## grid 2
   4638          ^example text that is wide|
   4639          r than the window        |
   4640                                   |*2
   4641          more text                |
   4642          {0:~                        }|*4
   4643        ## grid 3
   4644                                   |
   4645        ## grid 4
   4646          {1:some info!  }|
   4647        ]],
   4648          float_pos = { [4] = { 1001, 'SW', 2, 1, 7, true, 50, 1, 0, 7 } },
   4649        }
   4650      else
   4651        screen:expect {
   4652          grid = [[
   4653          ^example{1:some info!  }s wide|
   4654          r than the window        |
   4655                                   |*2
   4656          more text                |
   4657          {0:~                        }|*4
   4658                                   |
   4659        ]],
   4660        }
   4661      end
   4662 
   4663      command('set laststatus=0')
   4664      command('botright vnew')
   4665      if multigrid then
   4666        screen:expect {
   4667          grid = [[
   4668        ## grid 1
   4669          [2:----]{5:│}[5:--------------------]|*9
   4670          [3:-------------------------]|
   4671        ## grid 2
   4672          exam|
   4673          ple |
   4674          text|
   4675           tha|
   4676          t is|
   4677           wid|
   4678          er t|
   4679          han |
   4680          the |
   4681        ## grid 3
   4682                                   |
   4683        ## grid 4
   4684          {1:some info!  }|
   4685        ## grid 5
   4686          ^                    |
   4687          {0:~                   }|*8
   4688        ]],
   4689          float_pos = {
   4690            [4] = { 1001, 'SW', 2, 8, 0, true, 50, 1, 7, 0 },
   4691          },
   4692        }
   4693      else
   4694        screen:expect {
   4695          grid = [[
   4696          exam{5:│}^                    |
   4697          ple {5:│}{0:~                   }|
   4698          text{5:│}{0:~                   }|
   4699           tha{5:│}{0:~                   }|
   4700          t is{5:│}{0:~                   }|
   4701           wid{5:│}{0:~                   }|
   4702          er t{5:│}{0:~                   }|
   4703          {1:some info!  }{0:             }|
   4704          the {5:│}{0:~                   }|
   4705                                   |
   4706        ]],
   4707        }
   4708      end
   4709      command('close')
   4710 
   4711      api.nvim_win_set_config(win, { relative = 'win', bufpos = { 1, 32 }, anchor = 'NW', col = -2 })
   4712      if multigrid then
   4713        screen:expect {
   4714          grid = [[
   4715        ## grid 1
   4716          [2:-------------------------]|*9
   4717          [3:-------------------------]|
   4718        ## grid 2
   4719          ^example text that is wide|
   4720          r than the window        |
   4721                                   |*2
   4722          more text                |
   4723          {0:~                        }|*4
   4724        ## grid 3
   4725                                   |
   4726        ## grid 4
   4727          {1:some info!  }|
   4728        ]],
   4729          float_pos = { [4] = { 1001, 'NW', 2, 2, 5, true, 50, 1, 2, 5 } },
   4730        }
   4731      else
   4732        screen:expect {
   4733          grid = [[
   4734          ^example text that is wide|
   4735          r than the window        |
   4736               {1:some info!  }        |
   4737                                   |
   4738          more text                |
   4739          {0:~                        }|*4
   4740                                   |
   4741        ]],
   4742        }
   4743      end
   4744 
   4745      api.nvim_win_set_config(win, { relative = 'win', bufpos = { 1, 32 }, row = 2 })
   4746      if multigrid then
   4747        screen:expect {
   4748          grid = [[
   4749        ## grid 1
   4750          [2:-------------------------]|*9
   4751          [3:-------------------------]|
   4752        ## grid 2
   4753          ^example text that is wide|
   4754          r than the window        |
   4755                                   |*2
   4756          more text                |
   4757          {0:~                        }|*4
   4758        ## grid 3
   4759                                   |
   4760        ## grid 4
   4761          {1:some info!  }|
   4762        ]],
   4763          float_pos = { [4] = { 1001, 'NW', 2, 3, 7, true, 50, 1, 3, 7 } },
   4764        }
   4765      else
   4766        screen:expect {
   4767          grid = [[
   4768          ^example text that is wide|
   4769          r than the window        |
   4770                                   |
   4771                 {1:some info!  }      |
   4772          more text                |
   4773          {0:~                        }|*4
   4774                                   |
   4775        ]],
   4776        }
   4777      end
   4778 
   4779      command('%fold')
   4780      if multigrid then
   4781        screen:expect {
   4782          grid = [[
   4783        ## grid 1
   4784          [2:-------------------------]|*9
   4785          [3:-------------------------]|
   4786        ## grid 2
   4787          {28:^+--  5 lines: just some··}|
   4788          {0:~                        }|*8
   4789        ## grid 3
   4790                                   |
   4791        ## grid 4
   4792          {1:some info!  }|
   4793        ]],
   4794          float_pos = { [4] = { 1001, 'NW', 2, 2, 0, true, 50, 1, 2, 0 } },
   4795        }
   4796      else
   4797        screen:expect {
   4798          grid = [[
   4799          {28:^+--  5 lines: just some··}|
   4800          {0:~                        }|
   4801          {1:some info!  }{0:             }|
   4802          {0:~                        }|*6
   4803                                   |
   4804        ]],
   4805        }
   4806      end
   4807    end)
   4808 
   4809    it('validates cursor even when window is not entered', function()
   4810      screen:try_resize(30, 5)
   4811      command('set nowrap')
   4812      insert([[some text that is wider than the window]])
   4813      if multigrid then
   4814        screen:expect([[
   4815        ## grid 1
   4816          [2:------------------------------]|*4
   4817          [3:------------------------------]|
   4818        ## grid 2
   4819          that is wider than the windo^w |
   4820          {0:~                             }|*3
   4821        ## grid 3
   4822                                        |
   4823        ]])
   4824      else
   4825        screen:expect([[
   4826          that is wider than the windo^w |
   4827          {0:~                             }|*3
   4828                                        |
   4829        ]])
   4830      end
   4831 
   4832      local buf = api.nvim_create_buf(false, true)
   4833      api.nvim_buf_set_lines(buf, 0, -1, true, { 'some floaty text' })
   4834      api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 1, row = 3, col = 1 })
   4835      if multigrid then
   4836        screen:expect {
   4837          grid = [[
   4838        ## grid 1
   4839          [2:------------------------------]|*4
   4840          [3:------------------------------]|
   4841        ## grid 2
   4842          that is wider than the windo^w |
   4843          {0:~                             }|*3
   4844        ## grid 3
   4845                                        |
   4846        ## grid 4
   4847          {1:some floaty text    }|
   4848        ]],
   4849          float_pos = { [4] = { 1001, 'NW', 1, 3, 1, true, 50, 1, 3, 1 } },
   4850        }
   4851      else
   4852        screen:expect([[
   4853          that is wider than the windo^w |
   4854          {0:~                             }|*2
   4855          {0:~}{1:some floaty text    }{0:         }|
   4856                                        |
   4857        ]])
   4858      end
   4859    end)
   4860 
   4861    if multigrid then
   4862      pending('supports second UI without multigrid', function()
   4863        local session2 = n.connect(eval('v:servername'))
   4864        print(session2:request('nvim_eval', '2+2'))
   4865        local screen2 = Screen.new(40, 7)
   4866        screen2:attach(nil, session2)
   4867        screen2:set_default_attr_ids(attrs)
   4868        local buf = api.nvim_create_buf(false, false)
   4869        api.nvim_open_win(buf, true, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
   4870        local expected_pos = { [2] = { 1001, 'NW', 1, 2, 5 } }
   4871        screen:expect {
   4872          grid = [[
   4873        ## grid 1
   4874                                                  |
   4875          {0:~                                       }|*5
   4876                                                  |
   4877        ## grid 2
   4878          {1:^                    }|
   4879          {2:~                   }|
   4880        ]],
   4881          float_pos = expected_pos,
   4882        }
   4883        screen2:expect([[
   4884                                                  |
   4885          {0:~                                       }|
   4886          {0:~    }{1:^                    }{0:               }|
   4887          {0:~    }{2:~                   }{0:               }|
   4888          {0:~                                       }|*2
   4889                                                  |
   4890          ]])
   4891      end)
   4892    end
   4893 
   4894    it('handles resized screen', function()
   4895      local buf = api.nvim_create_buf(false, false)
   4896      api.nvim_buf_set_lines(buf, 0, -1, true, { 'such', 'very', 'float' })
   4897      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 15, height = 4, row = 2, col = 10 })
   4898      if multigrid then
   4899        screen:expect {
   4900          grid = [[
   4901        ## grid 1
   4902          [2:----------------------------------------]|*6
   4903          [3:----------------------------------------]|
   4904        ## grid 2
   4905          ^                                        |
   4906          {0:~                                       }|*5
   4907        ## grid 3
   4908                                                  |
   4909        ## grid 4
   4910          {1:such           }|
   4911          {1:very           }|
   4912          {1:float          }|
   4913          {2:~              }|
   4914        ]],
   4915          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 10 } },
   4916        }
   4917      else
   4918        screen:expect([[
   4919          ^                                        |
   4920          {0:~                                       }|
   4921          {0:~         }{1:such           }{0:               }|
   4922          {0:~         }{1:very           }{0:               }|
   4923          {0:~         }{1:float          }{0:               }|
   4924          {0:~         }{2:~              }{0:               }|
   4925                                                  |
   4926        ]])
   4927      end
   4928 
   4929      screen:try_resize(40, 5)
   4930      if multigrid then
   4931        screen:expect {
   4932          grid = [[
   4933        ## grid 1
   4934          [2:----------------------------------------]|*4
   4935          [3:----------------------------------------]|
   4936        ## grid 2
   4937          ^                                        |
   4938          {0:~                                       }|*3
   4939        ## grid 3
   4940                                                  |
   4941        ## grid 4
   4942          {1:such           }|
   4943          {1:very           }|
   4944          {1:float          }|
   4945          {2:~              }|
   4946        ]],
   4947          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 0, 10 } },
   4948        }
   4949      else
   4950        screen:expect([[
   4951          ^          {1:such           }               |
   4952          {0:~         }{1:very           }{0:               }|
   4953          {0:~         }{1:float          }{0:               }|
   4954          {0:~         }{2:~              }{0:               }|
   4955                                                  |
   4956        ]])
   4957      end
   4958 
   4959      screen:try_resize(40, 4)
   4960      if multigrid then
   4961        screen:expect {
   4962          grid = [[
   4963        ## grid 1
   4964          [2:----------------------------------------]|*3
   4965          [3:----------------------------------------]|
   4966        ## grid 2
   4967          ^                                        |
   4968          {0:~                                       }|*2
   4969        ## grid 3
   4970                                                  |
   4971        ## grid 4
   4972          {1:such           }|
   4973          {1:very           }|
   4974          {1:float          }|
   4975          {2:~              }|
   4976        ]],
   4977          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 0, 10 } },
   4978        }
   4979      else
   4980        screen:expect([[
   4981          ^          {1:such           }               |
   4982          {0:~         }{1:very           }{0:               }|
   4983          {0:~         }{1:float          }{0:               }|
   4984                                                  |
   4985        ]])
   4986      end
   4987 
   4988      screen:try_resize(40, 3)
   4989      if multigrid then
   4990        screen:expect {
   4991          grid = [[
   4992        ## grid 1
   4993          [2:----------------------------------------]|*2
   4994          [3:----------------------------------------]|
   4995        ## grid 2
   4996          ^                                        |
   4997          {0:~                                       }|
   4998        ## grid 3
   4999                                                  |
   5000        ## grid 4
   5001          {1:such           }|
   5002          {1:very           }|
   5003          {1:float          }|
   5004          {2:~              }|
   5005        ]],
   5006          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 0, 10 } },
   5007        }
   5008      else
   5009        screen:expect([[
   5010          ^          {1:such           }               |
   5011          {0:~         }{1:very           }{0:               }|
   5012                                                  |
   5013        ]])
   5014      end
   5015      feed('<c-w>wjj')
   5016      if multigrid then
   5017        screen:expect {
   5018          grid = [[
   5019        ## grid 1
   5020          [2:----------------------------------------]|*2
   5021          [3:----------------------------------------]|
   5022        ## grid 2
   5023                                                  |
   5024          {0:~                                       }|
   5025        ## grid 3
   5026                                                  |
   5027        ## grid 4
   5028          {1:such           }|
   5029          {1:very           }|
   5030          {1:^float          }|
   5031          {2:~              }|
   5032        ]],
   5033          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 0, 10 } },
   5034        }
   5035      else
   5036        screen:expect([[
   5037                    {1:very           }               |
   5038          {0:~         }{1:^float          }{0:               }|
   5039                                                  |
   5040        ]])
   5041      end
   5042 
   5043      screen:try_resize(40, 7)
   5044      if multigrid then
   5045        screen:expect {
   5046          grid = [[
   5047        ## grid 1
   5048          [2:----------------------------------------]|*6
   5049          [3:----------------------------------------]|
   5050        ## grid 2
   5051                                                  |
   5052          {0:~                                       }|*5
   5053        ## grid 3
   5054                                                  |
   5055        ## grid 4
   5056          {1:such           }|
   5057          {1:very           }|
   5058          {1:^float          }|
   5059          {2:~              }|
   5060        ]],
   5061          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 10 } },
   5062        }
   5063      else
   5064        screen:expect([[
   5065                                                  |
   5066          {0:~                                       }|
   5067          {0:~         }{1:such           }{0:               }|
   5068          {0:~         }{1:very           }{0:               }|
   5069          {0:~         }{1:^float          }{0:               }|
   5070          {0:~         }{2:~              }{0:               }|
   5071                                                  |
   5072        ]])
   5073      end
   5074 
   5075      api.nvim_win_set_config(win, { height = 3 })
   5076      feed('gg')
   5077      if multigrid then
   5078        screen:expect {
   5079          grid = [[
   5080        ## grid 1
   5081          [2:----------------------------------------]|*6
   5082          [3:----------------------------------------]|
   5083        ## grid 2
   5084                                                  |
   5085          {0:~                                       }|*5
   5086        ## grid 3
   5087                                                  |
   5088        ## grid 4
   5089          {1:^such           }|
   5090          {1:very           }|
   5091          {1:float          }|
   5092        ]],
   5093          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 10 } },
   5094        }
   5095      else
   5096        screen:expect([[
   5097                                                  |
   5098          {0:~                                       }|
   5099          {0:~         }{1:^such           }{0:               }|
   5100          {0:~         }{1:very           }{0:               }|
   5101          {0:~         }{1:float          }{0:               }|
   5102          {0:~                                       }|
   5103                                                  |
   5104        ]])
   5105      end
   5106 
   5107      screen:try_resize(26, 7)
   5108      if multigrid then
   5109        screen:expect {
   5110          grid = [[
   5111        ## grid 1
   5112          [2:--------------------------]|*6
   5113          [3:--------------------------]|
   5114        ## grid 2
   5115                                    |
   5116          {0:~                         }|*5
   5117        ## grid 3
   5118                                    |
   5119        ## grid 4
   5120          {1:^such           }|
   5121          {1:very           }|
   5122          {1:float          }|
   5123        ]],
   5124          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 10 } },
   5125        }
   5126      else
   5127        screen:expect([[
   5128                                    |
   5129          {0:~                         }|
   5130          {0:~         }{1:^such           }{0: }|
   5131          {0:~         }{1:very           }{0: }|
   5132          {0:~         }{1:float          }{0: }|
   5133          {0:~                         }|
   5134                                    |
   5135        ]])
   5136      end
   5137 
   5138      screen:try_resize(25, 7)
   5139      if multigrid then
   5140        screen:expect {
   5141          grid = [[
   5142        ## grid 1
   5143          [2:-------------------------]|*6
   5144          [3:-------------------------]|
   5145        ## grid 2
   5146                                   |
   5147          {0:~                        }|*5
   5148        ## grid 3
   5149                                   |
   5150        ## grid 4
   5151          {1:^such           }|
   5152          {1:very           }|
   5153          {1:float          }|
   5154        ]],
   5155          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 10 } },
   5156        }
   5157      else
   5158        screen:expect([[
   5159                                   |
   5160          {0:~                        }|
   5161          {0:~         }{1:^such           }|
   5162          {0:~         }{1:very           }|
   5163          {0:~         }{1:float          }|
   5164          {0:~                        }|
   5165                                   |
   5166        ]])
   5167      end
   5168 
   5169      screen:try_resize(24, 7)
   5170      if multigrid then
   5171        screen:expect {
   5172          grid = [[
   5173        ## grid 1
   5174          [2:------------------------]|*6
   5175          [3:------------------------]|
   5176        ## grid 2
   5177                                  |
   5178          {0:~                       }|*5
   5179        ## grid 3
   5180                                  |
   5181        ## grid 4
   5182          {1:^such           }|
   5183          {1:very           }|
   5184          {1:float          }|
   5185        ]],
   5186          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 9 } },
   5187        }
   5188      else
   5189        screen:expect([[
   5190                                  |
   5191          {0:~                       }|
   5192          {0:~        }{1:^such           }|
   5193          {0:~        }{1:very           }|
   5194          {0:~        }{1:float          }|
   5195          {0:~                       }|
   5196                                  |
   5197        ]])
   5198      end
   5199 
   5200      screen:try_resize(16, 7)
   5201      if multigrid then
   5202        screen:expect {
   5203          grid = [[
   5204        ## grid 1
   5205          [2:----------------]|*6
   5206          [3:----------------]|
   5207        ## grid 2
   5208                          |
   5209          {0:~               }|*5
   5210        ## grid 3
   5211                          |
   5212        ## grid 4
   5213          {1:^such           }|
   5214          {1:very           }|
   5215          {1:float          }|
   5216        ]],
   5217          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 1 } },
   5218        }
   5219      else
   5220        screen:expect([[
   5221                          |
   5222          {0:~               }|
   5223          {0:~}{1:^such           }|
   5224          {0:~}{1:very           }|
   5225          {0:~}{1:float          }|
   5226          {0:~               }|
   5227                          |
   5228        ]])
   5229      end
   5230 
   5231      screen:try_resize(15, 7)
   5232      if multigrid then
   5233        screen:expect {
   5234          grid = [[
   5235        ## grid 1
   5236          [2:---------------]|*6
   5237          [3:---------------]|
   5238        ## grid 2
   5239                         |
   5240          {0:~              }|*5
   5241        ## grid 3
   5242                         |
   5243        ## grid 4
   5244          {1:^such           }|
   5245          {1:very           }|
   5246          {1:float          }|
   5247        ]],
   5248          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 0 } },
   5249        }
   5250      else
   5251        screen:expect([[
   5252                         |
   5253          {0:~              }|
   5254          {1:^such           }|
   5255          {1:very           }|
   5256          {1:float          }|
   5257          {0:~              }|
   5258                         |
   5259        ]])
   5260      end
   5261 
   5262      screen:try_resize(14, 7)
   5263      if multigrid then
   5264        screen:expect {
   5265          grid = [[
   5266        ## grid 1
   5267          [2:--------------]|*6
   5268          [3:--------------]|
   5269        ## grid 2
   5270                        |
   5271          {0:~             }|*5
   5272        ## grid 3
   5273                        |
   5274        ## grid 4
   5275          {1:^such           }|
   5276          {1:very           }|
   5277          {1:float          }|
   5278        ]],
   5279          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 0 } },
   5280        }
   5281      else
   5282        screen:expect([[
   5283                        |
   5284          {0:~             }|
   5285          {1:^such          }|
   5286          {1:very          }|
   5287          {1:float         }|
   5288          {0:~             }|
   5289                        |
   5290        ]])
   5291      end
   5292 
   5293      screen:try_resize(12, 7)
   5294      if multigrid then
   5295        screen:expect {
   5296          grid = [[
   5297        ## grid 1
   5298          [2:------------]|*6
   5299          [3:------------]|
   5300        ## grid 2
   5301                      |
   5302          {0:~           }|*5
   5303        ## grid 3
   5304                      |
   5305        ## grid 4
   5306          {1:^such           }|
   5307          {1:very           }|
   5308          {1:float          }|
   5309        ]],
   5310          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 0 } },
   5311        }
   5312      else
   5313        screen:expect([[
   5314                      |
   5315          {0:~           }|
   5316          {1:^such        }|
   5317          {1:very        }|
   5318          {1:float       }|
   5319          {0:~           }|
   5320                      |
   5321        ]])
   5322      end
   5323 
   5324      -- Doesn't make much sense, but check nvim doesn't crash
   5325      screen:try_resize(1, 1)
   5326      if multigrid then
   5327        screen:expect {
   5328          grid = [[
   5329        ## grid 1
   5330          [2:------------]|
   5331          [3:------------]|
   5332        ## grid 2
   5333                      |
   5334        ## grid 3
   5335                      |
   5336        ## grid 4
   5337          {1:^such           }|
   5338          {1:very           }|
   5339          {1:float          }|
   5340        ]],
   5341          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 0, 0 } },
   5342        }
   5343      else
   5344        screen:expect([[
   5345          {1:^such        }|
   5346                      |
   5347        ]])
   5348      end
   5349 
   5350      screen:try_resize(40, 7)
   5351      if multigrid then
   5352        screen:expect {
   5353          grid = [[
   5354        ## grid 1
   5355          [2:----------------------------------------]|*6
   5356          [3:----------------------------------------]|
   5357        ## grid 2
   5358                                                  |
   5359          {0:~                                       }|*5
   5360        ## grid 3
   5361                                                  |
   5362        ## grid 4
   5363          {1:^such           }|
   5364          {1:very           }|
   5365          {1:float          }|
   5366        ]],
   5367          float_pos = { [4] = { 1001, 'NW', 1, 2, 10, true, 50, 1, 2, 10 } },
   5368        }
   5369      else
   5370        screen:expect([[
   5371                                                  |
   5372          {0:~                                       }|
   5373          {0:~         }{1:^such           }{0:               }|
   5374          {0:~         }{1:very           }{0:               }|
   5375          {0:~         }{1:float          }{0:               }|
   5376          {0:~                                       }|
   5377                                                  |
   5378        ]])
   5379      end
   5380    end)
   5381 
   5382    it('does not crash with inccommand #9379', function()
   5383      local expected_pos = { [4] = { 1001, 'NW', 1, 2, 0, true, 50, 1, 2, 0 } }
   5384      command('set inccommand=split')
   5385      command('set laststatus=2')
   5386      local buf = api.nvim_create_buf(false, false)
   5387      api.nvim_open_win(buf, true, { relative = 'editor', width = 30, height = 3, row = 2, col = 0 })
   5388      insert([[
   5389      foo
   5390      bar
   5391      ]])
   5392 
   5393      if multigrid then
   5394        screen:expect {
   5395          grid = [[
   5396          ## grid 1
   5397            [2:----------------------------------------]|*5
   5398            {5:[No Name]                               }|
   5399            [3:----------------------------------------]|
   5400          ## grid 2
   5401                                                    |
   5402            {0:~                                       }|*4
   5403          ## grid 3
   5404                                                    |
   5405          ## grid 4
   5406            {1:foo                           }|
   5407            {1:bar                           }|
   5408            {1:^                              }|
   5409        ]],
   5410          float_pos = expected_pos,
   5411        }
   5412      else
   5413        screen:expect([[
   5414                                                  |
   5415          {0:~                                       }|
   5416          {1:foo                           }{0:          }|
   5417          {1:bar                           }{0:          }|
   5418          {1:^                              }{0:          }|
   5419          {5:[No Name]                               }|
   5420                                                  |
   5421        ]])
   5422      end
   5423 
   5424      feed(':%s/.')
   5425      if multigrid then
   5426        screen:expect {
   5427          grid = [[
   5428          ## grid 1
   5429            [2:----------------------------------------]|*5
   5430            {5:[Preview]                               }|
   5431            [3:----------------------------------------]|
   5432          ## grid 2
   5433                                                    |
   5434          ## grid 3
   5435            :%s/.^                                   |
   5436          ## grid 4
   5437            {17:f}{1:oo                           }|
   5438            {17:b}{1:ar                           }|
   5439            {1:                              }|
   5440        ]],
   5441          float_pos = expected_pos,
   5442        }
   5443      else
   5444        screen:expect([[
   5445                                                  |
   5446          {5:[No Name]                               }|
   5447          {17:f}{1:oo                           }          |
   5448          {17:b}{1:ar                           }          |
   5449          {1:                              }{0:          }|
   5450          {5:[Preview]                               }|
   5451          :%s/.^                                   |
   5452        ]])
   5453      end
   5454 
   5455      feed('<Esc>')
   5456 
   5457      if multigrid then
   5458        screen:expect {
   5459          grid = [[
   5460          ## grid 1
   5461            [2:----------------------------------------]|*5
   5462            {5:[No Name]                               }|
   5463            [3:----------------------------------------]|
   5464          ## grid 2
   5465                                                    |
   5466            {0:~                                       }|*4
   5467          ## grid 3
   5468                                                    |
   5469          ## grid 4
   5470            {1:foo                           }|
   5471            {1:bar                           }|
   5472            {1:^                              }|
   5473        ]],
   5474          float_pos = expected_pos,
   5475        }
   5476      else
   5477        screen:expect([[
   5478                                                  |
   5479          {0:~                                       }|
   5480          {1:foo                           }{0:          }|
   5481          {1:bar                           }{0:          }|
   5482          {1:^                              }{0:          }|
   5483          {5:[No Name]                               }|
   5484                                                  |
   5485        ]])
   5486      end
   5487    end)
   5488 
   5489    it('does not crash when set cmdheight #9680', function()
   5490      local buf = api.nvim_create_buf(false, false)
   5491      api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
   5492      command('set cmdheight=2')
   5493      eq(1, api.nvim_eval('1'))
   5494    end)
   5495 
   5496    describe('and completion', function()
   5497      before_each(function()
   5498        local buf = api.nvim_create_buf(false, false)
   5499        local win = api.nvim_open_win(buf, true, { relative = 'editor', width = 12, height = 4, row = 2, col = 5 })
   5500        api.nvim_set_option_value('winhl', 'Normal:ErrorMsg', { win = win })
   5501        if multigrid then
   5502          screen:expect {
   5503            grid = [[
   5504          ## grid 1
   5505            [2:----------------------------------------]|*6
   5506            [3:----------------------------------------]|
   5507          ## grid 2
   5508                                                    |
   5509            {0:~                                       }|*5
   5510          ## grid 3
   5511                                                    |
   5512          ## grid 4
   5513            {7:^            }|
   5514            {12:~           }|*3
   5515          ]],
   5516            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   5517          }
   5518        else
   5519          screen:expect([[
   5520                                                    |
   5521            {0:~                                       }|
   5522            {0:~    }{7:^            }{0:                       }|
   5523            {0:~    }{12:~           }{0:                       }|*3
   5524                                                    |
   5525          ]])
   5526        end
   5527      end)
   5528 
   5529      it('with builtin popupmenu', function()
   5530        feed('ix ')
   5531        fn.complete(3, { 'aa', 'word', 'longtext' })
   5532        if multigrid then
   5533          screen:expect {
   5534            grid = [[
   5535          ## grid 1
   5536            [2:----------------------------------------]|*6
   5537            [3:----------------------------------------]|
   5538          ## grid 2
   5539                                                    |
   5540            {0:~                                       }|*5
   5541          ## grid 3
   5542            {3:-- INSERT --}                            |
   5543          ## grid 4
   5544            {7:x aa^        }|
   5545            {12:~           }|*3
   5546          ## grid 5
   5547            {13: aa             }|
   5548            {1: word           }|
   5549            {1: longtext       }|
   5550          ]],
   5551            float_pos = {
   5552              [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 },
   5553              [5] = { -1, 'NW', 4, 1, 1, false, 100, 2, 3, 6 },
   5554            },
   5555          }
   5556        else
   5557          screen:expect([[
   5558                                                    |
   5559            {0:~                                       }|
   5560            {0:~    }{7:x aa^        }{0:                       }|
   5561            {0:~    }{12:~}{13: aa             }{0:                  }|
   5562            {0:~    }{12:~}{1: word           }{0:                  }|
   5563            {0:~    }{12:~}{1: longtext       }{0:                  }|
   5564            {3:-- INSERT --}                            |
   5565          ]])
   5566        end
   5567 
   5568        feed('<esc>')
   5569        if multigrid then
   5570          screen:expect {
   5571            grid = [[
   5572          ## grid 1
   5573            [2:----------------------------------------]|*6
   5574            [3:----------------------------------------]|
   5575          ## grid 2
   5576                                                    |
   5577            {0:~                                       }|*5
   5578          ## grid 3
   5579                                                    |
   5580          ## grid 4
   5581            {7:x a^a        }|
   5582            {12:~           }|*3
   5583          ]],
   5584            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   5585          }
   5586        else
   5587          screen:expect([[
   5588                                                    |
   5589            {0:~                                       }|
   5590            {0:~    }{7:x a^a        }{0:                       }|
   5591            {0:~    }{12:~           }{0:                       }|*3
   5592                                                    |
   5593          ]])
   5594        end
   5595 
   5596        feed('<c-w>wi')
   5597        fn.complete(1, { 'xx', 'yy', 'zz' })
   5598        if multigrid then
   5599          screen:expect {
   5600            grid = [[
   5601          ## grid 1
   5602            [2:----------------------------------------]|*6
   5603            [3:----------------------------------------]|
   5604          ## grid 2
   5605            xx^                                      |
   5606            {0:~                                       }|*5
   5607          ## grid 3
   5608            {3:-- INSERT --}                            |
   5609          ## grid 4
   5610            {7:x aa        }|
   5611            {12:~           }|*3
   5612          ## grid 5
   5613            {13:xx             }|
   5614            {1:yy             }|
   5615            {1:zz             }|
   5616          ]],
   5617            float_pos = {
   5618              [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 },
   5619              [5] = { -1, 'NW', 2, 1, 0, false, 100, 2, 1, 0 },
   5620            },
   5621          }
   5622        else
   5623          screen:expect([[
   5624            xx^                                      |
   5625            {13:xx             }{0:                         }|
   5626            {1:yy             }{7:  }{0:                       }|
   5627            {1:zz             }{12:  }{0:                       }|
   5628            {0:~    }{12:~           }{0:                       }|*2
   5629            {3:-- INSERT --}                            |
   5630          ]])
   5631        end
   5632 
   5633        feed('<c-y>')
   5634        if multigrid then
   5635          screen:expect {
   5636            grid = [[
   5637          ## grid 1
   5638            [2:----------------------------------------]|*6
   5639            [3:----------------------------------------]|
   5640          ## grid 2
   5641            xx^                                      |
   5642            {0:~                                       }|*5
   5643          ## grid 3
   5644            {3:-- INSERT --}                            |
   5645          ## grid 4
   5646            {7:x aa        }|
   5647            {12:~           }|*3
   5648          ]],
   5649            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   5650          }
   5651        else
   5652          screen:expect([[
   5653            xx^                                      |
   5654            {0:~                                       }|
   5655            {0:~    }{7:x aa        }{0:                       }|
   5656            {0:~    }{12:~           }{0:                       }|*3
   5657            {3:-- INSERT --}                            |
   5658          ]])
   5659        end
   5660      end)
   5661 
   5662      it('command menu rendered above cursor (pum_above)', function()
   5663        command('set wildmenu wildmode=longest:full wildoptions=pum')
   5664        feed(':sign u<tab>')
   5665        if multigrid then
   5666          screen:expect {
   5667            grid = [[
   5668          ## grid 1
   5669            [2:----------------------------------------]|*6
   5670            [3:----------------------------------------]|
   5671          ## grid 2
   5672                                                    |
   5673            {0:~                                       }|*5
   5674          ## grid 3
   5675            :sign un^                                |
   5676          ## grid 4
   5677            {7:            }|
   5678            {12:~           }|*3
   5679          ## grid 5
   5680            {1: undefine       }|
   5681            {1: unplace        }|
   5682          ]],
   5683            float_pos = {
   5684              [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 },
   5685              [5] = { -1, 'SW', 1, 6, 5, false, 250, 3, 4, 5 },
   5686            },
   5687          }
   5688        else
   5689          screen:expect {
   5690            grid = [[
   5691                                                    |
   5692            {0:~                                       }|
   5693            {0:~    }{7:            }{0:                       }|
   5694            {0:~    }{12:~           }{0:                       }|
   5695            {0:~    }{1: undefine       }{0:                   }|
   5696            {0:~    }{1: unplace        }{0:                   }|
   5697            :sign un^                                |
   5698          ]],
   5699          }
   5700        end
   5701      end)
   5702 
   5703      it('with ext_popupmenu', function()
   5704        screen:set_option('ext_popupmenu', true)
   5705        feed('ix ')
   5706        fn.complete(3, { 'aa', 'word', 'longtext' })
   5707        local items = { { 'aa', '', '', '' }, { 'word', '', '', '' }, { 'longtext', '', '', '' } }
   5708        if multigrid then
   5709          screen:expect {
   5710            grid = [[
   5711          ## grid 1
   5712            [2:----------------------------------------]|*6
   5713            [3:----------------------------------------]|
   5714          ## grid 2
   5715                                                    |
   5716            {0:~                                       }|*5
   5717          ## grid 3
   5718            {3:-- INSERT --}                            |
   5719          ## grid 4
   5720            {7:x aa^        }|
   5721            {12:~           }|*3
   5722          ]],
   5723            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   5724            popupmenu = { anchor = { 4, 0, 2 }, items = items, pos = 0 },
   5725          }
   5726        else
   5727          screen:expect {
   5728            grid = [[
   5729                                                    |
   5730            {0:~                                       }|
   5731            {0:~    }{7:x aa^        }{0:                       }|
   5732            {0:~    }{12:~           }{0:                       }|*3
   5733            {3:-- INSERT --}                            |
   5734          ]],
   5735            popupmenu = { anchor = { 1, 2, 7 }, items = items, pos = 0 },
   5736          }
   5737        end
   5738 
   5739        feed('<esc>')
   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:x a^a        }|
   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:x a^a        }{0:                       }|
   5762            {0:~    }{12:~           }{0:                       }|*3
   5763                                                    |
   5764          ]])
   5765        end
   5766 
   5767        feed('<c-w>wi')
   5768        fn.complete(1, { 'xx', 'yy', 'zz' })
   5769        items = { { 'xx', '', '', '' }, { 'yy', '', '', '' }, { 'zz', '', '', '' } }
   5770        if multigrid then
   5771          screen:expect {
   5772            grid = [[
   5773          ## grid 1
   5774            [2:----------------------------------------]|*6
   5775            [3:----------------------------------------]|
   5776          ## grid 2
   5777            xx^                                      |
   5778            {0:~                                       }|*5
   5779          ## grid 3
   5780            {3:-- INSERT --}                            |
   5781          ## grid 4
   5782            {7:x aa        }|
   5783            {12:~           }|*3
   5784          ]],
   5785            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   5786            popupmenu = { anchor = { 2, 0, 0 }, items = items, pos = 0 },
   5787          }
   5788        else
   5789          screen:expect {
   5790            grid = [[
   5791            xx^                                      |
   5792            {0:~                                       }|
   5793            {0:~    }{7:x aa        }{0:                       }|
   5794            {0:~    }{12:~           }{0:                       }|*3
   5795            {3:-- INSERT --}                            |
   5796          ]],
   5797            popupmenu = { anchor = { 1, 0, 0 }, items = items, pos = 0 },
   5798          }
   5799        end
   5800 
   5801        feed('<c-y>')
   5802        if multigrid then
   5803          screen:expect {
   5804            grid = [[
   5805          ## grid 1
   5806            [2:----------------------------------------]|*6
   5807            [3:----------------------------------------]|
   5808          ## grid 2
   5809            xx^                                      |
   5810            {0:~                                       }|*5
   5811          ## grid 3
   5812            {3:-- INSERT --}                            |
   5813          ## grid 4
   5814            {7:x aa        }|
   5815            {12:~           }|*3
   5816          ]],
   5817            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   5818          }
   5819        else
   5820          screen:expect([[
   5821            xx^                                      |
   5822            {0:~                                       }|
   5823            {0:~    }{7:x aa        }{0:                       }|
   5824            {0:~    }{12:~           }{0:                       }|*3
   5825            {3:-- INSERT --}                            |
   5826          ]])
   5827        end
   5828      end)
   5829    end)
   5830 
   5831    describe('float shown after pum', function()
   5832      local win
   5833      before_each(function()
   5834        command('hi NormalFloat guibg=#333333 guifg=NONE')
   5835        feed('i')
   5836        fn.complete(1, { 'aa', 'word', 'longtext' })
   5837        if multigrid then
   5838          screen:expect {
   5839            grid = [[
   5840          ## grid 1
   5841            [2:----------------------------------------]|*6
   5842            [3:----------------------------------------]|
   5843          ## grid 2
   5844            aa^                                      |
   5845            {0:~                                       }|*5
   5846          ## grid 3
   5847            {3:-- INSERT --}                            |
   5848          ## grid 4
   5849            {13:aa             }|
   5850            {1:word           }|
   5851            {1:longtext       }|
   5852          ]],
   5853            float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
   5854          }
   5855        else
   5856          screen:expect([[
   5857            aa^                                      |
   5858            {13:aa             }{0:                         }|
   5859            {1:word           }{0:                         }|
   5860            {1:longtext       }{0:                         }|
   5861            {0:~                                       }|*2
   5862            {3:-- INSERT --}                            |
   5863          ]])
   5864        end
   5865 
   5866        local buf = api.nvim_create_buf(false, true)
   5867        api.nvim_buf_set_lines(buf, 0, -1, true, { 'some info', 'about item' })
   5868        win = api.nvim_open_win(buf, false, { relative = 'cursor', width = 12, height = 2, row = 1, col = 10 })
   5869        if multigrid then
   5870          screen:expect {
   5871            grid = [[
   5872          ## grid 1
   5873            [2:----------------------------------------]|*6
   5874            [3:----------------------------------------]|
   5875          ## grid 2
   5876            aa^                                      |
   5877            {0:~                                       }|*5
   5878          ## grid 3
   5879            {3:-- INSERT --}                            |
   5880          ## grid 4
   5881            {13:aa             }|
   5882            {1:word           }|
   5883            {1:longtext       }|
   5884          ## grid 5
   5885            {15:some info   }|
   5886            {15:about item  }|
   5887          ]],
   5888            float_pos = {
   5889              [5] = { 1001, 'NW', 2, 1, 12, true, 50, 1, 1, 12 },
   5890              [4] = { -1, 'NW', 2, 1, 0, false, 100, 2, 1, 0 },
   5891            },
   5892          }
   5893        else
   5894          screen:expect([[
   5895            aa^                                      |
   5896            {13:aa             }{15:e info   }{0:                }|
   5897            {1:word           }{15:ut item  }{0:                }|
   5898            {1:longtext       }{0:                         }|
   5899            {0:~                                       }|*2
   5900            {3:-- INSERT --}                            |
   5901          ]])
   5902        end
   5903      end)
   5904 
   5905      it('and close pum first', function()
   5906        feed('<c-y>')
   5907        if multigrid then
   5908          screen:expect {
   5909            grid = [[
   5910          ## grid 1
   5911            [2:----------------------------------------]|*6
   5912            [3:----------------------------------------]|
   5913          ## grid 2
   5914            aa^                                      |
   5915            {0:~                                       }|*5
   5916          ## grid 3
   5917            {3:-- INSERT --}                            |
   5918          ## grid 5
   5919            {15:some info   }|
   5920            {15:about item  }|
   5921          ]],
   5922            float_pos = { [5] = { 1001, 'NW', 2, 1, 12, true, 50, 1, 1, 12 } },
   5923          }
   5924        else
   5925          screen:expect([[
   5926            aa^                                      |
   5927            {0:~           }{15:some info   }{0:                }|
   5928            {0:~           }{15:about item  }{0:                }|
   5929            {0:~                                       }|*3
   5930            {3:-- INSERT --}                            |
   5931          ]])
   5932        end
   5933 
   5934        api.nvim_win_close(win, false)
   5935        if multigrid then
   5936          screen:expect([[
   5937          ## grid 1
   5938            [2:----------------------------------------]|*6
   5939            [3:----------------------------------------]|
   5940          ## grid 2
   5941            aa^                                      |
   5942            {0:~                                       }|*5
   5943          ## grid 3
   5944            {3:-- INSERT --}                            |
   5945          ]])
   5946        else
   5947          screen:expect([[
   5948            aa^                                      |
   5949            {0:~                                       }|*5
   5950            {3:-- INSERT --}                            |
   5951          ]])
   5952        end
   5953      end)
   5954 
   5955      it('and close float first', function()
   5956        api.nvim_win_close(win, false)
   5957        if multigrid then
   5958          screen:expect {
   5959            grid = [[
   5960          ## grid 1
   5961            [2:----------------------------------------]|*6
   5962            [3:----------------------------------------]|
   5963          ## grid 2
   5964            aa^                                      |
   5965            {0:~                                       }|*5
   5966          ## grid 3
   5967            {3:-- INSERT --}                            |
   5968          ## grid 4
   5969            {13:aa             }|
   5970            {1:word           }|
   5971            {1:longtext       }|
   5972          ]],
   5973            float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
   5974          }
   5975        else
   5976          screen:expect([[
   5977            aa^                                      |
   5978            {13:aa             }{0:                         }|
   5979            {1:word           }{0:                         }|
   5980            {1:longtext       }{0:                         }|
   5981            {0:~                                       }|*2
   5982            {3:-- INSERT --}                            |
   5983          ]])
   5984        end
   5985 
   5986        feed('<c-y>')
   5987        if multigrid then
   5988          screen:expect([[
   5989          ## grid 1
   5990            [2:----------------------------------------]|*6
   5991            [3:----------------------------------------]|
   5992          ## grid 2
   5993            aa^                                      |
   5994            {0:~                                       }|*5
   5995          ## grid 3
   5996            {3:-- INSERT --}                            |
   5997          ]])
   5998        else
   5999          screen:expect([[
   6000            aa^                                      |
   6001            {0:~                                       }|*5
   6002            {3:-- INSERT --}                            |
   6003          ]])
   6004        end
   6005      end)
   6006    end)
   6007 
   6008    it('can use Normal as background', function()
   6009      local buf = api.nvim_create_buf(false, false)
   6010      api.nvim_buf_set_lines(buf, 0, -1, true, { 'here', 'float' })
   6011      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
   6012      api.nvim_set_option_value('winhl', 'Normal:Normal', { win = win })
   6013 
   6014      if multigrid then
   6015        screen:expect {
   6016          grid = [[
   6017        ## grid 1
   6018          [2:----------------------------------------]|*6
   6019          [3:----------------------------------------]|
   6020        ## grid 2
   6021          ^                                        |
   6022          {0:~                                       }|*5
   6023        ## grid 3
   6024                                                  |
   6025        ## grid 4
   6026          here                |
   6027          float               |
   6028        ]],
   6029          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   6030          win_viewport = {
   6031            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   6032            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0 },
   6033          },
   6034        }
   6035      else
   6036        screen:expect {
   6037          grid = [[
   6038          ^                                        |
   6039          {0:~                                       }|
   6040          {0:~    }here                {0:               }|
   6041          {0:~    }float               {0:               }|
   6042          {0:~                                       }|*2
   6043                                                  |
   6044        ]],
   6045        }
   6046      end
   6047    end)
   6048 
   6049    describe('handles :wincmd', function()
   6050      local win
   6051      local expected_pos
   6052      before_each(function()
   6053        -- the default, but be explicit:
   6054        command('set laststatus=1')
   6055        command('set hidden')
   6056        api.nvim_buf_set_lines(0, 0, -1, true, { 'x' })
   6057        local buf = api.nvim_create_buf(false, false)
   6058        win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
   6059        api.nvim_buf_set_lines(buf, 0, -1, true, { 'y' })
   6060        expected_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } }
   6061        if multigrid then
   6062          screen:expect {
   6063            grid = [[
   6064          ## grid 1
   6065            [2:----------------------------------------]|*6
   6066            [3:----------------------------------------]|
   6067          ## grid 2
   6068            ^x                                       |
   6069            {0:~                                       }|*5
   6070          ## grid 3
   6071                                                    |
   6072          ## grid 4
   6073            {1:y                   }|
   6074            {2:~                   }|
   6075          ]],
   6076            float_pos = expected_pos,
   6077          }
   6078        else
   6079          screen:expect([[
   6080            ^x                                       |
   6081            {0:~                                       }|
   6082            {0:~    }{1:y                   }{0:               }|
   6083            {0:~    }{2:~                   }{0:               }|
   6084            {0:~                                       }|*2
   6085                                                    |
   6086          ]])
   6087        end
   6088      end)
   6089 
   6090      it('w', function()
   6091        feed('<c-w>w')
   6092        if multigrid then
   6093          screen:expect {
   6094            grid = [[
   6095          ## grid 1
   6096            [2:----------------------------------------]|*6
   6097            [3:----------------------------------------]|
   6098          ## grid 2
   6099            x                                       |
   6100            {0:~                                       }|*5
   6101          ## grid 3
   6102                                                    |
   6103          ## grid 4
   6104            {1:^y                   }|
   6105            {2:~                   }|
   6106          ]],
   6107            float_pos = expected_pos,
   6108          }
   6109        else
   6110          screen:expect([[
   6111            x                                       |
   6112            {0:~                                       }|
   6113            {0:~    }{1:^y                   }{0:               }|
   6114            {0:~    }{2:~                   }{0:               }|
   6115            {0:~                                       }|*2
   6116                                                    |
   6117          ]])
   6118        end
   6119 
   6120        feed('<c-w>w')
   6121        if multigrid then
   6122          screen:expect {
   6123            grid = [[
   6124          ## grid 1
   6125            [2:----------------------------------------]|*6
   6126            [3:----------------------------------------]|
   6127          ## grid 2
   6128            ^x                                       |
   6129            {0:~                                       }|*5
   6130          ## grid 3
   6131                                                    |
   6132          ## grid 4
   6133            {1:y                   }|
   6134            {2:~                   }|
   6135          ]],
   6136            float_pos = expected_pos,
   6137          }
   6138        else
   6139          screen:expect([[
   6140            ^x                                       |
   6141            {0:~                                       }|
   6142            {0:~    }{1:y                   }{0:               }|
   6143            {0:~    }{2:~                   }{0:               }|
   6144            {0:~                                       }|*2
   6145                                                    |
   6146          ]])
   6147        end
   6148      end)
   6149 
   6150      it('w with focusable=false', function()
   6151        api.nvim_win_set_config(win, { focusable = false })
   6152        expected_pos[4][6] = false
   6153        feed('<c-w>wi') -- i to provoke redraw
   6154        if multigrid then
   6155          screen:expect {
   6156            grid = [[
   6157          ## grid 1
   6158            [2:----------------------------------------]|*6
   6159            [3:----------------------------------------]|
   6160          ## grid 2
   6161            ^x                                       |
   6162            {0:~                                       }|*5
   6163          ## grid 3
   6164            {3:-- INSERT --}                            |
   6165          ## grid 4
   6166            {1:y                   }|
   6167            {2:~                   }|
   6168          ]],
   6169            float_pos = expected_pos,
   6170          }
   6171        else
   6172          screen:expect([[
   6173            ^x                                       |
   6174            {0:~                                       }|
   6175            {0:~    }{1:y                   }{0:               }|
   6176            {0:~    }{2:~                   }{0:               }|
   6177            {0:~                                       }|*2
   6178            {3:-- INSERT --}                            |
   6179          ]])
   6180        end
   6181 
   6182        feed('<esc><c-w>w')
   6183        if multigrid then
   6184          screen:expect {
   6185            grid = [[
   6186          ## grid 1
   6187            [2:----------------------------------------]|*6
   6188            [3:----------------------------------------]|
   6189          ## grid 2
   6190            ^x                                       |
   6191            {0:~                                       }|*5
   6192          ## grid 3
   6193                                                    |
   6194          ## grid 4
   6195            {1:y                   }|
   6196            {2:~                   }|
   6197          ]],
   6198            float_pos = expected_pos,
   6199          }
   6200        else
   6201          screen:expect([[
   6202            ^x                                       |
   6203            {0:~                                       }|
   6204            {0:~    }{1:y                   }{0:               }|
   6205            {0:~    }{2:~                   }{0:               }|
   6206            {0:~                                       }|*2
   6207                                                    |
   6208          ]])
   6209        end
   6210 
   6211        api.nvim_open_win(0, false, { relative = 'editor', width = 1, height = 1, row = 0, col = 0 })
   6212        api.nvim_open_win(0, false, { relative = 'editor', width = 1, height = 1, row = 0, col = 0, focusable = false })
   6213        api.nvim_open_win(0, false, { relative = 'editor', width = 1, height = 1, row = 0, col = 0, focusable = false })
   6214        api.nvim_open_win(0, false, { relative = 'editor', width = 1, height = 1, row = 0, col = 0, focusable = true })
   6215        api.nvim_open_win(0, false, { relative = 'editor', width = 1, height = 1, row = 0, col = 0, focusable = false })
   6216        local nr_focusable = {}
   6217        for _, winid in ipairs(api.nvim_tabpage_list_wins(0)) do
   6218          table.insert(nr_focusable, api.nvim_win_get_config(winid).focusable)
   6219        end
   6220        eq({ true, false, true, false, false, true, false }, nr_focusable)
   6221 
   6222        command('1wincmd w')
   6223        eq({ 1, 1000 }, { fn.winnr(), fn.win_getid() })
   6224        command('2wincmd w')
   6225        eq({ 2, 1005 }, { fn.winnr(), fn.win_getid() })
   6226        command('3wincmd w')
   6227        eq({ 2, 1005 }, { fn.winnr(), fn.win_getid() })
   6228        command('4wincmd w')
   6229        eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
   6230        command('5wincmd w')
   6231        eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
   6232        command('6wincmd w')
   6233        eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
   6234        command('7wincmd w')
   6235        eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
   6236 
   6237        feed('1<c-w>w')
   6238        eq({ 1, 1000 }, { fn.winnr(), fn.win_getid() })
   6239        feed('2<c-w>w')
   6240        eq({ 2, 1005 }, { fn.winnr(), fn.win_getid() })
   6241        feed('999<c-w>w')
   6242        eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
   6243      end)
   6244 
   6245      it('W', function()
   6246        feed('<c-w>W')
   6247        if multigrid then
   6248          screen:expect {
   6249            grid = [[
   6250          ## grid 1
   6251            [2:----------------------------------------]|*6
   6252            [3:----------------------------------------]|
   6253          ## grid 2
   6254            x                                       |
   6255            {0:~                                       }|*5
   6256          ## grid 3
   6257                                                    |
   6258          ## grid 4
   6259            {1:^y                   }|
   6260            {2:~                   }|
   6261          ]],
   6262            float_pos = expected_pos,
   6263          }
   6264        else
   6265          screen:expect([[
   6266            x                                       |
   6267            {0:~                                       }|
   6268            {0:~    }{1:^y                   }{0:               }|
   6269            {0:~    }{2:~                   }{0:               }|
   6270            {0:~                                       }|*2
   6271                                                    |
   6272          ]])
   6273        end
   6274 
   6275        feed('<c-w>W')
   6276        if multigrid then
   6277          screen:expect {
   6278            grid = [[
   6279          ## grid 1
   6280            [2:----------------------------------------]|*6
   6281            [3:----------------------------------------]|
   6282          ## grid 2
   6283            ^x                                       |
   6284            {0:~                                       }|*5
   6285          ## grid 3
   6286                                                    |
   6287          ## grid 4
   6288            {1:y                   }|
   6289            {2:~                   }|
   6290          ]],
   6291            float_pos = expected_pos,
   6292          }
   6293        else
   6294          screen:expect([[
   6295            ^x                                       |
   6296            {0:~                                       }|
   6297            {0:~    }{1:y                   }{0:               }|
   6298            {0:~    }{2:~                   }{0:               }|
   6299            {0:~                                       }|*2
   6300                                                    |
   6301          ]])
   6302        end
   6303      end)
   6304 
   6305      local function test_float_mouse_focus()
   6306        if send_mouse_grid then
   6307          api.nvim_input_mouse('left', 'press', '', 4, 0, 0)
   6308        else
   6309          api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
   6310        end
   6311        if multigrid then
   6312          screen:expect {
   6313            grid = [[
   6314          ## grid 1
   6315            [2:----------------------------------------]|*6
   6316            [3:----------------------------------------]|
   6317          ## grid 2
   6318            x                                       |
   6319            {0:~                                       }|*5
   6320          ## grid 3
   6321                                                    |
   6322          ## grid 4
   6323            {1:^y                   }|
   6324            {2:~                   }|
   6325          ]],
   6326            float_pos = expected_pos,
   6327          }
   6328        else
   6329          screen:expect([[
   6330            x                                       |
   6331            {0:~                                       }|
   6332            {0:~    }{1:^y                   }{0:               }|
   6333            {0:~    }{2:~                   }{0:               }|
   6334            {0:~                                       }|*2
   6335                                                    |
   6336          ]])
   6337        end
   6338 
   6339        if send_mouse_grid then
   6340          api.nvim_input_mouse('left', 'press', '', 2, 0, 0)
   6341        else
   6342          api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
   6343        end
   6344        if multigrid then
   6345          screen:expect {
   6346            grid = [[
   6347          ## grid 1
   6348            [2:----------------------------------------]|*6
   6349            [3:----------------------------------------]|
   6350          ## grid 2
   6351            ^x                                       |
   6352            {0:~                                       }|*5
   6353          ## grid 3
   6354                                                    |
   6355          ## grid 4
   6356            {1:y                   }|
   6357            {2:~                   }|
   6358          ]],
   6359            float_pos = expected_pos,
   6360          }
   6361        else
   6362          screen:expect([[
   6363            ^x                                       |
   6364            {0:~                                       }|
   6365            {0:~    }{1:y                   }{0:               }|
   6366            {0:~    }{2:~                   }{0:               }|
   6367            {0:~                                       }|*2
   6368                                                    |
   6369          ]])
   6370        end
   6371      end
   6372 
   6373      it('focus by mouse (focusable=true)', function()
   6374        test_float_mouse_focus()
   6375      end)
   6376 
   6377      it('focus by mouse (focusable=false, mouse=true)', function()
   6378        api.nvim_win_set_config(win, { focusable = false, mouse = true })
   6379        test_float_mouse_focus()
   6380      end)
   6381 
   6382      local function test_float_mouse_no_focus()
   6383        api.nvim_buf_set_lines(0, -1, -1, true, { 'a' })
   6384        expected_pos[4][6] = false
   6385        if send_mouse_grid then
   6386          api.nvim_input_mouse('left', 'press', '', 4, 0, 0)
   6387        else
   6388          api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
   6389        end
   6390        if multigrid then
   6391          if send_mouse_grid then
   6392            -- Sending input to grid 4 is a user error, you are not supposed to pass a grid
   6393            -- that isn't focusable. In this case, nothing happens and the input is not passed
   6394            -- through to grid 4, like normally happens when you pass grid 0.
   6395            screen:expect {
   6396              grid = [[
   6397            ## grid 1
   6398              [2:----------------------------------------]|*6
   6399              [3:----------------------------------------]|
   6400            ## grid 2
   6401              ^x                                       |
   6402              a                                       |
   6403              {0:~                                       }|*4
   6404            ## grid 3
   6405                                                      |
   6406            ## grid 4
   6407              {1:y                   }|
   6408              {2:~                   }|
   6409            ]],
   6410              float_pos = expected_pos,
   6411            }
   6412          else
   6413            screen:expect {
   6414              grid = [[
   6415            ## grid 1
   6416              [2:----------------------------------------]|*6
   6417              [3:----------------------------------------]|
   6418            ## grid 2
   6419              x                                       |
   6420              ^a                                       |
   6421              {0:~                                       }|*4
   6422            ## grid 3
   6423                                                      |
   6424            ## grid 4
   6425              {1:y                   }|
   6426              {2:~                   }|
   6427            ]],
   6428              float_pos = expected_pos,
   6429            }
   6430          end
   6431        else
   6432          screen:expect([[
   6433            x                                       |
   6434            ^a                                       |
   6435            {0:~    }{1:y                   }{0:               }|
   6436            {0:~    }{2:~                   }{0:               }|
   6437            {0:~                                       }|*2
   6438                                                    |
   6439          ]])
   6440        end
   6441 
   6442        if send_mouse_grid then
   6443          api.nvim_input_mouse('left', 'press', '', 2, 0, 0)
   6444        else
   6445          api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
   6446        end
   6447        if multigrid then
   6448          screen:expect {
   6449            grid = [[
   6450          ## grid 1
   6451            [2:----------------------------------------]|*6
   6452            [3:----------------------------------------]|
   6453          ## grid 2
   6454            ^x                                       |
   6455            a                                       |
   6456            {0:~                                       }|*4
   6457          ## grid 3
   6458                                                    |
   6459          ## grid 4
   6460            {1:y                   }|
   6461            {2:~                   }|
   6462          ]],
   6463            float_pos = expected_pos,
   6464            unchanged = true,
   6465          }
   6466        else
   6467          screen:expect([[
   6468            ^x                                       |
   6469            a                                       |
   6470            {0:~    }{1:y                   }{0:               }|
   6471            {0:~    }{2:~                   }{0:               }|
   6472            {0:~                                       }|*2
   6473                                                    |
   6474          ]])
   6475        end
   6476      end
   6477 
   6478      it('focus by mouse (focusable=false)', function()
   6479        api.nvim_win_set_config(win, { focusable = false })
   6480        test_float_mouse_no_focus()
   6481      end)
   6482 
   6483      it('focus by mouse (focusable=true, mouse=false)', function()
   6484        api.nvim_win_set_config(win, { mouse = false })
   6485        test_float_mouse_no_focus()
   6486      end)
   6487 
   6488      it(':help (focusable=false, hide=true)', function()
   6489        n.add_builddir_to_rtp()
   6490        local w = curwin()
   6491        for _, helpcmd in ipairs({
   6492          'help',
   6493          'helpgrep api-types',
   6494          'lhelpgrep api-types',
   6495        }) do
   6496          command(helpcmd)
   6497          local badwins = {
   6498            api.nvim_open_win(0, false, { focusable = false, relative = 'editor', width = 1, height = 1, row = 0, col = 0 }),
   6499            api.nvim_open_win(0, false, { hide = true, relative = 'editor', width = 1, height = 1, row = 0, col = 0 }),
   6500          }
   6501          command('helpclose')
   6502          command(helpcmd)
   6503          eq(false, tbl_contains(badwins, curwin()))
   6504          command('helpclose')
   6505          eq(w, curwin())
   6506        end
   6507      end)
   6508 
   6509      it('j', function()
   6510        feed('<c-w>ji') -- INSERT to trigger screen change
   6511        if multigrid then
   6512          screen:expect {
   6513            grid = [[
   6514          ## grid 1
   6515            [2:----------------------------------------]|*6
   6516            [3:----------------------------------------]|
   6517          ## grid 2
   6518            ^x                                       |
   6519            {0:~                                       }|*5
   6520          ## grid 3
   6521            {3:-- INSERT --}                            |
   6522          ## grid 4
   6523            {1:y                   }|
   6524            {2:~                   }|
   6525          ]],
   6526            float_pos = expected_pos,
   6527          }
   6528        else
   6529          screen:expect([[
   6530            ^x                                       |
   6531            {0:~                                       }|
   6532            {0:~    }{1:y                   }{0:               }|
   6533            {0:~    }{2:~                   }{0:               }|
   6534            {0:~                                       }|*2
   6535            {3:-- INSERT --}                            |
   6536          ]])
   6537        end
   6538 
   6539        feed('<esc><c-w>w')
   6540        if multigrid then
   6541          screen:expect {
   6542            grid = [[
   6543          ## grid 1
   6544            [2:----------------------------------------]|*6
   6545            [3:----------------------------------------]|
   6546          ## grid 2
   6547            x                                       |
   6548            {0:~                                       }|*5
   6549          ## grid 3
   6550                                                    |
   6551          ## grid 4
   6552            {1:^y                   }|
   6553            {2:~                   }|
   6554          ]],
   6555            float_pos = expected_pos,
   6556          }
   6557        else
   6558          screen:expect([[
   6559            x                                       |
   6560            {0:~                                       }|
   6561            {0:~    }{1:^y                   }{0:               }|
   6562            {0:~    }{2:~                   }{0:               }|
   6563            {0:~                                       }|*2
   6564                                                    |
   6565          ]])
   6566        end
   6567 
   6568        feed('<c-w>j')
   6569        if multigrid then
   6570          screen:expect {
   6571            grid = [[
   6572          ## grid 1
   6573            [2:----------------------------------------]|*6
   6574            [3:----------------------------------------]|
   6575          ## grid 2
   6576            ^x                                       |
   6577            {0:~                                       }|*5
   6578          ## grid 3
   6579                                                    |
   6580          ## grid 4
   6581            {1:y                   }|
   6582            {2:~                   }|
   6583          ]],
   6584            float_pos = expected_pos,
   6585          }
   6586        else
   6587          screen:expect([[
   6588            ^x                                       |
   6589            {0:~                                       }|
   6590            {0:~    }{1:y                   }{0:               }|
   6591            {0:~    }{2:~                   }{0:               }|
   6592            {0:~                                       }|*2
   6593                                                    |
   6594          ]])
   6595        end
   6596      end)
   6597 
   6598      it('vertical resize + - _', function()
   6599        feed('<c-w>w')
   6600        if multigrid then
   6601          screen:expect {
   6602            grid = [[
   6603          ## grid 1
   6604            [2:----------------------------------------]|*6
   6605            [3:----------------------------------------]|
   6606          ## grid 2
   6607            x                                       |
   6608            {0:~                                       }|*5
   6609          ## grid 3
   6610                                                    |
   6611          ## grid 4
   6612            {1:^y                   }|
   6613            {2:~                   }|
   6614          ]],
   6615            float_pos = expected_pos,
   6616          }
   6617        else
   6618          screen:expect([[
   6619            x                                       |
   6620            {0:~                                       }|
   6621            {0:~    }{1:^y                   }{0:               }|
   6622            {0:~    }{2:~                   }{0:               }|
   6623            {0:~                                       }|*2
   6624                                                    |
   6625          ]])
   6626        end
   6627 
   6628        feed('<c-w>+')
   6629        if multigrid then
   6630          screen:expect {
   6631            grid = [[
   6632          ## grid 1
   6633            [2:----------------------------------------]|*6
   6634            [3:----------------------------------------]|
   6635          ## grid 2
   6636            x                                       |
   6637            {0:~                                       }|*5
   6638          ## grid 3
   6639                                                    |
   6640          ## grid 4
   6641            {1:^y                   }|
   6642            {2:~                   }|*2
   6643          ]],
   6644            float_pos = expected_pos,
   6645          }
   6646        else
   6647          screen:expect([[
   6648            x                                       |
   6649            {0:~                                       }|
   6650            {0:~    }{1:^y                   }{0:               }|
   6651            {0:~    }{2:~                   }{0:               }|*2
   6652            {0:~                                       }|
   6653                                                    |
   6654          ]])
   6655        end
   6656 
   6657        feed('<c-w>2-')
   6658        if multigrid then
   6659          screen:expect {
   6660            grid = [[
   6661          ## grid 1
   6662            [2:----------------------------------------]|*6
   6663            [3:----------------------------------------]|
   6664          ## grid 2
   6665            x                                       |
   6666            {0:~                                       }|*5
   6667          ## grid 3
   6668                                                    |
   6669          ## grid 4
   6670            {1:^y                   }|
   6671          ]],
   6672            float_pos = expected_pos,
   6673          }
   6674        else
   6675          screen:expect([[
   6676            x                                       |
   6677            {0:~                                       }|
   6678            {0:~    }{1:^y                   }{0:               }|
   6679            {0:~                                       }|*3
   6680                                                    |
   6681          ]])
   6682        end
   6683 
   6684        feed('<c-w>4_')
   6685        if multigrid then
   6686          screen:expect {
   6687            grid = [[
   6688          ## grid 1
   6689            [2:----------------------------------------]|*6
   6690            [3:----------------------------------------]|
   6691          ## grid 2
   6692            x                                       |
   6693            {0:~                                       }|*5
   6694          ## grid 3
   6695                                                    |
   6696          ## grid 4
   6697            {1:^y                   }|
   6698            {2:~                   }|*3
   6699          ]],
   6700            float_pos = expected_pos,
   6701          }
   6702        else
   6703          screen:expect([[
   6704            x                                       |
   6705            {0:~                                       }|
   6706            {0:~    }{1:^y                   }{0:               }|
   6707            {0:~    }{2:~                   }{0:               }|*3
   6708                                                    |
   6709          ]])
   6710        end
   6711 
   6712        feed('<c-w>_')
   6713        if multigrid then
   6714          screen:expect {
   6715            grid = [[
   6716          ## grid 1
   6717            [2:----------------------------------------]|*6
   6718            [3:----------------------------------------]|
   6719          ## grid 2
   6720            x                                       |
   6721            {0:~                                       }|*5
   6722          ## grid 3
   6723                                                    |
   6724          ## grid 4
   6725            {1:^y                   }|
   6726            {2:~                   }|*5
   6727          ]],
   6728            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 0, 5 } },
   6729          }
   6730        else
   6731          screen:expect([[
   6732            x    {1:^y                   }               |
   6733            {0:~    }{2:~                   }{0:               }|*5
   6734                                                    |
   6735          ]])
   6736        end
   6737      end)
   6738 
   6739      it('horizontal resize > < |', function()
   6740        feed('<c-w>w')
   6741        if multigrid then
   6742          screen:expect {
   6743            grid = [[
   6744          ## grid 1
   6745            [2:----------------------------------------]|*6
   6746            [3:----------------------------------------]|
   6747          ## grid 2
   6748            x                                       |
   6749            {0:~                                       }|*5
   6750          ## grid 3
   6751                                                    |
   6752          ## grid 4
   6753            {1:^y                   }|
   6754            {2:~                   }|
   6755          ]],
   6756            float_pos = expected_pos,
   6757          }
   6758        else
   6759          screen:expect([[
   6760            x                                       |
   6761            {0:~                                       }|
   6762            {0:~    }{1:^y                   }{0:               }|
   6763            {0:~    }{2:~                   }{0:               }|
   6764            {0:~                                       }|*2
   6765                                                    |
   6766          ]])
   6767        end
   6768 
   6769        feed('<c-w>>')
   6770        if multigrid then
   6771          screen:expect {
   6772            grid = [[
   6773          ## grid 1
   6774            [2:----------------------------------------]|*6
   6775            [3:----------------------------------------]|
   6776          ## grid 2
   6777            x                                       |
   6778            {0:~                                       }|*5
   6779          ## grid 3
   6780                                                    |
   6781          ## grid 4
   6782            {1:^y                    }|
   6783            {2:~                    }|
   6784          ]],
   6785            float_pos = expected_pos,
   6786          }
   6787        else
   6788          screen:expect([[
   6789            x                                       |
   6790            {0:~                                       }|
   6791            {0:~    }{1:^y                    }{0:              }|
   6792            {0:~    }{2:~                    }{0:              }|
   6793            {0:~                                       }|*2
   6794                                                    |
   6795          ]])
   6796        end
   6797 
   6798        feed('<c-w>10<lt>')
   6799        if multigrid then
   6800          screen:expect {
   6801            grid = [[
   6802          ## grid 1
   6803            [2:----------------------------------------]|*6
   6804            [3:----------------------------------------]|
   6805          ## grid 2
   6806            x                                       |
   6807            {0:~                                       }|*5
   6808          ## grid 3
   6809                                                    |
   6810          ## grid 4
   6811            {1:^y          }|
   6812            {2:~          }|
   6813          ]],
   6814            float_pos = expected_pos,
   6815          }
   6816        else
   6817          screen:expect([[
   6818            x                                       |
   6819            {0:~                                       }|
   6820            {0:~    }{1:^y          }{0:                        }|
   6821            {0:~    }{2:~          }{0:                        }|
   6822            {0:~                                       }|*2
   6823                                                    |
   6824          ]])
   6825        end
   6826 
   6827        feed('<c-w>15|')
   6828        if multigrid then
   6829          screen:expect {
   6830            grid = [[
   6831          ## grid 1
   6832            [2:----------------------------------------]|*6
   6833            [3:----------------------------------------]|
   6834          ## grid 2
   6835            x                                       |
   6836            {0:~                                       }|*5
   6837          ## grid 3
   6838                                                    |
   6839          ## grid 4
   6840            {1:^y              }|
   6841            {2:~              }|
   6842          ]],
   6843            float_pos = expected_pos,
   6844          }
   6845        else
   6846          screen:expect([[
   6847            x                                       |
   6848            {0:~                                       }|
   6849            {0:~    }{1:^y              }{0:                    }|
   6850            {0:~    }{2:~              }{0:                    }|
   6851            {0:~                                       }|*2
   6852                                                    |
   6853          ]])
   6854        end
   6855 
   6856        feed('<c-w>|')
   6857        if multigrid then
   6858          screen:expect {
   6859            grid = [[
   6860          ## grid 1
   6861            [2:----------------------------------------]|*6
   6862            [3:----------------------------------------]|
   6863          ## grid 2
   6864            x                                       |
   6865            {0:~                                       }|*5
   6866          ## grid 3
   6867                                                    |
   6868          ## grid 4
   6869            {1:^y                                       }|
   6870            {2:~                                       }|
   6871          ]],
   6872            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 0 } },
   6873          }
   6874        else
   6875          screen:expect([[
   6876            x                                       |
   6877            {0:~                                       }|
   6878            {1:^y                                       }|
   6879            {2:~                                       }|
   6880            {0:~                                       }|*2
   6881                                                    |
   6882          ]])
   6883        end
   6884      end)
   6885 
   6886      it('s :split (non-float)', function()
   6887        feed('<c-w>s')
   6888        if multigrid then
   6889          screen:expect {
   6890            grid = [[
   6891          ## grid 1
   6892            [5:----------------------------------------]|*2
   6893            {4:[No Name] [+]                           }|
   6894            [2:----------------------------------------]|*2
   6895            {5:[No Name] [+]                           }|
   6896            [3:----------------------------------------]|
   6897          ## grid 2
   6898            x                                       |
   6899            {0:~                                       }|
   6900          ## grid 3
   6901                                                    |
   6902          ## grid 4
   6903            {1:y                   }|
   6904            {2:~                   }|
   6905          ## grid 5
   6906            ^x                                       |
   6907            {0:~                                       }|
   6908          ]],
   6909            float_pos = expected_pos,
   6910          }
   6911        else
   6912          screen:expect([[
   6913            ^x                                       |
   6914            {0:~                                       }|
   6915            {4:[No N}{1:y                   }{4:               }|
   6916            x    {2:~                   }               |
   6917            {0:~                                       }|
   6918            {5:[No Name] [+]                           }|
   6919                                                    |
   6920          ]])
   6921        end
   6922 
   6923        feed('<c-w>w')
   6924        if multigrid then
   6925          screen:expect {
   6926            grid = [[
   6927          ## grid 1
   6928            [5:----------------------------------------]|*2
   6929            {5:[No Name] [+]                           }|
   6930            [2:----------------------------------------]|*2
   6931            {4:[No Name] [+]                           }|
   6932            [3:----------------------------------------]|
   6933          ## grid 2
   6934            ^x                                       |
   6935            {0:~                                       }|
   6936          ## grid 3
   6937                                                    |
   6938          ## grid 4
   6939            {1:y                   }|
   6940            {2:~                   }|
   6941          ## grid 5
   6942            x                                       |
   6943            {0:~                                       }|
   6944          ]],
   6945            float_pos = expected_pos,
   6946          }
   6947        else
   6948          screen:expect([[
   6949            x                                       |
   6950            {0:~                                       }|
   6951            {5:[No N}{1:y                   }{5:               }|
   6952            ^x    {2:~                   }               |
   6953            {0:~                                       }|
   6954            {4:[No Name] [+]                           }|
   6955                                                    |
   6956          ]])
   6957        end
   6958 
   6959        feed('<c-w>w')
   6960        if multigrid then
   6961          screen:expect {
   6962            grid = [[
   6963          ## grid 1
   6964            [5:----------------------------------------]|*2
   6965            {5:[No Name] [+]                           }|
   6966            [2:----------------------------------------]|*2
   6967            {5:[No Name] [+]                           }|
   6968            [3:----------------------------------------]|
   6969          ## grid 2
   6970            x                                       |
   6971            {0:~                                       }|
   6972          ## grid 3
   6973                                                    |
   6974          ## grid 4
   6975            {1:^y                   }|
   6976            {2:~                   }|
   6977          ## grid 5
   6978            x                                       |
   6979            {0:~                                       }|
   6980          ]],
   6981            float_pos = expected_pos,
   6982          }
   6983        else
   6984          screen:expect([[
   6985            x                                       |
   6986            {0:~                                       }|
   6987            {5:[No N}{1:^y                   }{5:               }|
   6988            x    {2:~                   }               |
   6989            {0:~                                       }|
   6990            {5:[No Name] [+]                           }|
   6991                                                    |
   6992          ]])
   6993        end
   6994 
   6995        feed('<c-w>w')
   6996        if multigrid then
   6997          screen:expect {
   6998            grid = [[
   6999          ## grid 1
   7000            [5:----------------------------------------]|*2
   7001            {4:[No Name] [+]                           }|
   7002            [2:----------------------------------------]|*2
   7003            {5:[No Name] [+]                           }|
   7004            [3:----------------------------------------]|
   7005          ## grid 2
   7006            x                                       |
   7007            {0:~                                       }|
   7008          ## grid 3
   7009                                                    |
   7010          ## grid 4
   7011            {1:y                   }|
   7012            {2:~                   }|
   7013          ## grid 5
   7014            ^x                                       |
   7015            {0:~                                       }|
   7016          ]],
   7017            float_pos = expected_pos,
   7018          }
   7019        else
   7020          screen:expect([[
   7021            ^x                                       |
   7022            {0:~                                       }|
   7023            {4:[No N}{1:y                   }{4:               }|
   7024            x    {2:~                   }               |
   7025            {0:~                                       }|
   7026            {5:[No Name] [+]                           }|
   7027                                                    |
   7028          ]])
   7029        end
   7030      end)
   7031 
   7032      it('s :split (float)', function()
   7033        feed('<c-w>w<c-w>s')
   7034        if multigrid then
   7035          screen:expect {
   7036            grid = [[
   7037          ## grid 1
   7038            [5:----------------------------------------]|*2
   7039            {4:[No Name] [+]                           }|
   7040            [2:----------------------------------------]|*2
   7041            {5:[No Name] [+]                           }|
   7042            [3:----------------------------------------]|
   7043          ## grid 2
   7044            x                                       |
   7045            {0:~                                       }|
   7046          ## grid 3
   7047                                                    |
   7048          ## grid 4
   7049            {1:y                   }|
   7050            {2:~                   }|
   7051          ## grid 5
   7052            ^y                                       |
   7053            {0:~                                       }|
   7054          ]],
   7055            float_pos = expected_pos,
   7056          }
   7057        else
   7058          screen:expect([[
   7059            ^y                                       |
   7060            {0:~                                       }|
   7061            {4:[No N}{1:y                   }{4:               }|
   7062            x    {2:~                   }               |
   7063            {0:~                                       }|
   7064            {5:[No Name] [+]                           }|
   7065                                                    |
   7066          ]])
   7067        end
   7068 
   7069        feed('<c-w>j')
   7070        if multigrid then
   7071          screen:expect {
   7072            grid = [[
   7073          ## grid 1
   7074            [5:----------------------------------------]|*2
   7075            {5:[No Name] [+]                           }|
   7076            [2:----------------------------------------]|*2
   7077            {4:[No Name] [+]                           }|
   7078            [3:----------------------------------------]|
   7079          ## grid 2
   7080            ^x                                       |
   7081            {0:~                                       }|
   7082          ## grid 3
   7083                                                    |
   7084          ## grid 4
   7085            {1:y                   }|
   7086            {2:~                   }|
   7087          ## grid 5
   7088            y                                       |
   7089            {0:~                                       }|
   7090          ]],
   7091            float_pos = expected_pos,
   7092          }
   7093        else
   7094          screen:expect([[
   7095            y                                       |
   7096            {0:~                                       }|
   7097            {5:[No N}{1:y                   }{5:               }|
   7098            ^x    {2:~                   }               |
   7099            {0:~                                       }|
   7100            {4:[No Name] [+]                           }|
   7101                                                    |
   7102          ]])
   7103        end
   7104 
   7105        feed('<c-w>ji')
   7106        if multigrid then
   7107          screen:expect {
   7108            grid = [[
   7109          ## grid 1
   7110            [5:----------------------------------------]|*2
   7111            {5:[No Name] [+]                           }|
   7112            [2:----------------------------------------]|*2
   7113            {4:[No Name] [+]                           }|
   7114            [3:----------------------------------------]|
   7115          ## grid 2
   7116            ^x                                       |
   7117            {0:~                                       }|
   7118          ## grid 3
   7119            {3:-- INSERT --}                            |
   7120          ## grid 4
   7121            {1:y                   }|
   7122            {2:~                   }|
   7123          ## grid 5
   7124            y                                       |
   7125            {0:~                                       }|
   7126          ]],
   7127            float_pos = expected_pos,
   7128          }
   7129        else
   7130          screen:expect([[
   7131            y                                       |
   7132            {0:~                                       }|
   7133            {5:[No N}{1:y                   }{5:               }|
   7134            ^x    {2:~                   }               |
   7135            {0:~                                       }|
   7136            {4:[No Name] [+]                           }|
   7137            {3:-- INSERT --}                            |
   7138          ]])
   7139        end
   7140      end)
   7141 
   7142      it(':new (non-float)', function()
   7143        feed(':new<cr>')
   7144        if multigrid then
   7145          screen:expect {
   7146            grid = [[
   7147          ## grid 1
   7148            [5:----------------------------------------]|*2
   7149            {4:[No Name]                               }|
   7150            [2:----------------------------------------]|*2
   7151            {5:[No Name] [+]                           }|
   7152            [3:----------------------------------------]|
   7153          ## grid 2
   7154            x                                       |
   7155            {0:~                                       }|
   7156          ## grid 3
   7157            :new                                    |
   7158          ## grid 4
   7159            {1:y                   }|
   7160            {2:~                   }|
   7161          ## grid 5
   7162            ^                                        |
   7163            {0:~                                       }|
   7164          ]],
   7165            float_pos = expected_pos,
   7166          }
   7167        else
   7168          screen:expect([[
   7169            ^                                        |
   7170            {0:~                                       }|
   7171            {4:[No N}{1:y                   }{4:               }|
   7172            x    {2:~                   }               |
   7173            {0:~                                       }|
   7174            {5:[No Name] [+]                           }|
   7175            :new                                    |
   7176          ]])
   7177        end
   7178      end)
   7179 
   7180      it(':new (float)', function()
   7181        feed('<c-w>w:new<cr>')
   7182        if multigrid then
   7183          screen:expect {
   7184            grid = [[
   7185          ## grid 1
   7186            [5:----------------------------------------]|*2
   7187            {4:[No Name]                               }|
   7188            [2:----------------------------------------]|*2
   7189            {5:[No Name] [+]                           }|
   7190            [3:----------------------------------------]|
   7191          ## grid 2
   7192            x                                       |
   7193            {0:~                                       }|
   7194          ## grid 3
   7195            :new                                    |
   7196          ## grid 4
   7197            {1:y                   }|
   7198            {2:~                   }|
   7199          ## grid 5
   7200            ^                                        |
   7201            {0:~                                       }|
   7202          ]],
   7203            float_pos = expected_pos,
   7204          }
   7205        else
   7206          screen:expect([[
   7207            ^                                        |
   7208            {0:~                                       }|
   7209            {4:[No N}{1:y                   }{4:               }|
   7210            x    {2:~                   }               |
   7211            {0:~                                       }|
   7212            {5:[No Name] [+]                           }|
   7213            :new                                    |
   7214          ]])
   7215        end
   7216      end)
   7217 
   7218      it('v :vsplit (non-float)', function()
   7219        feed('<c-w>v')
   7220        if multigrid then
   7221          screen:expect {
   7222            grid = [[
   7223          ## grid 1
   7224            [5:--------------------]{5:│}[2:-------------------]|*5
   7225            {4:[No Name] [+]        }{5:[No Name] [+]      }|
   7226            [3:----------------------------------------]|
   7227          ## grid 2
   7228            x                  |
   7229            {0:~                  }|*4
   7230          ## grid 3
   7231                                                    |
   7232          ## grid 4
   7233            {1:y                   }|
   7234            {2:~                   }|
   7235          ## grid 5
   7236            ^x                   |
   7237            {0:~                   }|*4
   7238          ]],
   7239            float_pos = expected_pos,
   7240          }
   7241        else
   7242          screen:expect([[
   7243            ^x                   {5:}x                  |
   7244            {0:~                   }{5:}{0:~                  }|
   7245            {0:~    }{1:y                   }{0:               }|
   7246            {0:~    }{2:~                   }{0:               }|
   7247            {0:~                   }{5:}{0:~                  }|
   7248            {4:[No Name] [+]        }{5:[No Name] [+]      }|
   7249                                                    |
   7250          ]])
   7251        end
   7252      end)
   7253 
   7254      it(':vnew (non-float)', function()
   7255        feed(':vnew<cr>')
   7256        if multigrid then
   7257          screen:expect {
   7258            grid = [[
   7259          ## grid 1
   7260            [5:--------------------]{5:│}[2:-------------------]|*5
   7261            {4:[No Name]            }{5:[No Name] [+]      }|
   7262            [3:----------------------------------------]|
   7263          ## grid 2
   7264            x                  |
   7265            {0:~                  }|*4
   7266          ## grid 3
   7267            :vnew                                   |
   7268          ## grid 4
   7269            {1:y                   }|
   7270            {2:~                   }|
   7271          ## grid 5
   7272            ^                    |
   7273            {0:~                   }|*4
   7274          ]],
   7275            float_pos = expected_pos,
   7276          }
   7277        else
   7278          screen:expect([[
   7279            ^                    {5:}x                  |
   7280            {0:~                   }{5:}{0:~                  }|
   7281            {0:~    }{1:y                   }{0:               }|
   7282            {0:~    }{2:~                   }{0:               }|
   7283            {0:~                   }{5:}{0:~                  }|
   7284            {4:[No Name]            }{5:[No Name] [+]      }|
   7285            :vnew                                   |
   7286          ]])
   7287        end
   7288      end)
   7289 
   7290      it(':vnew (float)', function()
   7291        feed('<c-w>w:vnew<cr>')
   7292        if multigrid then
   7293          screen:expect {
   7294            grid = [[
   7295          ## grid 1
   7296            [5:--------------------]{5:│}[2:-------------------]|*5
   7297            {4:[No Name]            }{5:[No Name] [+]      }|
   7298            [3:----------------------------------------]|
   7299          ## grid 2
   7300            x                  |
   7301            {0:~                  }|*4
   7302          ## grid 3
   7303            :vnew                                   |
   7304          ## grid 4
   7305            {1:y                   }|
   7306            {2:~                   }|
   7307          ## grid 5
   7308            ^                    |
   7309            {0:~                   }|*4
   7310          ]],
   7311            float_pos = expected_pos,
   7312          }
   7313        else
   7314          screen:expect([[
   7315            ^                    {5:}x                  |
   7316            {0:~                   }{5:}{0:~                  }|
   7317            {0:~    }{1:y                   }{0:               }|
   7318            {0:~    }{2:~                   }{0:               }|
   7319            {0:~                   }{5:}{0:~                  }|
   7320            {4:[No Name]            }{5:[No Name] [+]      }|
   7321            :vnew                                   |
   7322          ]])
   7323        end
   7324      end)
   7325 
   7326      it('q (:quit) last non-float exits nvim', function()
   7327        command('autocmd VimLeave    * call rpcrequest(1, "exit")')
   7328        -- avoid unsaved change in other buffer
   7329        feed('<c-w><c-w>:w Xtest_written2<cr><c-w><c-w>')
   7330        -- quit in last non-float
   7331        feed(':wq Xtest_written<cr>')
   7332        local exited = false
   7333        local function on_request(name, args)
   7334          eq('exit', name)
   7335          eq({}, args)
   7336          exited = true
   7337          return 0
   7338        end
   7339        local function on_setup()
   7340          feed(':wq Xtest_written<cr>')
   7341        end
   7342        run(on_request, nil, on_setup)
   7343        os.remove('Xtest_written')
   7344        os.remove('Xtest_written2')
   7345        eq(true, exited)
   7346      end)
   7347 
   7348      it(':quit two floats in a row', function()
   7349        -- enter first float
   7350        feed('<c-w><c-w>')
   7351        -- enter second float
   7352        api.nvim_open_win(0, true, { relative = 'editor', width = 20, height = 2, row = 4, col = 8 })
   7353        if multigrid then
   7354          screen:expect {
   7355            grid = [[
   7356          ## grid 1
   7357            [2:----------------------------------------]|*6
   7358            [3:----------------------------------------]|
   7359          ## grid 2
   7360            x                                       |
   7361            {0:~                                       }|*5
   7362          ## grid 3
   7363                                                    |
   7364          ## grid 4
   7365            {1:y                   }|
   7366            {2:~                   }|
   7367          ## grid 5
   7368            {1:^y                   }|
   7369            {2:~                   }|
   7370          ]],
   7371            float_pos = {
   7372              [5] = { 1002, 'NW', 1, 4, 8, true, 50, 2, 4, 8 },
   7373              [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 },
   7374            },
   7375          }
   7376        else
   7377          screen:expect([[
   7378            x                                       |
   7379            {0:~                                       }|
   7380            {0:~    }{1:y                   }{0:               }|
   7381            {0:~    }{2:~                   }{0:               }|
   7382            {0:~       }{1:^y                   }{0:            }|
   7383            {0:~       }{2:~                   }{0:            }|
   7384                                                    |
   7385          ]])
   7386        end
   7387 
   7388        feed(':quit<cr>')
   7389        if multigrid then
   7390          screen:expect {
   7391            grid = [[
   7392          ## grid 1
   7393            [2:----------------------------------------]|*6
   7394            [3:----------------------------------------]|
   7395          ## grid 2
   7396            x                                       |
   7397            {0:~                                       }|*5
   7398          ## grid 3
   7399            :quit                                   |
   7400          ## grid 4
   7401            {1:^y                   }|
   7402            {2:~                   }|
   7403          ]],
   7404            float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   7405          }
   7406        else
   7407          screen:expect([[
   7408            x                                       |
   7409            {0:~                                       }|
   7410            {0:~    }{1:^y                   }{0:               }|
   7411            {0:~    }{2:~                   }{0:               }|
   7412            {0:~                                       }|*2
   7413            :quit                                   |
   7414          ]])
   7415        end
   7416 
   7417        feed(':quit<cr>')
   7418        if multigrid then
   7419          screen:expect([[
   7420          ## grid 1
   7421            [2:----------------------------------------]|*6
   7422            [3:----------------------------------------]|
   7423          ## grid 2
   7424            ^x                                       |
   7425            {0:~                                       }|*5
   7426          ## grid 3
   7427            :quit                                   |
   7428          ]])
   7429        else
   7430          screen:expect([[
   7431            ^x                                       |
   7432            {0:~                                       }|*5
   7433            :quit                                   |
   7434          ]])
   7435        end
   7436 
   7437        assert_alive()
   7438      end)
   7439 
   7440      it('o (:only) non-float', function()
   7441        feed('<c-w>o')
   7442        if multigrid then
   7443          screen:expect {
   7444            grid = [[
   7445          ## grid 1
   7446            [2:----------------------------------------]|*6
   7447            [3:----------------------------------------]|
   7448          ## grid 2
   7449            ^x                                       |
   7450            {0:~                                       }|*5
   7451          ## grid 3
   7452                                                    |
   7453          ]],
   7454          }
   7455        else
   7456          screen:expect([[
   7457            ^x                                       |
   7458            {0:~                                       }|*5
   7459                                                    |
   7460          ]])
   7461        end
   7462      end)
   7463 
   7464      it('o (:only) float fails', function()
   7465        feed('<c-w>w<c-w>o')
   7466        if multigrid then
   7467          screen:expect {
   7468            grid = [[
   7469          ## grid 1
   7470            [2:----------------------------------------]|*4
   7471            [3:----------------------------------------]|*3
   7472          ## grid 2
   7473            x                                       |
   7474            {0:~                                       }|*5
   7475          ## grid 3
   7476            {7:E5601: Cannot close window, only floatin}|
   7477            {7:g window would remain}                   |
   7478            {8:Press ENTER or type command to continue}^ |
   7479          ## grid 4
   7480            {1:y                   }|
   7481            {2:~                   }|
   7482          ]],
   7483            float_pos = expected_pos,
   7484          }
   7485        else
   7486          screen:expect([[
   7487            x                                       |
   7488            {0:~                                       }|
   7489            {0:~    }{1:y                   }{0:               }|
   7490            {4:                                        }|
   7491            {7:E5601: Cannot close window, only floatin}|
   7492            {7:g window would remain}                   |
   7493            {8:Press ENTER or type command to continue}^ |
   7494          ]])
   7495        end
   7496 
   7497        -- test message clear
   7498        feed('<cr>')
   7499        if multigrid then
   7500          screen:expect {
   7501            grid = [[
   7502          ## grid 1
   7503            [2:----------------------------------------]|*6
   7504            [3:----------------------------------------]|
   7505          ## grid 2
   7506            x                                       |
   7507            {0:~                                       }|*5
   7508          ## grid 3
   7509                                                    |
   7510          ## grid 4
   7511            {1:^y                   }|
   7512            {2:~                   }|
   7513          ]],
   7514            float_pos = expected_pos,
   7515          }
   7516        else
   7517          screen:expect([[
   7518            x                                       |
   7519            {0:~                                       }|
   7520            {0:~    }{1:^y                   }{0:               }|
   7521            {0:~    }{2:~                   }{0:               }|
   7522            {0:~                                       }|*2
   7523                                                    |
   7524          ]])
   7525        end
   7526      end)
   7527 
   7528      it('o (:only) non-float with split', function()
   7529        feed('<c-w>s')
   7530        if multigrid then
   7531          screen:expect {
   7532            grid = [[
   7533          ## grid 1
   7534            [5:----------------------------------------]|*2
   7535            {4:[No Name] [+]                           }|
   7536            [2:----------------------------------------]|*2
   7537            {5:[No Name] [+]                           }|
   7538            [3:----------------------------------------]|
   7539          ## grid 2
   7540            x                                       |
   7541            {0:~                                       }|
   7542          ## grid 3
   7543                                                    |
   7544          ## grid 4
   7545            {1:y                   }|
   7546            {2:~                   }|
   7547          ## grid 5
   7548            ^x                                       |
   7549            {0:~                                       }|
   7550        ]],
   7551            float_pos = expected_pos,
   7552          }
   7553        else
   7554          screen:expect([[
   7555            ^x                                       |
   7556            {0:~                                       }|
   7557            {4:[No N}{1:y                   }{4:               }|
   7558            x    {2:~                   }               |
   7559            {0:~                                       }|
   7560            {5:[No Name] [+]                           }|
   7561                                                    |
   7562          ]])
   7563        end
   7564 
   7565        feed('<c-w>o')
   7566        if multigrid then
   7567          screen:expect {
   7568            grid = [[
   7569          ## grid 1
   7570            [5:----------------------------------------]|*6
   7571            [3:----------------------------------------]|
   7572          ## grid 3
   7573                                                    |
   7574          ## grid 5
   7575            ^x                                       |
   7576            {0:~                                       }|*5
   7577          ]],
   7578          }
   7579        else
   7580          screen:expect([[
   7581            ^x                                       |
   7582            {0:~                                       }|*5
   7583                                                    |
   7584          ]])
   7585        end
   7586      end)
   7587 
   7588      it('o (:only) float with split', function()
   7589        feed('<c-w>s<c-w>W')
   7590        if multigrid then
   7591          screen:expect {
   7592            grid = [[
   7593          ## grid 1
   7594            [5:----------------------------------------]|*2
   7595            {5:[No Name] [+]                           }|
   7596            [2:----------------------------------------]|*2
   7597            {5:[No Name] [+]                           }|
   7598            [3:----------------------------------------]|
   7599          ## grid 2
   7600            x                                       |
   7601            {0:~                                       }|
   7602          ## grid 3
   7603                                                    |
   7604          ## grid 4
   7605            {1:^y                   }|
   7606            {2:~                   }|
   7607          ## grid 5
   7608            x                                       |
   7609            {0:~                                       }|
   7610          ]],
   7611            float_pos = expected_pos,
   7612          }
   7613        else
   7614          screen:expect([[
   7615            x                                       |
   7616            {0:~                                       }|
   7617            {5:[No N}{1:^y                   }{5:               }|
   7618            x    {2:~                   }               |
   7619            {0:~                                       }|
   7620            {5:[No Name] [+]                           }|
   7621                                                    |
   7622          ]])
   7623        end
   7624 
   7625        feed('<c-w>o')
   7626        if multigrid then
   7627          screen:expect {
   7628            grid = [[
   7629          ## grid 1
   7630            [5:----------------------------------------]|*2
   7631            {5:[No Name] [+]                           }|
   7632            [2:----------------------------------------]|
   7633            [3:----------------------------------------]|*3
   7634          ## grid 2
   7635            x                                       |
   7636            {0:~                                       }|
   7637          ## grid 3
   7638            {7:E5601: Cannot close window, only floatin}|
   7639            {7:g window would remain}                   |
   7640            {8:Press ENTER or type command to continue}^ |
   7641          ## grid 4
   7642            {1:y                   }|
   7643            {2:~                   }|
   7644          ## grid 5
   7645            x                                       |
   7646            {0:~                                       }|
   7647          ]],
   7648            float_pos = expected_pos,
   7649          }
   7650        else
   7651          screen:expect([[
   7652            x                                       |
   7653            {0:~                                       }|
   7654            {5:[No N}{1:y                   }{5:               }|
   7655            {4:                                        }|
   7656            {7:E5601: Cannot close window, only floatin}|
   7657            {7:g window would remain}                   |
   7658            {8:Press ENTER or type command to continue}^ |
   7659          ]])
   7660        end
   7661      end)
   7662 
   7663      it('J (float)', function()
   7664        feed('<c-w>w<c-w>J')
   7665        if multigrid then
   7666          screen:expect {
   7667            grid = [[
   7668          ## grid 1
   7669            [2:----------------------------------------]|*2
   7670            {5:[No Name] [+]                           }|
   7671            [4:----------------------------------------]|*2
   7672            {4:[No Name] [+]                           }|
   7673            [3:----------------------------------------]|
   7674          ## grid 2
   7675            x                                       |
   7676            {0:~                                       }|
   7677          ## grid 3
   7678                                                    |
   7679          ## grid 4
   7680            ^y                                       |
   7681            {0:~                                       }|
   7682          ]],
   7683          }
   7684        else
   7685          screen:expect([[
   7686            x                                       |
   7687            {0:~                                       }|
   7688            {5:[No Name] [+]                           }|
   7689            ^y                                       |
   7690            {0:~                                       }|
   7691            {4:[No Name] [+]                           }|
   7692                                                    |
   7693          ]])
   7694        end
   7695 
   7696        if multigrid then
   7697          api.nvim_win_set_config(0, { external = true, width = 30, height = 2 })
   7698          expected_pos = { [4] = { external = true } }
   7699          screen:expect {
   7700            grid = [[
   7701          ## grid 1
   7702            [2:----------------------------------------]|*5
   7703            {5:[No Name] [+]                           }|
   7704            [3:----------------------------------------]|
   7705          ## grid 2
   7706            x                                       |
   7707            {0:~                                       }|*4
   7708          ## grid 3
   7709                                                    |
   7710          ## grid 4
   7711            ^y                             |
   7712            {0:~                             }|
   7713          ]],
   7714            float_pos = expected_pos,
   7715          }
   7716        else
   7717          eq("UI doesn't support external windows", pcall_err(api.nvim_win_set_config, 0, { external = true, width = 30, height = 2 }))
   7718          return
   7719        end
   7720 
   7721        feed('<c-w>J')
   7722        if multigrid then
   7723          screen:expect([[
   7724          ## grid 1
   7725            [2:----------------------------------------]|*2
   7726            {5:[No Name] [+]                           }|
   7727            [4:----------------------------------------]|*2
   7728            {4:[No Name] [+]                           }|
   7729            [3:----------------------------------------]|
   7730          ## grid 2
   7731            x                                       |
   7732            {0:~                                       }|
   7733          ## grid 3
   7734                                                    |
   7735          ## grid 4
   7736            ^y                                       |
   7737            {0:~                                       }|
   7738          ]])
   7739        end
   7740      end)
   7741 
   7742      it('J (float with border)', function()
   7743        api.nvim_win_set_config(win, { relative = 'editor', width = 20, height = 2, row = 2, col = 5, border = 'single' })
   7744        if multigrid then
   7745          screen:expect {
   7746            grid = [[
   7747          ## grid 1
   7748            [2:----------------------------------------]|*6
   7749            [3:----------------------------------------]|
   7750          ## grid 2
   7751            ^x                                       |
   7752            {0:~                                       }|*5
   7753          ## grid 3
   7754                                                    |
   7755          ## grid 4
   7756            {5:┌────────────────────┐}|
   7757            {5:│}{1:y                   }{5:│}|
   7758            {5:│}{2:~                   }{5:│}|
   7759            {5:└────────────────────┘}|
   7760          ]],
   7761            float_pos = expected_pos,
   7762          }
   7763        else
   7764          screen:expect([[
   7765            ^x                                       |
   7766            {0:~                                       }|
   7767            {0:~    }{5:┌────────────────────┐}{0:             }|
   7768            {0:~    }{5:}{1:y                   }{5:}{0:             }|
   7769            {0:~    }{5:}{2:~                   }{5:}{0:             }|
   7770            {0:~    }{5:└────────────────────┘}{0:             }|
   7771                                                    |
   7772          ]])
   7773        end
   7774 
   7775        feed('<c-w>w<c-w>J')
   7776        if multigrid then
   7777          screen:expect {
   7778            grid = [[
   7779          ## grid 1
   7780            [2:----------------------------------------]|*2
   7781            {5:[No Name] [+]                           }|
   7782            [4:----------------------------------------]|*2
   7783            {4:[No Name] [+]                           }|
   7784            [3:----------------------------------------]|
   7785          ## grid 2
   7786            x                                       |
   7787            {0:~                                       }|
   7788          ## grid 3
   7789                                                    |
   7790          ## grid 4
   7791            ^y                                       |
   7792            {0:~                                       }|
   7793          ]],
   7794          }
   7795        else
   7796          screen:expect([[
   7797            x                                       |
   7798            {0:~                                       }|
   7799            {5:[No Name] [+]                           }|
   7800            ^y                                       |
   7801            {0:~                                       }|
   7802            {4:[No Name] [+]                           }|
   7803                                                    |
   7804          ]])
   7805        end
   7806      end)
   7807 
   7808      it('movements with nested split layout', function()
   7809        command('set hidden')
   7810        feed('<c-w>s<c-w>v<c-w>b<c-w>v')
   7811        if multigrid then
   7812          screen:expect {
   7813            grid = [[
   7814          ## grid 1
   7815            [6:--------------------]{5:│}[5:-------------------]|*2
   7816            {5:[No Name] [+]        [No Name] [+]      }|
   7817            [7:--------------------]{5:│}[2:-------------------]|*2
   7818            {4:[No Name] [+]        }{5:[No Name] [+]      }|
   7819            [3:----------------------------------------]|
   7820          ## grid 2
   7821            x                  |
   7822            {0:~                  }|
   7823          ## grid 3
   7824                                                    |
   7825          ## grid 4
   7826            {1:y                   }|
   7827            {2:~                   }|
   7828          ## grid 5
   7829            x                  |
   7830            {0:~                  }|
   7831          ## grid 6
   7832            x                   |
   7833            {0:~                   }|
   7834          ## grid 7
   7835            ^x                   |
   7836            {0:~                   }|
   7837        ]],
   7838            float_pos = expected_pos,
   7839          }
   7840        else
   7841          screen:expect([[
   7842            x                   {5:}x                  |
   7843            {0:~                   }{5:}{0:~                  }|
   7844            {5:[No N}{1:y                   }{5:Name] [+]      }|
   7845            ^x    {2:~                   }               |
   7846            {0:~                   }{5:}{0:~                  }|
   7847            {4:[No Name] [+]        }{5:[No Name] [+]      }|
   7848                                                    |
   7849          ]])
   7850        end
   7851 
   7852        -- verify that N<c-w>w works
   7853        for i = 1, 5 do
   7854          feed(i .. '<c-w>w')
   7855          feed_command('enew')
   7856          api.nvim_buf_set_lines(0, 0, -1, true, { tostring(i) })
   7857        end
   7858 
   7859        if multigrid then
   7860          screen:expect {
   7861            grid = [[
   7862          ## grid 1
   7863            [6:-------------------]{5:│}[5:--------------------]|*2
   7864            {5:[No Name] [+]       [No Name] [+]       }|
   7865            [7:-------------------]{5:│}[2:--------------------]|*2
   7866            {5:[No Name] [+]       [No Name] [+]       }|
   7867            [3:----------------------------------------]|
   7868          ## grid 2
   7869            4                   |
   7870            {0:~                   }|
   7871          ## grid 3
   7872            :enew                                   |
   7873          ## grid 4
   7874            {1:^5                   }|
   7875            {2:~                   }|
   7876          ## grid 5
   7877            2                   |
   7878            {0:~                   }|
   7879          ## grid 6
   7880            1                  |
   7881            {0:~                  }|
   7882          ## grid 7
   7883            3                  |
   7884            {0:~                  }|
   7885        ]],
   7886            float_pos = expected_pos,
   7887          }
   7888        else
   7889          screen:expect([[
   7890            1                  {5:}2                   |
   7891            {0:~                  }{5:}{0:~                   }|
   7892            {5:[No N}{1:^5                   }{5:ame] [+]       }|
   7893            3    {2:~                   }               |
   7894            {0:~                  }{5:}{0:~                   }|
   7895            {5:[No Name] [+]       [No Name] [+]       }|
   7896            :enew                                   |
   7897          ]])
   7898        end
   7899 
   7900        local movements = {
   7901          w = { 2, 3, 4, 5, 1 },
   7902          W = { 5, 1, 2, 3, 4 },
   7903          h = { 1, 1, 3, 3, 3 },
   7904          j = { 3, 3, 3, 4, 4 },
   7905          k = { 1, 2, 1, 1, 1 },
   7906          l = { 2, 2, 4, 4, 4 },
   7907          t = { 1, 1, 1, 1, 1 },
   7908          b = { 4, 4, 4, 4, 4 },
   7909        }
   7910 
   7911        for k, v in pairs(movements) do
   7912          for i = 1, 5 do
   7913            feed(i .. '<c-w>w')
   7914            feed('<c-w>' .. k)
   7915            local nr = fn.winnr()
   7916            eq(v[i], nr, 'when using <c-w>' .. k .. ' from window ' .. i)
   7917          end
   7918        end
   7919 
   7920        for i = 1, 5 do
   7921          feed(i .. '<c-w>w')
   7922          for j = 1, 5 do
   7923            if j ~= i then
   7924              feed(j .. '<c-w>w')
   7925              feed('<c-w>p')
   7926              local nr = fn.winnr()
   7927              eq(i, nr, 'when using <c-w>p to window ' .. i .. ' from window ' .. j)
   7928            end
   7929          end
   7930        end
   7931      end)
   7932 
   7933      it(':tabnew and :tabnext', function()
   7934        feed(':tabnew<cr>')
   7935        if multigrid then
   7936          -- grid is not freed, but float is marked as closed (should it rather be "invisible"?)
   7937          screen:expect {
   7938            grid = [[
   7939          ## grid 1
   7940            {9: }{10:2}{9:+ [No Name] }{3: [No Name] }{5:              }{9:X}|
   7941            [5:----------------------------------------]|*5
   7942            [3:----------------------------------------]|
   7943          ## grid 2 (hidden)
   7944            x                                       |
   7945            {0:~                                       }|*5
   7946          ## grid 3
   7947            :tabnew                                 |
   7948          ## grid 4 (hidden)
   7949            {1:y                   }|
   7950            {2:~                   }|
   7951          ## grid 5
   7952            ^                                        |
   7953            {0:~                                       }|*4
   7954          ]],
   7955          }
   7956        else
   7957          screen:expect([[
   7958            {9: }{10:2}{9:+ [No Name] }{3: [No Name] }{5:              }{9:X}|
   7959            ^                                        |
   7960            {0:~                                       }|*4
   7961            :tabnew                                 |
   7962          ]])
   7963        end
   7964 
   7965        feed(':tabnext<cr>')
   7966        if multigrid then
   7967          screen:expect {
   7968            grid = [[
   7969          ## grid 1
   7970            {3: }{11:2}{3:+ [No Name] }{9: [No Name] }{5:              }{9:X}|
   7971            [2:----------------------------------------]|*5
   7972            [3:----------------------------------------]|
   7973          ## grid 2
   7974            ^x                                       |
   7975            {0:~                                       }|*4
   7976          ## grid 3
   7977            :tabnext                                |
   7978          ## grid 4
   7979            {1:y                   }|
   7980            {2:~                   }|
   7981          ## grid 5 (hidden)
   7982                                                    |
   7983            {0:~                                       }|*4
   7984        ]],
   7985            float_pos = expected_pos,
   7986          }
   7987        else
   7988          screen:expect([[
   7989            {3: }{11:2}{3:+ [No Name] }{9: [No Name] }{5:              }{9:X}|
   7990            ^x                                       |
   7991            {0:~    }{1:y                   }{0:               }|
   7992            {0:~    }{2:~                   }{0:               }|
   7993            {0:~                                       }|*2
   7994            :tabnext                                |
   7995          ]])
   7996        end
   7997 
   7998        feed(':tabnext<cr>')
   7999        if multigrid then
   8000          screen:expect {
   8001            grid = [[
   8002          ## grid 1
   8003            {9: }{10:2}{9:+ [No Name] }{3: [No Name] }{5:              }{9:X}|
   8004            [5:----------------------------------------]|*5
   8005            [3:----------------------------------------]|
   8006          ## grid 2 (hidden)
   8007            x                                       |
   8008            {0:~                                       }|*4
   8009          ## grid 3
   8010            :tabnext                                |
   8011          ## grid 4 (hidden)
   8012            {1:y                   }|
   8013            {2:~                   }|
   8014          ## grid 5
   8015            ^                                        |
   8016            {0:~                                       }|*4
   8017        ]],
   8018          }
   8019        else
   8020          screen:expect([[
   8021            {9: }{10:2}{9:+ [No Name] }{3: [No Name] }{5:              }{9:X}|
   8022            ^                                        |
   8023            {0:~                                       }|*4
   8024            :tabnext                                |
   8025          ]])
   8026        end
   8027      end)
   8028 
   8029      it(':tabnew and :tabnext (external)', function()
   8030        if multigrid then
   8031          -- also test external window wider than main screen
   8032          api.nvim_win_set_config(win, { external = true, width = 65, height = 4 })
   8033          expected_pos = { [4] = { external = true } }
   8034          feed(':tabnew<cr>')
   8035          screen:expect {
   8036            grid = [[
   8037          ## grid 1
   8038            {9: + [No Name] }{3: }{11:2}{3:+ [No Name] }{5:            }{9:X}|
   8039            [5:----------------------------------------]|*5
   8040            [3:----------------------------------------]|
   8041          ## grid 2 (hidden)
   8042            x                                       |
   8043            {0:~                                       }|*5
   8044          ## grid 3
   8045            :tabnew                                 |
   8046          ## grid 4
   8047            y                                                                |
   8048            {0:~                                                                }|*3
   8049          ## grid 5
   8050            ^                                        |
   8051            {0:~                                       }|*4
   8052        ]],
   8053            float_pos = expected_pos,
   8054          }
   8055        else
   8056          eq("UI doesn't support external windows", pcall_err(api.nvim_win_set_config, 0, { external = true, width = 65, height = 4 }))
   8057        end
   8058 
   8059        feed(':tabnext<cr>')
   8060        if multigrid then
   8061          screen:expect {
   8062            grid = [[
   8063          ## grid 1
   8064            {3: }{11:2}{3:+ [No Name] }{9: [No Name] }{5:              }{9:X}|
   8065            [2:----------------------------------------]|*5
   8066            [3:----------------------------------------]|
   8067          ## grid 2
   8068            ^x                                       |
   8069            {0:~                                       }|*4
   8070          ## grid 3
   8071            :tabnext                                |
   8072          ## grid 4
   8073            y                                                                |
   8074            {0:~                                                                }|*3
   8075          ## grid 5 (hidden)
   8076                                                    |
   8077            {0:~                                       }|*4
   8078        ]],
   8079            float_pos = expected_pos,
   8080          }
   8081        end
   8082 
   8083        feed(':tabnext<cr>')
   8084        if multigrid then
   8085          screen:expect {
   8086            grid = [[
   8087          ## grid 1
   8088            {9: + [No Name] }{3: }{11:2}{3:+ [No Name] }{5:            }{9:X}|
   8089            [5:----------------------------------------]|*5
   8090            [3:----------------------------------------]|
   8091          ## grid 2 (hidden)
   8092            x                                       |
   8093            {0:~                                       }|*4
   8094          ## grid 3
   8095            :tabnext                                |
   8096          ## grid 4
   8097            y                                                                |
   8098            {0:~                                                                }|*3
   8099          ## grid 5
   8100            ^                                        |
   8101            {0:~                                       }|*4
   8102        ]],
   8103            float_pos = expected_pos,
   8104          }
   8105        end
   8106      end)
   8107    end)
   8108 
   8109    it('left drag changes visual selection in float window', function()
   8110      local buf = api.nvim_create_buf(false, false)
   8111      api.nvim_buf_set_lines(buf, 0, -1, true, { 'foo', 'bar', 'baz' })
   8112      api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 3, row = 2, col = 5 })
   8113      if multigrid then
   8114        screen:expect {
   8115          grid = [[
   8116        ## grid 1
   8117          [2:----------------------------------------]|*6
   8118          [3:----------------------------------------]|
   8119        ## grid 2
   8120          ^                                        |
   8121          {0:~                                       }|*5
   8122        ## grid 3
   8123                                                  |
   8124        ## grid 4
   8125          {1:foo                 }|
   8126          {1:bar                 }|
   8127          {1:baz                 }|
   8128        ]],
   8129          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   8130          win_viewport = {
   8131            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   8132            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
   8133          },
   8134        }
   8135 
   8136        if send_mouse_grid then
   8137          api.nvim_input_mouse('left', 'press', '', 4, 0, 0)
   8138        else
   8139          api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
   8140        end
   8141        screen:expect {
   8142          grid = [[
   8143        ## grid 1
   8144          [2:----------------------------------------]|*6
   8145          [3:----------------------------------------]|
   8146        ## grid 2
   8147                                                  |
   8148          {0:~                                       }|*5
   8149        ## grid 3
   8150                                                  |
   8151        ## grid 4
   8152          {1:^foo                 }|
   8153          {1:bar                 }|
   8154          {1:baz                 }|
   8155        ]],
   8156          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   8157          win_viewport = {
   8158            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   8159            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
   8160          },
   8161        }
   8162 
   8163        if send_mouse_grid then
   8164          api.nvim_input_mouse('left', 'drag', '', 4, 1, 2)
   8165        else
   8166          api.nvim_input_mouse('left', 'drag', '', 0, 3, 7)
   8167        end
   8168        screen:expect {
   8169          grid = [[
   8170        ## grid 1
   8171          [2:----------------------------------------]|*6
   8172          [3:----------------------------------------]|
   8173        ## grid 2
   8174                                                  |
   8175          {0:~                                       }|*5
   8176        ## grid 3
   8177          {3:-- VISUAL --}                            |
   8178        ## grid 4
   8179          {27:foo}{1:                 }|
   8180          {27:ba}{1:^r                 }|
   8181          {1:baz                 }|
   8182        ]],
   8183          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   8184          win_viewport = {
   8185            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   8186            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 3, sum_scroll_delta = 0 },
   8187          },
   8188        }
   8189      else
   8190        screen:expect {
   8191          grid = [[
   8192          ^                                        |
   8193          {0:~                                       }|
   8194          {0:~    }{1:foo                 }{0:               }|
   8195          {0:~    }{1:bar                 }{0:               }|
   8196          {0:~    }{1:baz                 }{0:               }|
   8197          {0:~                                       }|
   8198                                                  |
   8199        ]],
   8200        }
   8201 
   8202        api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
   8203        screen:expect {
   8204          grid = [[
   8205                                                  |
   8206          {0:~                                       }|
   8207          {0:~    }{1:^foo                 }{0:               }|
   8208          {0:~    }{1:bar                 }{0:               }|
   8209          {0:~    }{1:baz                 }{0:               }|
   8210          {0:~                                       }|
   8211                                                  |
   8212        ]],
   8213        }
   8214 
   8215        api.nvim_input_mouse('left', 'drag', '', 0, 3, 7)
   8216        screen:expect {
   8217          grid = [[
   8218                                                  |
   8219          {0:~                                       }|
   8220          {0:~    }{27:foo}{1:                 }{0:               }|
   8221          {0:~    }{27:ba}{1:^r                 }{0:               }|
   8222          {0:~    }{1:baz                 }{0:               }|
   8223          {0:~                                       }|
   8224          {3:-- VISUAL --}                            |
   8225        ]],
   8226        }
   8227      end
   8228    end)
   8229 
   8230    it('left drag changes visual selection in float window with border', function()
   8231      local buf = api.nvim_create_buf(false, false)
   8232      api.nvim_buf_set_lines(buf, 0, -1, true, { 'foo', 'bar', 'baz' })
   8233      api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 3, row = 0, col = 5, border = 'single' })
   8234      if multigrid then
   8235        screen:expect {
   8236          grid = [[
   8237        ## grid 1
   8238          [2:----------------------------------------]|*6
   8239          [3:----------------------------------------]|
   8240        ## grid 2
   8241          ^                                        |
   8242          {0:~                                       }|*5
   8243        ## grid 3
   8244                                                  |
   8245        ## grid 4
   8246          {5:┌────────────────────┐}|
   8247          {5:│}{1:foo                 }{5:│}|
   8248          {5:│}{1:bar                 }{5:│}|
   8249          {5:│}{1:baz                 }{5:│}|
   8250          {5:└────────────────────┘}|
   8251        ]],
   8252          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
   8253          win_viewport = {
   8254            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   8255            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
   8256          },
   8257        }
   8258 
   8259        if send_mouse_grid then
   8260          api.nvim_input_mouse('left', 'press', '', 4, 1, 1)
   8261        else
   8262          api.nvim_input_mouse('left', 'press', '', 0, 1, 6)
   8263        end
   8264        screen:expect {
   8265          grid = [[
   8266        ## grid 1
   8267          [2:----------------------------------------]|*6
   8268          [3:----------------------------------------]|
   8269        ## grid 2
   8270                                                  |
   8271          {0:~                                       }|*5
   8272        ## grid 3
   8273                                                  |
   8274        ## grid 4
   8275          {5:┌────────────────────┐}|
   8276          {5:│}{1:^foo                 }{5:│}|
   8277          {5:│}{1:bar                 }{5:│}|
   8278          {5:│}{1:baz                 }{5:│}|
   8279          {5:└────────────────────┘}|
   8280        ]],
   8281          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
   8282          win_viewport = {
   8283            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   8284            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
   8285          },
   8286        }
   8287 
   8288        if send_mouse_grid then
   8289          api.nvim_input_mouse('left', 'drag', '', 4, 2, 3)
   8290        else
   8291          api.nvim_input_mouse('left', 'drag', '', 0, 2, 8)
   8292        end
   8293        screen:expect {
   8294          grid = [[
   8295        ## grid 1
   8296          [2:----------------------------------------]|*6
   8297          [3:----------------------------------------]|
   8298        ## grid 2
   8299                                                  |
   8300          {0:~                                       }|*5
   8301        ## grid 3
   8302          {3:-- VISUAL --}                            |
   8303        ## grid 4
   8304          {5:┌────────────────────┐}|
   8305          {5:│}{27:foo}{1:                 }{5:│}|
   8306          {5:│}{27:ba}{1:^r                 }{5:│}|
   8307          {5:│}{1:baz                 }{5:│}|
   8308          {5:└────────────────────┘}|
   8309        ]],
   8310          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
   8311          win_viewport = {
   8312            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   8313            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 3, sum_scroll_delta = 0 },
   8314          },
   8315        }
   8316      else
   8317        screen:expect {
   8318          grid = [[
   8319          ^     {5:┌────────────────────┐}             |
   8320          {0:~    }{5:│}{1:foo                 }{5:│}{0:             }|
   8321          {0:~    }{5:│}{1:bar                 }{5:│}{0:             }|
   8322          {0:~    }{5:│}{1:baz                 }{5:│}{0:             }|
   8323          {0:~    }{5:└────────────────────┘}{0:             }|
   8324          {0:~                                       }|
   8325                                                  |
   8326        ]],
   8327        }
   8328 
   8329        api.nvim_input_mouse('left', 'press', '', 0, 1, 6)
   8330        screen:expect {
   8331          grid = [[
   8332               {5:┌────────────────────┐}             |
   8333          {0:~    }{5:│}{1:^foo                 }{5:│}{0:             }|
   8334          {0:~    }{5:│}{1:bar                 }{5:│}{0:             }|
   8335          {0:~    }{5:│}{1:baz                 }{5:│}{0:             }|
   8336          {0:~    }{5:└────────────────────┘}{0:             }|
   8337          {0:~                                       }|
   8338                                                  |
   8339        ]],
   8340        }
   8341 
   8342        api.nvim_input_mouse('left', 'drag', '', 0, 2, 8)
   8343        screen:expect {
   8344          grid = [[
   8345               {5:┌────────────────────┐}             |
   8346          {0:~    }{5:│}{27:foo}{1:                 }{5:│}{0:             }|
   8347          {0:~    }{5:│}{27:ba}{1:^r                 }{5:│}{0:             }|
   8348          {0:~    }{5:│}{1:baz                 }{5:│}{0:             }|
   8349          {0:~    }{5:└────────────────────┘}{0:             }|
   8350          {0:~                                       }|
   8351          {3:-- VISUAL --}                            |
   8352        ]],
   8353        }
   8354      end
   8355    end)
   8356 
   8357    it('left drag changes visual selection in float window with winbar', function()
   8358      local buf = api.nvim_create_buf(false, false)
   8359      api.nvim_buf_set_lines(buf, 0, -1, true, { 'foo', 'bar', 'baz' })
   8360      local float_win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 4, row = 1, col = 5 })
   8361      api.nvim_set_option_value('winbar', 'floaty bar', { win = float_win })
   8362      if multigrid then
   8363        screen:expect {
   8364          grid = [[
   8365        ## grid 1
   8366          [2:----------------------------------------]|*6
   8367          [3:----------------------------------------]|
   8368        ## grid 2
   8369          ^                                        |
   8370          {0:~                                       }|*5
   8371        ## grid 3
   8372                                                  |
   8373        ## grid 4
   8374          {3:floaty bar          }|
   8375          {1:foo                 }|
   8376          {1:bar                 }|
   8377          {1:baz                 }|
   8378        ]],
   8379          float_pos = { [4] = { 1001, 'NW', 1, 1, 5, true, 50, 1, 1, 5 } },
   8380          win_viewport = {
   8381            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   8382            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
   8383          },
   8384        }
   8385 
   8386        if send_mouse_grid then
   8387          api.nvim_input_mouse('left', 'press', '', 4, 1, 0)
   8388        else
   8389          api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
   8390        end
   8391        screen:expect {
   8392          grid = [[
   8393        ## grid 1
   8394          [2:----------------------------------------]|*6
   8395          [3:----------------------------------------]|
   8396        ## grid 2
   8397                                                  |
   8398          {0:~                                       }|*5
   8399        ## grid 3
   8400                                                  |
   8401        ## grid 4
   8402          {3:floaty bar          }|
   8403          {1:^foo                 }|
   8404          {1:bar                 }|
   8405          {1:baz                 }|
   8406        ]],
   8407          float_pos = { [4] = { 1001, 'NW', 1, 1, 5, true, 50, 1, 1, 5 } },
   8408          win_viewport = {
   8409            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   8410            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
   8411          },
   8412        }
   8413 
   8414        if send_mouse_grid then
   8415          api.nvim_input_mouse('left', 'drag', '', 4, 2, 2)
   8416        else
   8417          api.nvim_input_mouse('left', 'drag', '', 0, 3, 7)
   8418        end
   8419        screen:expect {
   8420          grid = [[
   8421        ## grid 1
   8422          [2:----------------------------------------]|*6
   8423          [3:----------------------------------------]|
   8424        ## grid 2
   8425                                                  |
   8426          {0:~                                       }|*5
   8427        ## grid 3
   8428          {3:-- VISUAL --}                            |
   8429        ## grid 4
   8430          {3:floaty bar          }|
   8431          {27:foo}{1:                 }|
   8432          {27:ba}{1:^r                 }|
   8433          {1:baz                 }|
   8434        ]],
   8435          float_pos = { [4] = { 1001, 'NW', 1, 1, 5, true, 50, 1, 1, 5 } },
   8436          win_viewport = {
   8437            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   8438            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 3, sum_scroll_delta = 0 },
   8439          },
   8440        }
   8441      else
   8442        screen:expect {
   8443          grid = [[
   8444          ^                                        |
   8445          {0:~    }{3:floaty bar          }{0:               }|
   8446          {0:~    }{1:foo                 }{0:               }|
   8447          {0:~    }{1:bar                 }{0:               }|
   8448          {0:~    }{1:baz                 }{0:               }|
   8449          {0:~                                       }|
   8450                                                  |
   8451        ]],
   8452        }
   8453 
   8454        api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
   8455        screen:expect {
   8456          grid = [[
   8457                                                  |
   8458          {0:~    }{3:floaty bar          }{0:               }|
   8459          {0:~    }{1:^foo                 }{0:               }|
   8460          {0:~    }{1:bar                 }{0:               }|
   8461          {0:~    }{1:baz                 }{0:               }|
   8462          {0:~                                       }|
   8463                                                  |
   8464        ]],
   8465        }
   8466 
   8467        api.nvim_input_mouse('left', 'drag', '', 0, 3, 7)
   8468        screen:expect {
   8469          grid = [[
   8470                                                  |
   8471          {0:~    }{3:floaty bar          }{0:               }|
   8472          {0:~    }{27:foo}{1:                 }{0:               }|
   8473          {0:~    }{27:ba}{1:^r                 }{0:               }|
   8474          {0:~    }{1:baz                 }{0:               }|
   8475          {0:~                                       }|
   8476          {3:-- VISUAL --}                            |
   8477        ]],
   8478        }
   8479      end
   8480    end)
   8481 
   8482    it('left drag changes visual selection if float window is turned into a split', function()
   8483      local buf = api.nvim_create_buf(false, false)
   8484      api.nvim_buf_set_lines(buf, 0, -1, true, { 'foo', 'bar', 'baz' })
   8485      api.nvim_open_win(buf, true, { relative = 'editor', width = 20, height = 3, row = 2, col = 5 })
   8486      command('wincmd L')
   8487      if multigrid then
   8488        screen:expect([[
   8489        ## grid 1
   8490          [2:-------------------]{5:│}[4:--------------------]|*5
   8491          {5:[No Name]           }{4:[No Name] [+]       }|
   8492          [3:----------------------------------------]|
   8493        ## grid 2
   8494                             |
   8495          {0:~                  }|*4
   8496        ## grid 3
   8497                                                  |
   8498        ## grid 4
   8499          ^foo                 |
   8500          bar                 |
   8501          baz                 |
   8502          {0:~                   }|*2
   8503        ]])
   8504 
   8505        if send_mouse_grid then
   8506          api.nvim_input_mouse('left', 'press', '', 4, 2, 2)
   8507        else
   8508          api.nvim_input_mouse('left', 'press', '', 0, 2, 22)
   8509        end
   8510        screen:expect([[
   8511        ## grid 1
   8512          [2:-------------------]{5:│}[4:--------------------]|*5
   8513          {5:[No Name]           }{4:[No Name] [+]       }|
   8514          [3:----------------------------------------]|
   8515        ## grid 2
   8516                             |
   8517          {0:~                  }|*4
   8518        ## grid 3
   8519                                                  |
   8520        ## grid 4
   8521          foo                 |
   8522          bar                 |
   8523          ba^z                 |
   8524          {0:~                   }|*2
   8525        ]])
   8526 
   8527        if send_mouse_grid then
   8528          api.nvim_input_mouse('left', 'drag', '', 4, 1, 1)
   8529        else
   8530          api.nvim_input_mouse('left', 'drag', '', 0, 1, 21)
   8531        end
   8532        screen:expect([[
   8533        ## grid 1
   8534          [2:-------------------]{5:│}[4:--------------------]|*5
   8535          {5:[No Name]           }{4:[No Name] [+]       }|
   8536          [3:----------------------------------------]|
   8537        ## grid 2
   8538                             |
   8539          {0:~                  }|*4
   8540        ## grid 3
   8541          {3:-- VISUAL --}                            |
   8542        ## grid 4
   8543          foo                 |
   8544          b^a{27:r}                 |
   8545          {27:baz}                 |
   8546          {0:~                   }|*2
   8547        ]])
   8548      else
   8549        screen:expect([[
   8550                             {5:}^foo                 |
   8551          {0:~                  }{5:}bar                 |
   8552          {0:~                  }{5:}baz                 |
   8553          {0:~                  }{5:}{0:~                   }|*2
   8554          {5:[No Name]           }{4:[No Name] [+]       }|
   8555                                                  |
   8556        ]])
   8557 
   8558        api.nvim_input_mouse('left', 'press', '', 0, 2, 22)
   8559        screen:expect([[
   8560                             {5:}foo                 |
   8561          {0:~                  }{5:}bar                 |
   8562          {0:~                  }{5:}ba^z                 |
   8563          {0:~                  }{5:}{0:~                   }|*2
   8564          {5:[No Name]           }{4:[No Name] [+]       }|
   8565                                                  |
   8566        ]])
   8567 
   8568        api.nvim_input_mouse('left', 'drag', '', 0, 1, 21)
   8569        screen:expect([[
   8570                             {5:}foo                 |
   8571          {0:~                  }{5:}b^a{27:r}                 |
   8572          {0:~                  }{5:}{27:baz}                 |
   8573          {0:~                  }{5:}{0:~                   }|*2
   8574          {5:[No Name]           }{4:[No Name] [+]       }|
   8575          {3:-- VISUAL --}                            |
   8576        ]])
   8577      end
   8578    end)
   8579 
   8580    it('left click sets correct curswant in float window with border', function()
   8581      local buf = api.nvim_create_buf(false, false)
   8582      api.nvim_buf_set_lines(buf, 0, -1, true, { '', '', '' })
   8583      api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 3, row = 0, col = 5, border = 'single' })
   8584      if multigrid then
   8585        screen:expect {
   8586          grid = [[
   8587        ## grid 1
   8588          [2:----------------------------------------]|*6
   8589          [3:----------------------------------------]|
   8590        ## grid 2
   8591          ^                                        |
   8592          {0:~                                       }|*5
   8593        ## grid 3
   8594                                                  |
   8595        ## grid 4
   8596          {5:┌────────────────────┐}|
   8597          {5:│}{1:                    }{5:│}|*3
   8598          {5:└────────────────────┘}|
   8599        ]],
   8600          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
   8601          win_viewport = {
   8602            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   8603            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
   8604          },
   8605        }
   8606      else
   8607        screen:expect {
   8608          grid = [[
   8609          ^     {5:┌────────────────────┐}             |
   8610          {0:~    }{5:│}{1:                    }{5:│}{0:             }|*3
   8611          {0:~    }{5:└────────────────────┘}{0:             }|
   8612          {0:~                                       }|
   8613                                                  |
   8614        ]],
   8615        }
   8616      end
   8617 
   8618      if send_mouse_grid then
   8619        api.nvim_input_mouse('left', 'press', '', 4, 3, 1)
   8620      else
   8621        api.nvim_input_mouse('left', 'press', '', 0, 3, 6)
   8622      end
   8623      eq({ 0, 3, 1, 0, 1 }, fn.getcurpos())
   8624 
   8625      if send_mouse_grid then
   8626        api.nvim_input_mouse('left', 'press', '', 4, 3, 2)
   8627      else
   8628        api.nvim_input_mouse('left', 'press', '', 0, 3, 7)
   8629      end
   8630      eq({ 0, 3, 1, 0, 2 }, fn.getcurpos())
   8631 
   8632      if send_mouse_grid then
   8633        api.nvim_input_mouse('left', 'press', '', 4, 3, 10)
   8634      else
   8635        api.nvim_input_mouse('left', 'press', '', 0, 3, 15)
   8636      end
   8637      eq({ 0, 3, 1, 0, 10 }, fn.getcurpos())
   8638 
   8639      command('setlocal foldcolumn=1')
   8640      feed('zfkgg')
   8641      if multigrid then
   8642        screen:expect {
   8643          grid = [[
   8644        ## grid 1
   8645          [2:----------------------------------------]|*6
   8646          [3:----------------------------------------]|
   8647        ## grid 2
   8648                                                  |
   8649          {0:~                                       }|*5
   8650        ## grid 3
   8651                                                  |
   8652        ## grid 4
   8653          {5:┌────────────────────┐}|
   8654          {5:│}{19: }{1:^                   }{5:│}|
   8655          {5:│}{19:+}{28:+--  2 lines: ·····}{5:│}|
   8656          {5:│}{2:~                   }{5:│}|
   8657          {5:└────────────────────┘}|
   8658        ]],
   8659          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
   8660          win_viewport = {
   8661            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   8662            [4] = { win = 1001, topline = 0, botline = 4, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
   8663          },
   8664        }
   8665      else
   8666        screen:expect {
   8667          grid = [[
   8668               {5:┌────────────────────┐}             |
   8669          {0:~    }{5:│}{19: }{1:^                   }{5:│}{0:             }|
   8670          {0:~    }{5:│}{19:+}{28:+--  2 lines: ·····}{5:│}{0:             }|
   8671          {0:~    }{5:│}{2:~                   }{5:│}{0:             }|
   8672          {0:~    }{5:└────────────────────┘}{0:             }|
   8673          {0:~                                       }|
   8674                                                  |
   8675        ]],
   8676        }
   8677      end
   8678 
   8679      if send_mouse_grid then
   8680        api.nvim_input_mouse('left', 'press', '', 4, 2, 1)
   8681      else
   8682        api.nvim_input_mouse('left', 'press', '', 0, 2, 6)
   8683      end
   8684      if multigrid then
   8685        screen:expect {
   8686          grid = [[
   8687        ## grid 1
   8688          [2:----------------------------------------]|*6
   8689          [3:----------------------------------------]|
   8690        ## grid 2
   8691                                                  |
   8692          {0:~                                       }|*5
   8693        ## grid 3
   8694                                                  |
   8695        ## grid 4
   8696          {5:┌────────────────────┐}|
   8697          {5:│}{19: }{1:^                   }{5:│}|
   8698          {5:│}{19:-}{1:                   }{5:│}|
   8699          {5:│}{19:│}{1:                   }{5:│}|
   8700          {5:└────────────────────┘}|
   8701        ]],
   8702          float_pos = { [4] = { 1001, 'NW', 1, 0, 5, true, 50, 1, 0, 5 } },
   8703          win_viewport = {
   8704            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   8705            [4] = { win = 1001, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3, sum_scroll_delta = 0 },
   8706          },
   8707        }
   8708      else
   8709        screen:expect {
   8710          grid = [[
   8711               {5:┌────────────────────┐}             |
   8712          {0:~    }{5:│}{19: }{1:^                   }{5:│}{0:             }|
   8713          {0:~    }{5:│}{19:-}{1:                   }{5:│}{0:             }|
   8714          {0:~    }{5:│}{19:│}{1:                   }{5:│}{0:             }|
   8715          {0:~    }{5:└────────────────────┘}{0:             }|
   8716          {0:~                                       }|
   8717                                                  |
   8718        ]],
   8719        }
   8720      end
   8721 
   8722      if send_mouse_grid then
   8723        api.nvim_input_mouse('left', 'press', '', 4, 2, 2)
   8724      else
   8725        api.nvim_input_mouse('left', 'press', '', 0, 2, 7)
   8726      end
   8727      eq({ 0, 2, 1, 0, 1 }, fn.getcurpos())
   8728 
   8729      if send_mouse_grid then
   8730        api.nvim_input_mouse('left', 'press', '', 4, 2, 3)
   8731      else
   8732        api.nvim_input_mouse('left', 'press', '', 0, 2, 8)
   8733      end
   8734      eq({ 0, 2, 1, 0, 2 }, fn.getcurpos())
   8735 
   8736      if send_mouse_grid then
   8737        api.nvim_input_mouse('left', 'press', '', 4, 2, 11)
   8738      else
   8739        api.nvim_input_mouse('left', 'press', '', 0, 2, 16)
   8740      end
   8741      eq({ 0, 2, 1, 0, 10 }, fn.getcurpos())
   8742    end)
   8743 
   8744    it("'winblend' option", function()
   8745      screen:try_resize(50, 9)
   8746      screen:set_default_attr_ids({
   8747        [1] = { background = Screen.colors.LightMagenta },
   8748        [2] = { foreground = Screen.colors.Grey0, background = tonumber('0xffcfff') },
   8749        [3] = { foreground = tonumber('0xb282b2'), background = tonumber('0xffcfff') },
   8750        [4] = { foreground = Screen.colors.Red, background = Screen.colors.LightMagenta },
   8751        [5] = { foreground = tonumber('0x990000'), background = tonumber('0xfff1ff') },
   8752        [6] = { foreground = tonumber('0x332533'), background = tonumber('0xfff1ff') },
   8753        [7] = { background = tonumber('0xffcfff'), bold = true, foreground = tonumber('0x0000d8') },
   8754        [8] = { background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1 },
   8755        [9] = { background = Screen.colors.LightMagenta, blend = 30 },
   8756        [10] = { foreground = Screen.colors.Red, background = Screen.colors.LightMagenta, blend = 0 },
   8757        [11] = { foreground = Screen.colors.Red, background = Screen.colors.LightMagenta, blend = 80 },
   8758        [12] = { background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1, blend = 30 },
   8759        [13] = { foreground = Screen.colors.Black, background = Screen.colors.LightGray, blend = 30 },
   8760        [14] = { foreground = Screen.colors.Black, background = Screen.colors.Grey88 },
   8761        [15] = { foreground = tonumber('0x939393'), background = Screen.colors.Grey88 },
   8762        [16] = { background = Screen.colors.Grey90 },
   8763        [17] = { blend = 100 },
   8764        [18] = { background = Screen.colors.LightMagenta, blend = 100 },
   8765        [19] = { background = Screen.colors.LightMagenta, bold = true, blend = 100, foreground = Screen.colors.Blue1 },
   8766        [20] = { background = Screen.colors.White, foreground = Screen.colors.Gray0 },
   8767        [21] = { background = Screen.colors.White, bold = true, foreground = tonumber('0x00007f') },
   8768        [22] = { background = Screen.colors.Gray90, foreground = Screen.colors.Gray0 },
   8769        [23] = { blend = 100, bold = true, foreground = Screen.colors.Magenta },
   8770        [24] = { foreground = tonumber('0x7f007f'), bold = true, background = Screen.colors.White },
   8771        [25] = { foreground = tonumber('0x7f007f'), bold = true, background = Screen.colors.Grey90 },
   8772        [26] = { foreground = Screen.colors.Black },
   8773        [27] = { bold = true, foreground = tonumber('0x7f007f') },
   8774        [28] = { foreground = tonumber('0x990000') },
   8775        [29] = { foreground = Screen.colors.Gray20 },
   8776        [30] = { bold = true, foreground = tonumber('0x00007f') },
   8777        [31] = { foreground = Screen.colors.Red, blend = 80 },
   8778        [32] = { foreground = Screen.colors.Blue1, blend = 100, bold = true },
   8779        [33] = { foreground = Screen.colors.Gray0, underline = true },
   8780        [34] = { underline = true },
   8781      })
   8782      insert([[
   8783        Lorem ipsum dolor sit amet, consectetur
   8784        adipisicing elit, sed do eiusmod tempor
   8785        incididunt ut labore et dolore magna aliqua.
   8786        Ut enim ad minim veniam, quis nostrud
   8787        exercitation ullamco laboris nisi ut aliquip ex
   8788        ea commodo consequat. Duis aute irure dolor in
   8789        reprehenderit in voluptate velit esse cillum
   8790        dolore eu fugiat nulla pariatur. Excepteur sint
   8791        occaecat cupidatat non proident, sunt in culpa
   8792        qui officia deserunt mollit anim id est
   8793        laborum.]])
   8794      local curbufnr = api.nvim_get_current_buf()
   8795      local buf = api.nvim_create_buf(false, false)
   8796      local test_data = { 'test', '', 'popup    text' }
   8797      api.nvim_buf_set_lines(buf, 0, -1, true, test_data)
   8798      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 15, height = 3, row = 2, col = 5 })
   8799      if multigrid then
   8800        screen:expect {
   8801          grid = [[
   8802        ## grid 1
   8803          [2:--------------------------------------------------]|*8
   8804          [3:--------------------------------------------------]|
   8805        ## grid 2
   8806          Ut enim ad minim veniam, quis nostrud             |
   8807          exercitation ullamco laboris nisi ut aliquip ex   |
   8808          ea commodo consequat. Duis aute irure dolor in    |
   8809          reprehenderit in voluptate velit esse cillum      |
   8810          dolore eu fugiat nulla pariatur. Excepteur sint   |
   8811          occaecat cupidatat non proident, sunt in culpa    |
   8812          qui officia deserunt mollit anim id est           |
   8813          laborum^.                                          |
   8814        ## grid 3
   8815                                                            |
   8816        ## grid 4
   8817          {1:test           }|
   8818          {1:               }|
   8819          {1:popup    text  }|
   8820        ]],
   8821          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   8822        }
   8823      else
   8824        screen:expect([[
   8825          Ut enim ad minim veniam, quis nostrud             |
   8826          exercitation ullamco laboris nisi ut aliquip ex   |
   8827          ea co{1:test           }. Duis aute irure dolor in    |
   8828          repre{1:               }uptate velit esse cillum      |
   8829          dolor{1:popup    text  }la pariatur. Excepteur sint   |
   8830          occaecat cupidatat non proident, sunt in culpa    |
   8831          qui officia deserunt mollit anim id est           |
   8832          laborum^.                                          |
   8833                                                            |
   8834        ]])
   8835      end
   8836 
   8837      api.nvim_set_option_value('winblend', 30, { win = win })
   8838      if multigrid then
   8839        screen:expect {
   8840          grid = [[
   8841        ## grid 1
   8842          [2:--------------------------------------------------]|*8
   8843          [3:--------------------------------------------------]|
   8844        ## grid 2
   8845          Ut enim ad minim veniam, quis nostrud             |
   8846          exercitation ullamco laboris nisi ut aliquip ex   |
   8847          ea commodo consequat. Duis aute irure dolor in    |
   8848          reprehenderit in voluptate velit esse cillum      |
   8849          dolore eu fugiat nulla pariatur. Excepteur sint   |
   8850          occaecat cupidatat non proident, sunt in culpa    |
   8851          qui officia deserunt mollit anim id est           |
   8852          laborum^.                                          |
   8853        ## grid 3
   8854                                                            |
   8855        ## grid 4
   8856          {9:test           }|
   8857          {9:               }|
   8858          {9:popup    text  }|
   8859        ]],
   8860          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   8861          unchanged = true,
   8862        }
   8863      else
   8864        screen:expect([[
   8865          Ut enim ad minim veniam, quis nostrud             |
   8866          exercitation ullamco laboris nisi ut aliquip ex   |
   8867          ea co{2:test}{3:o consequat}. Duis aute irure dolor in    |
   8868          repre{3:henderit in vol}uptate velit esse cillum      |
   8869          dolor{2:popup}{3:fugi}{2:text}{3:ul}la pariatur. Excepteur sint   |
   8870          occaecat cupidatat non proident, sunt in culpa    |
   8871          qui officia deserunt mollit anim id est           |
   8872          laborum^.                                          |
   8873                                                            |
   8874        ]])
   8875      end
   8876 
   8877      -- Treat for \u2800 (braille blank) as whitespace.
   8878      local braille_blank = '\226\160\128'
   8879      api.nvim_buf_set_lines(buf, 0, -1, true, { 'test' .. braille_blank, '', 'popup' .. braille_blank .. '   text' })
   8880      if multigrid then
   8881        screen:expect {
   8882          grid = [[
   8883        ## grid 1
   8884          [2:--------------------------------------------------]|*8
   8885          [3:--------------------------------------------------]|
   8886        ## grid 2
   8887          Ut enim ad minim veniam, quis nostrud             |
   8888          exercitation ullamco laboris nisi ut aliquip ex   |
   8889          ea commodo consequat. Duis aute irure dolor in    |
   8890          reprehenderit in voluptate velit esse cillum      |
   8891          dolore eu fugiat nulla pariatur. Excepteur sint   |
   8892          occaecat cupidatat non proident, sunt in culpa    |
   8893          qui officia deserunt mollit anim id est           |
   8894          laborum^.                                          |
   8895        ## grid 3
   8896                                                            |
   8897        ## grid 4
   8898          {9:test]] .. braille_blank .. [[          }|
   8899          {9:               }|
   8900          {9:popup]] .. braille_blank .. [[   text  }|
   8901        ]],
   8902          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   8903          unchanged = true,
   8904        }
   8905      else
   8906        screen:expect([[
   8907          Ut enim ad minim veniam, quis nostrud             |
   8908          exercitation ullamco laboris nisi ut aliquip ex   |
   8909          ea co{2:test}{3:o consequat}. Duis aute irure dolor in    |
   8910          repre{3:henderit in vol}uptate velit esse cillum      |
   8911          dolor{2:popup}{3:fugi}{2:text}{3:ul}la pariatur. Excepteur sint   |
   8912          occaecat cupidatat non proident, sunt in culpa    |
   8913          qui officia deserunt mollit anim id est           |
   8914          laborum^.                                          |
   8915                                                            |
   8916        ]])
   8917      end
   8918      api.nvim_buf_set_lines(buf, 0, -1, true, test_data)
   8919 
   8920      -- Check that 'winblend' works with NormalNC highlight
   8921      api.nvim_set_option_value('winhighlight', 'NormalNC:Visual', { win = win })
   8922      if multigrid then
   8923        screen:expect {
   8924          grid = [[
   8925        ## grid 1
   8926          [2:--------------------------------------------------]|*8
   8927          [3:--------------------------------------------------]|
   8928        ## grid 2
   8929          Ut enim ad minim veniam, quis nostrud             |
   8930          exercitation ullamco laboris nisi ut aliquip ex   |
   8931          ea commodo consequat. Duis aute irure dolor in    |
   8932          reprehenderit in voluptate velit esse cillum      |
   8933          dolore eu fugiat nulla pariatur. Excepteur sint   |
   8934          occaecat cupidatat non proident, sunt in culpa    |
   8935          qui officia deserunt mollit anim id est           |
   8936          laborum^.                                          |
   8937        ## grid 3
   8938                                                            |
   8939        ## grid 4
   8940          {13:test           }|
   8941          {13:               }|
   8942          {13:popup    text  }|
   8943        ]],
   8944          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   8945        }
   8946      else
   8947        screen:expect([[
   8948          Ut enim ad minim veniam, quis nostrud             |
   8949          exercitation ullamco laboris nisi ut aliquip ex   |
   8950          ea co{14:test}{15:o consequat}. Duis aute irure dolor in    |
   8951          repre{15:henderit in vol}uptate velit esse cillum      |
   8952          dolor{14:popup}{15:fugi}{14:text}{15:ul}la pariatur. Excepteur sint   |
   8953          occaecat cupidatat non proident, sunt in culpa    |
   8954          qui officia deserunt mollit anim id est           |
   8955          laborum^.                                          |
   8956                                                            |
   8957        ]])
   8958      end
   8959 
   8960      -- Also test with global NormalNC highlight
   8961      exec_lua(
   8962        [[
   8963        vim.api.nvim_set_option_value('winhighlight', '', {win = ...})
   8964        vim.api.nvim_set_hl(0, 'NormalNC', {link = 'Visual'})
   8965      ]],
   8966        win
   8967      )
   8968      screen:expect_unchanged()
   8969      command('hi clear NormalNC')
   8970 
   8971      command('hi SpecialRegion guifg=Red blend=0')
   8972      api.nvim_buf_add_highlight(buf, -1, 'SpecialRegion', 2, 0, -1)
   8973      if multigrid then
   8974        screen:expect {
   8975          grid = [[
   8976        ## grid 1
   8977          [2:--------------------------------------------------]|*8
   8978          [3:--------------------------------------------------]|
   8979        ## grid 2
   8980          Ut enim ad minim veniam, quis nostrud             |
   8981          exercitation ullamco laboris nisi ut aliquip ex   |
   8982          ea commodo consequat. Duis aute irure dolor in    |
   8983          reprehenderit in voluptate velit esse cillum      |
   8984          dolore eu fugiat nulla pariatur. Excepteur sint   |
   8985          occaecat cupidatat non proident, sunt in culpa    |
   8986          qui officia deserunt mollit anim id est           |
   8987          laborum^.                                          |
   8988        ## grid 3
   8989                                                            |
   8990        ## grid 4
   8991          {9:test           }|
   8992          {9:               }|
   8993          {10:popup    text}{9:  }|
   8994        ]],
   8995          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   8996        }
   8997      else
   8998        screen:expect([[
   8999          Ut enim ad minim veniam, quis nostrud             |
   9000          exercitation ullamco laboris nisi ut aliquip ex   |
   9001          ea co{2:test}{3:o consequat}. Duis aute irure dolor in    |
   9002          repre{3:henderit in vol}uptate velit esse cillum      |
   9003          dolor{10:popup    text}{3:ul}la pariatur. Excepteur sint   |
   9004          occaecat cupidatat non proident, sunt in culpa    |
   9005          qui officia deserunt mollit anim id est           |
   9006          laborum^.                                          |
   9007                                                            |
   9008        ]])
   9009      end
   9010 
   9011      command('hi SpecialRegion guifg=Red blend=80')
   9012      if multigrid then
   9013        screen:expect {
   9014          grid = [[
   9015        ## grid 1
   9016          [2:--------------------------------------------------]|*8
   9017          [3:--------------------------------------------------]|
   9018        ## grid 2
   9019          Ut enim ad minim veniam, quis nostrud             |
   9020          exercitation ullamco laboris nisi ut aliquip ex   |
   9021          ea commodo consequat. Duis aute irure dolor in    |
   9022          reprehenderit in voluptate velit esse cillum      |
   9023          dolore eu fugiat nulla pariatur. Excepteur sint   |
   9024          occaecat cupidatat non proident, sunt in culpa    |
   9025          qui officia deserunt mollit anim id est           |
   9026          laborum^.                                          |
   9027        ## grid 3
   9028                                                            |
   9029        ## grid 4
   9030          {9:test           }|
   9031          {9:               }|
   9032          {11:popup    text}{9:  }|
   9033        ]],
   9034          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   9035          unchanged = true,
   9036        }
   9037      else
   9038        screen:expect([[
   9039          Ut enim ad minim veniam, quis nostrud             |
   9040          exercitation ullamco laboris nisi ut aliquip ex   |
   9041          ea co{2:test}{3:o consequat}. Duis aute irure dolor in    |
   9042          repre{3:henderit in vol}uptate velit esse cillum      |
   9043          dolor{5:popup}{6:fugi}{5:text}{3:ul}la pariatur. Excepteur sint   |
   9044          occaecat cupidatat non proident, sunt in culpa    |
   9045          qui officia deserunt mollit anim id est           |
   9046          laborum^.                                          |
   9047                                                            |
   9048        ]])
   9049      end
   9050 
   9051      -- Test scrolling by mouse
   9052      if send_mouse_grid then
   9053        api.nvim_input_mouse('wheel', 'down', '', 4, 2, 2)
   9054      else
   9055        api.nvim_input_mouse('wheel', 'down', '', 0, 4, 7)
   9056      end
   9057      if multigrid then
   9058        screen:expect {
   9059          grid = [[
   9060        ## grid 1
   9061          [2:--------------------------------------------------]|*8
   9062          [3:--------------------------------------------------]|
   9063        ## grid 2
   9064          Ut enim ad minim veniam, quis nostrud             |
   9065          exercitation ullamco laboris nisi ut aliquip ex   |
   9066          ea commodo consequat. Duis aute irure dolor in    |
   9067          reprehenderit in voluptate velit esse cillum      |
   9068          dolore eu fugiat nulla pariatur. Excepteur sint   |
   9069          occaecat cupidatat non proident, sunt in culpa    |
   9070          qui officia deserunt mollit anim id est           |
   9071          laborum^.                                          |
   9072        ## grid 3
   9073                                                            |
   9074        ## grid 4
   9075          {11:popup    text}{9:  }|
   9076          {12:~              }|*2
   9077        ]],
   9078          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   9079        }
   9080      else
   9081        screen:expect([[
   9082          Ut enim ad minim veniam, quis nostrud             |
   9083          exercitation ullamco laboris nisi ut aliquip ex   |
   9084          ea co{5:popup}{6: con}{5:text}{3:at}. Duis aute irure dolor in    |
   9085          repre{7:~}{3:enderit in vol}uptate velit esse cillum      |
   9086          dolor{7:~}{3: eu fugiat nul}la pariatur. Excepteur sint   |
   9087          occaecat cupidatat non proident, sunt in culpa    |
   9088          qui officia deserunt mollit anim id est           |
   9089          laborum^.                                          |
   9090                                                            |
   9091        ]])
   9092      end
   9093 
   9094      -- Check that 'winblend' applies to border/title/footer
   9095      api.nvim_win_set_config(win, { border = 'single', title = 'Title', footer = 'Footer' })
   9096      api.nvim_set_option_value('winblend', 100, { win = win })
   9097      api.nvim_set_option_value('cursorline', true, { win = 0 })
   9098      -- 'winblend' with transparent background. #18576
   9099      command('hi clear VertSplit | hi Normal guibg=NONE ctermbg=NONE')
   9100      api.nvim_win_set_option(win, 'winhighlight', 'Normal:Normal')
   9101      feed('k0')
   9102      if multigrid then
   9103        screen:expect({
   9104          grid = [[
   9105          ## grid 1
   9106            [2:--------------------------------------------------]|*8
   9107            [3:--------------------------------------------------]|
   9108          ## grid 2
   9109            Ut enim ad minim veniam, quis nostrud             |
   9110            exercitation ullamco laboris nisi ut aliquip ex   |
   9111            ea commodo consequat. Duis aute irure dolor in    |
   9112            reprehenderit in voluptate velit esse cillum      |
   9113            dolore eu fugiat nulla pariatur. Excepteur sint   |
   9114            occaecat cupidatat non proident, sunt in culpa    |
   9115            {16:^qui officia deserunt mollit anim id est           }|
   9116            laborum.                                          |
   9117          ## grid 3
   9118                                                              |
   9119          ## grid 4
   9120            {17:┌}{23:Title}{17:──────────┐}|
   9121            {17:│}{31:popup    text}{17:  │}|
   9122            {17:│}{32:~              }{17:│}|*2
   9123            {17:└}{23:Footer}{17:─────────┘}|
   9124          ]],
   9125          win_pos = { [2] = { height = 8, startcol = 0, startrow = 0, width = 50, win = 1000 } },
   9126          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   9127          win_viewport = {
   9128            [2] = { win = 1000, topline = 3, botline = 11, curline = 9, curcol = 0, linecount = 11, sum_scroll_delta = 3 },
   9129            [4] = { win = 1001, topline = 2, botline = 4, curline = 2, curcol = 7, linecount = 3, sum_scroll_delta = 2 },
   9130          },
   9131          win_viewport_margins = {
   9132            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
   9133            [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 },
   9134          },
   9135        })
   9136      else
   9137        screen:expect([[
   9138          Ut enim ad minim veniam, quis nostrud             |
   9139          exercitation ullamco laboris nisi ut aliquip ex   |
   9140          ea co{26:}{27:Title}{26:──────────┐}Duis aute irure dolor in    |
   9141          repre{26:}{28:popup}{29:it i}{28:text}{26:lu}tate velit esse cillum      |
   9142          dolor{26:}{30:~}{26:eu fugiat null} pariatur. Excepteur sint   |
   9143          occae{26:}{30:~}{26:t cupidatat no} proident, sunt in culpa    |
   9144          {16:^qui o}{22:}{25:Footer}{22:─────────┘}{16:ollit anim id est           }|
   9145          laborum.                                          |
   9146                                                            |
   9147        ]])
   9148      end
   9149 
   9150      -- winblend highlight with underline (but without guisp) in a floatwin. #14453
   9151      command('fclose | hi TestUnderLine gui=underline')
   9152      api.nvim_buf_add_highlight(curbufnr, -1, 'TestUnderLine', 3, 0, -1)
   9153      api.nvim_buf_add_highlight(curbufnr, -1, 'TestUnderLine', 4, 0, -1)
   9154      api.nvim_buf_set_lines(buf, 0, -1, false, {})
   9155      api.nvim_open_win(buf, false, { relative = 'win', row = 0, col = 0, width = 50, height = 1 })
   9156      if multigrid then
   9157        screen:expect({
   9158          grid = [[
   9159          ## grid 1
   9160            [2:--------------------------------------------------]|*8
   9161            [3:--------------------------------------------------]|
   9162          ## grid 2
   9163            {34:Ut enim ad minim veniam, quis nostrud}             |
   9164            {34:exercitation ullamco laboris nisi ut aliquip ex}   |
   9165            ea commodo consequat. Duis aute irure dolor in    |
   9166            reprehenderit in voluptate velit esse cillum      |
   9167            dolore eu fugiat nulla pariatur. Excepteur sint   |
   9168            occaecat cupidatat non proident, sunt in culpa    |
   9169            {16:^qui officia deserunt mollit anim id est           }|
   9170            laborum.                                          |
   9171          ## grid 3
   9172                                                              |
   9173          ## grid 5
   9174            {17:                                                  }|
   9175          ]],
   9176          win_pos = { [2] = { height = 8, startcol = 0, startrow = 0, width = 50, win = 1000 } },
   9177          float_pos = { [5] = { 1002, 'NW', 2, 0, 0, true, 50, 1, 0, 0 } },
   9178          win_viewport = {
   9179            [2] = { win = 1000, topline = 3, botline = 11, curline = 9, curcol = 0, linecount = 11, sum_scroll_delta = 3 },
   9180            [5] = { win = 1002, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9181          },
   9182          win_viewport_margins = {
   9183            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
   9184            [5] = { bottom = 0, left = 0, right = 0, top = 0, win = 1002 },
   9185          },
   9186        })
   9187      else
   9188        screen:expect([[
   9189          {33:Ut enim ad minim veniam, quis nostrud}{26:             }|
   9190          {34:exercitation ullamco laboris nisi ut aliquip ex}   |
   9191          ea commodo consequat. Duis aute irure dolor in    |
   9192          reprehenderit in voluptate velit esse cillum      |
   9193          dolore eu fugiat nulla pariatur. Excepteur sint   |
   9194          occaecat cupidatat non proident, sunt in culpa    |
   9195          {16:^qui officia deserunt mollit anim id est           }|
   9196          laborum.                                          |
   9197                                                            |
   9198        ]])
   9199      end
   9200    end)
   9201 
   9202    it('can overlap doublewidth chars', function()
   9203      insert([[
   9204        # TODO: 测试字典信息的准确性
   9205        # FIXME: 测试字典信息的准确性]])
   9206      local buf = api.nvim_create_buf(false, false)
   9207      api.nvim_buf_set_lines(buf, 0, -1, true, { '口', '口' })
   9208      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 5, height = 3, row = 0, col = 11, style = 'minimal' })
   9209      if multigrid then
   9210        screen:expect {
   9211          grid = [[
   9212        ## grid 1
   9213          [2:----------------------------------------]|*6
   9214          [3:----------------------------------------]|
   9215        ## grid 2
   9216          # TODO: 测试字典信息的准确性            |
   9217          # FIXME: 测试字典信息的准确^性           |
   9218          {0:~                                       }|*4
   9219        ## grid 3
   9220                                                  |
   9221        ## grid 4
   9222          {1:口   }|*2
   9223          {1:     }|
   9224        ]],
   9225          float_pos = { [4] = { 1001, 'NW', 1, 0, 11, true, 50, 1, 0, 11 } },
   9226        }
   9227      else
   9228        screen:expect([[
   9229          # TODO:  {1:   }信息的准确性            |
   9230          # FIXME: {1:   } 信息的准确^           |
   9231          {0:~          }{1:     }{0:                        }|
   9232          {0:~                                       }|*3
   9233                                                  |
   9234        ]])
   9235      end
   9236 
   9237      api.nvim_win_close(win, false)
   9238      if multigrid then
   9239        screen:expect([[
   9240        ## grid 1
   9241          [2:----------------------------------------]|*6
   9242          [3:----------------------------------------]|
   9243        ## grid 2
   9244          # TODO: 测试字典信息的准确性            |
   9245          # FIXME: 测试字典信息的准确^           |
   9246          {0:~                                       }|*4
   9247        ## grid 3
   9248                                                  |
   9249        ]])
   9250      else
   9251        screen:expect([[
   9252          # TODO: 测试字典信息的准确性            |
   9253          # FIXME: 测试字典信息的准确^           |
   9254          {0:~                                       }|*4
   9255                                                  |
   9256        ]])
   9257      end
   9258 
   9259      -- The interaction between 'winblend' and doublewidth chars in the background
   9260      -- does not look very good. But check no chars get incorrectly placed
   9261      -- at least. Also check invisible EndOfBuffer region blends correctly.
   9262      api.nvim_buf_set_lines(buf, 0, -1, true, { ' x x  x   xx', '  x x  x   x' })
   9263      win = api.nvim_open_win(buf, false, { relative = 'editor', width = 12, height = 3, row = 0, col = 11, style = 'minimal' })
   9264      api.nvim_set_option_value('winblend', 30, { win = win })
   9265      screen:set_default_attr_ids({
   9266        [1] = { foreground = tonumber('0xb282b2'), background = tonumber('0xffcfff') },
   9267        [2] = { foreground = Screen.colors.Grey0, background = tonumber('0xffcfff') },
   9268        [3] = { bold = true, foreground = Screen.colors.Blue1 },
   9269        [4] = { background = tonumber('0xffcfff'), bold = true, foreground = tonumber('0xb282ff') },
   9270        [5] = { background = Screen.colors.LightMagenta, blend = 30 },
   9271      })
   9272      if multigrid then
   9273        screen:expect {
   9274          grid = [[
   9275        ## grid 1
   9276          [2:----------------------------------------]|*6
   9277          [3:----------------------------------------]|
   9278        ## grid 2
   9279          # TODO: 测试字典信息的准确性            |
   9280          # FIXME: 测试字典信息的准确^性           |
   9281          {3:~                                       }|*4
   9282        ## grid 3
   9283                                                  |
   9284        ## grid 5
   9285          {5: x x  x   xx}|
   9286          {5:  x x  x   x}|
   9287          {5:            }|
   9288        ]],
   9289          float_pos = { [5] = { 1002, 'NW', 1, 0, 11, true, 50, 1, 0, 11 } },
   9290        }
   9291      else
   9292        screen:expect([[
   9293          # TODO:  {2: x x  x}{1:}{2: xx} 确性            |
   9294          # FIXME: {1:}{2:x x  x}{1:}{2: x}准确^           |
   9295          {3:~          }{4:            }{3:                 }|
   9296          {3:~                                       }|*3
   9297                                                  |
   9298        ]])
   9299      end
   9300 
   9301      api.nvim_win_set_config(win, { relative = 'editor', row = 0, col = 12 })
   9302      if multigrid then
   9303        screen:expect {
   9304          grid = [[
   9305        ## grid 1
   9306          [2:----------------------------------------]|*6
   9307          [3:----------------------------------------]|
   9308        ## grid 2
   9309          # TODO: 测试字典信息的准确性            |
   9310          # FIXME: 测试字典信息的准确^性           |
   9311          {3:~                                       }|*4
   9312        ## grid 3
   9313                                                  |
   9314        ## grid 5
   9315          {5: x x  x   xx}|
   9316          {5:  x x  x   x}|
   9317          {5:            }|
   9318        ]],
   9319          float_pos = { [5] = { 1002, 'NW', 1, 0, 12, true, 50, 1, 0, 12 } },
   9320        }
   9321      else
   9322        screen:expect([[
   9323          # TODO: 测试{2: x x}{1:}{2:x }{1:}{2:xx}确性            |
   9324          # FIXME:  {2:  x x}{1:}{2:x }{1:}{2:x} ^           |
   9325          {3:~           }{4:            }{3:                }|
   9326          {3:~                                       }|*3
   9327                                                  |
   9328        ]])
   9329      end
   9330    end)
   9331 
   9332    it('correctly redraws when overlaid windows are resized #13991', function()
   9333      n.source([[
   9334        let popup_config = {"relative" : "editor",
   9335                    \ "width" : 7,
   9336                    \ "height" : 3,
   9337                    \ "row" : 1,
   9338                    \ "col" : 1,
   9339                    \ "style" : "minimal"}
   9340 
   9341        let border_config = {"relative" : "editor",
   9342                    \ "width" : 9,
   9343                    \ "height" : 5,
   9344                    \ "row" : 0,
   9345                    \ "col" : 0,
   9346                    \ "style" : "minimal"}
   9347 
   9348        let popup_buffer = nvim_create_buf(v:false, v:true)
   9349        let border_buffer = nvim_create_buf(v:false, v:true)
   9350        let popup_win = nvim_open_win(popup_buffer, v:true, popup_config)
   9351        let border_win = nvim_open_win(border_buffer, v:false, border_config)
   9352 
   9353        call nvim_buf_set_lines(popup_buffer, 0, -1, v:true,
   9354                    \ ["long", "longer", "longest"])
   9355 
   9356        call nvim_buf_set_lines(border_buffer, 0, -1, v:true,
   9357                    \ ["---------", "-       -", "-       -"])
   9358      ]])
   9359 
   9360      if multigrid then
   9361        screen:expect {
   9362          grid = [[
   9363 	## grid 1
   9364 	  [2:----------------------------------------]|*6
   9365 	  [3:----------------------------------------]|
   9366 	## grid 2
   9367 	                                          |
   9368 	  {1:~                                       }|*5
   9369 	## grid 3
   9370 	                                          |
   9371 	## grid 4
   9372 	  {2:^long   }|
   9373 	  {2:longer }|
   9374 	  {2:longest}|
   9375 	## grid 5
   9376 	  {2:---------}|
   9377 	  {2:-       -}|*2
   9378 	  {2:         }|*2
   9379 	]],
   9380          attr_ids = {
   9381            [1] = { foreground = Screen.colors.Blue1, bold = true },
   9382            [2] = { background = Screen.colors.LightMagenta },
   9383          },
   9384          float_pos = {
   9385            [4] = { 1001, 'NW', 1, 1, 1, true, 50, 2, 1, 1 },
   9386            [5] = { 1002, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
   9387          },
   9388        }
   9389      else
   9390        screen:expect([[
   9391        {1:---------}                               |
   9392        {1:-^long   -}{0:                               }|
   9393        {1:-longer -}{0:                               }|
   9394        {1: longest }{0:                               }|
   9395        {1:         }{0:                               }|
   9396        {0:~                                       }|
   9397                                                |
   9398        ]])
   9399      end
   9400 
   9401      n.source([[
   9402        let new_popup_config = {"width" : 1, "height" : 3}
   9403        let new_border_config = {"width" : 3, "height" : 5}
   9404 
   9405        function! Resize()
   9406            call nvim_win_set_config(g:popup_win, g:new_popup_config)
   9407            call nvim_win_set_config(g:border_win, g:new_border_config)
   9408 
   9409            call nvim_buf_set_lines(g:border_buffer, 0, -1, v:true,
   9410                        \ ["---", "- -", "- -"])
   9411        endfunction
   9412 
   9413        nnoremap zz <cmd>call Resize()<cr>
   9414      ]])
   9415 
   9416      n.feed('zz')
   9417      if multigrid then
   9418        screen:expect {
   9419          grid = [[
   9420        ## grid 1
   9421          [2:----------------------------------------]|*6
   9422          [3:----------------------------------------]|
   9423        ## grid 2
   9424                                                  |
   9425          {1:~                                       }|*5
   9426        ## grid 3
   9427                                                  |
   9428        ## grid 4
   9429          {2:^l}|
   9430          {2:o}|
   9431          {2:n}|
   9432        ## grid 5
   9433          {2:---}|
   9434          {2:- -}|*2
   9435          {2:   }|*2
   9436        ]],
   9437          attr_ids = {
   9438            [1] = { foreground = Screen.colors.Blue1, bold = true },
   9439            [2] = { background = Screen.colors.LightMagenta },
   9440          },
   9441          float_pos = {
   9442            [4] = { 1001, 'NW', 1, 1, 1, true, 50, 2, 1, 1 },
   9443            [5] = { 1002, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
   9444          },
   9445        }
   9446      else
   9447        screen:expect([[
   9448        {1:---}                                     |
   9449        {1:-^l-}{0:                                     }|
   9450        {1:-o-}{0:                                     }|
   9451        {1: n }{0:                                     }|
   9452        {1:   }{0:                                     }|
   9453        {0:~                                       }|
   9454                                                |
   9455        ]])
   9456      end
   9457    end)
   9458 
   9459    it('correctly orders multiple opened floats (current last)', function()
   9460      local buf = api.nvim_create_buf(false, false)
   9461      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
   9462      api.nvim_set_option_value('winhl', 'Normal:ErrorMsg,EndOfBuffer:ErrorMsg', { win = win })
   9463 
   9464      if multigrid then
   9465        screen:expect {
   9466          grid = [[
   9467        ## grid 1
   9468          [2:----------------------------------------]|*6
   9469          [3:----------------------------------------]|
   9470        ## grid 2
   9471          ^                                        |
   9472          {0:~                                       }|*5
   9473        ## grid 3
   9474                                                  |
   9475        ## grid 4
   9476          {7:                    }|
   9477          {7:~                   }|
   9478        ]],
   9479          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   9480          win_viewport = {
   9481            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9482            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9483          },
   9484        }
   9485      else
   9486        screen:expect {
   9487          grid = [[
   9488          ^                                        |
   9489          {0:~                                       }|
   9490          {0:~    }{7:                    }{0:               }|
   9491          {0:~    }{7:~                   }{0:               }|
   9492          {0:~                                       }|*2
   9493                                                  |
   9494        ]],
   9495        }
   9496      end
   9497 
   9498      exec_lua [[
   9499        local buf = vim.api.nvim_create_buf(false,false)
   9500        local win = vim.api.nvim_open_win(buf, false, {relative='editor', width=16, height=2, row=3, col=8})
   9501        vim.wo[win].winhl = "EndOfBuffer:Normal"
   9502        buf = vim.api.nvim_create_buf(false,false)
   9503        win = vim.api.nvim_open_win(buf, true, {relative='editor', width=12, height=2, row=4, col=10})
   9504        vim.wo[win].winhl = "Normal:Search,EndOfBuffer:Search"
   9505      ]]
   9506 
   9507      if multigrid then
   9508        screen:expect {
   9509          grid = [[
   9510        ## grid 1
   9511          [2:----------------------------------------]|*6
   9512          [3:----------------------------------------]|
   9513        ## grid 2
   9514                                                  |
   9515          {0:~                                       }|*5
   9516        ## grid 3
   9517                                                  |
   9518        ## grid 4
   9519          {7:                    }|
   9520          {7:~                   }|
   9521        ## grid 5
   9522          {1:                }|
   9523          {1:~               }|
   9524        ## grid 6
   9525          {17:^            }|
   9526          {17:~           }|
   9527        ]],
   9528          float_pos = {
   9529            [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 },
   9530            [5] = { 1002, 'NW', 1, 3, 8, true, 50, 2, 3, 8 },
   9531            [6] = { 1003, 'NW', 1, 4, 10, true, 50, 3, 4, 10 },
   9532          },
   9533          win_viewport = {
   9534            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9535            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9536            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9537            [6] = { win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9538          },
   9539        }
   9540      else
   9541        screen:expect {
   9542          grid = [[
   9543                                                  |
   9544          {0:~                                       }|
   9545          {0:~    }{7:                    }{0:               }|
   9546          {0:~    }{7:~  }{1:                }{7: }{0:               }|
   9547          {0:~       }{1:~ }{17:^            }{1:  }{0:                }|
   9548          {0:~         }{17:~           }{0:                  }|
   9549                                                  |
   9550        ]],
   9551        }
   9552      end
   9553 
   9554      -- This should bring win into focus on top
   9555      api.nvim_set_current_win(win)
   9556      if multigrid then
   9557        screen:expect({
   9558          grid = [[
   9559          ## grid 1
   9560            [2:----------------------------------------]|*6
   9561            [3:----------------------------------------]|
   9562          ## grid 2
   9563                                                    |
   9564            {0:~                                       }|*5
   9565          ## grid 3
   9566                                                    |
   9567          ## grid 4
   9568            {7:^                    }|
   9569            {7:~                   }|
   9570          ## grid 5
   9571            {1:                }|
   9572            {1:~               }|
   9573          ## grid 6
   9574            {17:            }|
   9575            {17:~           }|
   9576          ]],
   9577          win_pos = { [2] = { height = 6, startcol = 0, startrow = 0, width = 40, win = 1000 } },
   9578          float_pos = {
   9579            [4] = { 1001, 'NW', 1, 2, 5, true, 50, 3, 2, 5 },
   9580            [5] = { 1002, 'NW', 1, 3, 8, true, 50, 1, 3, 8 },
   9581            [6] = { 1003, 'NW', 1, 4, 10, true, 50, 2, 4, 10 },
   9582          },
   9583          win_viewport = {
   9584            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9585            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9586            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9587            [6] = { win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9588          },
   9589        })
   9590      else
   9591        screen:expect([[
   9592                                                  |
   9593          {0:~                                       }|
   9594          {0:~    }{7:^                    }{0:               }|
   9595          {0:~    }{7:~                   }{0:               }|
   9596          {0:~       }{1:~ }{17:            }{1:  }{0:                }|
   9597          {0:~         }{17:~           }{0:                  }|
   9598                                                  |
   9599        ]])
   9600      end
   9601    end)
   9602 
   9603    it('correctly orders multiple opened floats (non-current last)', function()
   9604      local buf = api.nvim_create_buf(false, false)
   9605      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 2, row = 2, col = 5 })
   9606      api.nvim_set_option_value('winhl', 'Normal:ErrorMsg,EndOfBuffer:ErrorMsg', { win = win })
   9607 
   9608      if multigrid then
   9609        screen:expect {
   9610          grid = [[
   9611        ## grid 1
   9612          [2:----------------------------------------]|*6
   9613          [3:----------------------------------------]|
   9614        ## grid 2
   9615          ^                                        |
   9616          {0:~                                       }|*5
   9617        ## grid 3
   9618                                                  |
   9619        ## grid 4
   9620          {7:                    }|
   9621          {7:~                   }|
   9622        ]],
   9623          float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
   9624          win_viewport = {
   9625            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9626            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9627          },
   9628        }
   9629      else
   9630        screen:expect {
   9631          grid = [[
   9632          ^                                        |
   9633          {0:~                                       }|
   9634          {0:~    }{7:                    }{0:               }|
   9635          {0:~    }{7:~                   }{0:               }|
   9636          {0:~                                       }|*2
   9637                                                  |
   9638        ]],
   9639        }
   9640      end
   9641 
   9642      exec_lua [[
   9643        local buf = vim.api.nvim_create_buf(false,false)
   9644        local win = vim.api.nvim_open_win(buf, true, {relative='editor', width=12, height=2, row=4, col=10})
   9645        vim.wo[win].winhl = "Normal:Search,EndOfBuffer:Search"
   9646        buf = vim.api.nvim_create_buf(false,false)
   9647        win = vim.api.nvim_open_win(buf, false, {relative='editor', width=16, height=2, row=3, col=8})
   9648        vim.wo[win].winhl = "EndOfBuffer:Normal"
   9649      ]]
   9650 
   9651      if multigrid then
   9652        screen:expect {
   9653          grid = [[
   9654        ## grid 1
   9655          [2:----------------------------------------]|*6
   9656          [3:----------------------------------------]|
   9657        ## grid 2
   9658                                                  |
   9659          {0:~                                       }|*5
   9660        ## grid 3
   9661                                                  |
   9662        ## grid 4
   9663          {7:                    }|
   9664          {7:~                   }|
   9665        ## grid 5
   9666          {17:^            }|
   9667          {17:~           }|
   9668        ## grid 6
   9669          {1:                }|
   9670          {1:~               }|
   9671        ]],
   9672          float_pos = {
   9673            [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 },
   9674            [5] = { 1002, 'NW', 1, 4, 10, true, 50, 3, 4, 10 },
   9675            [6] = { 1003, 'NW', 1, 3, 8, true, 50, 2, 3, 8 },
   9676          },
   9677          win_viewport = {
   9678            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9679            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9680            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9681            [6] = { win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9682          },
   9683        }
   9684      else
   9685        screen:expect {
   9686          grid = [[
   9687                                                  |
   9688          {0:~                                       }|
   9689          {0:~    }{7:                    }{0:               }|
   9690          {0:~    }{7:~  }{1:                }{7: }{0:               }|
   9691          {0:~       }{1:~ }{17:^            }{1:  }{0:                }|
   9692          {0:~         }{17:~           }{0:                  }|
   9693                                                  |
   9694        ]],
   9695        }
   9696      end
   9697 
   9698      -- This should bring win into focus on top
   9699      api.nvim_set_current_win(win)
   9700      if multigrid then
   9701        screen:expect({
   9702          grid = [[
   9703          ## grid 1
   9704            [2:----------------------------------------]|*6
   9705            [3:----------------------------------------]|
   9706          ## grid 2
   9707                                                    |
   9708            {0:~                                       }|*5
   9709          ## grid 3
   9710                                                    |
   9711          ## grid 4
   9712            {7:^                    }|
   9713            {7:~                   }|
   9714          ## grid 5
   9715            {17:            }|
   9716            {17:~           }|
   9717          ## grid 6
   9718            {1:                }|
   9719            {1:~               }|
   9720          ]],
   9721          win_pos = { [2] = { height = 6, startcol = 0, startrow = 0, width = 40, win = 1000 } },
   9722          float_pos = {
   9723            [4] = { 1001, 'NW', 1, 2, 5, true, 50, 3, 2, 5 },
   9724            [5] = { 1002, 'NW', 1, 4, 10, true, 50, 2, 4, 10 },
   9725            [6] = { 1003, 'NW', 1, 3, 8, true, 50, 1, 3, 8 },
   9726          },
   9727          win_viewport = {
   9728            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9729            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9730            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9731            [6] = { win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9732          },
   9733        })
   9734      else
   9735        screen:expect([[
   9736                                                  |
   9737          {0:~                                       }|
   9738          {0:~    }{7:^                    }{0:               }|
   9739          {0:~    }{7:~                   }{0:               }|
   9740          {0:~       }{1:~ }{17:            }{1:  }{0:                }|
   9741          {0:~         }{17:~           }{0:                  }|
   9742                                                  |
   9743        ]])
   9744      end
   9745    end)
   9746 
   9747    it('can use z-index', function()
   9748      local buf = api.nvim_create_buf(false, false)
   9749      local win1 = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 3, row = 1, col = 5, zindex = 30 })
   9750      api.nvim_set_option_value('winhl', 'Normal:ErrorMsg,EndOfBuffer:ErrorMsg', { win = win1 })
   9751      local win2 = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 3, row = 2, col = 6, zindex = 50 })
   9752      api.nvim_set_option_value('winhl', 'Normal:Search,EndOfBuffer:Search', { win = win2 })
   9753      local win3 = api.nvim_open_win(buf, false, { relative = 'editor', width = 20, height = 3, row = 3, col = 7, zindex = 40 })
   9754      api.nvim_set_option_value('winhl', 'Normal:Question,EndOfBuffer:Question', { win = win3 })
   9755 
   9756      if multigrid then
   9757        screen:expect {
   9758          grid = [[
   9759        ## grid 1
   9760          [2:----------------------------------------]|*6
   9761          [3:----------------------------------------]|
   9762        ## grid 2
   9763          ^                                        |
   9764          {0:~                                       }|*5
   9765        ## grid 3
   9766                                                  |
   9767        ## grid 4
   9768          {7:                    }|
   9769          {7:~                   }|*2
   9770        ## grid 5
   9771          {17:                    }|
   9772          {17:~                   }|*2
   9773        ## grid 6
   9774          {8:                    }|
   9775          {8:~                   }|*2
   9776        ]],
   9777          float_pos = {
   9778            [4] = { 1001, 'NW', 1, 1, 5, true, 30, 1, 1, 5 },
   9779            [5] = { 1002, 'NW', 1, 2, 6, true, 50, 3, 2, 6 },
   9780            [6] = { 1003, 'NW', 1, 3, 7, true, 40, 2, 3, 7 },
   9781          },
   9782          win_viewport = {
   9783            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9784            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9785            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9786            [6] = { win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9787          },
   9788        }
   9789      else
   9790        screen:expect {
   9791          grid = [[
   9792          ^                                        |
   9793          {0:~    }{7:                    }{0:               }|
   9794          {0:~    }{7:~}{17:                    }{0:              }|
   9795          {0:~    }{7:~}{17:~                   }{8: }{0:             }|
   9796          {0:~     }{17:~                   }{8: }{0:             }|
   9797          {0:~      }{8:~                   }{0:             }|
   9798                                                  |
   9799        ]],
   9800        }
   9801      end
   9802 
   9803      --
   9804      -- Check that floats are positioned correctly after changing the zindexes.
   9805      --
   9806      command('fclose')
   9807      exec_lua(
   9808        [[
   9809        local win1, win3 = ...
   9810        vim.api.nvim_win_set_config(win1, { zindex = 400, title = 'win_400', title_pos = 'center', border = 'double' })
   9811        vim.api.nvim_win_set_config(win3, { zindex = 300, title = 'win_300', title_pos = 'center', border = 'single' })
   9812      ]],
   9813        win1,
   9814        win3
   9815      )
   9816      if multigrid then
   9817        screen:expect({
   9818          grid = [[
   9819          ## grid 1
   9820            [2:----------------------------------------]|*6
   9821            [3:----------------------------------------]|
   9822          ## grid 2
   9823            ^                                        |
   9824            {0:~                                       }|*5
   9825          ## grid 3
   9826                                                    |
   9827          ## grid 4
   9828            {5:╔══════}{11:win_400}{5:═══════╗}|
   9829            {5:║}{7:                    }{5:║}|
   9830            {5:║}{7:~                   }{5:║}|*2
   9831            {5:╚════════════════════╝}|
   9832          ## grid 6
   9833            {5:┌──────}{11:win_300}{5:───────┐}|
   9834            {5:│}{8:                    }{5:│}|
   9835            {5:│}{8:~                   }{5:│}|*2
   9836            {5:└────────────────────┘}|
   9837          ]],
   9838          float_pos = {
   9839            [4] = { 1001, 'NW', 1, 1, 5, true, 400, 3, 1, 5 },
   9840            [6] = { 1003, 'NW', 1, 3, 7, true, 300, 2, 2, 7 },
   9841          },
   9842          win_viewport = {
   9843            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9844            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9845            [6] = { win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9846          },
   9847          win_viewport_margins = {
   9848            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
   9849            [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 },
   9850            [6] = { bottom = 1, left = 1, right = 1, top = 1, win = 1003 },
   9851          },
   9852        })
   9853      else
   9854        screen:expect({
   9855          grid = [[
   9856            ^                                        |
   9857            {0:~    }{5:╔══════}{11:win_400}{5:═══════╗}{0:             }|
   9858            {0:~    }{5:║}{7:                    }{5:║─┐}{0:           }|
   9859            {0:~    }{5:║}{7:~                   }{5:║}{8: }{5:│}{0:           }|*2
   9860            {0:~    }{5:╚════════════════════╝}{8: }{5:│}{0:           }|
   9861                   {5:└────────────────────┘}           |
   9862          ]],
   9863        })
   9864      end
   9865      exec_lua(
   9866        [[
   9867        local win1, win3 = ...
   9868        vim.api.nvim_win_set_config(win1, { zindex = 100, title='win_100' })
   9869        vim.api.nvim_win_set_config(win3, { zindex = 150, title='win_150' })
   9870      ]],
   9871        win1,
   9872        win3
   9873      )
   9874      if multigrid then
   9875        screen:expect({
   9876          grid = [[
   9877          ## grid 1
   9878            [2:----------------------------------------]|*6
   9879            [3:----------------------------------------]|
   9880          ## grid 2
   9881            ^                                        |
   9882            {0:~                                       }|*5
   9883          ## grid 3
   9884                                                    |
   9885          ## grid 4
   9886            {5:╔══════}{11:win_100}{5:═══════╗}|
   9887            {5:║}{7:                    }{5:║}|
   9888            {5:║}{7:~                   }{5:║}|*2
   9889            {5:╚════════════════════╝}|
   9890          ## grid 6
   9891            {5:┌──────}{11:win_150}{5:───────┐}|
   9892            {5:│}{8:                    }{5:│}|
   9893            {5:│}{8:~                   }{5:│}|*2
   9894            {5:└────────────────────┘}|
   9895          ]],
   9896          float_pos = {
   9897            [4] = { 1001, 'NW', 1, 1, 5, true, 100, 1, 1, 5 },
   9898            [6] = { 1003, 'NW', 1, 3, 7, true, 150, 2, 1, 7 },
   9899          },
   9900          win_viewport = {
   9901            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9902            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9903            [6] = { win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9904          },
   9905          win_viewport_margins = {
   9906            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
   9907            [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 },
   9908            [6] = { bottom = 1, left = 1, right = 1, top = 1, win = 1003 },
   9909          },
   9910        })
   9911      else
   9912        screen:expect([[
   9913          ^                                        |
   9914          {0:~    }{5:╔═┌──────}{11:win_150}{5:───────┐}{0:           }|
   9915          {0:~    }{5:}{7: }{5:}{8:                    }{5:}{0:           }|
   9916          {0:~    }{5:}{7:~}{5:}{8:~                   }{5:}{0:           }|*2
   9917          {0:~    }{5:╚═└────────────────────┘}{0:           }|
   9918                                                  |
   9919        ]])
   9920      end
   9921    end)
   9922 
   9923    it('can use winbar', function()
   9924      local buf = api.nvim_create_buf(false, false)
   9925      local win1 = api.nvim_open_win(buf, false, { relative = 'editor', width = 15, height = 3, row = 1, col = 5 })
   9926      api.nvim_set_option_value('winbar', 'floaty bar', { win = win1 })
   9927 
   9928      if multigrid then
   9929        screen:expect {
   9930          grid = [[
   9931        ## grid 1
   9932          [2:----------------------------------------]|*6
   9933          [3:----------------------------------------]|
   9934        ## grid 2
   9935          ^                                        |
   9936          {0:~                                       }|*5
   9937        ## grid 3
   9938                                                  |
   9939        ## grid 4
   9940          {3:floaty bar     }|
   9941          {1:               }|
   9942          {2:~              }|
   9943        ]],
   9944          float_pos = { [4] = { 1001, 'NW', 1, 1, 5, true, 50, 1, 1, 5 } },
   9945          win_viewport = {
   9946            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9947            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9948          },
   9949        }
   9950      else
   9951        screen:expect {
   9952          grid = [[
   9953          ^                                        |
   9954          {0:~    }{3:floaty bar     }{0:                    }|
   9955          {0:~    }{1:               }{0:                    }|
   9956          {0:~    }{2:~              }{0:                    }|
   9957          {0:~                                       }|*2
   9958                                                  |
   9959        ]],
   9960        }
   9961      end
   9962 
   9963      -- resize and add a border
   9964      api.nvim_win_set_config(win1, { relative = 'editor', width = 15, height = 4, row = 0, col = 4, border = 'single' })
   9965 
   9966      if multigrid then
   9967        screen:expect {
   9968          grid = [[
   9969        ## grid 1
   9970          [2:----------------------------------------]|*6
   9971          [3:----------------------------------------]|
   9972        ## grid 2
   9973          ^                                        |
   9974          {0:~                                       }|*5
   9975        ## grid 3
   9976                                                  |
   9977        ## grid 4
   9978          {5:┌───────────────┐}|
   9979          {5:│}{3:floaty bar     }{5:│}|
   9980          {5:│}{1:               }{5:│}|
   9981          {5:│}{2:~              }{5:│}|*2
   9982          {5:└───────────────┘}|
   9983        ]],
   9984          float_pos = { [4] = { 1001, 'NW', 1, 0, 4, true, 50, 1, 0, 4 } },
   9985          win_viewport = {
   9986            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9987            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
   9988          },
   9989          win_viewport_margins = {
   9990            [2] = { win = 1000, top = 0, bottom = 0, left = 0, right = 0 },
   9991            [4] = { win = 1001, top = 2, bottom = 1, left = 1, right = 1 },
   9992          },
   9993        }
   9994      else
   9995        screen:expect {
   9996          grid = [[
   9997          ^    {5:┌───────────────┐}                   |
   9998          {0:~   }{5:│}{3:floaty bar     }{5:│}{0:                   }|
   9999          {0:~   }{5:│}{1:               }{5:│}{0:                   }|
  10000          {0:~   }{5:│}{2:~              }{5:│}{0:                   }|*2
  10001          {0:~   }{5:└───────────────┘}{0:                   }|
  10002                                                  |
  10003        ]],
  10004        }
  10005      end
  10006    end)
  10007 
  10008    it('it can be resized with messages and cmdheight=0 #20106', function()
  10009      screen:try_resize(40, 9)
  10010      command 'set cmdheight=0'
  10011      local buf = api.nvim_create_buf(false, true)
  10012      local win = api.nvim_open_win(buf, false, {
  10013        relative = 'editor',
  10014        width = 40,
  10015        height = 4,
  10016        anchor = 'SW',
  10017        row = 9,
  10018        col = 0,
  10019        style = 'minimal',
  10020        border = 'single',
  10021        noautocmd = true,
  10022      })
  10023 
  10024      if multigrid then
  10025        screen:expect {
  10026          grid = [[
  10027        ## grid 1
  10028          [2:----------------------------------------]|*9
  10029        ## grid 2
  10030          ^                                        |
  10031          {0:~                                       }|*8
  10032        ## grid 3
  10033        ## grid 4
  10034          {5:┌────────────────────────────────────────┐}|
  10035          {5:│}{1:                                        }{5:│}|*4
  10036          {5:└────────────────────────────────────────┘}|
  10037        ]],
  10038          float_pos = { [4] = { 1001, 'SW', 1, 9, 0, true, 50, 1, 3, 0 } },
  10039          win_viewport = {
  10040            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10041            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10042          },
  10043        }
  10044      else
  10045        screen:expect {
  10046          grid = [[
  10047          ^                                        |
  10048          {0:~                                       }|*2
  10049          {5:┌──────────────────────────────────────┐}|
  10050          {5:│}{1:                                      }{5:│}|*4
  10051          {5:└──────────────────────────────────────┘}|
  10052        ]],
  10053        }
  10054      end
  10055 
  10056      exec_lua(
  10057        [[
  10058        local win = ...
  10059        vim.api.nvim_win_set_height(win, 2)
  10060        vim.api.nvim_echo({ { "" } }, false, {})
  10061      ]],
  10062        win
  10063      )
  10064 
  10065      if multigrid then
  10066        screen:expect {
  10067          grid = [[
  10068        ## grid 1
  10069          [2:----------------------------------------]|*9
  10070        ## grid 2
  10071          ^                                        |
  10072          {0:~                                       }|*8
  10073        ## grid 3
  10074        ## grid 4
  10075          {5:┌────────────────────────────────────────┐}|
  10076          {5:│}{1:                                        }{5:│}|*2
  10077          {5:└────────────────────────────────────────┘}|
  10078        ]],
  10079          float_pos = { [4] = { 1001, 'SW', 1, 9, 0, true, 50, 1, 5, 0 } },
  10080          win_viewport = {
  10081            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10082            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10083          },
  10084        }
  10085      else
  10086        screen:expect {
  10087          grid = [[
  10088          ^                                        |
  10089          {0:~                                       }|*4
  10090          {5:┌──────────────────────────────────────┐}|
  10091          {5:│}{1:                                      }{5:│}|*2
  10092          {5:└──────────────────────────────────────┘}|
  10093        ]],
  10094        }
  10095      end
  10096 
  10097      api.nvim_win_close(win, true)
  10098      if multigrid then
  10099        screen:expect {
  10100          grid = [[
  10101        ## grid 1
  10102          [2:----------------------------------------]|*9
  10103        ## grid 2
  10104          ^                                        |
  10105          {0:~                                       }|*8
  10106        ## grid 3
  10107        ]],
  10108          win_viewport = {
  10109            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10110          },
  10111        }
  10112      else
  10113        screen:expect {
  10114          grid = [[
  10115          ^                                        |
  10116          {0:~                                       }|*8
  10117        ]],
  10118        }
  10119      end
  10120    end)
  10121 
  10122    it('it can be resized with messages and cmdheight=1', function()
  10123      screen:try_resize(40, 9)
  10124      local buf = api.nvim_create_buf(false, true)
  10125      local win = api.nvim_open_win(buf, false, {
  10126        relative = 'editor',
  10127        width = 40,
  10128        height = 4,
  10129        anchor = 'SW',
  10130        row = 8,
  10131        col = 0,
  10132        style = 'minimal',
  10133        border = 'single',
  10134        noautocmd = true,
  10135      })
  10136 
  10137      if multigrid then
  10138        screen:expect {
  10139          grid = [[
  10140        ## grid 1
  10141          [2:----------------------------------------]|*8
  10142          [3:----------------------------------------]|
  10143        ## grid 2
  10144          ^                                        |
  10145          {0:~                                       }|*7
  10146        ## grid 3
  10147                                                  |
  10148        ## grid 4
  10149          {5:┌────────────────────────────────────────┐}|
  10150          {5:│}{1:                                        }{5:│}|*4
  10151          {5:└────────────────────────────────────────┘}|
  10152        ]],
  10153          float_pos = { [4] = { 1001, 'SW', 1, 8, 0, true, 50, 1, 2, 0 } },
  10154          win_viewport = {
  10155            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10156            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10157          },
  10158        }
  10159      else
  10160        screen:expect {
  10161          grid = [[
  10162          ^                                        |
  10163          {0:~                                       }|
  10164          {5:┌──────────────────────────────────────┐}|
  10165          {5:│}{1:                                      }{5:│}|*4
  10166          {5:└──────────────────────────────────────┘}|
  10167                                                  |
  10168        ]],
  10169        }
  10170      end
  10171 
  10172      exec_lua(
  10173        [[
  10174        -- echo prompt is blocking, so schedule
  10175        local win = ...
  10176        vim.schedule(function()
  10177          vim.api.nvim_win_set_height(win, 2)
  10178          vim.api.nvim_echo({ { "\n" } }, false, {})
  10179        end)
  10180      ]],
  10181        win
  10182      )
  10183 
  10184      if multigrid then
  10185        screen:expect {
  10186          grid = [[
  10187        ## grid 1
  10188          [2:----------------------------------------]|*7
  10189          [3:----------------------------------------]|*2
  10190        ## grid 2
  10191                                                  |
  10192          {0:~                                       }|*7
  10193        ## grid 3
  10194                                                  |
  10195          {8:Press ENTER or type command to continue}^ |
  10196        ## grid 4
  10197          {5:┌────────────────────────────────────────┐}|
  10198          {5:│}{1:                                        }{5:│}|*4
  10199          {5:└────────────────────────────────────────┘}|
  10200        ]],
  10201          float_pos = { [4] = { 1001, 'SW', 1, 8, 0, true, 50, 1, 4, 0 } },
  10202          win_viewport = {
  10203            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10204            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10205          },
  10206        }
  10207      else
  10208        screen:expect {
  10209          grid = [[
  10210                                                  |
  10211          {0:~                                       }|
  10212          {5:┌──────────────────────────────────────┐}|
  10213          {5:│}{1:                                      }{5:│}|*3
  10214          {4:                                        }|
  10215                                                  |
  10216          {8:Press ENTER or type command to continue}^ |
  10217        ]],
  10218        }
  10219      end
  10220 
  10221      feed('<cr>')
  10222      if multigrid then
  10223        screen:expect {
  10224          grid = [[
  10225        ## grid 1
  10226          [2:----------------------------------------]|*8
  10227          [3:----------------------------------------]|
  10228        ## grid 2
  10229          ^                                        |
  10230          {0:~                                       }|*7
  10231        ## grid 3
  10232                                                  |
  10233        ## grid 4
  10234          {5:┌────────────────────────────────────────┐}|
  10235          {5:│}{1:                                        }{5:│}|*2
  10236          {5:└────────────────────────────────────────┘}|
  10237        ]],
  10238          float_pos = { [4] = { 1001, 'SW', 1, 8, 0, true, 50, 1, 4, 0 } },
  10239          win_viewport = {
  10240            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10241            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10242          },
  10243        }
  10244      else
  10245        screen:expect {
  10246          grid = [[
  10247          ^                                        |
  10248          {0:~                                       }|*3
  10249          {5:┌──────────────────────────────────────┐}|
  10250          {5:│}{1:                                      }{5:│}|*2
  10251          {5:└──────────────────────────────────────┘}|
  10252                                                  |
  10253        ]],
  10254        }
  10255      end
  10256 
  10257      api.nvim_win_close(win, true)
  10258      if multigrid then
  10259        screen:expect {
  10260          grid = [[
  10261        ## grid 1
  10262          [2:----------------------------------------]|*8
  10263          [3:----------------------------------------]|
  10264        ## grid 2
  10265          ^                                        |
  10266          {0:~                                       }|*7
  10267        ## grid 3
  10268                                                  |
  10269        ]],
  10270          win_viewport = {
  10271            [2] = { win = 1000, 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:~                                       }|*7
  10279                                                  |
  10280        ]],
  10281        }
  10282      end
  10283    end)
  10284 
  10285    describe('no crash after moving and closing float window #21547', function()
  10286      local function test_float_move_close(cmd)
  10287        local float_opts = { relative = 'editor', row = 1, col = 1, width = 10, height = 10 }
  10288        api.nvim_open_win(api.nvim_create_buf(false, false), true, float_opts)
  10289        if multigrid then
  10290          screen:expect({ float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 0, 1 } } })
  10291        end
  10292        command(cmd)
  10293        exec_lua([[
  10294          vim.api.nvim_win_set_config(0, {relative = 'editor', row = 2, col = 2})
  10295          vim.api.nvim_win_close(0, {})
  10296          vim.api.nvim_echo({{''}}, false, {})
  10297        ]])
  10298        if multigrid then
  10299          screen:expect({ float_pos = {} })
  10300        end
  10301        assert_alive()
  10302      end
  10303 
  10304      it('if WinClosed autocommand flushes UI', function()
  10305        test_float_move_close('autocmd WinClosed * ++once redraw')
  10306      end)
  10307 
  10308      it('if closing buffer flushes UI', function()
  10309        test_float_move_close('autocmd BufWinLeave * ++once redraw')
  10310      end)
  10311    end)
  10312 
  10313    it(':sleep cursor placement #22639', function()
  10314      local float_opts = { relative = 'editor', row = 1, col = 1, width = 4, height = 3 }
  10315      local win = api.nvim_open_win(api.nvim_create_buf(false, false), true, float_opts)
  10316      feed('iab<CR>cd<Esc>')
  10317      feed(':sleep 100')
  10318      if multigrid then
  10319        screen:expect {
  10320          grid = [[
  10321        ## grid 1
  10322          [2:----------------------------------------]|*6
  10323          [3:----------------------------------------]|
  10324        ## grid 2
  10325                                                  |
  10326          {0:~                                       }|*5
  10327        ## grid 3
  10328          :sleep 100^                              |
  10329        ## grid 4
  10330          {1:ab  }|
  10331          {1:cd  }|
  10332          {2:~   }|
  10333        ]],
  10334          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
  10335          win_viewport = {
  10336            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10337            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0 },
  10338          },
  10339        }
  10340      else
  10341        screen:expect {
  10342          grid = [[
  10343                                                  |
  10344          {0:~}{1:ab  }{0:                                   }|
  10345          {0:~}{1:cd  }{0:                                   }|
  10346          {0:~}{2:~   }{0:                                   }|
  10347          {0:~                                       }|*2
  10348          :sleep 100^                              |
  10349        ]],
  10350        }
  10351      end
  10352 
  10353      feed('<CR>')
  10354      if multigrid then
  10355        screen:expect {
  10356          grid = [[
  10357        ## grid 1
  10358          [2:----------------------------------------]|*6
  10359          [3:----------------------------------------]|
  10360        ## grid 2
  10361                                                  |
  10362          {0:~                                       }|*5
  10363        ## grid 3
  10364          :sleep 100                              |
  10365        ## grid 4
  10366          {1:ab  }|
  10367          {1:c^d  }|
  10368          {2:~   }|
  10369        ]],
  10370          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
  10371          win_viewport = {
  10372            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10373            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0 },
  10374          },
  10375        }
  10376      else
  10377        screen:expect {
  10378          grid = [[
  10379                                                  |
  10380          {0:~}{1:ab  }{0:                                   }|
  10381          {0:~}{1:c^d  }{0:                                   }|
  10382          {0:~}{2:~   }{0:                                   }|
  10383          {0:~                                       }|*2
  10384          :sleep 100                              |
  10385        ]],
  10386        }
  10387      end
  10388      feed('<C-C>')
  10389      screen:expect_unchanged()
  10390 
  10391      api.nvim_win_set_config(win, { border = 'single' })
  10392      feed(':sleep 100')
  10393      if multigrid then
  10394        screen:expect {
  10395          grid = [[
  10396        ## grid 1
  10397          [2:----------------------------------------]|*6
  10398          [3:----------------------------------------]|
  10399        ## grid 2
  10400                                                  |
  10401          {0:~                                       }|*5
  10402        ## grid 3
  10403          :sleep 100^                              |
  10404        ## grid 4
  10405          {5:┌────┐}|
  10406          {5:│}{1:ab  }{5:│}|
  10407          {5:│}{1:cd  }{5:│}|
  10408          {5:│}{2:~   }{5:│}|
  10409          {5:└────┘}|
  10410        ]],
  10411          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
  10412          win_viewport = {
  10413            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10414            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0 },
  10415          },
  10416        }
  10417      else
  10418        screen:expect {
  10419          grid = [[
  10420                                                  |
  10421          {0:~}{5:┌────┐}{0:                                 }|
  10422          {0:~}{5:│}{1:ab  }{5:│}{0:                                 }|
  10423          {0:~}{5:│}{1:cd  }{5:│}{0:                                 }|
  10424          {0:~}{5:│}{2:~   }{5:│}{0:                                 }|
  10425          {0:~}{5:└────┘}{0:                                 }|
  10426          :sleep 100^                              |
  10427        ]],
  10428        }
  10429      end
  10430 
  10431      feed('<CR>')
  10432      if multigrid then
  10433        screen:expect {
  10434          grid = [[
  10435        ## grid 1
  10436          [2:----------------------------------------]|*6
  10437          [3:----------------------------------------]|
  10438        ## grid 2
  10439                                                  |
  10440          {0:~                                       }|*5
  10441        ## grid 3
  10442          :sleep 100                              |
  10443        ## grid 4
  10444          {5:┌────┐}|
  10445          {5:│}{1:ab  }{5:│}|
  10446          {5:│}{1:c^d  }{5:│}|
  10447          {5:│}{2:~   }{5:│}|
  10448          {5:└────┘}|
  10449        ]],
  10450          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
  10451          win_viewport = {
  10452            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10453            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0 },
  10454          },
  10455        }
  10456      else
  10457        screen:expect {
  10458          grid = [[
  10459                                                  |
  10460          {0:~}{5:┌────┐}{0:                                 }|
  10461          {0:~}{5:│}{1:ab  }{5:│}{0:                                 }|
  10462          {0:~}{5:│}{1:c^d  }{5:│}{0:                                 }|
  10463          {0:~}{5:│}{2:~   }{5:│}{0:                                 }|
  10464          {0:~}{5:└────┘}{0:                                 }|
  10465          :sleep 100                              |
  10466        ]],
  10467        }
  10468      end
  10469      feed('<C-C>')
  10470      screen:expect_unchanged()
  10471 
  10472      command('setlocal winbar=foo')
  10473      feed(':sleep 100')
  10474      if multigrid then
  10475        screen:expect {
  10476          grid = [[
  10477        ## grid 1
  10478          [2:----------------------------------------]|*6
  10479          [3:----------------------------------------]|
  10480        ## grid 2
  10481                                                  |
  10482          {0:~                                       }|*5
  10483        ## grid 3
  10484          :sleep 100^                              |
  10485        ## grid 4
  10486          {5:┌────┐}|
  10487          {5:│}{3:foo }{5:│}|
  10488          {5:│}{1:ab  }{5:│}|
  10489          {5:│}{1:cd  }{5:│}|
  10490          {5:└────┘}|
  10491        ]],
  10492          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
  10493          win_viewport = {
  10494            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10495            [4] = { win = 1001, topline = 0, botline = 2, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0 },
  10496          },
  10497        }
  10498      else
  10499        screen:expect {
  10500          grid = [[
  10501                                                  |
  10502          {0:~}{5:┌────┐}{0:                                 }|
  10503          {0:~}{5:│}{3:foo }{5:│}{0:                                 }|
  10504          {0:~}{5:│}{1:ab  }{5:│}{0:                                 }|
  10505          {0:~}{5:│}{1:cd  }{5:│}{0:                                 }|
  10506          {0:~}{5:└────┘}{0:                                 }|
  10507          :sleep 100^                              |
  10508        ]],
  10509        }
  10510      end
  10511 
  10512      feed('<CR>')
  10513      if multigrid then
  10514        screen:expect {
  10515          grid = [[
  10516        ## grid 1
  10517          [2:----------------------------------------]|*6
  10518          [3:----------------------------------------]|
  10519        ## grid 2
  10520                                                  |
  10521          {0:~                                       }|*5
  10522        ## grid 3
  10523          :sleep 100                              |
  10524        ## grid 4
  10525          {5:┌────┐}|
  10526          {5:│}{3:foo }{5:│}|
  10527          {5:│}{1:ab  }{5:│}|
  10528          {5:│}{1:c^d  }{5:│}|
  10529          {5:└────┘}|
  10530        ]],
  10531          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
  10532          win_viewport = {
  10533            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10534            [4] = { win = 1001, topline = 0, botline = 2, curline = 1, curcol = 1, linecount = 2, sum_scroll_delta = 0 },
  10535          },
  10536        }
  10537      else
  10538        screen:expect {
  10539          grid = [[
  10540                                                  |
  10541          {0:~}{5:┌────┐}{0:                                 }|
  10542          {0:~}{5:│}{3:foo }{5:│}{0:                                 }|
  10543          {0:~}{5:│}{1:ab  }{5:│}{0:                                 }|
  10544          {0:~}{5:│}{1:c^d  }{5:│}{0:                                 }|
  10545          {0:~}{5:└────┘}{0:                                 }|
  10546          :sleep 100                              |
  10547        ]],
  10548        }
  10549      end
  10550      feed('<C-C>')
  10551      screen:expect_unchanged()
  10552    end)
  10553 
  10554    it('with rightleft and border #22640', function()
  10555      local float_opts = { relative = 'editor', width = 5, height = 3, row = 1, col = 1, border = 'single' }
  10556      api.nvim_open_win(api.nvim_create_buf(false, false), true, float_opts)
  10557      command('setlocal rightleft')
  10558      feed('iabc<CR>def<Esc>')
  10559      if multigrid then
  10560        screen:expect {
  10561          grid = [[
  10562        ## grid 1
  10563          [2:----------------------------------------]|*6
  10564          [3:----------------------------------------]|
  10565        ## grid 2
  10566                                                  |
  10567          {0:~                                       }|*5
  10568        ## grid 3
  10569                                                  |
  10570        ## grid 4
  10571          {5:┌─────┐}|
  10572          {5:│}{1:  cba}{5:│}|
  10573          {5:│}{1:  ^fed}{5:│}|
  10574          {5:│}{2:    ~}{5:│}|
  10575          {5:└─────┘}|
  10576        ]],
  10577          float_pos = { [4] = { 1001, 'NW', 1, 1, 1, true, 50, 1, 1, 1 } },
  10578          win_viewport = {
  10579            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10580            [4] = { win = 1001, topline = 0, botline = 3, curline = 1, curcol = 2, linecount = 2, sum_scroll_delta = 0 },
  10581          },
  10582        }
  10583      else
  10584        screen:expect {
  10585          grid = [[
  10586                                                  |
  10587          {0:~}{5:┌─────┐}{0:                                }|
  10588          {0:~}{5:│}{1:  cba}{5:│}{0:                                }|
  10589          {0:~}{5:│}{1:  ^fed}{5:│}{0:                                }|
  10590          {0:~}{5:│}{2:    ~}{5:│}{0:                                }|
  10591          {0:~}{5:└─────┘}{0:                                }|
  10592                                                  |
  10593        ]],
  10594        }
  10595      end
  10596    end)
  10597 
  10598    it('float window with hide option', function()
  10599      local cwin = api.nvim_get_current_win()
  10600      local buf = api.nvim_create_buf(false, false)
  10601      local win = api.nvim_open_win(buf, false, { relative = 'editor', width = 10, height = 2, row = 2, col = 5, hide = true })
  10602      local expected_pos = {
  10603        [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 },
  10604      }
  10605 
  10606      if multigrid then
  10607        screen:expect {
  10608          grid = [[
  10609        ## grid 1
  10610          [2:----------------------------------------]|*6
  10611          [3:----------------------------------------]|
  10612        ## grid 2
  10613          ^                                        |
  10614          {0:~                                       }|*5
  10615        ## grid 3
  10616                                                  |
  10617 
  10618        ## grid 4 (hidden)
  10619          {1:          }|
  10620          {2:~         }|
  10621        ]],
  10622          float_pos = {},
  10623        }
  10624      else
  10625        screen:expect([[
  10626          ^                                        |
  10627          {0:~                                       }|*5
  10628                                                  |
  10629        ]])
  10630      end
  10631 
  10632      api.nvim_win_set_config(win, { hide = false })
  10633      if multigrid then
  10634        screen:expect {
  10635          grid = [[
  10636        ## grid 1
  10637          [2:----------------------------------------]|*6
  10638          [3:----------------------------------------]|
  10639        ## grid 2
  10640          ^                                        |
  10641          {0:~                                       }|*5
  10642        ## grid 3
  10643                                                  |
  10644 
  10645        ## grid 4
  10646          {1:          }|
  10647          {2:~         }|
  10648        ]],
  10649          float_pos = expected_pos,
  10650        }
  10651      else
  10652        screen:expect([[
  10653          ^                                        |
  10654          {0:~                                       }|
  10655          {0:~    }{1:          }{0:                         }|
  10656          {0:~    }{2:~         }{0:                         }|
  10657          {0:~                                       }|*2
  10658                                                  |
  10659        ]])
  10660      end
  10661 
  10662      api.nvim_win_set_config(win, { hide = true })
  10663      if multigrid then
  10664        screen:expect {
  10665          grid = [[
  10666        ## grid 1
  10667          [2:----------------------------------------]|*6
  10668          [3:----------------------------------------]|
  10669        ## grid 2
  10670          ^                                        |
  10671          {0:~                                       }|*5
  10672        ## grid 3
  10673                                                  |
  10674 
  10675        ## grid 4 (hidden)
  10676          {1:          }|
  10677          {2:~         }|
  10678        ]],
  10679          float_pos = {},
  10680        }
  10681      else
  10682        screen:expect([[
  10683          ^                                        |
  10684          {0:~                                       }|*5
  10685                                                  |
  10686        ]])
  10687      end
  10688 
  10689      --
  10690      -- Cursor visibility:
  10691      --
  10692      -- Cursor is not visible in a hide=true floating window.
  10693      api.nvim_set_current_win(win)
  10694      if multigrid then
  10695        screen:expect({
  10696          grid = [[
  10697          ## grid 1
  10698            [2:----------------------------------------]|*6
  10699            [3:----------------------------------------]|
  10700          ## grid 2
  10701                                                    |
  10702            {0:~                                       }|*5
  10703          ## grid 3
  10704                                                    |
  10705          ## grid 4 (hidden)
  10706            {1:          }|
  10707            {2:~         }|
  10708          ]],
  10709          win_viewport = {
  10710            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10711            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10712          },
  10713          win_viewport_margins = {
  10714            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
  10715            [4] = { bottom = 0, left = 0, right = 0, top = 0, win = 1001 },
  10716          },
  10717        })
  10718      else
  10719        screen:expect({
  10720          grid = [[
  10721                                                    |
  10722            {0:~                                       }|*5
  10723                                                    |
  10724          ]],
  10725        })
  10726      end
  10727 
  10728      -- Show cursor if cmdline is entered while curwin is a hide=true floating window.
  10729      feed(':')
  10730      if multigrid then
  10731        screen:expect({
  10732          grid = [[
  10733          ## grid 1
  10734            [2:----------------------------------------]|*6
  10735            [3:----------------------------------------]|
  10736          ## grid 2
  10737                                                    |
  10738            {0:~                                       }|*5
  10739          ## grid 3
  10740            :^                                       |
  10741          ## grid 4 (hidden)
  10742            {1:          }|
  10743            {2:~         }|
  10744          ]],
  10745          win_viewport = {
  10746            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10747            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10748          },
  10749          win_viewport_margins = {
  10750            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
  10751            [4] = { bottom = 0, left = 0, right = 0, top = 0, win = 1001 },
  10752          },
  10753        })
  10754      else
  10755        screen:expect({
  10756          grid = [[
  10757                                                    |
  10758            {0:~                                       }|*5
  10759            :^                                       |
  10760          ]],
  10761        })
  10762      end
  10763 
  10764      command('set keymap=dvorak')
  10765      feed('<C-^>')
  10766      screen:expect_unchanged()
  10767 
  10768      feed('<C-^>')
  10769      command('set keymap&')
  10770      screen:expect_unchanged()
  10771 
  10772      feed('<ESC>')
  10773 
  10774      -- Show cursor after switching to a normal window (hide=false).
  10775      api.nvim_set_current_win(cwin)
  10776      if multigrid then
  10777        screen:expect({
  10778          grid = [[
  10779          ## grid 1
  10780            [2:----------------------------------------]|*6
  10781            [3:----------------------------------------]|
  10782          ## grid 2
  10783            ^                                        |
  10784            {0:~                                       }|*5
  10785          ## grid 3
  10786                                                    |
  10787          ## grid 4 (hidden)
  10788            {1:          }|
  10789            {2:~         }|
  10790          ]],
  10791          win_viewport = {
  10792            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10793            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10794          },
  10795          win_viewport_margins = {
  10796            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
  10797            [4] = { bottom = 0, left = 0, right = 0, top = 0, win = 1001 },
  10798          },
  10799        })
  10800      else
  10801        screen:expect({
  10802          grid = [[
  10803            ^                                        |
  10804            {0:~                                       }|*5
  10805                                                    |
  10806          ]],
  10807        })
  10808      end
  10809      api.nvim_set_current_win(win)
  10810      local win1 = api.nvim_open_win(buf, false, { relative = 'editor', width = 4, height = 4, row = 1, col = 2 })
  10811      api.nvim_set_current_win(win1)
  10812      if multigrid then
  10813        screen:expect({
  10814          grid = [[
  10815        ## grid 1
  10816          [2:----------------------------------------]|*6
  10817          [3:----------------------------------------]|
  10818        ## grid 2
  10819                                                  |
  10820          {0:~                                       }|*5
  10821        ## grid 3
  10822                                                  |
  10823        ## grid 4 (hidden)
  10824          {1:          }|
  10825          {2:~         }|
  10826        ## grid 5
  10827          {1:^    }|
  10828          {2:~   }|*3
  10829        ]],
  10830          float_pos = { [5] = { 1002, 'NW', 1, 1, 2, true, 50, 1, 1, 2 } },
  10831          win_viewport = {
  10832            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10833            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10834            [5] = { win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  10835          },
  10836          win_viewport_margins = {
  10837            [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
  10838            [4] = { bottom = 0, left = 0, right = 0, top = 0, win = 1001 },
  10839            [5] = { bottom = 0, left = 0, right = 0, top = 0, win = 1002 },
  10840          },
  10841        })
  10842      else
  10843        screen:expect({
  10844          grid = [[
  10845                                                    |
  10846            {0:~ }{1:^    }{0:                                  }|
  10847            {0:~ }{2:~   }{0:                                  }|*3
  10848            {0:~                                       }|
  10849                                                    |
  10850          ]],
  10851        })
  10852      end
  10853      api.nvim_win_close(win1, true)
  10854 
  10855      -- check window jump with hide
  10856      feed('<C-W><C-W>')
  10857      -- should keep on current window
  10858      eq(cwin, api.nvim_get_current_win())
  10859      api.nvim_win_set_config(win, { hide = false })
  10860      api.nvim_set_current_win(win)
  10861      local win3 = api.nvim_open_win(buf, true, { relative = 'editor', width = 4, height = 4, row = 2, col = 5, hide = false })
  10862      api.nvim_win_set_config(win, { hide = true })
  10863      feed('<C-W>w')
  10864      -- should goto the first window with prev
  10865      eq(cwin, api.nvim_get_current_win())
  10866      -- windo
  10867      command('windo set winheight=6')
  10868      eq(win3, api.nvim_get_current_win())
  10869      eq(6, api.nvim_win_get_height(win3))
  10870      eq(2, api.nvim_win_get_height(win))
  10871    end)
  10872 
  10873    it(':fclose command #9663', function()
  10874      local buf_a = api.nvim_create_buf(false, false)
  10875      local buf_b = api.nvim_create_buf(false, false)
  10876      local buf_c = api.nvim_create_buf(false, false)
  10877      local buf_d = api.nvim_create_buf(false, false)
  10878      local config_a = { relative = 'editor', width = 11, height = 11, row = 5, col = 5, border = 'single', zindex = 50 }
  10879      local config_b = { relative = 'editor', width = 8, height = 8, row = 7, col = 7, border = 'single', zindex = 70 }
  10880      local config_c = { relative = 'editor', width = 4, height = 4, row = 9, col = 9, border = 'single', zindex = 90 }
  10881      local config_d = { relative = 'editor', width = 2, height = 2, row = 10, col = 10, border = 'single', zindex = 100 }
  10882      api.nvim_open_win(buf_a, false, config_a)
  10883      api.nvim_open_win(buf_b, false, config_b)
  10884      api.nvim_open_win(buf_c, false, config_c)
  10885      api.nvim_open_win(buf_d, false, config_d)
  10886      local expected_pos = {
  10887        [4] = { 1001, 'NW', 1, 5, 5, true, 50, 1, 0, 5 },
  10888        [5] = { 1002, 'NW', 1, 7, 7, true, 70, 2, 0, 7 },
  10889        [6] = { 1003, 'NW', 1, 9, 9, true, 90, 3, 0, 9 },
  10890        [7] = { 1004, 'NW', 1, 10, 10, true, 100, 4, 2, 10 },
  10891      }
  10892      if multigrid then
  10893        screen:expect {
  10894          grid = [[
  10895        ## grid 1
  10896          [2:----------------------------------------]|*6
  10897          [3:----------------------------------------]|
  10898        ## grid 2
  10899          ^                                        |
  10900          {0:~                                       }|*5
  10901        ## grid 3
  10902                                                  |
  10903        ## grid 4
  10904          {5:┌───────────┐}|
  10905          {5:│}{1:           }{5:│}|
  10906          {5:│}{2:~          }{5:│}|*10
  10907          {5:└───────────┘}|
  10908        ## grid 5
  10909          {5:┌────────┐}|
  10910          {5:│}{1:        }{5:│}|
  10911          {5:│}{2:~       }{5:│}|*7
  10912          {5:└────────┘}|
  10913        ## grid 6
  10914          {5:┌────┐}|
  10915          {5:│}{1:    }{5:│}|
  10916          {5:│}{2:~   }{5:│}|*3
  10917          {5:└────┘}|
  10918        ## grid 7
  10919          {5:┌──┐}|
  10920          {5:│}{1:  }{5:│}|
  10921          {5:│}{2:~ }{5:│}|
  10922          {5:└──┘}|
  10923        ]],
  10924          float_pos = expected_pos,
  10925        }
  10926      else
  10927        screen:expect([[
  10928          ^     {5:┌─┌─┌────┐─┐┐}                      |
  10929          {0:~    }{5:}{1: }{5:}{1: }{5:}{1:    }{5:}{1: }{5:││}{0:                      }|
  10930          {0:~    }{5:}{2:~}{5:}{2:~}{5:│┌──┐│}{2: }{5:││}{0:                      }|
  10931          {0:~    }{5:}{2:~}{5:}{2:~}{5:││}{1:  }{5:││}{2: }{5:││}{0:                      }|
  10932          {0:~    }{5:}{2:~}{5:}{2:~}{5:││}{2:~ }{5:││}{2: }{5:││}{0:                      }|
  10933          {0:~    }{5:└─└─└└──┘┘─┘┘}{0:                      }|
  10934                                                  |
  10935        ]])
  10936      end
  10937      -- close the window with the highest zindex value
  10938      command('fclose')
  10939      expected_pos[7] = nil
  10940      if multigrid then
  10941        screen:expect {
  10942          grid = [[
  10943        ## grid 1
  10944          [2:----------------------------------------]|*6
  10945          [3:----------------------------------------]|
  10946        ## grid 2
  10947          ^                                        |
  10948          {0:~                                       }|*5
  10949        ## grid 3
  10950                                                  |
  10951 
  10952        ## grid 4
  10953          {5:┌───────────┐}|
  10954          {5:│}{1:           }{5:│}|
  10955          {5:│}{2:~          }{5:│}|*10
  10956          {5:└───────────┘}|
  10957        ## grid 5
  10958          {5:┌────────┐}|
  10959          {5:│}{1:        }{5:│}|
  10960          {5:│}{2:~       }{5:│}|*7
  10961          {5:└────────┘}|
  10962        ## grid 6
  10963          {5:┌────┐}|
  10964          {5:│}{1:    }{5:│}|
  10965          {5:│}{2:~   }{5:│}|*3
  10966          {5:└────┘}|
  10967        ]],
  10968          float_pos = expected_pos,
  10969        }
  10970      else
  10971        screen:expect([[
  10972          ^     {5:┌─┌─┌────┐─┐┐}                      |
  10973          {0:~    }{5:}{1: }{5:}{1: }{5:}{1:    }{5:}{1: }{5:││}{0:                      }|
  10974          {0:~    }{5:}{2:~}{5:}{2:~}{5:}{2:~   }{5:}{2: }{5:││}{0:                      }|*3
  10975          {0:~    }{5:└─└─└────┘─┘┘}{0:                      }|
  10976                                                  |
  10977        ]])
  10978      end
  10979      -- with range
  10980      command('1fclose')
  10981      expected_pos[6] = nil
  10982      if multigrid then
  10983        screen:expect {
  10984          grid = [[
  10985        ## grid 1
  10986          [2:----------------------------------------]|*6
  10987          [3:----------------------------------------]|
  10988        ## grid 2
  10989          ^                                        |
  10990          {0:~                                       }|*5
  10991        ## grid 3
  10992                                                  |
  10993 
  10994        ## grid 4
  10995          {5:┌───────────┐}|
  10996          {5:│}{1:           }{5:│}|
  10997          {5:│}{2:~          }{5:│}|*10
  10998          {5:└───────────┘}|
  10999        ## grid 5
  11000          {5:┌────────┐}|
  11001          {5:│}{1:        }{5:│}|
  11002          {5:│}{2:~       }{5:│}|*7
  11003          {5:└────────┘}|
  11004        ]],
  11005          float_pos = expected_pos,
  11006        }
  11007      else
  11008        screen:expect([[
  11009          ^     {5:┌─┌────────┐┐}                      |
  11010          {0:~    }{5:}{1: }{5:}{1:        }{5:││}{0:                      }|
  11011          {0:~    }{5:}{2:~}{5:}{2:~       }{5:││}{0:                      }|*3
  11012          {0:~    }{5:└─└────────┘┘}{0:                      }|
  11013                                                  |
  11014        ]])
  11015      end
  11016      -- with bang
  11017      command('fclose!')
  11018      if multigrid then
  11019        screen:expect {
  11020          grid = [[
  11021        ## grid 1
  11022          [2:----------------------------------------]|*6
  11023          [3:----------------------------------------]|
  11024        ## grid 2
  11025          ^                                        |
  11026          {0:~                                       }|*5
  11027        ## grid 3
  11028                                                  |
  11029 
  11030        ]],
  11031          float_pos = {},
  11032        }
  11033      else
  11034        screen:expect([[
  11035          ^                                        |
  11036          {0:~                                       }|*5
  11037                                                  |
  11038        ]])
  11039      end
  11040      -- allow use with trailing bar
  11041      eq('hello', n.exec_capture('fclose | echo "hello"'))
  11042    end)
  11043 
  11044    it('correctly placed in or above message area', function()
  11045      local float_opts = { relative = 'editor', width = 5, height = 1, row = 100, col = 1, border = 'single' }
  11046      api.nvim_set_option_value('cmdheight', 3, {})
  11047      command("echo 'cmdline'")
  11048      local win = api.nvim_open_win(api.nvim_create_buf(false, false), true, float_opts)
  11049      -- Not hidden behind message area but placed above it.
  11050      if multigrid then
  11051        screen:expect {
  11052          grid = [[
  11053          ## grid 1
  11054            [2:----------------------------------------]|*4
  11055            [3:----------------------------------------]|*3
  11056          ## grid 2
  11057                                                    |
  11058            {0:~                                       }|*3
  11059          ## grid 3
  11060            cmdline                                 |
  11061                                                    |*2
  11062          ## grid 4
  11063            {5:┌─────┐}|
  11064            {5:│}{1:^     }{5:│}|
  11065            {5:└─────┘}|
  11066          ]],
  11067          float_pos = { [4] = { 1001, 'NW', 1, 100, 1, true, 50, 1, 1, 1 } },
  11068          win_viewport = {
  11069            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  11070            [4] = { win = 1001, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  11071          },
  11072        }
  11073      else
  11074        screen:expect {
  11075          grid = [[
  11076                                                  |
  11077          {0:~}{5:┌─────┐}{0:                                }|
  11078          {0:~}{5:│}{1:^     }{5:│}{0:                                }|
  11079          {0:~}{5:└─────┘}{0:                                }|
  11080          cmdline                                 |
  11081                                                  |*2
  11082        ]],
  11083        }
  11084      end
  11085      -- Not placed above message area and visible on top of it.
  11086      api.nvim_win_set_config(win, { zindex = 300 })
  11087      if multigrid then
  11088        screen:expect {
  11089          grid = [[
  11090        ## grid 1
  11091          [2:----------------------------------------]|*4
  11092          [3:----------------------------------------]|*3
  11093        ## grid 2
  11094                                                  |
  11095          {0:~                                       }|*3
  11096        ## grid 3
  11097          cmdline                                 |
  11098                                                  |*2
  11099        ## grid 4
  11100          {5:┌─────┐}|
  11101          {5:│}{1:^     }{5:│}|
  11102          {5:└─────┘}|
  11103        ]],
  11104          float_pos = { [4] = { 1001, 'NW', 1, 100, 1, true, 300, 2, 4, 1 } },
  11105          win_viewport = {
  11106            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  11107            [4] = { win = 1001, topline = 0, botline = 1, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  11108          },
  11109        }
  11110      else
  11111        screen:expect {
  11112          grid = [[
  11113                                                  |
  11114          {0:~                                       }|*3
  11115          c{5:┌─────┐}                                |
  11116           {5:│}{1:^     }{5:│}                                |
  11117           {5:└─────┘}                                |
  11118        ]],
  11119        }
  11120      end
  11121    end)
  11122 
  11123    it('attempt to turn into split with no room', function()
  11124      eq('Vim(split):E36: Not enough room', pcall_err(command, 'execute "split |"->repeat(&lines)'))
  11125      command('vsplit | wincmd | | wincmd p')
  11126      api.nvim_open_win(0, true, { relative = 'editor', row = 0, col = 0, width = 5, height = 5 })
  11127      local config = api.nvim_win_get_config(0)
  11128      eq('editor', config.relative)
  11129 
  11130      local layout = fn.winlayout()
  11131      local restcmd = fn.winrestcmd()
  11132      eq('Vim(wincmd):E36: Not enough room', pcall_err(command, 'wincmd K'))
  11133      eq('Vim(wincmd):E36: Not enough room', pcall_err(command, 'wincmd J'))
  11134      eq(layout, fn.winlayout())
  11135      eq(restcmd, fn.winrestcmd())
  11136      eq(config, api.nvim_win_get_config(0))
  11137    end)
  11138 
  11139    it('error when relative to itself', function()
  11140      local buf = api.nvim_create_buf(false, true)
  11141      local config = { relative = 'win', width = 5, height = 2, row = 3, col = 3 }
  11142      local winid = api.nvim_open_win(buf, false, config)
  11143      api.nvim_set_current_win(winid)
  11144      eq('floating window cannot be relative to itself', pcall_err(api.nvim_win_set_config, winid, config))
  11145    end)
  11146 
  11147    it('bufpos out of range', function()
  11148      local buf = api.nvim_create_buf(false, true)
  11149      api.nvim_buf_set_lines(0, 0, -1, false, {})
  11150      local config = { relative = 'win', width = 5, height = 2, row = 0, col = 0, bufpos = { 3, 3 } }
  11151      api.nvim_open_win(buf, false, config)
  11152      if multigrid then
  11153        screen:expect({
  11154          grid = [[
  11155          ## grid 1
  11156            [2:----------------------------------------]|*6
  11157            [3:----------------------------------------]|
  11158          ## grid 2
  11159            ^                                        |
  11160            {0:~                                       }|*5
  11161          ## grid 3
  11162                                                    |
  11163          ## grid 4
  11164            {1:     }|
  11165            {2:~    }|
  11166          ]],
  11167          float_pos = { [4] = { 1001, 'NW', 2, 0, 0, true, 50, 1, 0, 0 } },
  11168          win_viewport = {
  11169            [2] = { win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  11170            [4] = { win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0 },
  11171          },
  11172        })
  11173      else
  11174        screen:expect({
  11175          grid = [[
  11176            {1:^     }                                   |
  11177            {2:~    }{0:                                   }|
  11178            {0:~                                       }|*4
  11179                                                    |
  11180          ]],
  11181        })
  11182      end
  11183    end)
  11184 
  11185    it("1-line float does not inherit 'winbar' #19464", function()
  11186      local res = exec_lua([[
  11187        local win = vim.api.nvim_get_current_win()
  11188        vim.wo[win].winbar = '%f'
  11189        local grp = vim.api.nvim_create_augroup('asdf', { clear = true })
  11190        vim.api.nvim_create_autocmd('WinEnter', {
  11191          group = grp,
  11192          pattern = '*',
  11193          desc = 'winbar crash?',
  11194          callback = function()
  11195            vim.wo[win].winbar = '%f'
  11196          end,
  11197        })
  11198 
  11199        local buf = vim.api.nvim_create_buf(false, true)
  11200        local float_winid = vim.api.nvim_open_win(buf, true, {
  11201          relative = 'win',
  11202          win = win,
  11203          border = 'single',
  11204          col = 1,
  11205          row = 1,
  11206          height = 1,
  11207          width = 40,
  11208        })
  11209        return {vim.wo[win].winbar, vim.wo[float_winid].winbar}
  11210      ]])
  11211      eq({ '%f', '' }, res)
  11212    end)
  11213 
  11214    it('winborder option', function()
  11215      local buf = api.nvim_create_buf(false, false)
  11216      local config = { relative = 'editor', width = 4, height = 4, row = 2, col = 2 }
  11217      command('set winborder=single')
  11218      local winid = api.nvim_open_win(buf, true, config)
  11219      eq('┌', api.nvim_win_get_config(winid).border[1])
  11220      command('fclose')
  11221 
  11222      command('set winborder=double')
  11223      winid = api.nvim_open_win(buf, true, config)
  11224      eq('╔', api.nvim_win_get_config(winid).border[1])
  11225      command('fclose!')
  11226 
  11227      command('set winborder=none')
  11228      winid = api.nvim_open_win(buf, true, config)
  11229      eq('none', api.nvim_win_get_config(winid).border)
  11230      command('fclose!')
  11231 
  11232      -- respect config.border
  11233      command('set winborder=rounded')
  11234      config.border = 'single'
  11235      winid = api.nvim_open_win(buf, false, config)
  11236      eq('┌', api.nvim_win_get_config(winid).border[1])
  11237 
  11238      -- don't use winborder when reconfig a floating window
  11239      -- still show a single border
  11240      config.border = nil
  11241      api.nvim_win_set_config(winid, config)
  11242      eq('┌', api.nvim_win_get_config(winid).border[1])
  11243      command('fclose!')
  11244 
  11245      command('set winborder=bold')
  11246      winid = api.nvim_open_win(buf, false, config)
  11247      eq('┏', api.nvim_win_get_config(winid).border[1])
  11248 
  11249      command([[set winborder=+,-,+,\|,+,-,+,\|]])
  11250      winid = api.nvim_open_win(buf, false, config)
  11251      eq('+', api.nvim_win_get_config(winid).border[1])
  11252 
  11253      command([[set winborder=,,,,,,,]])
  11254      winid = api.nvim_open_win(buf, false, config)
  11255      eq('●', api.nvim_win_get_config(winid).border[1])
  11256 
  11257      eq('Vim(set):E474: Invalid argument: winborder=,,', pcall_err(command, 'set winborder=,,'))
  11258      eq('Vim(set):E474: Invalid argument: winborder=+,-,+,|,+,-,+,', pcall_err(command, [[set winborder=+,-,+,\|,+,-,+,]]))
  11259      eq('Vim(set):E474: Invalid argument: winborder=custom', pcall_err(command, 'set winborder=custom'))
  11260    end)
  11261 
  11262    it('cursor shape when the cursor is covered by a floating window', function()
  11263      local normal_win = api.nvim_get_current_win()
  11264      api.nvim_buf_set_lines(0, 0, -1, true, { 'one', 'two' })
  11265      api.nvim_win_set_cursor(0, { 2, 2 })
  11266      local buf = api.nvim_create_buf(false, false)
  11267      api.nvim_buf_set_lines(buf, 0, 0, true, { 'the only line' })
  11268      local win = api.nvim_open_win(buf, false, { relative = 'editor', row = 0, col = 0, height = 2, width = 20 })
  11269      if multigrid then
  11270        screen:expect({
  11271          grid = [[
  11272          ## grid 1
  11273            [2:----------------------------------------]|*6
  11274            [3:----------------------------------------]|
  11275          ## grid 2
  11276            one                                     |
  11277            tw^o                                     |
  11278            {0:~                                       }|*4
  11279          ## grid 3
  11280                                                    |
  11281          ## grid 4
  11282            {1:the only line       }|
  11283            {1:                    }|
  11284          ]],
  11285          win_pos = {
  11286            [2] = { height = 6, startcol = 0, startrow = 0, width = 40, win = 1000 },
  11287          },
  11288          float_pos = {
  11289            [4] = { 1001, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
  11290          },
  11291          mode = 'normal',
  11292        })
  11293      else
  11294        screen:expect {
  11295          grid = [[
  11296          {1:the only line       }                    |
  11297          {1:  ^                  }                    |
  11298          {0:~                                       }|*4
  11299                                                  |
  11300        ]],
  11301          mode = 'replace',
  11302        }
  11303      end
  11304      api.nvim_buf_set_lines(0, 0, -1, true, { 'one', 'two', 'three' })
  11305      feed('<Down>')
  11306      if multigrid then
  11307        screen:expect({
  11308          grid = [[
  11309          ## grid 1
  11310            [2:----------------------------------------]|*6
  11311            [3:----------------------------------------]|
  11312          ## grid 2
  11313            one                                     |
  11314            two                                     |
  11315            th^ree                                   |
  11316            {0:~                                       }|*3
  11317          ## grid 3
  11318                                                    |
  11319          ## grid 4
  11320            {1:the only line       }|
  11321            {1:                    }|
  11322          ]],
  11323          win_pos = {
  11324            [2] = { height = 6, startcol = 0, startrow = 0, width = 40, win = 1000 },
  11325          },
  11326          float_pos = {
  11327            [4] = { 1001, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
  11328          },
  11329          mode = 'normal',
  11330        })
  11331      else
  11332        screen:expect { mode = 'normal' }
  11333      end
  11334      -- Cursor shape on a lower z-index floating window
  11335      buf = api.nvim_create_buf(false, false)
  11336      api.nvim_buf_set_lines(buf, 0, 0, true, { 'highest' })
  11337      local high_win = api.nvim_open_win(buf, false, { relative = 'editor', row = 0, col = 0, height = 2, width = 7, zindex = 150 })
  11338      api.nvim_set_current_win(win)
  11339      api.nvim_win_set_cursor(win, { 2, 1 })
  11340      if multigrid then
  11341        screen:expect({
  11342          grid = [[
  11343          ## grid 1
  11344            [2:----------------------------------------]|*6
  11345            [3:----------------------------------------]|
  11346          ## grid 2
  11347            one                                     |
  11348            two                                     |
  11349            three                                   |
  11350            {0:~                                       }|*3
  11351          ## grid 3
  11352                                                    |
  11353          ## grid 4
  11354            {1:the only line       }|
  11355            {1:^                    }|
  11356          ## grid 5
  11357            {1:highest}|
  11358            {1:       }|
  11359          ]],
  11360          win_pos = {
  11361            [2] = { height = 6, startcol = 0, startrow = 0, width = 40, win = 1000 },
  11362          },
  11363          float_pos = {
  11364            [5] = { 1002, 'NW', 1, 0, 0, true, 150, 2, 0, 0 },
  11365            [4] = { 1001, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
  11366          },
  11367          mode = 'normal',
  11368        })
  11369      else
  11370        screen:expect { mode = 'replace' }
  11371      end
  11372 
  11373      api.nvim_set_current_win(high_win)
  11374      if multigrid then
  11375        screen:expect({
  11376          grid = [[
  11377          ## grid 1
  11378            [2:----------------------------------------]|*6
  11379            [3:----------------------------------------]|
  11380          ## grid 2
  11381            one                                     |
  11382            two                                     |
  11383            three                                   |
  11384            {0:~                                       }|*3
  11385          ## grid 3
  11386                                                    |
  11387          ## grid 4
  11388            {1:the only line       }|
  11389            {1:                    }|
  11390          ## grid 5
  11391            {1:^highest}|
  11392            {1:       }|
  11393          ]],
  11394          win_pos = {
  11395            [2] = { height = 6, startcol = 0, startrow = 0, width = 40, win = 1000 },
  11396          },
  11397          float_pos = {
  11398            [5] = { 1002, 'NW', 1, 0, 0, true, 150, 2, 0, 0 },
  11399            [4] = { 1001, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
  11400          },
  11401          mode = 'normal',
  11402        })
  11403      else
  11404        screen:expect {
  11405          grid = [[
  11406          {1:^highesty line       }                    |
  11407          {1:                    }                    |
  11408          three                                   |
  11409          {0:~                                       }|*3
  11410                                                  |
  11411        ]],
  11412          mode = 'normal',
  11413        }
  11414      end
  11415 
  11416      buf = api.nvim_create_buf(false, false)
  11417      api.nvim_buf_set_lines(buf, 0, 0, true, { 'another' })
  11418      api.nvim_open_win(buf, true, { relative = 'editor', row = 0, col = 0, height = 2, width = 7, zindex = 160 })
  11419      if multigrid then
  11420        screen:expect({
  11421          grid = [[
  11422          ## grid 1
  11423            [2:----------------------------------------]|*6
  11424            [3:----------------------------------------]|
  11425          ## grid 2
  11426            one                                     |
  11427            two                                     |
  11428            three                                   |
  11429            {0:~                                       }|*3
  11430          ## grid 3
  11431                                                    |
  11432          ## grid 4
  11433            {1:the only line       }|
  11434            {1:                    }|
  11435          ## grid 5
  11436            {1:highest}|
  11437            {1:       }|
  11438          ## grid 6
  11439            {1:^another}|
  11440            {1:       }|
  11441          ]],
  11442          win_pos = {
  11443            [2] = { height = 6, startcol = 0, startrow = 0, width = 40, win = 1000 },
  11444          },
  11445          float_pos = {
  11446            [4] = { 1001, 'NW', 1, 0, 0, true, 50, 1, 0, 0 },
  11447            [5] = { 1002, 'NW', 1, 0, 0, true, 150, 2, 0, 0 },
  11448            [6] = { 1003, 'NW', 1, 0, 0, true, 160, 3, 0, 0 },
  11449          },
  11450          mode = 'normal',
  11451        })
  11452      else
  11453        screen:expect {
  11454          grid = [[
  11455          {1:^anothery line       }                    |
  11456          {1:                    }                    |
  11457          three                                   |
  11458          {0:~                                       }|*3
  11459                                                  |
  11460        ]],
  11461          mode = 'normal',
  11462        }
  11463      end
  11464      api.nvim_set_current_win(normal_win)
  11465      command('only')
  11466      screen:try_resize(50, 20)
  11467      buf = api.nvim_create_buf(false, false)
  11468      api.nvim_buf_set_lines(buf, 0, -1, true, { 'x' })
  11469      local float_win = api.nvim_open_win(buf, true, {
  11470        relative = 'editor',
  11471        width = 5,
  11472        height = 5,
  11473        row = 8,
  11474        col = 9,
  11475        border = 'single',
  11476        zindex = 1,
  11477      })
  11478      local buf2 = api.nvim_create_buf(false, false)
  11479      local float_win_above = api.nvim_open_win(buf2, false, {
  11480        relative = 'editor',
  11481        width = 10,
  11482        height = 10,
  11483        row = 0,
  11484        col = 0,
  11485        zindex = 2,
  11486      })
  11487      if multigrid then
  11488        screen:expect({
  11489          grid = [[
  11490          ## grid 1
  11491            [2:--------------------------------------------------]|*19
  11492            [3:--------------------------------------------------]|
  11493          ## grid 2
  11494            one                                               |
  11495            two                                               |
  11496            three                                             |
  11497            {0:~                                                 }|*16
  11498          ## grid 3
  11499                                                              |
  11500          ## grid 7
  11501            {5:┌─────┐}|
  11502            {5:│}{1:^x    }{5:│}|
  11503            {5:│}{2:~    }{5:│}|*4
  11504            {5:└─────┘}|
  11505          ## grid 8
  11506            {1:          }|
  11507            {2:~         }|*9
  11508          ]],
  11509          win_pos = {
  11510            [2] = { height = 19, startcol = 0, startrow = 0, width = 50, win = 1000 },
  11511          },
  11512          float_pos = {
  11513            [7] = { 1004, 'NW', 1, 8, 9, true, 1, 1, 8, 9 },
  11514            [8] = { 1005, 'NW', 1, 0, 0, true, 2, 2, 0, 0 },
  11515          },
  11516          mode = 'normal',
  11517        })
  11518      else
  11519        screen:expect {
  11520          grid = [[
  11521          {1:          }                                        |
  11522          {2:~         }                                        |*2
  11523          {2:~         }{0:                                        }|*5
  11524          {2:~         }{5:─────┐}{0:                                  }|
  11525          {2:~         }{1:^x    }{5:│}{0:                                  }|
  11526          {0:~        }{5:│}{2:~    }{5:│}{0:                                  }|*4
  11527          {0:~        }{5:└─────┘}{0:                                  }|
  11528          {0:~                                                 }|*4
  11529                                                            |
  11530        ]],
  11531          mode = 'normal',
  11532        }
  11533      end
  11534      -- Move window
  11535      api.nvim_win_set_config(float_win, { relative = 'editor', row = 9, col = 8 })
  11536      if multigrid then
  11537        screen:expect({
  11538          grid = [[
  11539          ## grid 1
  11540            [2:--------------------------------------------------]|*19
  11541            [3:--------------------------------------------------]|
  11542          ## grid 2
  11543            one                                               |
  11544            two                                               |
  11545            three                                             |
  11546            {0:~                                                 }|*16
  11547          ## grid 3
  11548                                                              |
  11549          ## grid 7
  11550            {5:┌─────┐}|
  11551            {5:│}{1:^x    }{5:│}|
  11552            {5:│}{2:~    }{5:│}|*4
  11553            {5:└─────┘}|
  11554          ## grid 8
  11555            {1:          }|
  11556            {2:~         }|*9
  11557          ]],
  11558          win_pos = {
  11559            [2] = { height = 19, startcol = 0, startrow = 0, width = 50, win = 1000 },
  11560          },
  11561          float_pos = {
  11562            [7] = { 1004, 'NW', 1, 9, 8, true, 1, 1, 9, 8 },
  11563            [8] = { 1005, 'NW', 1, 0, 0, true, 2, 2, 0, 0 },
  11564          },
  11565          mode = 'normal',
  11566        })
  11567      else
  11568        screen:expect {
  11569          grid = [[
  11570          {1:          }                                        |
  11571          {2:~         }                                        |*2
  11572          {2:~         }{0:                                        }|*6
  11573          {2:~         }{5:────┐}{0:                                   }|
  11574          {0:~       }{5:│}{1:^x    }{5:│}{0:                                   }|
  11575          {0:~       }{5:│}{2:~    }{5:│}{0:                                   }|*4
  11576          {0:~       }{5:└─────┘}{0:                                   }|
  11577          {0:~                                                 }|*3
  11578                                                            |
  11579        ]],
  11580          mode = 'normal',
  11581        }
  11582      end
  11583 
  11584      -- rightleft
  11585      api.nvim_win_set_config(float_win, { relative = 'editor', row = 8, col = 8 })
  11586      command('set rightleft')
  11587      if multigrid then
  11588        screen:expect({
  11589          grid = [[
  11590          ## grid 1
  11591            [2:--------------------------------------------------]|*19
  11592            [3:--------------------------------------------------]|
  11593          ## grid 2
  11594            one                                               |
  11595            two                                               |
  11596            three                                             |
  11597            {0:~                                                 }|*16
  11598          ## grid 3
  11599                                                              |
  11600          ## grid 7
  11601            {5:┌─────┐}|
  11602            {5:│}{1:    ^x}{5:│}|
  11603            {5:│}{2:    ~}{5:│}|*4
  11604            {5:└─────┘}|
  11605          ## grid 8
  11606            {1:          }|
  11607            {2:~         }|*9
  11608          ]],
  11609          win_pos = {
  11610            [2] = { height = 19, startcol = 0, startrow = 0, width = 50, win = 1000 },
  11611          },
  11612          float_pos = {
  11613            [7] = { 1004, 'NW', 1, 8, 8, true, 1, 1, 8, 8 },
  11614            [8] = { 1005, 'NW', 1, 0, 0, true, 2, 2, 0, 0 },
  11615          },
  11616          mode = 'normal',
  11617        })
  11618      else
  11619        screen:expect {
  11620          grid = [[
  11621          {1:          }                                        |
  11622          {2:~         }                                        |*2
  11623          {2:~         }{0:                                        }|*5
  11624          {2:~         }{5:────┐}{0:                                   }|
  11625          {2:~         }{1:   ^x}{5:│}{0:                                   }|
  11626          {0:~       }{5:│}{2:    ~}{5:│}{0:                                   }|*4
  11627          {0:~       }{5:└─────┘}{0:                                   }|
  11628          {0:~                                                 }|*4
  11629                                                            |
  11630        ]],
  11631          mode = 'normal',
  11632        }
  11633      end
  11634 
  11635      command('set virtualedit=all')
  11636      fn.setpos('.', { 0, 1, 1, 4 })
  11637      if multigrid then
  11638        screen:expect({
  11639          grid = [[
  11640          ## grid 1
  11641            [2:--------------------------------------------------]|*19
  11642            [3:--------------------------------------------------]|
  11643          ## grid 2
  11644            one                                               |
  11645            two                                               |
  11646            three                                             |
  11647            {0:~                                                 }|*16
  11648          ## grid 3
  11649                                                              |
  11650          ## grid 7
  11651            {5:┌─────┐}|
  11652            {5:│}{1:^    x}{5:│}|
  11653            {5:│}{2:    ~}{5:│}|*4
  11654            {5:└─────┘}|
  11655          ## grid 8
  11656            {1:          }|
  11657            {2:~         }|*9
  11658          ]],
  11659          win_pos = {
  11660            [2] = { height = 19, startcol = 0, startrow = 0, width = 50, win = 1000 },
  11661          },
  11662          float_pos = {
  11663            [7] = { 1004, 'NW', 1, 8, 8, true, 1, 1, 8, 8 },
  11664            [8] = { 1005, 'NW', 1, 0, 0, true, 2, 2, 0, 0 },
  11665          },
  11666          mode = 'normal',
  11667        })
  11668      else
  11669        screen:expect { mode = 'replace' }
  11670      end
  11671 
  11672      -- Not obscured by a hidden floatwin.
  11673      api.nvim_win_set_config(float_win_above, { hide = true })
  11674      if multigrid then
  11675        screen:expect({
  11676          grid = [[
  11677          ## grid 1
  11678            [2:--------------------------------------------------]|*19
  11679            [3:--------------------------------------------------]|
  11680          ## grid 2
  11681            one                                               |
  11682            two                                               |
  11683            three                                             |
  11684            {0:~                                                 }|*16
  11685          ## grid 3
  11686                                                              |
  11687          ## grid 7
  11688            {5:┌─────┐}|
  11689            {5:│}{1:^    x}{5:│}|
  11690            {5:│}{2:    ~}{5:│}|*4
  11691            {5:└─────┘}|
  11692          ## grid 8 (hidden)
  11693            {1:          }|
  11694            {2:~         }|*9
  11695          ]],
  11696          float_pos = {
  11697            [7] = { 1004, 'NW', 1, 8, 8, true, 1, 1, 8, 8 },
  11698          },
  11699          mode = 'normal',
  11700        })
  11701      else
  11702        screen:expect { mode = 'normal' }
  11703      end
  11704 
  11705      -- Not obscured in the command-line if curwin's cursor is obscured.
  11706      api.nvim_win_set_config(float_win_above, { hide = false })
  11707      feed(':')
  11708      if multigrid then
  11709        screen:expect({
  11710          grid = [[
  11711          ## grid 1
  11712            [2:--------------------------------------------------]|*19
  11713            [3:--------------------------------------------------]|
  11714          ## grid 2
  11715            one                                               |
  11716            two                                               |
  11717            three                                             |
  11718            {0:~                                                 }|*16
  11719          ## grid 3
  11720            :^                                                 |
  11721          ## grid 7
  11722            {5:┌─────┐}|
  11723            {5:│}{1:    x}{5:│}|
  11724            {5:│}{2:    ~}{5:│}|*4
  11725            {5:└─────┘}|
  11726          ## grid 8
  11727            {1:          }|
  11728            {2:~         }|*9
  11729          ]],
  11730          float_pos = {
  11731            [7] = { 1004, 'NW', 1, 8, 8, true, 1, 1, 8, 8 },
  11732            [8] = { 1005, 'NW', 1, 0, 0, true, 2, 2, 0, 0 },
  11733          },
  11734          mode = 'cmdline_normal',
  11735        })
  11736      else
  11737        screen:expect { mode = 'cmdline_normal' }
  11738      end
  11739    end)
  11740 
  11741    it("window is not enlarged behind 'cmdheight'", function()
  11742      local opts = { relative = 'editor', width = 10, height = 4, row = 0, col = 0, zindex = 199 }
  11743      opts.border = 'single'
  11744      api.nvim_open_win(0, true, opts)
  11745      opts.zindex, opts.col = 200, 12
  11746      local above = api.nvim_open_win(0, false, opts)
  11747      command('echo "cmdline" | wincmd +')
  11748      if multigrid then
  11749        screen:expect({
  11750          grid = [[
  11751          ## grid 1
  11752            [2:----------------------------------------]|*6
  11753            [3:----------------------------------------]|
  11754          ## grid 2
  11755                                                    |
  11756            {0:~                                       }|*5
  11757          ## grid 3
  11758            cmdline                                 |
  11759          ## grid 4
  11760            {5:┌──────────┐}|
  11761            {5:│}{1:^          }{5:│}|
  11762            {5:│}{2:~         }{5:│}|*4
  11763            {5:└──────────┘}|
  11764          ## grid 5
  11765            {5:┌──────────┐}|
  11766            {5:│}{1:          }{5:│}|
  11767            {5:│}{2:~         }{5:│}|*3
  11768            {5:└──────────┘}|
  11769          ]],
  11770          float_pos = {
  11771            [5] = { 1002, 'NW', 1, 0, 12, true, 200, 3, 0, 12 },
  11772            [4] = { 1001, 'NW', 1, 0, 0, true, 199, 1, 0, 0 },
  11773          },
  11774        })
  11775      else
  11776        screen:expect([[
  11777          {5:┌──────────┐┌──────────┐}                |
  11778          {5:}{1:^          }{5:││}{1:          }{5:}{0:                }|
  11779          {5:}{2:~         }{5:││}{2:~         }{5:}{0:                }|*3
  11780          {5:└──────────┘└──────────┘}{0:                }|
  11781          cmdline                                 |
  11782        ]])
  11783      end
  11784      api.nvim_set_current_win(above)
  11785      command('wincmd +')
  11786      if multigrid then
  11787        screen:expect({
  11788          grid = [[
  11789          ## grid 1
  11790            [2:----------------------------------------]|*6
  11791            [3:----------------------------------------]|
  11792          ## grid 2
  11793                                                    |
  11794            {0:~                                       }|*5
  11795          ## grid 3
  11796            cmdline                                 |
  11797          ## grid 4
  11798            {5:┌──────────┐}|
  11799            {5:│}{1:          }{5:│}|
  11800            {5:│}{2:~         }{5:│}|*4
  11801            {5:└──────────┘}|
  11802          ## grid 5
  11803            {5:┌──────────┐}|
  11804            {5:│}{1:^          }{5:│}|
  11805            {5:│}{2:~         }{5:│}|*4
  11806            {5:└──────────┘}|
  11807          ]],
  11808          float_pos = {
  11809            [5] = { 1002, 'NW', 1, 0, 12, true, 200, 3, 0, 12 },
  11810            [4] = { 1001, 'NW', 1, 0, 0, true, 199, 1, 0, 0 },
  11811          },
  11812        })
  11813      else
  11814        screen:expect([[
  11815          {5:┌──────────┐┌──────────┐}                |
  11816          {5:}{1:          }{5:││}{1:^          }{5:}{0:                }|
  11817          {5:}{2:~         }{5:││}{2:~         }{5:}{0:                }|*3
  11818          {5:└──────────┘│}{2:~         }{5:}{0:                }|
  11819          cmdline     {5:└──────────┘}                |
  11820        ]])
  11821      end
  11822    end)
  11823  end
  11824 
  11825  describe('with ext_multigrid and actual mouse grid', function()
  11826    with_ext_multigrid(true, true)
  11827  end)
  11828 
  11829  describe('with ext_multigrid and mouse grid 0', function()
  11830    with_ext_multigrid(true, false)
  11831  end)
  11832 
  11833  describe('without ext_multigrid', function()
  11834    with_ext_multigrid(false, false)
  11835  end)
  11836 end)