From d129e86738cb6af3e5860110c3ee6e24d4b11306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Schwanck=20dos=20Santos?= Date: Thu, 30 Mar 2023 17:46:52 +0100 Subject: [PATCH] feat(groups): close and unpin (#698) add a command to allow a buffer to be both closed and unpinned so that it isn't autopinned on next re-opening it --- lua/bufferline.lua | 1 + lua/bufferline/commands.lua | 8 ++++++++ lua/bufferline/groups.lua | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/lua/bufferline.lua b/lua/bufferline.lua index 67edd408..02c6bb32 100644 --- a/lua/bufferline.lua +++ b/lua/bufferline.lua @@ -48,6 +48,7 @@ local M = { go_to_buffer = commands.go_to, sort_buffers_by = commands.sort_by, close_buffer_with_pick = commands.close_with_pick, + unpin_and_close = commands.unpin_and_close, } -----------------------------------------------------------------------------// -- Helpers diff --git a/lua/bufferline/commands.lua b/lua/bufferline/commands.lua index 3bed2e8c..155c2ded 100644 --- a/lua/bufferline/commands.lua +++ b/lua/bufferline/commands.lua @@ -123,6 +123,14 @@ function M.close_with_pick() pick.choose_then(function(id) handle_close(id) end) end +function M.unpin_and_close(id) + local win_id = id or vim.api.nvim_get_current_buf() + + handle_close(win_id) + + groups.remove_id_from_manual_groupings(win_id) +end + --- Open a element based on it's visible position in the list --- unless absolute is specified in which case this will open it based on it place in the full list --- this is significantly less helpful if you have a lot of elements open diff --git a/lua/bufferline/groups.lua b/lua/bufferline/groups.lua index d91a4907..223e35a8 100644 --- a/lua/bufferline/groups.lua +++ b/lua/bufferline/groups.lua @@ -350,6 +350,11 @@ function M.remove_from_group(group_name, element) end end +---@param id number +function M.remove_id_from_manual_groupings(id) + state.manual_groupings[id] = nil +end + ---@param id string ---@param value boolean function M.set_hidden(id, value)