fix(picker): better handling when entering the root layout window. Closes #894

This commit is contained in:
Folke Lemaitre 2025-02-03 14:20:04 +01:00
parent bdb9c864c6
commit e294fd8a27
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -297,20 +297,18 @@ function M:init_layout(layout)
left_picker = self:is_focused()
end)
local last_win = self.input.filter.current_win
local last_pwin ---@type number?
self.layout.root:on("WinEnter", function()
local win = vim.api.nvim_get_current_win()
if self:is_focused() then
last_pwin = win
elseif win ~= self.layout.root.win then
last_win = win
last_pwin = vim.api.nvim_get_current_win()
end
end)
self.layout.root:on("WinEnter", function()
if left_picker and last_win and vim.api.nvim_win_is_valid(last_win) then
vim.api.nvim_set_current_win(last_win)
if left_picker then
local pos = self.layout.root.opts.position
local wincmds = { left = "l", right = "h", top = "j", bottom = "k" }
vim.cmd("wincmd " .. wincmds[pos])
elseif last_pwin and vim.api.nvim_win_is_valid(last_pwin) then
vim.api.nvim_set_current_win(last_pwin)
else