From 6dbb3d44a6149b1919f7b13e117416fb18f0814b Mon Sep 17 00:00:00 2001 From: Akin <22454918+akinsho@users.noreply.github.com> Date: Tue, 21 Feb 2023 10:01:09 +0000 Subject: [PATCH 1/3] fix(groups): clear unpinned buffers from session (#688) --- lua/bufferline/groups.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lua/bufferline/groups.lua b/lua/bufferline/groups.lua index 7985ed09..858115a7 100644 --- a/lua/bufferline/groups.lua +++ b/lua/bufferline/groups.lua @@ -199,10 +199,7 @@ local function get_manual_group(element) return state.manual_groupings[element.i -- can vary i.e. buffer id or path and this should be changed in a centralised way. ---@param id number ---@param group_id string? -local function set_manual_group(id, group_id) - state.manual_groupings[id] = group_id - if group_id == PINNED_ID then persist_pinned_buffers() end -end +local function set_manual_group(id, group_id) state.manual_groupings[id] = group_id end ---Group buffers based on user criteria ---buffers only carry a copy of the group ID which is then used to retrieve the correct group @@ -258,7 +255,10 @@ local function restore_pinned_buffers() local manual_groupings = vim.split(pinned, ",") or {} for _, path in ipairs(manual_groupings) do local buf_id = fn.bufnr(path) - if buf_id ~= -1 then set_manual_group(buf_id, PINNED_ID) end + if buf_id ~= -1 then + set_manual_group(buf_id, PINNED_ID) + persist_pinned_buffers() + end end ui.refresh() end @@ -339,6 +339,7 @@ function M.remove_from_group(group_name, element) if group then local id = get_manual_group(element) set_manual_group(element.id, id ~= group.id and id or nil) + if group_name == PINNED_ID then persist_pinned_buffers() end end end From 894d0e80583cacd27facdb6676a6b08764662537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Schwanck=20dos=20Santos?= Date: Wed, 22 Feb 2023 07:53:36 +0000 Subject: [PATCH 2/3] fix(groups): ensure groups are persisted correctly (#693) Co-authored-by: Akin Sowemimo <22454918+akinsho@users.noreply.github.com> --- lua/bufferline.lua | 1 + lua/bufferline/groups.lua | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lua/bufferline.lua b/lua/bufferline.lua index e1b7973d..95b59d3d 100644 --- a/lua/bufferline.lua +++ b/lua/bufferline.lua @@ -135,6 +135,7 @@ function M.group_action(name, action) if action == "close" then groups.command(name, function(b) api.nvim_buf_delete(b.id, { force = true }) end) ui.refresh() + groups.reset_manual_groupings() elseif action == "toggle" then groups.toggle_hidden(nil, name) ui.refresh() diff --git a/lua/bufferline/groups.lua b/lua/bufferline/groups.lua index 858115a7..03caae03 100644 --- a/lua/bufferline/groups.lua +++ b/lua/bufferline/groups.lua @@ -187,8 +187,12 @@ local function persist_pinned_buffers() for buf, group in pairs(state.manual_groupings) do if group == PINNED_ID then table.insert(pinned, api.nvim_buf_get_name(buf)) end end - if #pinned == 0 then return end - vim.g[PINNED_KEY] = table.concat(pinned, ",") + + if #pinned == 0 then + vim.g[PINNED_KEY] = "" + else + vim.g[PINNED_KEY] = table.concat(pinned, ",") + end end ---@param element TabElement @@ -329,7 +333,10 @@ function M.is_pinned(element) return get_manual_group(element) == PINNED_ID end ---@param element TabElement? function M.add_to_group(group_name, element) local group = group_by_name(group_name) - if group and element then set_manual_group(element.id, group.id) end + if group and element then + set_manual_group(element.id, group.id) + persist_pinned_buffers() + end end ---@param group_name string @@ -454,6 +461,12 @@ local function sort_by_groups(components) return sorted, clustered end +--- Resets manual mappings. +function M.reset_manual_groupings() + vim.g[PINNED_KEY] = {} + state.manual_groupings = {} +end + function M.get_all() return state.user_groups end -- FIXME: From 2c232bf5c19017b4cd97417098b88f5175b02efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Schwanck=20dos=20Santos?= Date: Thu, 23 Feb 2023 05:03:45 +0000 Subject: [PATCH 3/3] fix(groups): only reset the pinned group if it closed (#696) --- lua/bufferline.lua | 3 ++- lua/bufferline/groups.lua | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lua/bufferline.lua b/lua/bufferline.lua index 95b59d3d..67edd408 100644 --- a/lua/bufferline.lua +++ b/lua/bufferline.lua @@ -135,7 +135,8 @@ function M.group_action(name, action) if action == "close" then groups.command(name, function(b) api.nvim_buf_delete(b.id, { force = true }) end) ui.refresh() - groups.reset_manual_groupings() + + groups.reset_manual_groupings(name) elseif action == "toggle" then groups.toggle_hidden(nil, name) ui.refresh() diff --git a/lua/bufferline/groups.lua b/lua/bufferline/groups.lua index 03caae03..479298cb 100644 --- a/lua/bufferline/groups.lua +++ b/lua/bufferline/groups.lua @@ -462,9 +462,17 @@ local function sort_by_groups(components) end --- Resets manual mappings. -function M.reset_manual_groupings() - vim.g[PINNED_KEY] = {} - state.manual_groupings = {} +---@param name string Group name +function M.reset_manual_groupings(name) + if name == PINNED_NAME then + vim.g[PINNED_KEY] = {} + end + + for buf, group_id in pairs(state.manual_groupings) do + if group_id == name then + state.manual_groupings[buf] = nil + end + end end function M.get_all() return state.user_groups end