From 2d9f82146d76e122bfd07adb9f45737e28ebad0a Mon Sep 17 00:00:00 2001 From: psychhim Date: Thu, 16 Oct 2025 23:33:41 +0530 Subject: [PATCH] Fix: after opening new tab and insert, closing the tab, then coming back to the first and only tab, kept listed buffer count to 1. But then after inserting on it added 1 more hidden buffer so total listed buffer count became 2 while the total tab+file was 1. --- lua/plugins/custom/alpha.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lua/plugins/custom/alpha.lua b/lua/plugins/custom/alpha.lua index 0bd4b6b..93b0b02 100644 --- a/lua/plugins/custom/alpha.lua +++ b/lua/plugins/custom/alpha.lua @@ -46,10 +46,24 @@ return { alpha.redraw() end + -- Function to handle New File logic + local function new_file_alpha() + local listed = vim.fn.getbufinfo { buflisted = 1 } -- all listed buffers + local tabs = vim.api.nvim_list_tabpages() -- all tabs + -- If exactly one listed buffer AND one tab, delete all listed buffers and open insert mode in a new buffer + if #listed == 1 and #tabs == 1 then + for _, buf in ipairs(listed) do + pcall(vim.api.nvim_buf_delete, buf.bufnr, { force = true }) + end + end + vim.cmd 'enew' + vim.cmd 'startinsert' + end + -- Setup buttons dashboard.section.buttons.val = { -- New file - dashboard.button('i', ' New File', 'enewstartinsert'), + dashboard.button('i', ' New File', new_file_alpha), -- Create new tab and open Alpha dashboard.button('e', ' New Tab', 'tabnewlua require("alpha").start(true)'), -- Open Neo-tree in current directory