Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ Following is the default configuration. See |nvim-tree-opts| for details. >lua
},
},
experimental = {
multi_instance = false,
},
log = {
enable = false,
Expand Down
4 changes: 3 additions & 1 deletion lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
},
},
experimental = {
multi_instance = false,
},
log = {
enable = false,
Expand Down Expand Up @@ -668,7 +669,7 @@ function M.purge_all_state()
local explorer = core.get_explorer()
if explorer then
explorer.view:close_all_tabs()
explorer.view:abandon_all_windows()
explorer.view:abandon_all_windows("purge_all_state")
require("nvim-tree.git").purge_state()
explorer:destroy()
core.reset_explorer()
Expand Down Expand Up @@ -726,6 +727,7 @@ function M.setup(conf)
require("nvim-tree.buffers").setup(opts)
require("nvim-tree.help").setup(opts)
require("nvim-tree.watcher").setup(opts)
require("nvim-tree.multi-instance-debug").setup(opts)

setup_autocommands(opts)

Expand Down
6 changes: 3 additions & 3 deletions lua/nvim-tree/actions/fs/remove-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ local function close_windows(windows)
-- Prevent from closing when the win count equals 1 or 2,
-- where the win to remove could be the last opened.
-- For details see #2503.
if explorer and explorer.opts.view.float.enable and #vim.api.nvim_list_wins() < 3 then
if explorer and explorer.view.float.enable and #vim.api.nvim_list_wins() < 3 then
return
end

Expand All @@ -36,12 +36,12 @@ local function clear_buffer(absolute_path)
for _, buf in pairs(bufs) do
if buf.name == absolute_path then
local tree_winnr = vim.api.nvim_get_current_win()
if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.opts.view.float.enable) then
if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.view.float.enable) then
vim.api.nvim_set_current_win(buf.windows[1])
vim.cmd(":bn")
end
vim.api.nvim_buf_delete(buf.bufnr, { force = true })
if explorer and not explorer.opts.view.float.quit_on_focus_loss then
if explorer and not explorer.view.float.quit_on_focus_loss then
vim.api.nvim_set_current_win(tree_winnr)
end
if M.config.actions.remove_file.close_window then
Expand Down
12 changes: 6 additions & 6 deletions lua/nvim-tree/actions/node/open-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ local function usable_win_ids()
local explorer = core.get_explorer()
local tabpage = vim.api.nvim_get_current_tabpage()
local win_ids = vim.api.nvim_tabpage_list_wins(tabpage)
local tree_winid = explorer and explorer.view:get_winid(tabpage)
local tree_winid = explorer and explorer.view:get_winnr(tabpage, "open-file.usable_win_ids")

