mirror of
https://github.com/neovim/neovim.git
synced 2026-05-27 07:18:36 +00:00
fix(shada): bdelete'd buffers not stored in oldfiles #39070
Problem:
b98eefd added `!b_p_bl` to `ignore_buf()`, which also
skips bdelete'd buffers since bdelete unsets `b_p_bl`.
Solution:
Check `b_p_initialized` together with `b_p_bl` so that
bdelete'd buffers (which have b_p_initialized=false) are not
filtered out. Keep `b_p_bl` check only in `shada_get_buflist()`.
This commit is contained in:
@@ -1991,8 +1991,8 @@ static inline ShaDaWriteResult shada_read_when_writing(FileDescriptor *const sd_
|
||||
static inline bool ignore_buf(const buf_T *const buf, Set(ptr_t) *const removable_bufs)
|
||||
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE
|
||||
{
|
||||
return (buf == NULL || buf->b_ffname == NULL || !buf->b_p_bl || bt_quickfix(buf) \
|
||||
|| bt_terminal(buf) || set_has(ptr_t, removable_bufs, (ptr_t)buf));
|
||||
return (buf == NULL || buf->b_ffname == NULL || (!buf->b_p_bl && buf->b_p_initialized)
|
||||
|| bt_quickfix(buf) || bt_terminal(buf) || set_has(ptr_t, removable_bufs, (ptr_t)buf));
|
||||
}
|
||||
|
||||
/// Get list of buffers to write to the shada file
|
||||
@@ -2006,7 +2006,7 @@ static inline ShadaEntry shada_get_buflist(Set(ptr_t) *const removable_bufs)
|
||||
int max_bufs = get_shada_parameter('%');
|
||||
size_t buf_count = 0;
|
||||
FOR_ALL_BUFFERS(buf) {
|
||||
if (!ignore_buf(buf, removable_bufs)
|
||||
if (!ignore_buf(buf, removable_bufs) && buf->b_p_bl
|
||||
&& (max_bufs < 0 || buf_count < (size_t)max_bufs)) {
|
||||
buf_count++;
|
||||
}
|
||||
@@ -2025,7 +2025,7 @@ static inline ShadaEntry shada_get_buflist(Set(ptr_t) *const removable_bufs)
|
||||
};
|
||||
size_t i = 0;
|
||||
FOR_ALL_BUFFERS(buf) {
|
||||
if (ignore_buf(buf, removable_bufs)) {
|
||||
if (ignore_buf(buf, removable_bufs) || !buf->b_p_bl) {
|
||||
continue;
|
||||
}
|
||||
if (i >= buf_count) {
|
||||
|
||||
@@ -104,4 +104,27 @@ describe('shada support code', function()
|
||||
eq(1, #oldfiles)
|
||||
t.matches(vim.pesc(testfilename_2), oldfiles[1])
|
||||
end)
|
||||
|
||||
it("saves bdelete'd buffer to v:oldfiles #39010", function()
|
||||
reset("set shada='100")
|
||||
nvim_command('edit ' .. testfilename)
|
||||
nvim_command('bdelete')
|
||||
nvim_command('edit ' .. testfilename_2)
|
||||
expect_exit(nvim_command, 'qall')
|
||||
reset("set shada='100")
|
||||
local oldfiles = api.nvim_get_vvar('oldfiles')
|
||||
eq(2, #oldfiles)
|
||||
end)
|
||||
|
||||
it("does not dump bdelete'd buffer to buffer list", function()
|
||||
reset('set shada+=%')
|
||||
nvim_command('edit ' .. testfilename)
|
||||
nvim_command('edit ' .. testfilename_2)
|
||||
nvim_command('bdelete ' .. testfilename)
|
||||
expect_exit(nvim_command, 'qall')
|
||||
reset('set shada+=%')
|
||||
eq(2, fn.bufnr('$'))
|
||||
eq('', fn.bufname(1))
|
||||
eq(testfilename_2, fn.bufname(2))
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user