Skip to content

Commit e397756

Browse files
phanenalex-courtis
andauthored
fix: prevent NvimTree to be alternate buffer when tab open (#3205)
* fix: prevent NvimTree to be alternate buffer when tab open * fix: prevent tabnew leave a dangling "[No Name]" buffer * Update lua/nvim-tree/actions/node/open-file.lua Co-authored-by: Alexander Courtis <[email protected]> --------- Co-authored-by: Alexander Courtis <[email protected]>
1 parent 87d096a commit e397756

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lua/nvim-tree/actions/node/open-file.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,15 @@ local function open_file_in_tab(filename)
198198
if M.relative_path then
199199
filename = utils.path_relative(filename, vim.fn.getcwd())
200200
end
201-
vim.cmd("tabe " .. vim.fn.fnameescape(filename))
201+
vim.cmd.tabnew()
202+
vim.bo.bufhidden = "wipe"
203+
-- Following vim.fn.tabnew the # buffer may be set to the tree buffer. There is no way to clear the # buffer via vim.fn.setreg as it requires a valid buffer. Clear # by setting it to a new temporary scratch buffer.
204+
if utils.is_nvim_tree_buf(vim.fn.bufnr("#")) then
205+
local tmpbuf = vim.api.nvim_create_buf(false, true)
206+
vim.fn.setreg("#", tmpbuf)
207+
vim.api.nvim_buf_delete(tmpbuf, { force = true })
208+
end
209+
vim.cmd.edit(vim.fn.fnameescape(filename))
202210
end
203211

204212
local function drop(filename)

0 commit comments

Comments
 (0)