* feat(#2654): add `binaries` field to `filters` * feat(#2648): allow functions in `filters.custom` * ci: fix: stylua check * ci: fix: add new keybind and config to docs * fix: replace os-specific binary filter with `vim.fn.executable` * fix: remove function and mapping for `binaries` filter * fix: add `node` parameter to custom filter function * fix: update doc for custom filter function signature * fix: add custom filter to `ACCEPTED_TYPES` * fix: accept single function for custom filter * fix: change custom filter on `ACCEPTED_TYPES` * fix: revert to using `path` for custom filter function * fix: use `function` type for custom filter * fix: type for custom filter in help * fix: custom filter single function no longer mutates `M.config.filter_custom` * fix: remove dead `if` statement in custom filter * fix: separate custom filter function from `M.ignore_list` * doc nit --------- Co-authored-by: darcy <44690813+darccyy@users.noreply.github.com> Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
parent
2dbe4ea2b5
commit
4a87b8b46b
@ -1262,7 +1262,7 @@ Enabling this is not useful as there is no means yet to persist bookmarks.
|
||||
Custom list of vim regex for file/directory names that will not be shown.
|
||||
Backslashes must be escaped e.g. "^\\.git". See |string-match|.
|
||||
Toggle via |nvim-tree-api.tree.toggle_custom_filter()|, default `U`
|
||||
Type: {string}, Default: `{}`
|
||||
Type: {string} | `function(absolute_path)`, Default: `{}`
|
||||
|
||||
*nvim-tree.filters.exclude*
|
||||
List of directories or files to exclude from filtering: always show them.
|
||||
|
||||
@ -623,6 +623,9 @@ local ACCEPTED_TYPES = {
|
||||
group_empty = { "boolean", "function" },
|
||||
root_folder_label = { "function", "string", "boolean" },
|
||||
},
|
||||
filters = {
|
||||
custom = { "function" },
|
||||
},
|
||||
actions = {
|
||||
open_file = {
|
||||
window_picker = {
|
||||
|
||||
@ -4,6 +4,7 @@ local marks = require "nvim-tree.marks"
|
||||
local M = {
|
||||
ignore_list = {},
|
||||
exclude_list = {},
|
||||
custom_function = nil,
|
||||
}
|
||||
|
||||
---@param path string
|
||||
@ -84,6 +85,11 @@ local function custom(path)
|
||||
|
||||
local basename = utils.path_basename(path)
|
||||
|
||||
-- filter user's custom function
|
||||
if M.custom_function and M.custom_function(path) then
|
||||
return true
|
||||
end
|
||||
|
||||
-- filter custom regexes
|
||||
local relpath = utils.path_relative(path, vim.loop.cwd())
|
||||
for pat, _ in pairs(M.ignore_list) do
|
||||
@ -153,11 +159,15 @@ function M.setup(opts)
|
||||
M.exclude_list = opts.filters.exclude
|
||||
|
||||
local custom_filter = opts.filters.custom
|
||||
if type(custom_filter) == "function" then
|
||||
M.custom_function = custom_filter
|
||||
else
|
||||
if custom_filter and #custom_filter > 0 then
|
||||
for _, filter_name in pairs(custom_filter) do
|
||||
M.ignore_list[filter_name] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Loading…
Reference in New Issue
Block a user