Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(close): Close current buffer #977

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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