akinsho / akinsho/bufferline.nvim

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

Abierto
#1,037 1 comentario 1 reacción 0 asignados Ver en GitHub
bug
Lenguaje dominante
Lua
Estrellas
4.4k
Forks
240
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.