mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 03:08:13 +00:00
feat(explorer): focus on first file when searching in the explorer
This commit is contained in:
parent
93d5abf133
commit
1d4bea4a9e
2 changed files with 21 additions and 15 deletions
|
@ -7,6 +7,7 @@ local Async = require("snacks.picker.util.async")
|
|||
---@class snacks.picker.matcher.Config
|
||||
---@field regex? boolean used internally for positions of sources that use regex
|
||||
---@field on_match? fun(matcher: snacks.picker.Matcher, item: snacks.picker.Item)
|
||||
---@field on_done? fun(matcher: snacks.picker.Matcher)
|
||||
|
||||
---@class snacks.picker.Matcher
|
||||
---@field opts snacks.picker.matcher.Config
|
||||
|
@ -91,6 +92,9 @@ function M:run(picker)
|
|||
if not (self.sorting or picker.finder.task:running()) then
|
||||
picker.list.items = picker.finder.items
|
||||
picker:update({ force = true })
|
||||
if self.opts.on_done then
|
||||
self.opts.on_done(self)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -157,6 +161,11 @@ function M:run(picker)
|
|||
until idx >= #picker.finder.items and not picker.finder.task:running()
|
||||
|
||||
picker:update({ force = true })
|
||||
if self.opts.on_done then
|
||||
vim.schedule(function()
|
||||
self.opts.on_done(self)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
@ -163,6 +163,18 @@ function M.setup(opts)
|
|||
end
|
||||
end
|
||||
end,
|
||||
on_done = function()
|
||||
local picker = ref.value
|
||||
if not picker or picker.closed then
|
||||
return
|
||||
end
|
||||
for item, idx in picker:iter() do
|
||||
if not item.dir then
|
||||
picker.list:view(idx)
|
||||
return
|
||||
end
|
||||
end
|
||||
end,
|
||||
},
|
||||
formatters = {
|
||||
file = {
|
||||
|
@ -265,21 +277,6 @@ function M.search(opts, ctx)
|
|||
---@async
|
||||
return function(cb)
|
||||
cb(root)
|
||||
-- focus the first non-internal item
|
||||
ctx.picker.matcher.task:on(
|
||||
"done",
|
||||
vim.schedule_wrap(function()
|
||||
if ctx.picker.closed then
|
||||
return
|
||||
end
|
||||
for item, idx in ctx.picker:iter() do
|
||||
if not item.internal then
|
||||
ctx.picker.list:view(idx)
|
||||
return
|
||||
end
|
||||
end
|
||||
end)
|
||||
)
|
||||
|
||||
---@param item snacks.picker.explorer.Item
|
||||
local function add(item)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue