Skip to content

Commit a634a1b

Browse files
committed
fix: api and filtration
1 parent 9deac32 commit a634a1b

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

lua/nvim-tree/api.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,17 @@ Api.git.reload = wrap(actions.reloaders.reload_git)
264264
Api.events.subscribe = events.subscribe
265265
Api.events.Event = events.Event
266266

267-
Api.live_filter.start = wrap_explorer(function(explorer)
268-
return wrap(function(...)
267+
Api.live_filter.start = wrap(function(...)
268+
local explorer = core.get_explorer()
269+
if explorer then
269270
return explorer.live_filter:start_filtering(...)
270-
end)
271+
end
271272
end)
272-
Api.live_filter.clear = wrap_explorer(function(explorer)
273-
return wrap(function(...)
273+
Api.live_filter.clear = wrap(function(...)
274+
local explorer = core.get_explorer()
275+
if explorer then
274276
return explorer.live_filter:clear_filter(...)
275-
end)
277+
end
276278
end)
277279

278280
Api.marks.get = wrap_node(wrap_explorer_member("marks", "get_mark"))

lua/nvim-tree/explorer/live-filter.lua

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ local LiveFilter = {}
77
function LiveFilter:new(opts, explorer)
88
local o = {
99
explorer = explorer,
10-
config = vim.deepcopy(opts.live_filter),
10+
prefix = opts.live_filter.prefix,
11+
always_show_folders = opts.live_filter.always_show_folders,
1112
filter = nil,
1213
}
1314
setmetatable(o, self)
@@ -57,8 +58,8 @@ local function remove_overlay(self)
5758
overlay_bufnr = 0
5859
overlay_winnr = 0
5960

60-
if self.explorer.live_filter.filter == "" then
61-
self.explorer.live_filter.clear_filter()
61+
if self.filter == "" then
62+
self:clear_filter()
6263
end
6364
end
6465

@@ -96,7 +97,7 @@ function LiveFilter:apply_filter(node_)
9697
end
9798
end
9899

99-
local has_nodes = nodes and (self.config.always_show_folders or #nodes > filtered_nodes)
100+
local has_nodes = nodes and (self.always_show_folders or #nodes > filtered_nodes)
100101
local ok, is_match = pcall(matches, self, node)
101102
node.hidden = not (has_nodes or (ok and is_match))
102103
end
@@ -106,8 +107,8 @@ end
106107

107108
local function record_char(self)
108109
vim.schedule(function()
109-
self.explorer.live_filter.filter = vim.api.nvim_buf_get_lines(overlay_bufnr, 0, -1, false)[1]
110-
self.explorer.live_filter.apply_filter()
110+
self.filter = vim.api.nvim_buf_get_lines(overlay_bufnr, 0, -1, false)[1]
111+
self:apply_filter()
111112
redraw()
112113
end)
113114
end
@@ -132,7 +133,7 @@ local function calculate_overlay_win_width(self)
132133
local wininfo = vim.fn.getwininfo(view.get_winnr())[1]
133134

134135
if wininfo then
135-
return wininfo.width - wininfo.textoff - #self.explorer.live_filter.prefix
136+
return wininfo.width - wininfo.textoff - #self.prefix
136137
end
137138

138139
return 20
@@ -153,7 +154,7 @@ local function create_overlay(self)
153154
col = 1,
154155
row = 0,
155156
relative = "cursor",
156-
width = calculate_overlay_win_width(self.explorer),
157+
width = calculate_overlay_win_width(self),
157158
height = 1,
158159
border = "none",
159160
style = "minimal",
@@ -165,9 +166,9 @@ local function create_overlay(self)
165166
vim.api.nvim_buf_set_option(overlay_bufnr, "modifiable", true) ---@diagnostic disable-line: deprecated
166167
end
167168

168-
vim.api.nvim_buf_set_lines(overlay_bufnr, 0, -1, false, { self.explorer.live_filter.filter })
169+
vim.api.nvim_buf_set_lines(overlay_bufnr, 0, -1, false, { self.filter })
169170
vim.cmd "startinsert"
170-
vim.api.nvim_win_set_cursor(overlay_winnr, { 1, #self.explorer.live_filter.filter + 1 })
171+
vim.api.nvim_win_set_cursor(overlay_winnr, { 1, #self.filter + 1 })
171172
end
172173

173174
function LiveFilter:start_filtering()

0 commit comments

Comments
 (0)