return vim.tbl_filter(function(id)
local bufid = vim.api.nvim_win_get_buf(id)
Expand Down Expand Up @@ -196,7 +196,7 @@ local function open_file_in_tab(filename)
if M.quit_on_open then
local explorer = core.get_explorer()
if explorer then
explorer.view:close()
explorer.view:close(nil, "open-file.open_file_in_tab")
end
end
if M.relative_path then
Expand All @@ -209,7 +209,7 @@ local function drop(filename)
if M.quit_on_open then
local explorer = core.get_explorer()
if explorer then
explorer.view:close()
explorer.view:close(nil, "open-file.drop")
end
end
if M.relative_path then
Expand All @@ -222,7 +222,7 @@ local function tab_drop(filename)
if M.quit_on_open then
local explorer = core.get_explorer()
if explorer then
explorer.view:close()
explorer.view:close(nil, "open-file.tab_drop")
end
end
if M.relative_path then
Expand Down Expand Up @@ -352,7 +352,7 @@ local function open_in_new_window(filename, mode)
end
end

if (mode == "preview" or mode == "preview_no_picker") and explorer and explorer.opts.view.float.enable then
if (mode == "preview" or mode == "preview_no_picker") and explorer and explorer.view.float.enable then
-- ignore "WinLeave" autocmd on preview
-- because the registered "WinLeave"
-- will kill the floating window immediately
Expand Down Expand Up @@ -453,7 +453,7 @@ function M.fn(mode, filename)
end

if M.quit_on_open and explorer then
explorer.view:close()
explorer.view:close(nil, "open-file.fn")
end
end

Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/root/change-dir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ M.force_dirchange = add_profiling_to(function(foldername, should_open_view)
if should_change_dir() then
cd(M.options.global, foldername)
end
core.init(foldername)
core.init(foldername, "change-dir")
end

if should_open_view then
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/tree/toggle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function M.fn(opts, no_focus, cwd, bang)

if explorer and explorer.view:is_visible() then
-- close
explorer.view:close()
explorer.view:close(nil, "toggle.fn")
else
-- open
lib.open({
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ local function edit(mode, node, edit_opts)
local mode_unsupported_quit_on_open = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
if not mode_unsupported_quit_on_open and edit_opts.quit_on_open then
if explorer then
explorer.view:close(cur_tabpage)
explorer.view:close(cur_tabpage, "api.edit " .. mode)
end
end

Expand Down
5 changes: 4 additions & 1 deletion lua/nvim-tree/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ local TreeExplorer = nil
local first_init_done = false

---@param foldername string
function M.init(foldername)
---@param callsite string
function M.init(foldername, callsite)
local profile = log.profile_start("core init %s", foldername)

log.line("dev", "core.init(%s, %s)", foldername, callsite)

if TreeExplorer then
TreeExplorer:destroy()
end
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function M.update_coc()

local bufnr
if explorer then
bufnr = explorer.view:get_bufnr()
bufnr = explorer.view:get_bufnr("diagnostics.update_coc")
end

local should_draw = bufnr and vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_is_loaded(bufnr)
Expand Down
28 changes: 25 additions & 3 deletions lua/nvim-tree/explorer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ function Explorer:create_autocmds()
vim.api.nvim_create_autocmd("WinLeave", {
group = self.augroup_id,
pattern = "NvimTree_*",
callback = function()
callback = function(data)
if self.opts.experimental.multi_instance then
log.line("dev", "WinLeave %s", vim.inspect(data, { newline = "" }))
end
if utils.is_nvim_tree_buf(0) then
self.view:close()
self.view:close(nil, "WinLeave")
end
end,
})
Expand Down Expand Up @@ -165,6 +168,25 @@ function Explorer:create_autocmds()
end,
})

-- prevent new opened file from opening in the same window as nvim-tree
vim.api.nvim_create_autocmd("BufWipeout", {
group = self.augroup_id,
pattern = "NvimTree_*",
callback = function(data)
if self.opts.experimental.multi_instance then
log.line("dev", "BufWipeout %s", vim.inspect(data, { newline = "" }))
end
if not utils.is_nvim_tree_buf(0) then
return
end
if self.opts.actions.open_file.eject then
self.view:prevent_buffer_override()
else
self.view:abandon_current_window()
end
end,
})

vim.api.nvim_create_autocmd("BufEnter", {
group = self.augroup_id,
pattern = "NvimTree_*",
Expand Down Expand Up @@ -532,7 +554,7 @@ end
---nil on no explorer or invalid view win
---@return integer[]|nil
function Explorer:get_cursor_position()
local winnr = self.view:get_winid()
local winnr = self.view:get_winnr(nil, "Explorer:get_cursor_position")
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
return
end
Expand Down
4 changes: 2 additions & 2 deletions lua/nvim-tree/explorer/live-filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ local overlay_bufnr = 0
local overlay_winnr = 0

local function remove_overlay(self)
if self.explorer.opts.view.float.enable and self.explorer.opts.view.float.quit_on_focus_loss then
if self.explorer.view.float.enable and self.explorer.view.float.quit_on_focus_loss then
-- return to normal nvim-tree float behaviour when filter window is closed
vim.api.nvim_create_autocmd("WinLeave", {
pattern = "NvimTree_*",
Expand Down Expand Up @@ -171,7 +171,7 @@ local function calculate_overlay_win_width(self)
end

local function create_overlay(self)
if self.explorer.opts.view.float.enable then
if self.explorer.view.float.enable then
-- don't close nvim-tree float when focus is changed to filter window
vim.api.nvim_clear_autocmds({
event = "WinLeave",
Expand Down
Loading
Loading