Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lua/bufferline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions lua/bufferline/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,24 @@ 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

local item = current_item
if length ~= 1 then
item = state.components[index + 1]
if not item then item = state.components[index - 1] end
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
Expand Down