Skip to content

Commit 9b289ab

Browse files
authored
revert(#3180, #3177): invalid group or tabpage (#3181)
* Revert "feat(#2826): allow only one window with nvim-tree buffer per tab (#3174)" This reverts commit dd2364d. * Revert "refactor(#2826): View tracks winids and bufnrs via events, unused for now (#3170)" This reverts commit 65bae44. * Revert "refactor(#2826): remove view debug/cc, enable new codepaths for get_winid and get_bufnr (#3169)" This reverts commit a9156c0.
1 parent dd2364d commit 9b289ab

File tree

16 files changed

+437
-259
lines changed

16 files changed

+437
-259
lines changed

doc/nvim-tree-lua.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ Following is the default configuration. See |nvim-tree-opts| for details. >lua
639639
},
640640
},
641641
experimental = {
642+
multi_instance = false,
642643
},
643644
log = {
644645
enable = false,

lua/nvim-tree.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
486486
},
487487
},
488488
experimental = {
489+
multi_instance = false,
489490
},
490491
log = {
491492
enable = false,
@@ -668,7 +669,7 @@ function M.purge_all_state()
668669
local explorer = core.get_explorer()
669670
if explorer then
670671
explorer.view:close_all_tabs()
671-
explorer.view:abandon_all_windows()
672+
explorer.view:abandon_all_windows("purge_all_state")
672673
require("nvim-tree.git").purge_state()
673674
explorer:destroy()
674675
core.reset_explorer()
@@ -726,6 +727,7 @@ function M.setup(conf)
726727
require("nvim-tree.buffers").setup(opts)
727728
require("nvim-tree.help").setup(opts)
728729
require("nvim-tree.watcher").setup(opts)
730+
require("nvim-tree.multi-instance-debug").setup(opts)
729731

730732
setup_autocommands(opts)
731733

lua/nvim-tree/actions/fs/remove-file.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ local function close_windows(windows)
1818
-- Prevent from closing when the win count equals 1 or 2,
1919
-- where the win to remove could be the last opened.
2020
-- For details see #2503.
21-
if explorer and explorer.opts.view.float.enable and #vim.api.nvim_list_wins() < 3 then
21+
if explorer and explorer.view.float.enable and #vim.api.nvim_list_wins() < 3 then
2222
return
2323
end
2424

@@ -36,12 +36,12 @@ local function clear_buffer(absolute_path)
3636
for _, buf in pairs(bufs) do
3737
if buf.name == absolute_path then
3838
local tree_winnr = vim.api.nvim_get_current_win()
39-
if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.opts.view.float.enable) then
39+
if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.view.float.enable) then
4040
vim.api.nvim_set_current_win(buf.windows[1])
4141
vim.cmd(":bn")
4242
end
4343
vim.api.nvim_buf_delete(buf.bufnr, { force = true })
44-
if explorer and not explorer.opts.view.float.quit_on_focus_loss then
44+
if explorer and not explorer.view.float.quit_on_focus_loss then
4545
vim.api.nvim_set_current_win(tree_winnr)
4646
end
4747
if M.config.actions.remove_file.close_window then

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ local function usable_win_ids()
2323
local explorer = core.get_explorer()
2424
local tabpage = vim.api.nvim_get_current_tabpage()
2525
local win_ids = vim.api.nvim_tabpage_list_wins(tabpage)
26-
local tree_winid = explorer and explorer.view:get_winid(tabpage)
26+
local tree_winid = explorer and explorer.view:get_winnr(tabpage, "open-file.usable_win_ids")
2727

