akinsho / akinsho/bufferline.nvim

[Bug]: a unpinned buffer was pinned after session restore

未关闭
#1,037 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
Lua
星标
4.4k
派生
240
PR 合并指标
30 天内没有已合并 PR

描述

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What happened?

Reproduce:
1. pin a buffer A, and I execute `:lua print(vim.g["BufferlinePinnedBuffers])`, the output is the filepath of buffer A
2. unpin the buffer A, and I re-execute the print cmd above, the output is an empty string
3. mksession and exit neovim
4. open neovim and restore the session, the buffer A is pinned, and I also execute the print cmd above, the output is the filepath of buffer A

I try to solve this problem, it seems like caused by the neovim's session mechanism, we have to do `unlet g:BufferlinePinnedBuffers` before `mksession` if `#vim.g["BufferlinePinnedBuffers"] == 0`

I write a autocmd just like this, the problem seems to be solved:
```lua
vim.api.nvim_create_autocmd("User", {
group = vim.api.nvim_create_augroup("CelesteFixBufferlineForPinnedBuffer", { clear = true }),
pattern = "UserDefinedBeforeSessionSave",
callback = function()
if vim.fn.exists("g:BufferlinePinnedBuffers") then
if #vim.g["BufferlinePinnedBuffers"] == 0 then
vim.cmd("unlet g:BufferlinePinnedBuffers")
end
end
end,
})
```

### What did you expect to happen?

1. pin a buffer A, and I execute `:lua print(vim.g["BufferlinePinnedBuffers])`, the output is the filepath of buffer A
2. unpin the buffer A, and I re-execute the print cmd above, the output is an empty string
3. mksession and exit neovim
4. open neovim and restore the session, the buffer A wasn't pinned

### Config
```
opts = {
options = {
mode = "buffers",
numbers = function(opts)
return string.format("%s.%s", opts.id, opts.raise(opts.ordinal))
end,
buffer_close_icon = "󰅖",
modified_icon = "●",
close_icon = "",
left_trunc_marker = " ",
right_trunc_marker = " ",

offsets = {
{
filetype = "NvimTree",
text = "File Explorer",
text_align = "center",
highlight = "Directory",
separator = true,
},
},

color_icons = true,
get_element_icon = function(element)
return require("nvim-web-devicons").get_icon_by_filetype(element.filetype, { default = false })
end,
show_buffer_icons = true,
show_buffer_close_icons = true,
show_close_icon = true,
show_tab_indicators = true,

max_name_length = 18,
max_prefix_length = 15,
truncate_names = true,
diagnostics = "nvim_lsp",
diagnostics_update_on_event = true,

pick = {
alphabet = "abcdefghijklmopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ1234567890",
},
}, -- options
},
```

### Additional Information

_No response_

### commit

_No response_

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。