mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 11:18:26 +00:00
fix(dashboard): added optional filter for recent files
This commit is contained in:
parent
920a9d28f1
commit
32cd34383c
1 changed files with 11 additions and 9 deletions
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue