Skip to content

Commit

Permalink
feat: close current buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
umkh committed Nov 11, 2024
1 parent 5cc447c commit b0a6dcf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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
19 changes: 19 additions & 0 deletions lua/bufferline/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b0a6dcf

Please sign in to comment.