From 057d4ab80e42d76ae0d24d0582d27cf3630c0ec1 Mon Sep 17 00:00:00 2001 From: Masayuki Izumi Date: Sun, 19 Oct 2025 18:11:38 +0900 Subject: [PATCH] fix(dashboard): fix path filtering for `recent_files` with `cwd` option (#2201) ## Description Fix incorrect path filtering when using `recent_files` section with `cwd` option in dashboard. Previously, when setting cwd to `/foo/bar/baz`, files from directories with the same prefix like `/foo/bar/bazbaz` were incorrectly included in the recent files list. This was due to simple string prefix matching without considering directory boundaries. The fix ensures proper directory boundary checking by verifying that the path either exactly matches the filter path or is followed by a "/" character. ## Screenshots ```lua return { "snacks.nvim", ---@type snacks.Config opts = { dashboard = { enabled = true, sections = { { title = "Recent Files " .. vim.uv.cwd(), section = "recent_files", cwd = true, }, }, }, }, } ``` ### before CleanShot 2025-09-24 at 00 00 13 ### after CleanShot 2025-09-24 at 00 01 01 --- lua/snacks/dashboard.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/snacks/dashboard.lua b/lua/snacks/dashboard.lua index 1bce17af..8ebd5ff4 100644 --- a/lua/snacks/dashboard.lua +++ b/lua/snacks/dashboard.lua @@ -806,7 +806,9 @@ function M.oldfiles(opts) if want then done[file] = true for _, f in ipairs(filter) do - if (file:sub(1, #f.path) == f.path) ~= f.want then + local matches = file:sub(1, #f.path) == f.path and + (file:len() == #f.path or file:sub(#f.path + 1, #f.path + 1) == "/") + if matches ~= f.want then want = false break end