Skip to content

Commit a50fd77

Browse files
authored
#857 add filter_custom action, filter_ignored->filter_git_ignored (#1077)
1 parent b136c7b commit a50fd77

File tree

6 files changed

+33
-10
lines changed

6 files changed

+33
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ local list = {
282282
{ key = "<Tab>", action = "preview" },
283283
{ key = "K", action = "first_sibling" },
284284
{ key = "J", action = "last_sibling" },
285-
{ key = "I", action = "toggle_ignored" },
285+
{ key = "I", action = "toggle_git_ignored" },
286286
{ key = "H", action = "toggle_dotfiles" },
287287
{ key = "R", action = "refresh" },
288288
{ key = "a", action = "create" },

doc/nvim-tree-lua.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,9 @@ INFORMATIONS *nvim-tree-info*
667667
- <C-x> will open the file in a horizontal split
668668
- <C-t> will open the file in a new tab
669669
- <Tab> will open the file as a preview (keeps the cursor in the tree)
670-
- `I` will toggle visibility of folders hidden via |git.ignore| option
670+
- `I` will toggle visibility of files/folders hidden via |git.ignore| option
671671
- `H` will toggle visibility of dotfiles (files/folders starting with a `.`)
672+
- U will toggle visibility of files/folders hidden via |filters.custom| option
672673
- `R` will refresh the tree
673674
- Double left click acts like <CR>
674675
- Double right click acts like <C-]>
@@ -695,7 +696,7 @@ Defaults to:
695696
{ key = "<Tab>", action = "preview" },
696697
{ key = "K", action = "first_sibling" },
697698
{ key = "J", action = "last_sibling" },
698-
{ key = "I", action = "toggle_ignored" },
699+
{ key = "I", action = "toggle_git_ignored" },
699700
{ key = "H", action = "toggle_dotfiles" },
700701
{ key = "R", action = "refresh" },
701702
{ key = "a", action = "create" },
@@ -719,6 +720,7 @@ Defaults to:
719720
{ key = "S", action = "search_node" },
720721
{ key = ".", action = "run_file_command" },
721722
{ key = "<C-k>", action = "toggle_file_info" }
723+
{ key = "U", action = "toggle_custom" },
722724
}
723725
<
724726
The `list` option in `view.mappings.list` is a table of

lua/nvim-tree/actions/init.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ local M = {
2222
{ key = "<Tab>", action = "preview" },
2323
{ key = "K", action = "first_sibling" },
2424
{ key = "J", action = "last_sibling" },
25-
{ key = "I", action = "toggle_ignored" },
25+
{ key = "I", action = "toggle_git_ignored" },
2626
{ key = "H", action = "toggle_dotfiles" },
2727
{ key = "R", action = "refresh" },
2828
{ key = "a", action = "create" },
@@ -46,6 +46,7 @@ local M = {
4646
{ key = "S", action = "search_node" },
4747
{ key = ".", action = "run_file_command" },
4848
{ key = "<C-k>", action = "toggle_file_info" },
49+
{ key = "U", action = "toggle_custom" },
4950
},
5051
custom_keypress_funcs = {},
5152
}
@@ -79,7 +80,8 @@ local keypress_funcs = {
7980
system_open = require("nvim-tree.actions.system-open").fn,
8081
toggle_dotfiles = require("nvim-tree.actions.toggles").dotfiles,
8182
toggle_help = require("nvim-tree.actions.toggles").help,
82-
toggle_ignored = require("nvim-tree.actions.toggles").ignored,
83+
toggle_custom = require("nvim-tree.actions.toggles").custom,
84+
toggle_git_ignored = require("nvim-tree.actions.toggles").git_ignored,
8385
trash = require("nvim-tree.actions.trash").fn,
8486
}
8587

lua/nvim-tree/actions/toggles.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ local reloaders = require "nvim-tree.actions.reloaders"
55

66
local M = {}
77

8-
function M.ignored()
9-
filters.config.filter_ignored = not filters.config.filter_ignored
8+
function M.custom()
9+
filters.config.filter_custom = not filters.config.filter_custom
10+
return reloaders.reload_explorer()
11+
end
12+
13+
function M.git_ignored()
14+
filters.config.filter_git_ignored = not filters.config.filter_git_ignored
1015
return reloaders.reload_explorer()
1116
end
1217

lua/nvim-tree/explorer/filters.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function M.should_ignore(path)
3030
end
3131
end
3232

33-
if not M.config.filter_ignored then
33+
if not M.config.filter_custom then
3434
return false
3535
end
3636

@@ -50,14 +50,14 @@ function M.should_ignore(path)
5050
end
5151

5252
function M.should_ignore_git(path, status)
53-
return M.config.filter_ignored
53+
return M.config.filter_git_ignored
5454
and (M.config.filter_git_ignored and status and status[path] == "!!")
5555
and not is_excluded(path)
5656
end
5757

5858
function M.setup(opts)
5959
M.config = {
60-
filter_ignored = true,
60+
filter_custom = true,
6161
filter_dotfiles = opts.filters.dotfiles,
6262
filter_git_ignored = opts.git.ignore,
6363
}

lua/nvim-tree/legacy.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ local migrations = {
180180
function M.migrate_legacy_options(opts)
181181
local msg = nil
182182

183+
-- g: options
183184
for g, m in pairs(migrations) do
184185
if vim.fn.exists("g:" .. g) ~= 0 then
185186
m(opts)
@@ -190,6 +191,19 @@ function M.migrate_legacy_options(opts)
190191
if msg then
191192
require("nvim-tree.utils").warn(msg)
192193
end
194+
195+
-- regular opts
196+
if opts.view then
197+
if opts.view.mappings then
198+
if opts.view.mappings.list then
199+
for _, m in pairs(opts.view.mappings.list) do
200+
if m.action == "toggle_ignored" then
201+
m.action = "toggle_git_ignored"
202+
end
203+
end
204+
end
205+
end
206+
end
193207
end
194208

195209
return M

0 commit comments

Comments
 (0)