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,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 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
ret[#ret + 1] = { if not opts.filter or opts.filter(file) then
file = file, ret[#ret + 1] = {
icon = "file", file = file,
action = ":e " .. file, icon = "file",
autokey = true, action = ":e " .. file,
} autokey = true,
if #ret >= limit then }
break if #ret >= limit then
break
end
end end
end end
return ret return ret