-
-
Notifications
You must be signed in to change notification settings - Fork 611
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
Changes from all commits
7345b66
7458e54
442a6a8
f90002d
24fe92b
13aa861
7668769
e968d65
211ffa8
b03dc7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,19 +71,36 @@ local function dotfile(path) | |
end | ||
|
||
---@param path string | ||
---@param bookmarks table<string, boolean> absolute paths bookmarked | ||
local function bookmark(path, bookmarks) | ||
---@param path_type string|nil filetype of path | ||
---@param bookmarks table<string, string|nil> path, filetype table of bookmarked files | ||
local function bookmark(path, path_type, bookmarks) | ||
if not M.config.filter_no_bookmark then | ||
return false | ||
end | ||
-- if bookmark is empty, we should see a empty filetree | ||
if next(bookmarks) == nil then | ||
return true | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
-- add trailing slash to make it match only mark's parent directory | ||
-- not it's siblings | ||
local parent = utils.path_add_trailing(path) | ||
for mark, _ in pairs(bookmarks) do | ||
if path == mark or vim.fn.stridx(mark, parent) == 0 then | ||
local mark_parent = utils.path_add_trailing(path) | ||
for mark, mark_type in pairs(bookmarks) do | ||
if path == mark 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 | ||
return false | ||
end | ||
end | ||
if mark_type == "directory" then | ||
-- check if mark is path's parent | ||
local path_parent = utils.path_add_trailing(mark) | ||
if vim.fn.stridx(path, path_parent) == 0 then | ||
return false | ||
end | ||
end | ||
end | ||
|
||
return true | ||
|
@@ -139,17 +156,18 @@ function M.prepare(git_status) | |
end | ||
|
||
for _, node in pairs(marks.get_marks()) do | ||
status.bookmarks[node.absolute_path] = true | ||
status.bookmarks[node.absolute_path] = node.type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nicely efficient. Future PR: create a proper class for the return. It will be done when we apply all the 0.10 annotations and the enum is present. |
||
end | ||
|
||
return status | ||
end | ||
|
||
---Check if the given path should be filtered. | ||
---@param path string Absolute path | ||
---@param fs_stat uv.fs_stat.result|nil fs_stat of file | ||
---@param status table from prepare | ||
---@return boolean | ||
function M.should_filter(path, status) | ||
function M.should_filter(path, fs_stat, status) | ||
if not M.config.enable then | ||
return false | ||
end | ||
|
@@ -159,7 +177,11 @@ function M.should_filter(path, status) | |
return false | ||
end | ||
|
||
return git(path, status.git_status) or buf(path, status.bufinfo) or dotfile(path) or custom(path) or bookmark(path, status.bookmarks) | ||
return git(path, status.git_status) | ||
or buf(path, status.bufinfo) | ||
or dotfile(path) | ||
or custom(path) | ||
or bookmark(path, fs_stat and fs_stat.type, status.bookmarks) | ||
end | ||
|
||
function M.setup(opts) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks!