feat(explorer): added support for live search

This commit is contained in:
Folke Lemaitre 2025-02-06 10:25:39 +01:00
parent 7904aed195
commit 82c4a50985
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
3 changed files with 8 additions and 2 deletions

View file

@ -46,6 +46,7 @@ M.buffers = {
M.explorer = { M.explorer = {
finder = "explorer", finder = "explorer",
sort = { fields = { "sort" } }, sort = { fields = { "sort" } },
supports_live = true,
tree = true, tree = true,
watch = true, watch = true,
git_status = true, git_status = true,

View file

@ -51,6 +51,10 @@ function M:init(opts)
return self return self
end end
function M:is_empty()
return vim.trim(self.pattern) == "" and vim.trim(self.search) == ""
end
---@param cwd string ---@param cwd string
function M:set_cwd(cwd) function M:set_cwd(cwd)
self.cwd = cwd self.cwd = cwd

View file

@ -106,7 +106,7 @@ function State:setup(ctx)
if opts.watch then if opts.watch then
require("snacks.explorer.watch").watch(ctx.filter.cwd) require("snacks.explorer.watch").watch(ctx.filter.cwd)
end end
return #ctx.filter.pattern > 0 return not ctx.filter:is_empty()
end end
---@param opts snacks.picker.explorer.Config ---@param opts snacks.picker.explorer.Config
@ -123,7 +123,7 @@ function M.setup(opts)
---@param filter snacks.picker.Filter ---@param filter snacks.picker.Filter
transform = function(picker, filter) transform = function(picker, filter)
ref = picker:ref() ref = picker:ref()
local s = #filter.pattern > 0 local s = not filter:is_empty()
if searching ~= s then if searching ~= s then
searching = s searching = s
filter.meta.searching = searching filter.meta.searching = searching
@ -146,6 +146,7 @@ function M.setup(opts)
if parent.score == 0 or parent.match_tick ~= matcher.tick then if parent.score == 0 or parent.match_tick ~= matcher.tick then
parent.score = 1 parent.score = 1
parent.match_tick = matcher.tick parent.match_tick = matcher.tick
parent.match_topk = nil
picker.list:add(parent) picker.list:add(parent)
else else
break break