refactor(actions): move actions into semantic modules (#1410)
This commit is contained in:
@@ -7,12 +7,12 @@ local colors = require "nvim-tree.colors"
|
|||||||
local renderer = require "nvim-tree.renderer"
|
local renderer = require "nvim-tree.renderer"
|
||||||
local view = require "nvim-tree.view"
|
local view = require "nvim-tree.view"
|
||||||
local utils = require "nvim-tree.utils"
|
local utils = require "nvim-tree.utils"
|
||||||
local change_dir = require "nvim-tree.actions.change-dir"
|
local change_dir = require "nvim-tree.actions.root.change-dir"
|
||||||
local legacy = require "nvim-tree.legacy"
|
local legacy = require "nvim-tree.legacy"
|
||||||
local core = require "nvim-tree.core"
|
local core = require "nvim-tree.core"
|
||||||
local reloaders = require "nvim-tree.actions.reloaders"
|
local reloaders = require "nvim-tree.actions.reloaders.reloaders"
|
||||||
local copy_paste = require "nvim-tree.actions.copy-paste"
|
local copy_paste = require "nvim-tree.actions.fs.copy-paste"
|
||||||
local collapse_all = require "nvim-tree.actions.collapse-all"
|
local collapse_all = require "nvim-tree.actions.tree-modifiers.collapse-all"
|
||||||
local git = require "nvim-tree.git"
|
local git = require "nvim-tree.git"
|
||||||
|
|
||||||
local _config = {}
|
local _config = {}
|
||||||
@@ -116,7 +116,7 @@ function M.open_replacing_current_buffer(cwd)
|
|||||||
end
|
end
|
||||||
view.open_in_current_win { hijack_current_buf = false, resize = false }
|
view.open_in_current_win { hijack_current_buf = false, resize = false }
|
||||||
require("nvim-tree.renderer").draw()
|
require("nvim-tree.renderer").draw()
|
||||||
require("nvim-tree.actions.find-file").fn(bufname)
|
require("nvim-tree.actions.finders.find-file").fn(bufname)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.tab_change()
|
function M.tab_change()
|
||||||
@@ -163,7 +163,7 @@ function M.find_file(with_open, bufnr, bang)
|
|||||||
if bang or _config.update_focused_file.update_root then
|
if bang or _config.update_focused_file.update_root then
|
||||||
M.change_root(filepath, bufnr)
|
M.change_root(filepath, bufnr)
|
||||||
end
|
end
|
||||||
require("nvim-tree.actions.find-file").fn(filepath)
|
require("nvim-tree.actions.finders.find-file").fn(filepath)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -5,43 +5,51 @@ local M = {}
|
|||||||
|
|
||||||
local Actions = {
|
local Actions = {
|
||||||
close = view.close,
|
close = view.close,
|
||||||
close_node = require("nvim-tree.actions.movements").parent_node(true),
|
|
||||||
collapse_all = require("nvim-tree.actions.collapse-all").fn,
|
-- Tree modifiers
|
||||||
expand_all = require("nvim-tree.actions.expand-all").fn,
|
collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn,
|
||||||
copy_absolute_path = require("nvim-tree.actions.copy-paste").copy_absolute_path,
|
expand_all = require("nvim-tree.actions.tree-modifiers.expand-all").fn,
|
||||||
copy_name = require("nvim-tree.actions.copy-paste").copy_filename,
|
toggle_dotfiles = require("nvim-tree.actions.tree-modifiers.toggles").dotfiles,
|
||||||
copy_path = require("nvim-tree.actions.copy-paste").copy_path,
|
toggle_custom = require("nvim-tree.actions.tree-modifiers.toggles").custom,
|
||||||
copy = require("nvim-tree.actions.copy-paste").copy,
|
toggle_git_ignored = require("nvim-tree.actions.tree-modifiers.toggles").git_ignored,
|
||||||
create = require("nvim-tree.actions.create-file").fn,
|
|
||||||
cut = require("nvim-tree.actions.copy-paste").cut,
|
-- Filesystem operations
|
||||||
dir_up = require("nvim-tree.actions.dir-up").fn,
|
copy_absolute_path = require("nvim-tree.actions.fs.copy-paste").copy_absolute_path,
|
||||||
first_sibling = require("nvim-tree.actions.movements").sibling(-math.huge),
|
copy_name = require("nvim-tree.actions.fs.copy-paste").copy_filename,
|
||||||
full_rename = require("nvim-tree.actions.rename-file").fn(true),
|
copy_path = require("nvim-tree.actions.fs.copy-paste").copy_path,
|
||||||
last_sibling = require("nvim-tree.actions.movements").sibling(math.huge),
|
copy = require("nvim-tree.actions.fs.copy-paste").copy,
|
||||||
next_diag_item = require("nvim-tree.actions.movements").find_item("next", "diag"),
|
create = require("nvim-tree.actions.fs.create-file").fn,
|
||||||
next_git_item = require("nvim-tree.actions.movements").find_item("next", "git"),
|
cut = require("nvim-tree.actions.fs.copy-paste").cut,
|
||||||
next_sibling = require("nvim-tree.actions.movements").sibling(1),
|
full_rename = require("nvim-tree.actions.fs.rename-file").fn(true),
|
||||||
parent_node = require("nvim-tree.actions.movements").parent_node(false),
|
paste = require("nvim-tree.actions.fs.copy-paste").paste,
|
||||||
paste = require("nvim-tree.actions.copy-paste").paste,
|
trash = require("nvim-tree.actions.fs.trash").fn,
|
||||||
prev_diag_item = require("nvim-tree.actions.movements").find_item("prev", "diag"),
|
remove = require("nvim-tree.actions.fs.remove-file").fn,
|
||||||
prev_git_item = require("nvim-tree.actions.movements").find_item("prev", "git"),
|
rename = require("nvim-tree.actions.fs.rename-file").fn(false),
|
||||||
prev_sibling = require("nvim-tree.actions.movements").sibling(-1),
|
|
||||||
refresh = require("nvim-tree.actions.reloaders").reload_explorer,
|
-- Movements in tree
|
||||||
remove = require("nvim-tree.actions.remove-file").fn,
|
close_node = require("nvim-tree.actions.moves.movements").parent_node(true),
|
||||||
rename = require("nvim-tree.actions.rename-file").fn(false),
|
first_sibling = require("nvim-tree.actions.moves.movements").sibling(-math.huge),
|
||||||
run_file_command = require("nvim-tree.actions.run-command").run_file_command,
|
last_sibling = require("nvim-tree.actions.moves.movements").sibling(math.huge),
|
||||||
search_node = require("nvim-tree.actions.search-node").fn,
|
next_diag_item = require("nvim-tree.actions.moves.movements").find_item("next", "diag"),
|
||||||
toggle_file_info = require("nvim-tree.actions.file-popup").toggle_file_info,
|
next_git_item = require("nvim-tree.actions.moves.movements").find_item("next", "git"),
|
||||||
system_open = require("nvim-tree.actions.system-open").fn,
|
next_sibling = require("nvim-tree.actions.moves.movements").sibling(1),
|
||||||
toggle_dotfiles = require("nvim-tree.actions.toggles").dotfiles,
|
parent_node = require("nvim-tree.actions.moves.movements").parent_node(false),
|
||||||
toggle_custom = require("nvim-tree.actions.toggles").custom,
|
prev_diag_item = require("nvim-tree.actions.moves.movements").find_item("prev", "diag"),
|
||||||
toggle_git_ignored = require("nvim-tree.actions.toggles").git_ignored,
|
prev_git_item = require("nvim-tree.actions.moves.movements").find_item("prev", "git"),
|
||||||
trash = require("nvim-tree.actions.trash").fn,
|
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)
|
local function handle_action_on_help_ui(action)
|
||||||
if action == "close" or action == "toggle_help" then
|
if action == "close" or action == "toggle_help" then
|
||||||
require("nvim-tree.actions.toggles").help()
|
require("nvim-tree.actions.tree-modifiers.toggles").help()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -55,9 +63,9 @@ end
|
|||||||
|
|
||||||
local function change_dir_action(node)
|
local function change_dir_action(node)
|
||||||
if node.name == ".." then
|
if node.name == ".." then
|
||||||
require("nvim-tree.actions.change-dir").fn ".."
|
require("nvim-tree.actions.root.change-dir").fn ".."
|
||||||
elseif node.nodes ~= nil then
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -66,7 +74,7 @@ local function open_file(action, node)
|
|||||||
if node.link_to and not node.nodes then
|
if node.link_to and not node.nodes then
|
||||||
path = node.link_to
|
path = node.link_to
|
||||||
end
|
end
|
||||||
require("nvim-tree.actions.open-file").fn(action, path)
|
require("nvim-tree.actions.node.open-file").fn(action, path)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function handle_tree_actions(action)
|
local function handle_tree_actions(action)
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
local api = vim.api
|
local api = vim.api
|
||||||
local uv = vim.loop
|
local uv = vim.loop
|
||||||
|
|
||||||
local utils = require "nvim-tree.utils"
|
local utils = require "nvim-tree.utils"
|
||||||
local core = require "nvim-tree.core"
|
local core = require "nvim-tree.core"
|
||||||
local filters = require "nvim-tree.explorer.filters"
|
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 = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ local function do_paste(node, action_type, action_fn)
|
|||||||
|
|
||||||
clipboard[action_type] = {}
|
clipboard[action_type] = {}
|
||||||
if M.enable_reload then
|
if M.enable_reload then
|
||||||
return require("nvim-tree.actions.reloaders").reload_explorer()
|
return require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ function M.fn(node)
|
|||||||
end
|
end
|
||||||
events._dispatch_folder_created(new_file_path)
|
events._dispatch_folder_created(new_file_path)
|
||||||
if M.enable_reload then
|
if M.enable_reload then
|
||||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
|
||||||
end
|
end
|
||||||
-- INFO: defer needed when reload is automatic (watchers)
|
-- INFO: defer needed when reload is automatic (watchers)
|
||||||
vim.defer_fn(function()
|
vim.defer_fn(function()
|
||||||
@@ -87,7 +87,7 @@ function M.fn(node)
|
|||||||
clear_buffer(node.absolute_path)
|
clear_buffer(node.absolute_path)
|
||||||
end
|
end
|
||||||
if M.enable_reload then
|
if M.enable_reload then
|
||||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -38,7 +38,7 @@ function M.fn(with_sub)
|
|||||||
utils.rename_loaded_buffers(node.absolute_path, new_file_path)
|
utils.rename_loaded_buffers(node.absolute_path, new_file_path)
|
||||||
events._dispatch_node_renamed(abs_path, new_file_path)
|
events._dispatch_node_renamed(abs_path, new_file_path)
|
||||||
if M.enable_reload then
|
if M.enable_reload then
|
||||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@@ -88,7 +88,7 @@ function M.fn(node)
|
|||||||
end
|
end
|
||||||
events._dispatch_folder_removed(node.absolute_path)
|
events._dispatch_folder_removed(node.absolute_path)
|
||||||
if M.enable_reload then
|
if M.enable_reload then
|
||||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
@@ -100,7 +100,7 @@ function M.fn(node)
|
|||||||
events._dispatch_file_removed(node.absolute_path)
|
events._dispatch_file_removed(node.absolute_path)
|
||||||
clear_buffer(node.absolute_path)
|
clear_buffer(node.absolute_path)
|
||||||
if M.enable_reload then
|
if M.enable_reload then
|
||||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@@ -342,15 +342,15 @@ local DEFAULT_MAPPING_CONFIG = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
require("nvim-tree.actions.system-open").setup(opts)
|
require("nvim-tree.actions.fs.trash").setup(opts)
|
||||||
require("nvim-tree.actions.trash").setup(opts)
|
require("nvim-tree.actions.node.system-open").setup(opts)
|
||||||
require("nvim-tree.actions.open-file").setup(opts)
|
require("nvim-tree.actions.node.open-file").setup(opts)
|
||||||
require("nvim-tree.actions.change-dir").setup(opts)
|
require("nvim-tree.actions.root.change-dir").setup(opts)
|
||||||
require("nvim-tree.actions.create-file").setup(opts)
|
require("nvim-tree.actions.fs.create-file").setup(opts)
|
||||||
require("nvim-tree.actions.rename-file").setup(opts)
|
require("nvim-tree.actions.fs.rename-file").setup(opts)
|
||||||
require("nvim-tree.actions.remove-file").setup(opts)
|
require("nvim-tree.actions.fs.remove-file").setup(opts)
|
||||||
require("nvim-tree.actions.copy-paste").setup(opts)
|
require("nvim-tree.actions.fs.copy-paste").setup(opts)
|
||||||
require("nvim-tree.actions.expand-all").setup(opts)
|
require("nvim-tree.actions.tree-modifiers.expand-all").setup(opts)
|
||||||
|
|
||||||
cleanup_existing_mappings()
|
cleanup_existing_mappings()
|
||||||
M.mappings = vim.deepcopy(DEFAULT_MAPPINGS)
|
M.mappings = vim.deepcopy(DEFAULT_MAPPINGS)
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ local M = {}
|
|||||||
|
|
||||||
function M.fn(node)
|
function M.fn(node)
|
||||||
if not node or node.name == ".." then
|
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
|
else
|
||||||
local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(core.get_cwd()), ":h")
|
local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(core.get_cwd()), ":h")
|
||||||
require("nvim-tree.actions.change-dir").fn(newdir)
|
require("nvim-tree.actions.root.change-dir").fn(newdir)
|
||||||
return require("nvim-tree.actions.find-file").fn(node.absolute_path)
|
return require("nvim-tree.actions.finders.find-file").fn(node.absolute_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
local view = require "nvim-tree.view"
|
local view = require "nvim-tree.view"
|
||||||
local filters = require "nvim-tree.explorer.filters"
|
local filters = require "nvim-tree.explorer.filters"
|
||||||
local renderer = require "nvim-tree.renderer"
|
local renderer = require "nvim-tree.renderer"
|
||||||
local reloaders = require "nvim-tree.actions.reloaders"
|
local reloaders = require "nvim-tree.actions.reloaders.reloaders"
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ end
|
|||||||
|
|
||||||
local function handle_buf_cwd(cwd)
|
local function handle_buf_cwd(cwd)
|
||||||
if M.respect_buf_cwd and cwd ~= core.get_cwd() then
|
if M.respect_buf_cwd and cwd ~= core.get_cwd() then
|
||||||
require("nvim-tree.actions.change-dir").fn(cwd)
|
require("nvim-tree.actions.root.change-dir").fn(cwd)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -107,18 +107,18 @@ function M.open(cwd)
|
|||||||
view.restore_tab_state()
|
view.restore_tab_state()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- @deprecated: use nvim-tree.actions.collapse-all.fn
|
-- @deprecated: use nvim-tree.actions.tree-modifiers.collapse-all.fn
|
||||||
M.collapse_all = require("nvim-tree.actions.collapse-all").fn
|
M.collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn
|
||||||
-- @deprecated: use nvim-tree.actions.dir-up.fn
|
-- @deprecated: use nvim-tree.actions.root.dir-up.fn
|
||||||
M.dir_up = require("nvim-tree.actions.dir-up").fn
|
M.dir_up = require("nvim-tree.actions.root.dir-up").fn
|
||||||
-- @deprecated: use nvim-tree.actions.change-dir.fn
|
-- @deprecated: use nvim-tree.actions.root.change-dir.fn
|
||||||
M.change_dir = require("nvim-tree.actions.change-dir").fn
|
M.change_dir = require("nvim-tree.actions.root.change-dir").fn
|
||||||
-- @deprecated: use nvim-tree.actions.reloaders.reload_explorer
|
-- @deprecated: use nvim-tree.actions.reloaders.reloaders.reload_explorer
|
||||||
M.refresh_tree = require("nvim-tree.actions.reloaders").reload_explorer
|
M.refresh_tree = require("nvim-tree.actions.reloaders.reloaders").reload_explorer
|
||||||
-- @deprecated: use nvim-tree.actions.reloaders.reload_git
|
-- @deprecated: use nvim-tree.actions.reloaders.reloaders.reload_git
|
||||||
M.reload_git = require("nvim-tree.actions.reloaders").reload_git
|
M.reload_git = require("nvim-tree.actions.reloaders.reloaders").reload_git
|
||||||
-- @deprecated: use nvim-tree.actions.find-file.fn
|
-- @deprecated: use nvim-tree.actions.finders.find-file.fn
|
||||||
M.set_index_and_redraw = require("nvim-tree.actions.find-file").fn
|
M.set_index_and_redraw = require("nvim-tree.actions.finders.find-file").fn
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
M.hijack_unnamed_buffer_when_opening = opts.hijack_unnamed_buffer_when_opening
|
M.hijack_unnamed_buffer_when_opening = opts.hijack_unnamed_buffer_when_opening
|
||||||
|
|||||||
@@ -404,7 +404,7 @@ function M._prevent_buffer_override()
|
|||||||
M.open { focus_tree = false }
|
M.open { focus_tree = false }
|
||||||
require("nvim-tree.renderer").draw()
|
require("nvim-tree.renderer").draw()
|
||||||
pcall(a.nvim_win_close, curwin, { force = true })
|
pcall(a.nvim_win_close, curwin, { force = true })
|
||||||
require("nvim-tree.actions.open-file").fn("edit", bufname)
|
require("nvim-tree.actions.node.open-file").fn("edit", bufname)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user