akinsho / akinsho/bufferline.nvim

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

Đang mở
#1,037 1 bình luận 1 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Lua
Star
4.4k
Fork
240
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### 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_

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.