fix(eval): winnr('$') counts non-current hidden/unfocusable windows #34207

Problem:  Non-visible/focusable windows are assigned a window number,
          whereas commands that use this window number skip over them.

Solution: Skip over non-visible/focusable windows when computing
          the window number, unless it is made the current window
          through the API in which case an identifiable window number
          is still useful. This also ensures it matches the window
          number of the window entered by `<winnr>wincmd w` since
          403fcacf.
This commit is contained in:
luukvbaal
2025-06-02 00:12:12 +02:00
committed by GitHub
parent 5cfbc35aa8
commit 981d4ba45e
10 changed files with 62 additions and 34 deletions

View File

@@ -1090,6 +1090,17 @@ describe('float window', function()
]])
end)
it('non-visible/focusable are not assigned a window number', function()
local win = api.nvim_open_win(0, false, { relative = 'editor', width = 2, height = 2, row = 2, col = 2, focusable = false })
api.nvim_open_win(0, false, { relative = 'editor', width = 2, height = 2, row = 2, col = 2, hide = true })
api.nvim_open_win(0, false, { relative = 'editor', width = 2, height = 2, row = 2, col = 2 })
eq(2, fn.winnr('$'))
eq(0, fn.win_id2win(win))
-- Unless it is the current window.
api.nvim_set_current_win(win)
eq({ 3, 3 }, { fn.winnr(), fn.win_id2win(win) })
end)
local function with_ext_multigrid(multigrid)
local screen, attrs
before_each(function()
@@ -6417,32 +6428,32 @@ describe('float window', function()
api.nvim_open_win(0, false, { relative = 'editor', width = 1, height = 1, row = 0, col = 0, focusable = true })
api.nvim_open_win(0, false, { relative = 'editor', width = 1, height = 1, row = 0, col = 0, focusable = false })
local nr_focusable = {}
for nr = 1, fn.winnr('$') do
table.insert(nr_focusable, api.nvim_win_get_config(fn.win_getid(nr)).focusable)
for _, winid in ipairs(api.nvim_tabpage_list_wins(0)) do
table.insert(nr_focusable, api.nvim_win_get_config(winid).focusable)
end
eq({ true, false, true, false, false, true, false }, nr_focusable)
command('1wincmd w')
eq(1, fn.winnr())
eq({ 1, 1000 }, { fn.winnr(), fn.win_getid() })
command('2wincmd w')
eq(3, fn.winnr())
eq({ 2, 1005 }, { fn.winnr(), fn.win_getid() })
command('3wincmd w')
eq(3, fn.winnr())
eq({ 2, 1005 }, { fn.winnr(), fn.win_getid() })
command('4wincmd w')
eq(6, fn.winnr())
eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
command('5wincmd w')
eq(6, fn.winnr())
eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
command('6wincmd w')
eq(6, fn.winnr())
eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
command('7wincmd w')
eq(6, fn.winnr())
eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
feed('1<c-w>w')
eq(1, fn.winnr())
eq({ 1, 1000 }, { fn.winnr(), fn.win_getid() })
feed('2<c-w>w')
eq(3, fn.winnr())
eq({ 2, 1005 }, { fn.winnr(), fn.win_getid() })
feed('999<c-w>w')
eq(6, fn.winnr())
eq({ 3, 1002 }, { fn.winnr(), fn.win_getid() })
end)
it('W', function()