fix(window): don't make hidden/unfocusable previous window current #36142

Problem:  Previous window is made current while it is unfocusable/hidden.
Solution: Treat hidden/unfocusable window as an invalid previous window.
This commit is contained in:
luukvbaal
2025-10-12 04:41:09 +02:00
committed by GitHub
parent fec02ae8e4
commit c7fd0c17b1
2 changed files with 14 additions and 1 deletions

View File

@@ -462,7 +462,7 @@ newwindow:
// cursor to last accessed (previous) window
case 'p':
case Ctrl_P:
if (!win_valid(prevwin)) {
if (!win_valid(prevwin) || prevwin->w_config.hide || !prevwin->w_config.focusable) {
beep_flush();
} else {
win_goto(prevwin);

View File

@@ -962,6 +962,19 @@ describe('float window', function()
eq(1, fn.tabpagewinnr(2))
end)
it('non-visible/focusable is not a valid previous window', function()
local win = api.nvim_open_win(0, true, { relative = 'editor', width = 2, height = 2, row = 2, col = 2, focusable = false })
command('wincmd p')
command('wincmd p')
neq(win, api.nvim_get_current_win())
api.nvim_win_set_config(win, { focusable = true, hide = true })
command('wincmd p')
neq(win, api.nvim_get_current_win())
api.nvim_win_set_config(win, { hide = false })
command('wincmd p')
eq(win, api.nvim_get_current_win())
end)
it('no crash for unallocated relative window grid', function()
local win = api.nvim_open_win(0, false, { relative = 'editor', row = 0, col = 0, height = 1, width = 1 })
exec_lua(function()