refacto: move toggle help and filter toggles into actions
also fix explorer to properly remove element on update when filter is applied
This commit is contained in:
parent
230a61db91
commit
47ccc2913f
@ -1,7 +1,6 @@
|
||||
local a = vim.api
|
||||
|
||||
local lib = require'nvim-tree.lib'
|
||||
local config = require'nvim-tree.config'
|
||||
local view = require'nvim-tree.view'
|
||||
local nvim_tree_callback = require'nvim-tree.config'.nvim_tree_callback
|
||||
|
||||
@ -44,15 +43,6 @@ local M = {
|
||||
custom_keypress_funcs = {},
|
||||
}
|
||||
|
||||
local function go_to(mode)
|
||||
local icon_state = config.get_icon_state()
|
||||
local flags = mode == 'prev_git_item' and 'b' or ''
|
||||
local icons = table.concat(vim.tbl_values(icon_state.icons.git_icons), '\\|')
|
||||
return function()
|
||||
return icon_state.show_git_icon and vim.fn.search(icons, flags)
|
||||
end
|
||||
end
|
||||
|
||||
local keypress_funcs = {
|
||||
close = view.close,
|
||||
close_node = require'nvim-tree.actions.movements'.parent_node(true),
|
||||
@ -66,19 +56,19 @@ local keypress_funcs = {
|
||||
first_sibling = require'nvim-tree.actions.movements'.sibling(-math.huge),
|
||||
full_rename = require'nvim-tree.actions.rename-file'.fn(true),
|
||||
last_sibling = require'nvim-tree.actions.movements'.sibling(math.huge),
|
||||
next_git_item = go_to('next_git_item'),
|
||||
next_git_item = require"nvim-tree.actions.movements".find_git_item('next'),
|
||||
next_sibling = require'nvim-tree.actions.movements'.sibling(1),
|
||||
parent_node = require'nvim-tree.actions.movements'.parent_node(false),
|
||||
paste = require'nvim-tree.actions.copy-paste'.paste,
|
||||
prev_git_item = go_to('prev_git_item'),
|
||||
prev_git_item = require"nvim-tree.actions.movements".find_git_item('prev'),
|
||||
prev_sibling = require'nvim-tree.actions.movements'.sibling(-1),
|
||||
refresh = require'nvim-tree.actions.reloaders'.reload_explorer,
|
||||
remove = require'nvim-tree.actions.remove-file'.fn,
|
||||
rename = require'nvim-tree.actions.rename-file'.fn(false),
|
||||
system_open = require'nvim-tree.actions.system-open'.fn,
|
||||
toggle_dotfiles = lib.toggle_dotfiles,
|
||||
toggle_help = lib.toggle_help,
|
||||
toggle_ignored = lib.toggle_ignored,
|
||||
toggle_dotfiles = require"nvim-tree.actions.toggle-ignore".dotfiles,
|
||||
toggle_help = require"nvim-tree.actions.toggle-help".fn,
|
||||
toggle_ignored = require"nvim-tree.actions.toggle-ignore".ignored,
|
||||
trash = require'nvim-tree.actions.trash'.fn,
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
local utils = require'nvim-tree.utils'
|
||||
local view = require'nvim-tree.view'
|
||||
local diagnostics = require'nvim-tree.diagnostics'
|
||||
local config = require"nvim-tree.config"
|
||||
local lib = function() return require'nvim-tree.lib' end
|
||||
|
||||
local M = {}
|
||||
@ -103,4 +104,13 @@ function M.sibling(direction)
|
||||
end
|
||||
end
|
||||
|
||||
function M.find_git_item(where)
|
||||
local icon_state = config.get_icon_state()
|
||||
local flags = where == 'next' and 'b' or ''
|
||||
local icons = table.concat(vim.tbl_values(icon_state.icons.git_icons), '\\|')
|
||||
return function()
|
||||
return icon_state.show_git_icon and vim.fn.search(icons, flags)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
8
lua/nvim-tree/actions/toggle-help.lua
Normal file
8
lua/nvim-tree/actions/toggle-help.lua
Normal file
@ -0,0 +1,8 @@
|
||||
local M = {}
|
||||
|
||||
function M.fn()
|
||||
require"nvim-tree.view".toggle_help()
|
||||
return require"nvim-tree.lib".redraw()
|
||||
end
|
||||
|
||||
return M
|
||||
15
lua/nvim-tree/actions/toggle-ignore.lua
Normal file
15
lua/nvim-tree/actions/toggle-ignore.lua
Normal file
@ -0,0 +1,15 @@
|
||||
local M = {}
|
||||
|
||||
function M.ignored()
|
||||
local config = require"nvim-tree.explorer.utils".config
|
||||
config.filter_ignored = not config.filter_ignored
|
||||
return require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
end
|
||||
|
||||
function M.dotfiles()
|
||||
local config = require"nvim-tree.explorer.utils".config
|
||||
config.filter_dotfiles = not config.filter_dotfiles
|
||||
return require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
end
|
||||
|
||||
return M
|
||||
@ -37,8 +37,8 @@ function M.reload(node, cwd, status)
|
||||
|
||||
local abs = utils.path_join({cwd, name})
|
||||
t = t or (uv.fs_stat(abs) or {}).type
|
||||
child_names[abs] = true
|
||||
if not nodes_by_path[abs] and not eutils.should_ignore(abs) and not eutils.should_ignore_git(abs, status.files) then
|
||||
child_names[abs] = true
|
||||
if t == 'directory' and uv.fs_access(abs, 'R') then
|
||||
table.insert(node.nodes, builders.folder(abs, name, status, node_ignored))
|
||||
elseif t == 'file' then
|
||||
@ -52,6 +52,7 @@ function M.reload(node, cwd, status)
|
||||
end
|
||||
end
|
||||
|
||||
dump(child_names)
|
||||
for i, n in ipairs(node.nodes) do
|
||||
if not child_names[n.absolute_path] then
|
||||
table.remove(node.nodes, i)
|
||||
|
||||
@ -119,23 +119,6 @@ function M.open()
|
||||
end
|
||||
end
|
||||
|
||||
function M.toggle_ignored()
|
||||
local config = require"nvim-tree.explorer.utils".config
|
||||
config.filter_ignored = not config.filter_ignored
|
||||
return require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
end
|
||||
|
||||
function M.toggle_dotfiles()
|
||||
local config = require"nvim-tree.explorer.utils".config
|
||||
config.filter_dotfiles = not config.filter_dotfiles
|
||||
return require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
end
|
||||
|
||||
function M.toggle_help()
|
||||
view.toggle_help()
|
||||
return M.redraw()
|
||||
end
|
||||
|
||||
-- @deprecated: use nvim-tree.actions.collapse-all.fn
|
||||
M.collapse_all = require'nvim-tree.actions.collapse-all'.fn
|
||||
-- @deprecated: use nvim-tree.actions.dir-up.fn
|
||||
|
||||
Loading…
Reference in New Issue
Block a user