Skip to content

Commit a4699c0

Browse files
authored
revert(#3180, #3177): resolve live filter failures (#3183)
* Revert "fix(#3172): live filter exception (#3173)" This reverts commit 0a7fcdf. * Revert "refactor(#2826): move view to instanced window class (#3153)" This reverts commit 0a06f65. * feat(#3157): add view.cursorlineopt
1 parent 9b289ab commit a4699c0

35 files changed

+822
-1249
lines changed

doc/nvim-tree-lua.txt

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

lua/nvim-tree.lua

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local log = require("nvim-tree.log")
2+
local view = require("nvim-tree.view")
23
local utils = require("nvim-tree.utils")
34
local actions = require("nvim-tree.actions")
45
local core = require("nvim-tree.core")
@@ -73,8 +74,7 @@ function M.change_root(path, bufnr)
7374
end
7475

7576
function M.tab_enter()
76-
local explorer = core.get_explorer()
77-
if explorer and explorer.view:is_visible({ any_tabpage = true }) then
77+
if view.is_visible({ any_tabpage = true }) then
7878
local bufname = vim.api.nvim_buf_get_name(0)
7979

8080
local ft
@@ -89,15 +89,17 @@ function M.tab_enter()
8989
return
9090
end
9191
end
92-
explorer.view:open({ focus_tree = false })
92+
view.open({ focus_tree = false })
9393

94-
explorer.renderer:draw()
94+
local explorer = core.get_explorer()
95+
if explorer then
96+
explorer.renderer:draw()
97+
end
9598
end
9699
end
97100

98101
function M.open_on_directory()
99-
local explorer = core.get_explorer()
100-
local should_proceed = _config.hijack_directories.auto_open or explorer and explorer.view:is_visible()
102+
local should_proceed = _config.hijack_directories.auto_open or view.is_visible()
101103
if not should_proceed then
102104
return
103105
end
@@ -148,6 +150,21 @@ local function setup_autocommands(opts)
148150
vim.api.nvim_create_autocmd(name, vim.tbl_extend("force", default_opts, custom_opts))
149151
end
150152

153+
-- prevent new opened file from opening in the same window as nvim-tree
154+
create_nvim_tree_autocmd("BufWipeout", {
155+
pattern = "NvimTree_*",
156+
callback = function()
157+
if not utils.is_nvim_tree_buf(0) then
158+
return
159+
end
160+
if opts.actions.open_file.eject then
161+
view._prevent_buffer_override()
162+
else
163+
view.abandon_current_window()
164+
end
165+
end,
166+
})
167+
151168
if opts.tab.sync.open then
152169
create_nvim_tree_autocmd("TabEnter", { callback = vim.schedule_wrap(M.tab_enter) })
153170
end
@@ -209,6 +226,17 @@ local function setup_autocommands(opts)
209226
})
210227
end
211228

229+
if opts.view.float.enable and opts.view.float.quit_on_focus_loss then
230+
create_nvim_tree_autocmd("WinLeave", {
231+
pattern = "NvimTree_*",
232+
callback = function()
233+
if utils.is_nvim_tree_buf(0) then
234+
view.close()
235+
end
236+
end,
237+
})
238+
end
239+
212240
-- Handles event dispatch when tree is closed by `:q`
213241
create_nvim_tree_autocmd("WinClosed", {
214242
pattern = "*",
@@ -486,7 +514,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
486514
},
487515
},
488516
experimental = {
489-
multi_instance = false,
490517
},
491518
log = {
492519
enable = false,
@@ -666,10 +693,10 @@ local function localise_default_opts()
666693
end
667694

668695
function M.purge_all_state()
696+
view.close_all_tabs()
697+
view.abandon_all_windows()
669698
local explorer = core.get_explorer()
670699
if explorer then
671-
explorer.view:close_all_tabs()
672-
explorer.view:abandon_all_windows("purge_all_state")
673700
require("nvim-tree.git").purge_state()
674701
explorer:destroy()
675702
core.reset_explorer()
@@ -722,12 +749,12 @@ function M.setup(conf)
722749
require("nvim-tree.explorer.watch").setup(opts)
723750
require("nvim-tree.git").setup(opts)
724751
require("nvim-tree.git.utils").setup(opts)
752+
require("nvim-tree.view").setup(opts)
725753
require("nvim-tree.lib").setup(opts)
726754
require("nvim-tree.renderer.components").setup(opts)
727755
require("nvim-tree.buffers").setup(opts)
728756
require("nvim-tree.help").setup(opts)
729757
require("nvim-tree.watcher").setup(opts)
730-
require("nvim-tree.multi-instance-debug").setup(opts)
731758

732759
setup_autocommands(opts)
733760

lua/nvim-tree/actions/finders/find-file.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local log = require("nvim-tree.log")
2+
local view = require("nvim-tree.view")
23
local utils = require("nvim-tree.utils")
34
local core = require("nvim-tree.core")
45

@@ -13,7 +14,7 @@ local running = {}
1314
---@param path string relative or absolute
1415
function M.fn(path)
1516
local explorer = core.get_explorer()
16-
if not explorer or not explorer.view:is_visible() then
17+
if not explorer or not view.is_visible() then
1718
return
1819
end
1920

@@ -83,9 +84,9 @@ function M.fn(path)
8384
end)
8485
:iterate()
8586

