mirror of
https://github.com/neovim/neovim.git
synced 2026-08-29 10:31:48 +00:00
fix(cwd): keep buffer-local dir when re-editing #41215
Problem: Re-editing a buffer (`:edit!`, re-reading a dir.lua buffer, etc.) drops its `:bcd` directory, so the CWD falls back to the global one. Whereas other buffer-local state (`b:` vars, local options) survives a reload. Solution: Don't clear buf dir in `buf_freeall()`; `do_ecmd()` calls that when reloading/re-editing. `free_buffer_stuff()` still clears them when a buffer is freed or reused for another file.
This commit is contained in:
@@ -436,6 +436,12 @@ for _, cmd in ipairs { 'bcd', 'bchdir' } do
|
||||
command('edit ' .. tmpfile .. '2')
|
||||
eq(startdir, cwd())
|
||||
eq(0, blwd())
|
||||
|
||||
-- But re-editing the same buffer keeps it, like any other buffer-local state. #41213
|
||||
command(('%s %s'):format(cmd, directories.buffer))
|
||||
command('let b:kept = 1')
|
||||
command('edit!')
|
||||
eq({ 1, bufdir, 1 }, { blwd(), cwd(), n.eval('get(b:, "kept", 0)') })
|
||||
end)
|
||||
|
||||
it('is not cleared or overridden by :lcd/:tcd/:cd', function()
|
||||
|
||||
Reference in New Issue
Block a user