diff --git a/lua/keymaps.lua b/lua/keymaps.lua index 52bf584..1f4d5da 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -217,6 +217,19 @@ local function listed_buffer_count() end return count end +-- Helper function: check if any Alpha buffer exists anywhere +local function is_alpha_running() + for _, buf in ipairs(vim.api.nvim_list_bufs()) do + if vim.api.nvim_buf_is_valid(buf) then + local buftype = vim.api.nvim_buf_get_option(buf, 'buftype') + local ft = vim.api.nvim_buf_get_option(buf, 'filetype') + if buftype == 'nofile' and ft == 'alpha' then + return true + end + end + end + return false +end -- Main function local function close_window(mode) local bufnr = vim.api.nvim_get_current_buf() @@ -272,6 +285,12 @@ local function close_window(mode) end end end + -- Special case: only 1 listed buffer but an Alpha dashboard exists somewhere + if total_listed == 1 and is_alpha_running() then + -- Just close the current window instead of quitting Neovim + vim.cmd 'close' + return + end -- Special case: last listed buffer in last window if total_listed == 1 and win_count == 1 then if modified and mode ~= 'save' then diff --git a/lua/plugins/custom/alpha.lua b/lua/plugins/custom/alpha.lua index d00654e..d65320c 100644 --- a/lua/plugins/custom/alpha.lua +++ b/lua/plugins/custom/alpha.lua @@ -18,20 +18,33 @@ return { vim.cmd 'enew' vim.cmd 'startinsert' end), - -- Create new empty buffer in a new tab + -- Create new tab dashboard.button('e', ' New Tab', function() - local alpha_buf = vim.api.nvim_get_current_buf() - -- Close Alpha buffer - vim.api.nvim_buf_delete(alpha_buf, { force = true }) - -- Create new tab and empty buffer + -- Open a new tab vim.cmd 'tabnew' - vim.cmd 'enew' + -- Open Alpha in that new tab + require('alpha').start(true) end), -- Open Neo-tree in current directory dashboard.button('n', ' Open Neo-tree', 'Neotree toggle float'), - -- Close Neovim + -- Close Alpha window or quit Neovim dashboard.button('q', ' Exit', function() - vim.cmd 'qa!' + -- Get current tab windows + local wins = vim.api.nvim_tabpage_list_wins(0) + if #wins > 1 then + -- If there are other windows in this tab, just close the Alpha window + vim.cmd 'close' + else + -- If this is the only window in the tab, check total tabs + local tab_count = #vim.api.nvim_list_tabpages() + if tab_count > 1 then + -- Close only the current tab + vim.cmd 'tabclose' + else + -- Quit Neovim if this is the last tab + vim.cmd 'qa!' + end + end end), }