Skip to content

Commit bb320f9

Browse files
committed
fix: should redraw when buffer is unloaded and trying to open
1 parent 155682e commit bb320f9

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(false)
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! NvimTreeFindFileToggle lua require'nvim-tree'.toggle(true)
@@ -399,6 +399,7 @@ local function setup_autocommands(opts)
399399
if opts.update_focused_file.enable then
400400
vim.cmd "au BufEnter * lua require'nvim-tree'.find_file(false)"
401401
end
402+
vim.cmd "au BufUnload NvimTree lua require'nvim-tree.view'.View.tabpages = {}"
402403

403404
vim.cmd "augroup end"
404405
end

lua/nvim-tree/lib.lua

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

461461
local cwd = vim.fn.getcwd()
462-
view.open()
462+
local should_redraw = view.open()
463463

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

470473
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)