Skip to content

Commit 078a555

Browse files
committed
fix: should redraw when buffer is unloaded and trying to open
1 parent eb3e299 commit 078a555

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

lua/nvim-tree.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ local function setup_vim_commands()
358358
command! NvimTreeClose lua require'nvim-tree'.close()
359359
command! NvimTreeToggle lua require'nvim-tree'.toggle()
360360
command! NvimTreeFocus lua require'nvim-tree'.focus()
361-
command! NvimTreeRefresh lua require'nvim-tree'.refresh()
361+
command! NvimTreeRefresh lua require'nvim-tree.lib'.refresh_tree(true)
362362
command! NvimTreeClipboard lua require'nvim-tree'.print_clipboard()
363363
command! NvimTreeFindFile lua require'nvim-tree'.find_file(true)
364364
command! -nargs=1 NvimTreeResize lua require'nvim-tree'.resize(<args>)
@@ -398,6 +398,7 @@ local function setup_autocommands(opts)
398398
if opts.update_focused_file.enable then
399399
vim.cmd "au BufEnter * lua require'nvim-tree'.find_file(false)"
400400
end
401+
vim.cmd "au BufUnload NvimTree lua require'nvim-tree.view'.View.winnr = {}"
401402

402403
vim.cmd "augroup end"
403404
end

lua/nvim-tree/lib.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,15 @@ function M.open()
460460
M.set_target_win()
461461

462462
local cwd = vim.fn.getcwd()
463-
view.open()
463+
local should_redraw = view.open()
464464

465465
local respect_buf_cwd = vim.g.nvim_tree_respect_buf_cwd or 0
466466
if respect_buf_cwd == 1 and cwd ~= M.Tree.cwd then
467467
M.change_dir(cwd)
468468
end
469+
if should_redraw then
470+
M.redraw()
471+
end
469472
end
470473

471474
function M.sibling(node, direction)

lua/nvim-tree/view.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ local function is_buf_valid(bufnr)
302302
end
303303

304304
function M.open(options)
305+
local should_redraw = false
305306
if not is_buf_valid(M.View.bufnr) then
307+
should_redraw = true
306308
create_buffer()
307309
end
308310

@@ -320,6 +322,7 @@ function M.open(options)
320322
if not opts.focus_tree then
321323
vim.cmd("wincmd p")
322324
end
325+
return should_redraw
323326
end
324327

325328
local function get_existing_buffers()

0 commit comments

Comments
 (0)