refactor(actions): move actions into semantic modules (#1410)

This commit is contained in:
Kiyan
2022-07-10 09:47:52 +02:00
committed by GitHub
parent 90bf14014e
commit 831f1158c3
23 changed files with 85 additions and 76 deletions

View File

@@ -5,43 +5,51 @@ local M = {}
local Actions = {
close = view.close,
close_node = require("nvim-tree.actions.movements").parent_node(true),
collapse_all = require("nvim-tree.actions.collapse-all").fn,
expand_all = require("nvim-tree.actions.expand-all").fn,
copy_absolute_path = require("nvim-tree.actions.copy-paste").copy_absolute_path,
copy_name = require("nvim-tree.actions.copy-paste").copy_filename,
copy_path = require("nvim-tree.actions.copy-paste").copy_path,
copy = require("nvim-tree.actions.copy-paste").copy,
create = require("nvim-tree.actions.create-file").fn,
cut = require("nvim-tree.actions.copy-paste").cut,
dir_up = require("nvim-tree.actions.dir-up").fn,
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_diag_item = require("nvim-tree.actions.movements").find_item("next", "diag"),
next_git_item = require("nvim-tree.actions.movements").find_item("next", "git"),
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_diag_item = require("nvim-tree.actions.movements").find_item("prev", "diag"),
prev_git_item = require("nvim-tree.actions.movements").find_item("prev", "git"),
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),
run_file_command = require("nvim-tree.actions.run-command").run_file_command,
search_node = require("nvim-tree.actions.search-node").fn,
toggle_file_info = require("nvim-tree.actions.file-popup").toggle_file_info,
system_open = require("nvim-tree.actions.system-open").fn,
toggle_dotfiles = require("nvim-tree.actions.toggles").dotfiles,
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,
-- Tree modifiers
collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn,
expand_all = require("nvim-tree.actions.tree-modifiers.expand-all").fn,
toggle_dotfiles = require("nvim-tree.actions.tree-modifiers.toggles").dotfiles,
toggle_custom = require("nvim-tree.actions.tree-modifiers.toggles").custom,
toggle_git_ignored = require("nvim-tree.actions.tree-modifiers.toggles").git_ignored,
-- Filesystem operations
copy_absolute_path = require("nvim-tree.actions.fs.copy-paste").copy_absolute_path,
copy_name = require("nvim-tree.actions.fs.copy-paste").copy_filename,
copy_path = require("nvim-tree.actions.fs.copy-paste").copy_path,
copy = require("nvim-tree.actions.fs.copy-paste").copy,
create = require("nvim-tree.actions.fs.create-file").fn,
cut = require("nvim-tree.actions.fs.copy-paste").cut,
full_rename = require("nvim-tree.actions.fs.rename-file").fn(true),
paste = require("nvim-tree.actions.fs.copy-paste").paste,
trash = require("nvim-tree.actions.fs.trash").fn,
remove = require("nvim-tree.actions.fs.remove-file").fn,
rename = require("nvim-tree.actions.fs.rename-file").fn(false),
-- Movements in tree
close_node = require("nvim-tree.actions.moves.movements").parent_node(true),
first_sibling = require("nvim-tree.actions.moves.movements").sibling(-math.huge),
last_sibling = require("nvim-tree.actions.moves.movements").sibling(math.huge),
next_diag_item = require("nvim-tree.actions.moves.movements").find_item("next", "diag"),
next_git_item = require("nvim-tree.actions.moves.movements").find_item("next", "git"),
next_sibling = require("nvim-tree.actions.moves.movements").sibling(1),
parent_node = require("nvim-tree.actions.moves.movements").parent_node(false),
prev_diag_item = require("nvim-tree.actions.moves.movements").find_item("prev", "diag"),
prev_git_item = require("nvim-tree.actions.moves.movements").find_item("prev", "git"),
prev_sibling = require("nvim-tree.actions.moves.movements").sibling(-1),
-- Other types
refresh = require("nvim-tree.actions.reloaders.reloaders").reload_explorer,
dir_up = require("nvim-tree.actions.root.dir-up").fn,
search_node = require("nvim-tree.actions.finders.search-node").fn,
run_file_command = require("nvim-tree.actions.node.run-command").run_file_command,
toggle_file_info = require("nvim-tree.actions.node.file-popup").toggle_file_info,
system_open = require("nvim-tree.actions.node.system-open").fn,
}
local function handle_action_on_help_ui(action)
if action == "close" or action == "toggle_help" then
require("nvim-tree.actions.toggles").help()
require("nvim-tree.actions.tree-modifiers.toggles").help()
end
end
@@ -55,9 +63,9 @@ end
local function change_dir_action(node)
if node.name == ".." then
require("nvim-tree.actions.change-dir").fn ".."
require("nvim-tree.actions.root.change-dir").fn ".."
elseif node.nodes ~= nil then
require("nvim-tree.actions.change-dir").fn(lib.get_last_group_node(node).absolute_path)
require("nvim-tree.actions.root.change-dir").fn(lib.get_last_group_node(node).absolute_path)
end
end
@@ -66,7 +74,7 @@ local function open_file(action, node)
if node.link_to and not node.nodes then
path = node.link_to
end
require("nvim-tree.actions.open-file").fn(action, path)
require("nvim-tree.actions.node.open-file").fn(action, path)
end
local function handle_tree_actions(action)

