diff --git a/lua/bufferline.lua b/lua/bufferline.lua index 60bce661..1e291f9a 100644 --- a/lua/bufferline.lua +++ b/lua/bufferline.lua @@ -34,6 +34,7 @@ local M = { rename_tab = commands.rename_tab, close_others = commands.close_others, unpin_and_close = commands.unpin_and_close, + close_current = commands.close_current, ---@deprecated pick_buffer = commands.pick, @@ -162,6 +163,7 @@ local function setup_commands() command("BufferLineCloseRight", function() M.close_in_direction("right") end) command("BufferLineCloseLeft", function() M.close_in_direction("left") end) command("BufferLineCloseOthers", function() M.close_others() end) + command("BufferLineCloseCurrent", function() M.close_current() end) command("BufferLineMoveNext", function() M.move(1) end) command("BufferLineMovePrev", function() M.move(-1) end) command("BufferLineSortByExtension", function() M.sort_by("extension") end) diff --git a/lua/bufferline/commands.lua b/lua/bufferline/commands.lua index 55a07152..12868b07 100644 --- a/lua/bufferline/commands.lua +++ b/lua/bufferline/commands.lua @@ -276,6 +276,25 @@ function M.rename_tab(args) tabpage.rename_tab(tabnr, name) end +---Close current buffer +function M.close_current() + local index = M.get_current_element_index(state) + if not index then return end + + local current_item = state.components[index] + + local length = #state.components + if length == 1 then return end + + local item = state.components[index+1] + if not item then + item = state.components[index-1] + end + + delete_element(current_item.id) + open_element(item.id) +end + _G.___bufferline_private.handle_close = handle_close _G.___bufferline_private.handle_click = handle_click _G.___bufferline_private.handle_group_click = handle_group_click