fix(floatwin): don't use same window as altwin (#40748)

Fixes a regression from #34486
Fix #40745
This commit is contained in:
zeertzjq
2026-07-15 13:59:45 +08:00
committed by GitHub
parent 4b69d3fd2d
commit 39bc59a8f1
2 changed files with 15 additions and 9 deletions

View File

@@ -388,7 +388,7 @@ win_T *win_float_find_altwin(const win_T *win, const tabpage_T *tp)
assert(tp != curtab);
wp = tabpage_win_valid(tp, tp->tp_prevwin) ? tp->tp_prevwin : tp->tp_firstwin;
return (wp->w_config.focusable && !wp->w_config.hide) ? wp : tp->tp_firstwin;
return (wp != win && wp->w_config.focusable && !wp->w_config.hide) ? wp : tp->tp_firstwin;
}
/// Inline helper function for handling errors and cleanup in win_float_create_preview.

View File

@@ -756,18 +756,13 @@ describe('API/win', function()
eq('', fn.getcmdwintype())
end)
it('closing current (float) window of another tabpage #15313', function()
it('closing current (float) window of another tabpage #15313 #40745', function()
command('tabedit')
command('botright split')
local prevwin = curwin()
eq(2, eval('tabpagenr()'))
local win = api.nvim_open_win(0, true, {
relative = 'editor',
row = 10,
col = 10,
width = 50,
height = 10,
})
local opts = { relative = 'editor', row = 10, col = 10, width = 50, height = 10 }
local win = vim.api.nvim_open_win(0, true, opts)
local tab = eval('tabpagenr()')
command('tabprevious')
eq(1, eval('tabpagenr()'))
@@ -775,6 +770,17 @@ describe('API/win', function()
eq(prevwin, api.nvim_tabpage_get_win(tab))
assert_alive()
command('tabnext')
local win1 = api.nvim_open_win(0, true, opts)
local win2 = api.nvim_open_win(0, true, opts)
command('tabprevious')
-- win1 becomes the tabpage's current window after win2 is closed
api.nvim_win_close(win2, false)
api.nvim_win_close(win1, false)
eq(prevwin, api.nvim_tabpage_get_win(tab))
assert_alive()
end)
it('closing a float does not enter unfocusable or hidden prevwin', function()