From 8d49e6884d616ec430446f9a1a75436ddaa4e2b6 Mon Sep 17 00:00:00 2001 From: xiantang Date: Sat, 24 Jan 2026 16:55:50 +0800 Subject: [PATCH 1/2] refactor: use Node objects in Filters:bookmark for improved type safety --- lua/nvim-tree/explorer/filters.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lua/nvim-tree/explorer/filters.lua b/lua/nvim-tree/explorer/filters.lua index 7ec5a6abf8e..83bd27f1895 100644 --- a/lua/nvim-tree/explorer/filters.lua +++ b/lua/nvim-tree/explorer/filters.lua @@ -121,35 +121,35 @@ end ---@private ---@param path string ---@param path_type string|nil filetype of path ----@param bookmarks table path, filetype table of bookmarked files +---@param bookmarks table path to bookmarked Node ---@return boolean function Filters:bookmark(path, path_type, bookmarks) if not self.state.no_bookmark then return false end - -- if bookmark is empty, we should see a empty filetree + if next(bookmarks) == nil then return true end + local DirectoryNode = require("nvim-tree.node.directory") local mark_parent = utils.path_add_trailing(path) - for mark, mark_type in pairs(bookmarks) do - if type(mark_type) == "table" and mark_type.type then - mark_type = mark_type.type - end - if path == mark then + + for bookmark_path, bookmark_entry in pairs(bookmarks) do + if path == bookmark_path then return false end if path_type == "directory" then - -- check if path is mark's parent - if vim.fn.stridx(mark, mark_parent) == 0 then + if vim.fn.stridx(bookmark_path, mark_parent) == 0 then return false end end - if mark_type == "directory" then - -- check if mark is path's parent - local path_parent = utils.path_add_trailing(mark) + + ---@type DirectoryNode? + local dir = bookmark_entry:as(DirectoryNode) + if dir then + local path_parent = utils.path_add_trailing(bookmark_path) if vim.fn.stridx(path, path_parent) == 0 then return false end From d3fa463257d0ed79773851345357a8c5b7f47652 Mon Sep 17 00:00:00 2001 From: xiantang Date: Sat, 24 Jan 2026 16:58:18 +0800 Subject: [PATCH 2/2] docs(filters): add clarifying comments to bookmark filter logic --- lua/nvim-tree/explorer/filters.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/nvim-tree/explorer/filters.lua b/lua/nvim-tree/explorer/filters.lua index 83bd27f1895..f988dfc3170 100644 --- a/lua/nvim-tree/explorer/filters.lua +++ b/lua/nvim-tree/explorer/filters.lua @@ -127,7 +127,7 @@ function Filters:bookmark(path, path_type, bookmarks) if not self.state.no_bookmark then return false end - + -- if bookmark is empty, we should see a empty filetree if next(bookmarks) == nil then return true end @@ -141,6 +141,7 @@ function Filters:bookmark(path, path_type, bookmarks) end if path_type == "directory" then + -- check if path is mark's parent if vim.fn.stridx(bookmark_path, mark_parent) == 0 then return false end @@ -149,6 +150,7 @@ function Filters:bookmark(path, path_type, bookmarks) ---@type DirectoryNode? local dir = bookmark_entry:as(DirectoryNode) if dir then + -- check if mark is path's parent local path_parent = utils.path_add_trailing(bookmark_path) if vim.fn.stridx(path, path_parent) == 0 then return false