fix: api and filtration
This commit is contained in:
parent
9deac32a40
commit
a634a1bb4d
@ -264,15 +264,17 @@ Api.git.reload = wrap(actions.reloaders.reload_git)
|
|||||||
Api.events.subscribe = events.subscribe
|
Api.events.subscribe = events.subscribe
|
||||||
Api.events.Event = events.Event
|
Api.events.Event = events.Event
|
||||||
|
|
||||||
Api.live_filter.start = wrap_explorer(function(explorer)
|
Api.live_filter.start = wrap(function(...)
|
||||||
return wrap(function(...)
|
local explorer = core.get_explorer()
|
||||||
|
if explorer then
|
||||||
return explorer.live_filter:start_filtering(...)
|
return explorer.live_filter:start_filtering(...)
|
||||||
end)
|
end
|
||||||
end)
|
end)
|
||||||
Api.live_filter.clear = wrap_explorer(function(explorer)
|
Api.live_filter.clear = wrap(function(...)
|
||||||
return wrap(function(...)
|
local explorer = core.get_explorer()
|
||||||
|
if explorer then
|
||||||
return explorer.live_filter:clear_filter(...)
|
return explorer.live_filter:clear_filter(...)
|
||||||
end)
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Api.marks.get = wrap_node(wrap_explorer_member("marks", "get_mark"))
|
Api.marks.get = wrap_node(wrap_explorer_member("marks", "get_mark"))
|
||||||
|
|||||||
@ -7,7 +7,8 @@ local LiveFilter = {}
|
|||||||
function LiveFilter:new(opts, explorer)
|
function LiveFilter:new(opts, explorer)
|
||||||
local o = {
|
local o = {
|
||||||
explorer = explorer,
|
explorer = explorer,
|
||||||
config = vim.deepcopy(opts.live_filter),
|
prefix = opts.live_filter.prefix,
|
||||||
|
always_show_folders = opts.live_filter.always_show_folders,
|
||||||
filter = nil,
|
filter = nil,
|
||||||
}
|
}
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
@ -57,8 +58,8 @@ local function remove_overlay(self)
|
|||||||
overlay_bufnr = 0
|
overlay_bufnr = 0
|
||||||
overlay_winnr = 0
|
overlay_winnr = 0
|
||||||
|
|
||||||
if self.explorer.live_filter.filter == "" then
|
if self.filter == "" then
|
||||||
self.explorer.live_filter.clear_filter()
|
self:clear_filter()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -96,7 +97,7 @@ function LiveFilter:apply_filter(node_)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local has_nodes = nodes and (self.config.always_show_folders or #nodes > filtered_nodes)
|
local has_nodes = nodes and (self.always_show_folders or #nodes > filtered_nodes)
|
||||||
local ok, is_match = pcall(matches, self, node)
|
local ok, is_match = pcall(matches, self, node)
|
||||||
node.hidden = not (has_nodes or (ok and is_match))
|
node.hidden = not (has_nodes or (ok and is_match))
|
||||||
end
|
end
|
||||||
@ -106,8 +107,8 @@ end
|
|||||||
|
|
||||||
local function record_char(self)
|
local function record_char(self)
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
self.explorer.live_filter.filter = vim.api.nvim_buf_get_lines(overlay_bufnr, 0, -1, false)[1]
|
self.filter = vim.api.nvim_buf_get_lines(overlay_bufnr, 0, -1, false)[1]
|
||||||
self.explorer.live_filter.apply_filter()
|
self:apply_filter()
|
||||||
redraw()
|
redraw()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@ -132,7 +133,7 @@ local function calculate_overlay_win_width(self)
|
|||||||
local wininfo = vim.fn.getwininfo(view.get_winnr())[1]
|
local wininfo = vim.fn.getwininfo(view.get_winnr())[1]
|
||||||
|
|
||||||
if wininfo then
|
if wininfo then
|
||||||
return wininfo.width - wininfo.textoff - #self.explorer.live_filter.prefix
|
return wininfo.width - wininfo.textoff - #self.prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
return 20
|
return 20
|
||||||
@ -153,7 +154,7 @@ local function create_overlay(self)
|
|||||||
col = 1,
|
col = 1,
|
||||||
row = 0,
|
row = 0,
|
||||||
relative = "cursor",
|
relative = "cursor",
|
||||||
width = calculate_overlay_win_width(self.explorer),
|
width = calculate_overlay_win_width(self),
|
||||||
height = 1,
|
height = 1,
|
||||||
border = "none",
|
border = "none",
|
||||||
style = "minimal",
|
style = "minimal",
|
||||||
@ -165,9 +166,9 @@ local function create_overlay(self)
|
|||||||
vim.api.nvim_buf_set_option(overlay_bufnr, "modifiable", true) ---@diagnostic disable-line: deprecated
|
vim.api.nvim_buf_set_option(overlay_bufnr, "modifiable", true) ---@diagnostic disable-line: deprecated
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_buf_set_lines(overlay_bufnr, 0, -1, false, { self.explorer.live_filter.filter })
|
vim.api.nvim_buf_set_lines(overlay_bufnr, 0, -1, false, { self.filter })
|
||||||
vim.cmd "startinsert"
|
vim.cmd "startinsert"
|
||||||
vim.api.nvim_win_set_cursor(overlay_winnr, { 1, #self.explorer.live_filter.filter + 1 })
|
vim.api.nvim_win_set_cursor(overlay_winnr, { 1, #self.filter + 1 })
|
||||||
end
|
end
|
||||||
|
|
||||||
function LiveFilter:start_filtering()
|
function LiveFilter:start_filtering()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user