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 --- Get the most recent files, optionally filtered by the
--- current working directory or a custom directory. --- 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 ---@return snacks.dashboard.Gen
function M.sections.recent_files(opts) function M.sections.recent_files(opts)
return function() return function()
@ -850,6 +850,7 @@ 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 root = opts.cwd and vim.fs.normalize(opts.cwd == true and vim.fn.getcwd() or opts.cwd) or ""
local ret = {} ---@type snacks.dashboard.Section local ret = {} ---@type snacks.dashboard.Section
for file in M.oldfiles({ filter = { [root] = true } }) do for file in M.oldfiles({ filter = { [root] = true } }) do
if not opts.filter or opts.filter(file) then
ret[#ret + 1] = { ret[#ret + 1] = {
file = file, file = file,
icon = "file", icon = "file",
@ -860,6 +861,7 @@ function M.sections.recent_files(opts)
break break
end end
end end
end
return ret return ret
end end
end end