mirror of
https://github.com/neovim/neovim
synced 2025-07-16 09:11:51 +00:00
fix(shada): prevent 'nobuflisted' buffers in v:oldfiles #34373
Problem: 'nobuflisted' buffers are incorrectly added to v:oldfiles. Solution: Use ignore_buf() consistently in shada_write() for buffer marks processing.
This commit is contained in:
@ -2027,7 +2027,7 @@ 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->b_ffname == NULL || !buf->b_p_bl || bt_quickfix(buf) \
|
||||
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));
|
||||
}
|
||||
|
||||
@ -2489,8 +2489,7 @@ static ShaDaWriteResult shada_write(FileDescriptor *const sd_writer,
|
||||
fname = fm.fname;
|
||||
} else {
|
||||
const buf_T *const buf = buflist_findnr(fm.fmark.fnum);
|
||||
if (buf == NULL || buf->b_ffname == NULL
|
||||
|| set_has(ptr_t, &removable_bufs, (ptr_t)buf)) {
|
||||
if (ignore_buf(buf, &removable_bufs)) {
|
||||
continue;
|
||||
}
|
||||
fname = buf->b_ffname;
|
||||
@ -2526,7 +2525,7 @@ static ShaDaWriteResult shada_write(FileDescriptor *const sd_writer,
|
||||
// Initialize buffers
|
||||
if (num_marked_files > 0) {
|
||||
FOR_ALL_BUFFERS(buf) {
|
||||
if (buf->b_ffname == NULL || set_has(ptr_t, &removable_bufs, buf)) {
|
||||
if (ignore_buf(buf, &removable_bufs)) {
|
||||
continue;
|
||||
}
|
||||
const void *local_marks_iter = NULL;
|
||||
|
@ -91,4 +91,18 @@ describe('shada support code', function()
|
||||
eq('', fn.bufname(1))
|
||||
eq(testfilename, fn.bufname(2))
|
||||
end)
|
||||
|
||||
it("does not add 'nobuflisted' buffers to v:oldfiles", function()
|
||||
reset("set shada='100")
|
||||
nvim_command('edit ' .. testfilename)
|
||||
nvim_command('setlocal nobuflisted')
|
||||
nvim_command('edit ' .. testfilename_2)
|
||||
nvim_command('setlocal buflisted')
|
||||
nvim_command('write')
|
||||
expect_exit(nvim_command, 'qall')
|
||||
reset("set shada='100")
|
||||
local oldfiles = api.nvim_get_vvar('oldfiles')
|
||||
eq(1, #oldfiles)
|
||||
t.matches(vim.pesc(testfilename_2), oldfiles[1])
|
||||
end)
|
||||
end)
|
||||
|
Reference in New Issue
Block a user