fix(dashboard): added optional filter for recent files

This commit is contained in:
Folke Lemaitre 2025-01-20 12:14:54 +01:00
parent 920a9d28f1
commit 32cd34383c
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -841,7 +841,7 @@ end
--- Get the most recent files, optionally filtered by the
--- current working directory or a custom directory.
---@param opts? {limit?:number, cwd?:string|boolean}
---@param opts? {limit?:number, cwd?:string|boolean, filter?:fun(file:string):boolean?}
---@return snacks.dashboard.Gen
function M.sections.recent_files(opts)
return function()
@ -850,14 +850,16 @@ function M.sections.recent_files(opts)
local root = opts.cwd and vim.fs.normalize(opts.cwd == true and vim.fn.getcwd() or opts.cwd) or ""
local ret = {} ---@type snacks.dashboard.Section
for file in M.oldfiles({ filter = { [root] = true } }) do
ret[#ret + 1] = {
file = file,
icon = "file",
action = ":e " .. file,
autokey = true,
}
if #ret >= limit then
break
if not opts.filter or opts.filter(file) then
ret[#ret + 1] = {
file = file,
icon = "file",
action = ":e " .. file,
autokey = true,
}
if #ret >= limit then
break
end
end
end
return ret