Skip to content

#857 add filter_custom action, filter_ignored->filter_git_ignored #1077

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 2 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ local list = {
{ key = "<Tab>", action = "preview" },
{ key = "K", action = "first_sibling" },
{ key = "J", action = "last_sibling" },
{ key = "I", action = "toggle_ignored" },
{ key = "I", action = "toggle_git_ignored" },
{ key = "H", action = "toggle_dotfiles" },
{ key = "R", action = "refresh" },
{ key = "a", action = "create" },
Expand Down
6 changes: 4 additions & 2 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,9 @@ INFORMATIONS *nvim-tree-info*
- <C-x> will open the file in a horizontal split
- <C-t> will open the file in a new tab
- <Tab> will open the file as a preview (keeps the cursor in the tree)
- `I` will toggle visibility of folders hidden via |git.ignore| option
- `I` will toggle visibility of files/folders hidden via |git.ignore| option
- `H` will toggle visibility of dotfiles (files/folders starting with a `.`)
- U will toggle visibility of files/folders hidden via |filters.custom| option
- `R` will refresh the tree
- Double left click acts like <CR>
- Double right click acts like <C-]>
Expand All @@ -691,7 +692,7 @@ Defaults to:
{ key = "<Tab>", action = "preview" },
{ key = "K", action = "first_sibling" },
{ key = "J", action = "last_sibling" },
{ key = "I", action = "toggle_ignored" },
{ key = "I", action = "toggle_git_ignored" },
{ key = "H", action = "toggle_dotfiles" },
{ key = "R", action = "refresh" },
{ key = "a", action = "create" },
Expand All @@ -715,6 +716,7 @@ Defaults to:
{ key = "S", action = "search_node" },
{ key = ".", action = "run_file_command" },
{ key = "<C-k>", action = "toggle_file_info" }
{ key = "U", action = "toggle_custom" },
}
<
The `list` option in `view.mappings.list` is a table of
Expand Down
6 changes: 4 additions & 2 deletions lua/nvim-tree/actions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ local M = {
{ key = "<Tab>", action = "preview" },
{ key = "K", action = "first_sibling" },
{ key = "J", action = "last_sibling" },
{ key = "I", action = "toggle_ignored" },
{ key = "I", action = "toggle_git_ignored" },
{ key = "H", action = "toggle_dotfiles" },
{ key = "R", action = "refresh" },
{ key = "a", action = "create" },
Expand All @@ -46,6 +46,7 @@ local M = {
{ key = "S", action = "search_node" },
{ key = ".", action = "run_file_command" },
{ key = "<C-k>", action = "toggle_file_info" },
{ key = "U", action = "toggle_custom" },
},
custom_keypress_funcs = {},
}
Expand Down Expand Up @@ -79,7 +80,8 @@ local keypress_funcs = {
system_open = require("nvim-tree.actions.system-open").fn,
toggle_dotfiles = require("nvim-tree.actions.toggles").dotfiles,
toggle_help = require("nvim-tree.actions.toggles").help,
toggle_ignored = require("nvim-tree.actions.toggles").ignored,
toggle_custom = require("nvim-tree.actions.toggles").custom,
toggle_git_ignored = require("nvim-tree.actions.toggles").git_ignored,
trash = require("nvim-tree.actions.trash").fn,
}

Expand Down
9 changes: 7 additions & 2 deletions lua/nvim-tree/actions/toggles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ local reloaders = require "nvim-tree.actions.reloaders"

local M = {}

function M.ignored()
filters.config.filter_ignored = not filters.config.filter_ignored
function M.custom()
filters.config.filter_custom = not filters.config.filter_custom
return reloaders.reload_explorer()
end

function M.git_ignored()
filters.config.filter_git_ignored = not filters.config.filter_git_ignored
return reloaders.reload_explorer()
end

Expand Down
6 changes: 3 additions & 3 deletions lua/nvim-tree/explorer/filters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function M.should_ignore(path)
end
end

if not M.config.filter_ignored then
if not M.config.filter_custom then
return false
end

Expand All @@ -50,14 +50,14 @@ function M.should_ignore(path)
end

function M.should_ignore_git(path, status)
return M.config.filter_ignored
return M.config.filter_git_ignored
and (M.config.filter_git_ignored and status and status[path] == "!!")
and not is_excluded(path)
end

function M.setup(opts)
M.config = {
filter_ignored = true,
filter_custom = true,
filter_dotfiles = opts.filters.dotfiles,
filter_git_ignored = opts.git.ignore,
}
Expand Down
14 changes: 14 additions & 0 deletions lua/nvim-tree/legacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ local migrations = {
function M.migrate_legacy_options(opts)
local msg = nil

-- g: options
for g, m in pairs(migrations) do
if vim.fn.exists("g:" .. g) ~= 0 then
m(opts)
Expand All @@ -190,6 +191,19 @@ function M.migrate_legacy_options(opts)
if msg then
require("nvim-tree.utils").warn(msg)
end

-- regular opts
if opts.view then
if opts.view.mappings then
if opts.view.mappings.list then
for _, m in pairs(opts.view.mappings.list) do
if m.action == "toggle_ignored" then
m.action = "toggle_git_ignored"
Copy link
Member Author

Choose a reason for hiding this comment

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

This is silent. We could add a message.

Copy link
Member

Choose a reason for hiding this comment

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

that's okay for now i guess. Thanks :)

end
end
end
end
end
end

return M