View File

@@ -1,9 +1,10 @@
local api = vim.api
local uv = vim.loop
local utils = require "nvim-tree.utils"
local core = require "nvim-tree.core"
local filters = require "nvim-tree.explorer.filters"
local find_file = require("nvim-tree.actions.find-file").fn
local find_file = require("nvim-tree.actions.finders.find-file").fn
local M = {}

View File

@@ -166,7 +166,7 @@ local function do_paste(node, action_type, action_fn)
clipboard[action_type] = {}
if M.enable_reload then
return require("nvim-tree.actions.reloaders").reload_explorer()
return require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
end

View File

@@ -108,7 +108,7 @@ function M.fn(node)
end
events._dispatch_folder_created(new_file_path)
if M.enable_reload then
require("nvim-tree.actions.reloaders").reload_explorer()
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
-- INFO: defer needed when reload is automatic (watchers)
vim.defer_fn(function()

View File

@@ -87,7 +87,7 @@ function M.fn(node)
clear_buffer(node.absolute_path)
end
if M.enable_reload then
require("nvim-tree.actions.reloaders").reload_explorer()
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
end
end

View File

@@ -38,7 +38,7 @@ function M.fn(with_sub)
utils.rename_loaded_buffers(node.absolute_path, new_file_path)
events._dispatch_node_renamed(abs_path, new_file_path)
if M.enable_reload then
require("nvim-tree.actions.reloaders").reload_explorer()
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
end)
end

View File

@@ -88,7 +88,7 @@ function M.fn(node)
end
events._dispatch_folder_removed(node.absolute_path)
if M.enable_reload then
require("nvim-tree.actions.reloaders").reload_explorer()
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
end)
else
@@ -100,7 +100,7 @@ function M.fn(node)
events._dispatch_file_removed(node.absolute_path)
clear_buffer(node.absolute_path)
if M.enable_reload then
require("nvim-tree.actions.reloaders").reload_explorer()
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
end)
end

View File

@@ -342,15 +342,15 @@ local DEFAULT_MAPPING_CONFIG = {
}
function M.setup(opts)
require("nvim-tree.actions.system-open").setup(opts)
require("nvim-tree.actions.trash").setup(opts)
require("nvim-tree.actions.open-file").setup(opts)
require("nvim-tree.actions.change-dir").setup(opts)
require("nvim-tree.actions.create-file").setup(opts)
require("nvim-tree.actions.rename-file").setup(opts)
require("nvim-tree.actions.remove-file").setup(opts)
require("nvim-tree.actions.copy-paste").setup(opts)
require("nvim-tree.actions.expand-all").setup(opts)
require("nvim-tree.actions.fs.trash").setup(opts)
require("nvim-tree.actions.node.system-open").setup(opts)
require("nvim-tree.actions.node.open-file").setup(opts)
require("nvim-tree.actions.root.change-dir").setup(opts)
require("nvim-tree.actions.fs.create-file").setup(opts)
require("nvim-tree.actions.fs.rename-file").setup(opts)
require("nvim-tree.actions.fs.remove-file").setup(opts)
require("nvim-tree.actions.fs.copy-paste").setup(opts)
require("nvim-tree.actions.tree-modifiers.expand-all").setup(opts)
cleanup_existing_mappings()
M.mappings = vim.deepcopy(DEFAULT_MAPPINGS)

View File

@@ -5,11 +5,11 @@ local M = {}
function M.fn(node)
if not node or node.name == ".." then
return require("nvim-tree.actions.change-dir").fn ".."
return require("nvim-tree.actions.root.change-dir").fn ".."
else
local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(core.get_cwd()), ":h")
require("nvim-tree.actions.change-dir").fn(newdir)
return require("nvim-tree.actions.find-file").fn(node.absolute_path)
require("nvim-tree.actions.root.change-dir").fn(newdir)
return require("nvim-tree.actions.finders.find-file").fn(node.absolute_path)
end
end

View File

@@ -1,7 +1,7 @@
local view = require "nvim-tree.view"
local filters = require "nvim-tree.explorer.filters"
local renderer = require "nvim-tree.renderer"
local reloaders = require "nvim-tree.actions.reloaders"
local reloaders = require "nvim-tree.actions.reloaders.reloaders"
local M = {}