akinsho / akinsho/bufferline.nvim

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

Aperta
#1,037 1 commento 1 reazione 0 assegnatari Vedi su GitHub
bug
Lingua principale
Lua
Stelle
4.4k
Fork
240
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.