86-
if found and explorer.view:is_visible() then
87+
if found and view.is_visible() then
8788
explorer.renderer:draw()
88-
explorer.view:set_cursor({ line, 0 })
89+
view.set_cursor({ line, 0 })
8990
end
9091

9192
running[path_real] = false

lua/nvim-tree/actions/fs/clipboard.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ local Clipboard = Class:extend()
3131
---@protected
3232
---@param args ClipboardArgs
3333
function Clipboard:new(args)
34-
args.explorer:log_new("Clipboard")
35-
3634
self.explorer = args.explorer
3735

3836
self.data = {
@@ -44,10 +42,6 @@ function Clipboard:new(args)
4442
self.reg = self.explorer.opts.actions.use_system_clipboard and "+" or "1"
4543
end
4644

47-
function Clipboard:destroy()
48-
self.explorer:log_destroy("Clipboard")
49-
end
50-
5145
---@param source string
5246
---@param destination string
5347
---@return boolean

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local core = require("nvim-tree.core")
22
local utils = require("nvim-tree.utils")
33
local events = require("nvim-tree.events")
4+
local view = require("nvim-tree.view")
45
local lib = require("nvim-tree.lib")
56
local notify = require("nvim-tree.notify")
67

@@ -13,12 +14,10 @@ local M = {
1314

1415
---@param windows integer[]
1516
local function close_windows(windows)
16-
local explorer = core.get_explorer()
17-
1817
-- Prevent from closing when the win count equals 1 or 2,
1918
-- where the win to remove could be the last opened.
2019
-- For details see #2503.
21-
if explorer and explorer.view.float.enable and #vim.api.nvim_list_wins() < 3 then
20+
if view.View.float.enable and #vim.api.nvim_list_wins() < 3 then
2221
return
2322
end
2423

@@ -31,17 +30,16 @@ end
3130

3231
---@param absolute_path string
3332
local function clear_buffer(absolute_path)
34-
local explorer = core.get_explorer()
3533
local bufs = vim.fn.getbufinfo({ bufloaded = 1, buflisted = 1 })
3634
for _, buf in pairs(bufs) do
3735
if buf.name == absolute_path then
3836
local tree_winnr = vim.api.nvim_get_current_win()
39-
if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.view.float.enable) then
37+
if buf.hidden == 0 and (#bufs > 1 or view.View.float.enable) then
4038
vim.api.nvim_set_current_win(buf.windows[1])
4139
vim.cmd(":bn")
4240
end
4341
vim.api.nvim_buf_delete(buf.bufnr, { force = true })
44-
if explorer and not explorer.view.float.quit_on_focus_loss then
42+
if not view.View.float.quit_on_focus_loss then
4543
vim.api.nvim_set_current_win(tree_winnr)
4644
end
4745
if M.config.actions.remove_file.close_window then

lua/nvim-tree/actions/moves/item.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local utils = require("nvim-tree.utils")
2+
local view = require("nvim-tree.view")
23
local core = require("nvim-tree.core")
34
local diagnostics = require("nvim-tree.diagnostics")
45

@@ -66,9 +67,9 @@ local function move(explorer, where, what, skip_gitignored)
6667
end
6768

6869
if nex then
69-
explorer.view:set_cursor({ nex, 0 })
70+
view.set_cursor({ nex, 0 })
7071
elseif vim.o.wrapscan and first then
71-
explorer.view:set_cursor({ first, 0 })
72+
view.set_cursor({ first, 0 })
7273
end
7374
end
7475

@@ -188,13 +189,13 @@ local function move_prev_recursive(explorer, what, skip_gitignored)
188189

189190
-- 4.3)
190191
if node_init.name == ".." then -- root node
191-
explorer.view:set_cursor({ 1, 0 }) -- move to root node (position 1)
192+
view.set_cursor({ 1, 0 }) -- move to root node (position 1)
192193
else
193194
local node_init_line = utils.find_node_line(node_init)
194195
if node_init_line < 0 then
195196
return
196197
end
197-
explorer.view:set_cursor({ node_init_line, 0 })
198+
view.set_cursor({ node_init_line, 0 })
198199
end
199200

200201
-- 4.4)

lua/nvim-tree/actions/moves/parent.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local view = require("nvim-tree.view")
12
local utils = require("nvim-tree.utils")
23

34
local DirectoryNode = require("nvim-tree.node.directory")
@@ -24,15 +25,15 @@ function M.fn(should_close)
2425
local parent = (node:get_parent_of_group() or node).parent
2526

2627
if not parent or not parent.parent then
27-
node.explorer.view:set_cursor({ 1, 0 })
28+
view.set_cursor({ 1, 0 })
2829
return
2930
end
3031

3132
local _, line = utils.find_node(parent.explorer.nodes, function(n)
3233
return n.absolute_path == parent.absolute_path
3334
end)
3435

35-
node.explorer.view:set_cursor({ line + 1, 0 })
36+
view.set_cursor({ line + 1, 0 })
3637
if should_close then
3738
parent.open = false
3839
parent.explorer.renderer:draw()

0 commit comments

Comments
 (0)