Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bookmark filter shows marked directory children #2719

Merged
merged 10 commits into from
Mar 30, 2024
13 changes: 11 additions & 2 deletions lua/nvim-tree/explorer/filters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,18 @@ local function bookmark(path, bookmarks)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the interests of efficiency let's return early in the first line if bookmarks is empty or nil.

That will avoid the first utils.path_add_trailing

-- add trailing slash to make it match only mark's parent directory
-- not it's siblings
local parent = utils.path_add_trailing(path)
local markParent = utils.path_add_trailing(path)
for mark, _ in pairs(bookmarks) do
if path == mark or vim.fn.stridx(mark, parent) == 0 then
if path == mark then
return false
end
-- check if path is mark's parent (assume path is a directory)
if vim.fn.stridx(mark, markParent) == 0 then
return false
end
-- check if mark is path's parent (assume mark is a directory)
local pathParent = utils.path_add_trailing(mark)
if vim.fn.stridx(path, pathParent) == 0 then
return false
end
end
Expand Down
Loading