mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 11:18:26 +00:00
feat(explorer): added support for live search
This commit is contained in:
parent
7904aed195
commit
82c4a50985
3 changed files with 8 additions and 2 deletions
|
@ -46,6 +46,7 @@ M.buffers = {
|
|||
M.explorer = {
|
||||
finder = "explorer",
|
||||
sort = { fields = { "sort" } },
|
||||
supports_live = true,
|
||||
tree = true,
|
||||
watch = true,
|
||||
git_status = true,
|
||||
|
|
|
@ -51,6 +51,10 @@ function M:init(opts)
|
|||
return self
|
||||
end
|
||||
|
||||
function M:is_empty()
|
||||
return vim.trim(self.pattern) == "" and vim.trim(self.search) == ""
|
||||
end
|
||||
|
||||
---@param cwd string
|
||||
function M:set_cwd(cwd)
|
||||
self.cwd = cwd
|
||||
|
|
|
@ -106,7 +106,7 @@ function State:setup(ctx)
|
|||
if opts.watch then
|
||||
require("snacks.explorer.watch").watch(ctx.filter.cwd)
|
||||
end
|
||||
return #ctx.filter.pattern > 0
|
||||
return not ctx.filter:is_empty()
|
||||
end
|
||||
|
||||
---@param opts snacks.picker.explorer.Config
|
||||
|
@ -123,7 +123,7 @@ function M.setup(opts)
|
|||
---@param filter snacks.picker.Filter
|
||||
transform = function(picker, filter)
|
||||
ref = picker:ref()
|
||||
local s = #filter.pattern > 0
|
||||
local s = not filter:is_empty()
|
||||
if searching ~= s then
|
||||
searching = s
|
||||
filter.meta.searching = searching
|
||||
|
@ -146,6 +146,7 @@ function M.setup(opts)
|
|||
if parent.score == 0 or parent.match_tick ~= matcher.tick then
|
||||
parent.score = 1
|
||||
parent.match_tick = matcher.tick
|
||||
parent.match_topk = nil
|
||||
picker.list:add(parent)
|
||||
else
|
||||
break
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue