Skip to content

feat: add api.tree.toggle_enable_filters #2706

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

Merged
merged 10 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Show the mappings: `g?`
`>` Next Sibling |nvim-tree-api.node.navigate.sibling.next()|
`<` Previous Sibling |nvim-tree-api.node.navigate.sibling.prev()|
`.` Run Command |nvim-tree-api.node.run.cmd()|
`,` Toggle Enable Filters |nvim-tree-api.tree.toggle_enable_filters()|
`-` Up |nvim-tree-api.tree.change_root_to_parent()|
`a` Create File Or Directory |nvim-tree-api.fs.create()|
`bd` Delete Bookmarked |nvim-tree-api.marks.bulk.delete()|
Expand Down Expand Up @@ -537,6 +538,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
show_on_open_dirs = true,
},
filters = {
enable = true,
git_ignored = true,
dotfiles = false,
git_clean = false,
Expand Down Expand Up @@ -1242,6 +1244,11 @@ Only relevant when |modified.show_on_dirs| is `true`.

File / folder filters that may be toggled.

*nvim-tree.filters.enable*
Enable / disable filters.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Enable / disable filters.
Enable / disable all filters including live filter.

Toggle via |nvim-tree-api.tree.toggle_enable_filters()|, default `,`
Type: `boolean`, Default: `true`

*nvim-tree.filters.git_ignored*
Ignore files based on `.gitignore`. Requires |git.enable| `= true`
Toggle via |nvim-tree-api.tree.toggle_gitignore_filter()|, default `I`
Expand Down Expand Up @@ -2221,6 +2228,7 @@ You are encouraged to copy these to your own |nvim-tree.on_attach| function.
vim.keymap.set('n', '>', api.node.navigate.sibling.next, opts('Next Sibling'))
vim.keymap.set('n', '<', api.node.navigate.sibling.prev, opts('Previous Sibling'))
vim.keymap.set('n', '.', api.node.run.cmd, opts('Run Command'))
vim.keymap.set('n', ',', api.tree.toggle_enable_filters, opts('Toggle Enable Filters'))
vim.keymap.set('n', '-', api.tree.change_root_to_parent, opts('Up'))
vim.keymap.set('n', 'a', api.fs.create, opts('Create File Or Directory'))
vim.keymap.set('n', 'bd', api.marks.bulk.delete, opts('Delete Bookmarked'))
Expand Down Expand Up @@ -2757,6 +2765,7 @@ highlight group is not, hard linking as follows: >
|nvim-tree.filesystem_watchers.ignore_dirs|
|nvim-tree.filters.custom|
|nvim-tree.filters.dotfiles|
|nvim-tree.filters.enable|
|nvim-tree.filters.exclude|
|nvim-tree.filters.git_clean|
|nvim-tree.filters.git_ignored|
Expand Down
1 change: 1 addition & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
show_on_open_dirs = true,
},
filters = {
enable = true,
git_ignored = true,
dotfiles = false,
git_clean = false,
Expand Down
5 changes: 5 additions & 0 deletions lua/nvim-tree/actions/tree/modifiers/toggles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ function M.dotfiles()
reload()
end

function M.enable()
filters.config.enable = not filters.config.enable
reload()
end

return M
1 change: 1 addition & 0 deletions lua/nvim-tree/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Api.tree.find_file = wrap(actions.tree.find_file.fn)
Api.tree.search_node = wrap(actions.finders.search_node.fn)
Api.tree.collapse_all = wrap(actions.tree.modifiers.collapse_all.fn)
Api.tree.expand_all = wrap_node(actions.tree.modifiers.expand_all.fn)
Api.tree.toggle_enable_filters = wrap(actions.tree.modifiers.toggles.enable)
Api.tree.toggle_gitignore_filter = wrap(actions.tree.modifiers.toggles.git_ignored)
Api.tree.toggle_git_clean_filter = wrap(actions.tree.modifiers.toggles.git_clean)
Api.tree.toggle_no_buffer_filter = wrap(actions.tree.modifiers.toggles.no_buffer)
Expand Down
5 changes: 5 additions & 0 deletions lua/nvim-tree/explorer/filters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ end
---@param status table from prepare
---@return boolean
function M.should_filter(path, status)
if not M.config.enable then
return false
end

-- exclusions override all filters
if is_excluded(path) then
return false
Expand All @@ -160,6 +164,7 @@ end

function M.setup(opts)
M.config = {
enable = opts.filters.enable,
filter_custom = true,
filter_dotfiles = opts.filters.dotfiles,
filter_git_ignored = opts.filters.git_ignored,
Expand Down
1 change: 1 addition & 0 deletions lua/nvim-tree/keymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function M.default_on_attach(bufnr)
vim.keymap.set('n', '>', api.node.navigate.sibling.next, opts('Next Sibling'))
vim.keymap.set('n', '<', api.node.navigate.sibling.prev, opts('Previous Sibling'))
vim.keymap.set('n', '.', api.node.run.cmd, opts('Run Command'))
vim.keymap.set('n', ',', api.tree.toggle_enable_filters, opts('Toggle Enable Filters'))
vim.keymap.set('n', '-', api.tree.change_root_to_parent, opts('Up'))
vim.keymap.set('n', 'a', api.fs.create, opts('Create File Or Directory'))
vim.keymap.set('n', 'bd', api.marks.bulk.delete, opts('Delete Bookmarked'))
Expand Down