fix(picker.actions): don't open a new tab if the current tab is empty. Closes #2461

This commit is contained in:
Folke Lemaitre 2025-11-06 22:16:35 +01:00
parent aeedfdbb75
commit 4e2424eca7
No known key found for this signature in database
GPG key ID: 9B52594D560070AB

View file

@ -59,6 +59,9 @@ function M.jump(picker, _, action)
and vim.api.nvim_buf_line_count(current_buf) == 1 and vim.api.nvim_buf_line_count(current_buf) == 1
and vim.api.nvim_buf_get_lines(current_buf, 0, -1, false)[1] == "" and vim.api.nvim_buf_get_lines(current_buf, 0, -1, false)[1] == ""
and vim.api.nvim_buf_get_name(current_buf) == "" and vim.api.nvim_buf_get_name(current_buf) == ""
local current_tab_windows = #vim.tbl_filter(function(w)
return not Snacks.util.is_float(w)
end, vim.api.nvim_tabpage_list_wins(current_tab))
if not current_empty then if not current_empty then
-- save position in jump list -- save position in jump list
@ -121,6 +124,11 @@ function M.jump(picker, _, action)
find_win(true) find_win(true)
end end
-- Don't open a new tab if current buffer is empty
if cmd == "tab sbuffer" and current_empty and current_tab_windows == 1 then
cmd = "buffer"
end
-- open the first buffer -- open the first buffer
vim.cmd(("%s %d"):format(cmd, first_buf)) vim.cmd(("%s %d"):format(cmd, first_buf))
win = vim.api.nvim_get_current_win() win = vim.api.nvim_get_current_win()