2828
return vim.tbl_filter(function(id)
2929
local bufid = vim.api.nvim_win_get_buf(id)
@@ -196,7 +196,7 @@ local function open_file_in_tab(filename)
196196
if M.quit_on_open then
197197
local explorer = core.get_explorer()
198198
if explorer then
199-
explorer.view:close()
199+
explorer.view:close(nil, "open-file.open_file_in_tab")
200200
end
201201
end
202202
if M.relative_path then
@@ -209,7 +209,7 @@ local function drop(filename)
209209
if M.quit_on_open then
210210
local explorer = core.get_explorer()
211211
if explorer then
212-
explorer.view:close()
212+
explorer.view:close(nil, "open-file.drop")
213213
end
214214
end
215215
if M.relative_path then
@@ -222,7 +222,7 @@ local function tab_drop(filename)
222222
if M.quit_on_open then
223223
local explorer = core.get_explorer()
224224
if explorer then
225-
explorer.view:close()
225+
explorer.view:close(nil, "open-file.tab_drop")
226226
end
227227
end
228228
if M.relative_path then
@@ -352,7 +352,7 @@ local function open_in_new_window(filename, mode)
352352
end
353353
end
354354

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

455455
if M.quit_on_open and explorer then
456-
explorer.view:close()
456+
explorer.view:close(nil, "open-file.fn")
457457
end
458458
end
459459

lua/nvim-tree/actions/root/change-dir.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ M.force_dirchange = add_profiling_to(function(foldername, should_open_view)
8585
if should_change_dir() then
8686
cd(M.options.global, foldername)
8787
end
88-
core.init(foldername)
88+
core.init(foldername, "change-dir")
8989
end
9090

9191
if should_open_view then

lua/nvim-tree/actions/tree/toggle.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function M.fn(opts, no_focus, cwd, bang)
4444

4545
if explorer and explorer.view:is_visible() then
4646
-- close
47-
explorer.view:close()
47+
explorer.view:close(nil, "toggle.fn")
4848
else
4949
-- open
5050
lib.open({

lua/nvim-tree/api.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ local function edit(mode, node, edit_opts)
247247
local mode_unsupported_quit_on_open = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
248248
if not mode_unsupported_quit_on_open and edit_opts.quit_on_open then
249249
if explorer then
250-
explorer.view:close(cur_tabpage)
250+
explorer.view:close(cur_tabpage, "api.edit " .. mode)
251251
end
252252
end
253253

lua/nvim-tree/core.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ local TreeExplorer = nil
99
local first_init_done = false
1010

1111
---@param foldername string
12-
function M.init(foldername)
12+
---@param callsite string
13+
function M.init(foldername, callsite)
1314
local profile = log.profile_start("core init %s", foldername)
1415

16+
log.line("dev", "core.init(%s, %s)", foldername, callsite)
17+
1518
if TreeExplorer then
1619
TreeExplorer:destroy()
1720
end

lua/nvim-tree/diagnostics.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function M.update_coc()
185185

186186
local bufnr
187187
if explorer then
188-
bufnr = explorer.view:get_bufnr()
188+
bufnr = explorer.view:get_bufnr("diagnostics.update_coc")
189189
end
190190

191191
local should_draw = bufnr and vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_is_loaded(bufnr)

lua/nvim-tree/explorer/init.lua

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ function Explorer:create_autocmds()
105105
vim.api.nvim_create_autocmd("WinLeave", {
106106
group = self.augroup_id,
107107
pattern = "NvimTree_*",
108-
callback = function()
108+
callback = function(data)
109+
if self.opts.experimental.multi_instance then
110+
log.line("dev", "WinLeave %s", vim.inspect(data, { newline = "" }))
111+
end
109112
if utils.is_nvim_tree_buf(0) then
110-
self.view:close()
113+
self.view:close(nil, "WinLeave")
111114
end
112115
end,
113116
})
@@ -165,6 +168,25 @@ function Explorer:create_autocmds()
165168
end,
166169
})
167170

171+
-- prevent new opened file from opening in the same window as nvim-tree
172+
vim.api.nvim_create_autocmd("BufWipeout", {
173+
group = self.augroup_id,
174+
pattern = "NvimTree_*",
175+
callback = function(data)
176+
if self.opts.experimental.multi_instance then
177+
log.line("dev", "BufWipeout %s", vim.inspect(data, { newline = "" }))
178+
end
179+
if not utils.is_nvim_tree_buf(0) then
180+
return
181+
end
182+
if self.opts.actions.open_file.eject then
183+
self.view:prevent_buffer_override()
184+
else
185+
self.view:abandon_current_window()
186+
end
187+
end,
188+
})
189+
168190
vim.api.nvim_create_autocmd("BufEnter", {
169191
group = self.augroup_id,
170192
pattern = "NvimTree_*",
@@ -532,7 +554,7 @@ end
532554
---nil on no explorer or invalid view win
533555
---@return integer[]|nil
534556
function Explorer:get_cursor_position()
535-
local winnr = self.view:get_winid()
557+
local winnr = self.view:get_winnr(nil, "Explorer:get_cursor_position")
536558
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
537559
return
538560
end

0 commit comments

Comments
 (0)