Skip to content

Commit 47ccc29

Browse files
committed
refacto: move toggle help and filter toggles into actions
also fix explorer to properly remove element on update when filter is applied
1 parent 230a61d commit 47ccc29

File tree

6 files changed

+40
-33
lines changed

6 files changed

+40
-33
lines changed

lua/nvim-tree/actions/init.lua

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
local a = vim.api
22

33
local lib = require'nvim-tree.lib'
4-
local config = require'nvim-tree.config'
54
local view = require'nvim-tree.view'
65
local nvim_tree_callback = require'nvim-tree.config'.nvim_tree_callback
76

@@ -44,15 +43,6 @@ local M = {
4443
custom_keypress_funcs = {},
4544
}
4645

47-
local function go_to(mode)
48-
local icon_state = config.get_icon_state()
49-
local flags = mode == 'prev_git_item' and 'b' or ''
50-
local icons = table.concat(vim.tbl_values(icon_state.icons.git_icons), '\\|')
51-
return function()
52-
return icon_state.show_git_icon and vim.fn.search(icons, flags)
53-
end
54-
end
55-
5646
local keypress_funcs = {
5747
close = view.close,
5848
close_node = require'nvim-tree.actions.movements'.parent_node(true),
@@ -66,19 +56,19 @@ local keypress_funcs = {
6656
first_sibling = require'nvim-tree.actions.movements'.sibling(-math.huge),
6757
full_rename = require'nvim-tree.actions.rename-file'.fn(true),
6858
last_sibling = require'nvim-tree.actions.movements'.sibling(math.huge),
69-
next_git_item = go_to('next_git_item'),
59+
next_git_item = require"nvim-tree.actions.movements".find_git_item('next'),
7060
next_sibling = require'nvim-tree.actions.movements'.sibling(1),
7161
parent_node = require'nvim-tree.actions.movements'.parent_node(false),
7262
paste = require'nvim-tree.actions.copy-paste'.paste,
73-
prev_git_item = go_to('prev_git_item'),
63+
prev_git_item = require"nvim-tree.actions.movements".find_git_item('prev'),
7464
prev_sibling = require'nvim-tree.actions.movements'.sibling(-1),
7565
refresh = require'nvim-tree.actions.reloaders'.reload_explorer,
7666
remove = require'nvim-tree.actions.remove-file'.fn,
7767
rename = require'nvim-tree.actions.rename-file'.fn(false),
7868
system_open = require'nvim-tree.actions.system-open'.fn,
79-
toggle_dotfiles = lib.toggle_dotfiles,
80-
toggle_help = lib.toggle_help,
81-
toggle_ignored = lib.toggle_ignored,
69+
toggle_dotfiles = require"nvim-tree.actions.toggle-ignore".dotfiles,
70+
toggle_help = require"nvim-tree.actions.toggle-help".fn,
71+
toggle_ignored = require"nvim-tree.actions.toggle-ignore".ignored,
8272
trash = require'nvim-tree.actions.trash'.fn,
8373
}
8474

lua/nvim-tree/actions/movements.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local utils = require'nvim-tree.utils'
22
local view = require'nvim-tree.view'
33
local diagnostics = require'nvim-tree.diagnostics'
4+
local config = require"nvim-tree.config"
45
local lib = function() return require'nvim-tree.lib' end
56

67
local M = {}
@@ -103,4 +104,13 @@ function M.sibling(direction)
103104
end
104105
end
105106

107+
function M.find_git_item(where)
108+
local icon_state = config.get_icon_state()
109+
local flags = where == 'next' and 'b' or ''
110+
local icons = table.concat(vim.tbl_values(icon_state.icons.git_icons), '\\|')
111+
return function()
112+
return icon_state.show_git_icon and vim.fn.search(icons, flags)
113+
end
114+
end
115+
106116
return M

lua/nvim-tree/actions/toggle-help.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
local M = {}
2+
3+
function M.fn()
4+
require"nvim-tree.view".toggle_help()
5+
return require"nvim-tree.lib".redraw()
6+
end
7+
8+
return M
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
local M = {}
2+
3+
function M.ignored()
4+
local config = require"nvim-tree.explorer.utils".config
5+
config.filter_ignored = not config.filter_ignored
6+
return require'nvim-tree.actions.reloaders'.reload_explorer()
7+
end
8+
9+
function M.dotfiles()
10+
local config = require"nvim-tree.explorer.utils".config
11+
config.filter_dotfiles = not config.filter_dotfiles
12+
return require'nvim-tree.actions.reloaders'.reload_explorer()
13+
end
14+
15+
return M

lua/nvim-tree/explorer/reload.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ function M.reload(node, cwd, status)
3737

3838
local abs = utils.path_join({cwd, name})
3939
t = t or (uv.fs_stat(abs) or {}).type
40-
child_names[abs] = true
4140
if not nodes_by_path[abs] and not eutils.should_ignore(abs) and not eutils.should_ignore_git(abs, status.files) then
41+
child_names[abs] = true
4242
if t == 'directory' and uv.fs_access(abs, 'R') then
4343
table.insert(node.nodes, builders.folder(abs, name, status, node_ignored))
4444
elseif t == 'file' then
@@ -52,6 +52,7 @@ function M.reload(node, cwd, status)
5252
end
5353
end
5454

55+
dump(child_names)
5556
for i, n in ipairs(node.nodes) do
5657
if not child_names[n.absolute_path] then
5758
table.remove(node.nodes, i)

lua/nvim-tree/lib.lua

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,6 @@ function M.open()
119119
end
120120
end
121121

122-
function M.toggle_ignored()
123-
local config = require"nvim-tree.explorer.utils".config
124-
config.filter_ignored = not config.filter_ignored
125-
return require'nvim-tree.actions.reloaders'.reload_explorer()
126-
end
127-
128-
function M.toggle_dotfiles()
129-
local config = require"nvim-tree.explorer.utils".config
130-
config.filter_dotfiles = not config.filter_dotfiles
131-
return require'nvim-tree.actions.reloaders'.reload_explorer()
132-
end
133-
134-
function M.toggle_help()
135-
view.toggle_help()
136-
return M.redraw()
137-
end
138-
139122
-- @deprecated: use nvim-tree.actions.collapse-all.fn
140123
M.collapse_all = require'nvim-tree.actions.collapse-all'.fn
141124
-- @deprecated: use nvim-tree.actions.dir-up.fn

0 commit comments

Comments
 (0)