Skip to content

Commit 9deac32

Browse files
committed
refactor: all usages going through the explorer
1 parent c6ae243 commit 9deac32

File tree

7 files changed

+22
-14
lines changed

7 files changed

+22
-14
lines changed

lua/nvim-tree.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,6 @@ function M.setup(conf)
837837
require("nvim-tree.view").setup(opts)
838838
require("nvim-tree.lib").setup(opts)
839839
require("nvim-tree.renderer").setup(opts)
840-
require("nvim-tree.live-filter").setup(opts)
841840
require("nvim-tree.marks").setup(opts)
842841
require("nvim-tree.buffers").setup(opts)
843842
require("nvim-tree.help").setup(opts)

lua/nvim-tree/api.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ local actions = require "nvim-tree.actions"
66
local appearance_diagnostics = require "nvim-tree.appearance.diagnostics"
77
local events = require "nvim-tree.events"
88
local help = require "nvim-tree.help"
9-
local live_filter = require "nvim-tree.live-filter"
109
local marks_navigation = require "nvim-tree.marks.navigation"
1110
local marks_bulk_delete = require "nvim-tree.marks.bulk-delete"
1211
local marks_bulk_trash = require "nvim-tree.marks.bulk-trash"
@@ -265,8 +264,16 @@ Api.git.reload = wrap(actions.reloaders.reload_git)
265264
Api.events.subscribe = events.subscribe
266265
Api.events.Event = events.Event
267266

268-
Api.live_filter.start = wrap(live_filter.start_filtering)
269-
Api.live_filter.clear = wrap(live_filter.clear_filter)
267+
Api.live_filter.start = wrap_explorer(function(explorer)
268+
return wrap(function(...)
269+
return explorer.live_filter:start_filtering(...)
270+
end)
271+
end)
272+
Api.live_filter.clear = wrap_explorer(function(explorer)
273+
return wrap(function(...)
274+
return explorer.live_filter:clear_filter(...)
275+
end)
276+
end)
270277

271278
Api.marks.get = wrap_node(wrap_explorer_member("marks", "get_mark"))
272279
Api.marks.list = wrap_explorer_member("marks", "get_marks")

lua/nvim-tree/explorer/explore.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ local utils = require "nvim-tree.utils"
22
local builders = require "nvim-tree.explorer.node-builders"
33
local explorer_node = require "nvim-tree.explorer.node"
44
local git = require "nvim-tree.git"
5-
local live_filter = require "nvim-tree.live-filter"
65
local log = require "nvim-tree.log"
76

87
local Watcher = require "nvim-tree.watcher"
@@ -82,7 +81,7 @@ function M.explore(node, status, parent)
8281
end
8382

8483
parent.sorters:sort(node.nodes)
85-
live_filter.apply_filter(node)
84+
parent.live_filter:apply_filter(node)
8685

8786
log.profile_end(profile)
8887
return node.nodes

lua/nvim-tree/explorer/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local watch = require "nvim-tree.explorer.watch"
44
local explorer_node = require "nvim-tree.explorer.node"
55
local Filters = require "nvim-tree.explorer.filters"
66
local Marks = require "nvim-tree.marks"
7-
local LiveFilter = require "nvim-tree.live-filter"
7+
local LiveFilter = require "nvim-tree.explorer.live-filter"
88
local Sorters = require "nvim-tree.explorer.sorters"
99

1010
local M = {}

lua/nvim-tree/explorer/reload.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
local utils = require "nvim-tree.utils"
22
local builders = require "nvim-tree.explorer.node-builders"
33
local explorer_node = require "nvim-tree.explorer.node"
4-
local live_filter = require "nvim-tree.live-filter"
54
local git = require "nvim-tree.git"
65
local log = require "nvim-tree.log"
76

@@ -165,7 +164,7 @@ function M.reload(node, git_status)
165164
end
166165

167166
explorer.sorters:sort(node.nodes)
168-
live_filter.apply_filter(node)
167+
explorer.live_filter:apply_filter(node)
169168
log.profile_end(profile)
170169
return node.nodes
171170
end

lua/nvim-tree/renderer/builder.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
local core = require "nvim-tree.core"
2-
local live_filter = require "nvim-tree.live-filter"
32
local notify = require "nvim-tree.notify"
43
local utils = require "nvim-tree.utils"
54
local view = require "nvim-tree.view"
@@ -352,7 +351,8 @@ end
352351

353352
---@private
354353
function Builder:get_nodes_number(nodes)
355-
if not live_filter.filter then
354+
local explorer = core.get_explorer()
355+
if not explorer or not explorer.live_filter.filter then
356356
return #nodes
357357
end
358358

@@ -398,15 +398,16 @@ end
398398

399399
---@private
400400
function Builder:build_header()
401+
local explorer = core.get_explorer()
401402
if view.is_root_folder_visible(core.get_cwd()) then
402403
local root_name = self:format_root_name(M.opts.renderer.root_folder_label)
403404
table.insert(self.lines, root_name)
404405
self:insert_highlight({ "NvimTreeRootFolder" }, 0, string.len(root_name))
405406
self.index = 1
406407
end
407408

408-
if live_filter.filter then
409-
local filter_line = string.format("%s/%s/", M.opts.live_filter.prefix, live_filter.filter)
409+
if explorer and explorer.live_filter.filter then
410+
local filter_line = string.format("%s/%s/", M.opts.live_filter.prefix, explorer.live_filter.filter)
410411
table.insert(self.lines, filter_line)
411412
local prefix_length = string.len(M.opts.live_filter.prefix)
412413
self:insert_highlight({ "NvimTreeLiveFilterPrefix" }, 0, prefix_length)

lua/nvim-tree/utils.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ function M.find_node(nodes, fn)
112112
end)
113113
:iterate()
114114
i = require("nvim-tree.view").is_root_folder_visible() and i or i - 1
115-
i = require("nvim-tree.live-filter").filter and i + 1 or i
115+
local explorer = require("nvim-tree.core").get_explorer()
116+
if explorer and explorer.live_filter.filter then
117+
i = i + 1
118+
end
116119
return node, i
117120
end
118121

0 commit comments

Comments
 (0)