fix(picker.actions): get win after splitting or tabnew. Fixes #896

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

View file

@ -86,18 +86,18 @@ function M.jump(picker, _, action)
local path = assert(Snacks.picker.util.path(item), "Either item.buf or item.file is required") local path = assert(Snacks.picker.util.path(item), "Either item.buf or item.file is required")
buf = vim.fn.bufadd(path) buf = vim.fn.bufadd(path)
end end
vim.bo[buf].buflisted = true
-- use an existing window if possible -- use an existing window if possible
if #items == 1 and picker.opts.jump.reuse_win and buf ~= current_buf then if cmd == "buffer" and #items == 1 and picker.opts.jump.reuse_win and buf ~= current_buf then
win = vim.fn.win_findbuf(buf)[1] or win win = vim.fn.win_findbuf(buf)[1] or win
vim.api.nvim_set_current_win(win) vim.api.nvim_set_current_win(win)
end end
vim.bo[buf].buflisted = true
-- open the first buffer -- open the first buffer
if i == 1 then if i == 1 then
vim.cmd(("%s %d"):format(cmd, buf)) vim.cmd(("%s %d"):format(cmd, buf))
win = vim.api.nvim_get_current_win()
end end
end end
end end