diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 5625b416a2a..3067eae9267 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -7,12 +7,12 @@ local colors = require "nvim-tree.colors" local renderer = require "nvim-tree.renderer" local view = require "nvim-tree.view" 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 core = require "nvim-tree.core" -local reloaders = require "nvim-tree.actions.reloaders" -local copy_paste = require "nvim-tree.actions.copy-paste" -local collapse_all = require "nvim-tree.actions.collapse-all" +local reloaders = require "nvim-tree.actions.reloaders.reloaders" +local copy_paste = require "nvim-tree.actions.fs.copy-paste" +local collapse_all = require "nvim-tree.actions.tree-modifiers.collapse-all" local git = require "nvim-tree.git" local _config = {} @@ -116,7 +116,7 @@ function M.open_replacing_current_buffer(cwd) end view.open_in_current_win { hijack_current_buf = false, resize = false } require("nvim-tree.renderer").draw() - require("nvim-tree.actions.find-file").fn(bufname) + require("nvim-tree.actions.finders.find-file").fn(bufname) end 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 M.change_root(filepath, bufnr) end - require("nvim-tree.actions.find-file").fn(filepath) + require("nvim-tree.actions.finders.find-file").fn(filepath) end) end diff --git a/lua/nvim-tree/actions/dispatch.lua b/lua/nvim-tree/actions/dispatch.lua index c439e171868..cf8850d68cb 100644 --- a/lua/nvim-tree/actions/dispatch.lua +++ b/lua/nvim-tree/actions/dispatch.lua @@ -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) diff --git a/lua/nvim-tree/actions/find-file.lua b/lua/nvim-tree/actions/finders/find-file.lua similarity index 100% rename from lua/nvim-tree/actions/find-file.lua rename to lua/nvim-tree/actions/finders/find-file.lua diff --git a/lua/nvim-tree/actions/search-node.lua b/lua/nvim-tree/actions/finders/search-node.lua similarity index 95% rename from lua/nvim-tree/actions/search-node.lua rename to lua/nvim-tree/actions/finders/search-node.lua index cd137a379e1..5e410796390 100644 --- a/lua/nvim-tree/actions/search-node.lua +++ b/lua/nvim-tree/actions/finders/search-node.lua @@ -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 = {} diff --git a/lua/nvim-tree/actions/copy-paste.lua b/lua/nvim-tree/actions/fs/copy-paste.lua similarity index 98% rename from lua/nvim-tree/actions/copy-paste.lua rename to lua/nvim-tree/actions/fs/copy-paste.lua index 3b0a4d11a21..03d8ae2ce0a 100644 --- a/lua/nvim-tree/actions/copy-paste.lua +++ b/lua/nvim-tree/actions/fs/copy-paste.lua @@ -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 diff --git a/lua/nvim-tree/actions/create-file.lua b/lua/nvim-tree/actions/fs/create-file.lua similarity index 97% rename from lua/nvim-tree/actions/create-file.lua rename to lua/nvim-tree/actions/fs/create-file.lua index cda896c596d..85122bac7b5 100644 --- a/lua/nvim-tree/actions/create-file.lua +++ b/lua/nvim-tree/actions/fs/create-file.lua @@ -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() diff --git a/lua/nvim-tree/actions/remove-file.lua b/lua/nvim-tree/actions/fs/remove-file.lua similarity index 97% rename from lua/nvim-tree/actions/remove-file.lua rename to lua/nvim-tree/actions/fs/remove-file.lua index 3ddfeae5615..fb28f34a038 100644 --- a/lua/nvim-tree/actions/remove-file.lua +++ b/lua/nvim-tree/actions/fs/remove-file.lua @@ -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 diff --git a/lua/nvim-tree/actions/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua similarity index 94% rename from lua/nvim-tree/actions/rename-file.lua rename to lua/nvim-tree/actions/fs/rename-file.lua index 5c19c727f23..921dead6ec7 100644 --- a/lua/nvim-tree/actions/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -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 diff --git a/lua/nvim-tree/actions/trash.lua b/lua/nvim-tree/actions/fs/trash.lua similarity index 94% rename from lua/nvim-tree/actions/trash.lua rename to lua/nvim-tree/actions/fs/trash.lua index f02335cd4b5..fbf5bd36562 100644 --- a/lua/nvim-tree/actions/trash.lua +++ b/lua/nvim-tree/actions/fs/trash.lua @@ -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 diff --git a/lua/nvim-tree/actions/init.lua b/lua/nvim-tree/actions/init.lua index 9c112919f0f..4c18cb3a75a 100644 --- a/lua/nvim-tree/actions/init.lua +++ b/lua/nvim-tree/actions/init.lua @@ -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) diff --git a/lua/nvim-tree/actions/movements.lua b/lua/nvim-tree/actions/moves/movements.lua similarity index 100% rename from lua/nvim-tree/actions/movements.lua rename to lua/nvim-tree/actions/moves/movements.lua diff --git a/lua/nvim-tree/actions/file-popup.lua b/lua/nvim-tree/actions/node/file-popup.lua similarity index 100% rename from lua/nvim-tree/actions/file-popup.lua rename to lua/nvim-tree/actions/node/file-popup.lua diff --git a/lua/nvim-tree/actions/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua similarity index 100% rename from lua/nvim-tree/actions/open-file.lua rename to lua/nvim-tree/actions/node/open-file.lua diff --git a/lua/nvim-tree/actions/run-command.lua b/lua/nvim-tree/actions/node/run-command.lua similarity index 100% rename from lua/nvim-tree/actions/run-command.lua rename to lua/nvim-tree/actions/node/run-command.lua diff --git a/lua/nvim-tree/actions/system-open.lua b/lua/nvim-tree/actions/node/system-open.lua similarity index 100% rename from lua/nvim-tree/actions/system-open.lua rename to lua/nvim-tree/actions/node/system-open.lua diff --git a/lua/nvim-tree/actions/reloaders.lua b/lua/nvim-tree/actions/reloaders/reloaders.lua similarity index 100% rename from lua/nvim-tree/actions/reloaders.lua rename to lua/nvim-tree/actions/reloaders/reloaders.lua diff --git a/lua/nvim-tree/actions/change-dir.lua b/lua/nvim-tree/actions/root/change-dir.lua similarity index 100% rename from lua/nvim-tree/actions/change-dir.lua rename to lua/nvim-tree/actions/root/change-dir.lua diff --git a/lua/nvim-tree/actions/dir-up.lua b/lua/nvim-tree/actions/root/dir-up.lua similarity index 56% rename from lua/nvim-tree/actions/dir-up.lua rename to lua/nvim-tree/actions/root/dir-up.lua index 1ffd9f00f8c..439baa8cebc 100644 --- a/lua/nvim-tree/actions/dir-up.lua +++ b/lua/nvim-tree/actions/root/dir-up.lua @@ -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 diff --git a/lua/nvim-tree/actions/collapse-all.lua b/lua/nvim-tree/actions/tree-modifiers/collapse-all.lua similarity index 100% rename from lua/nvim-tree/actions/collapse-all.lua rename to lua/nvim-tree/actions/tree-modifiers/collapse-all.lua diff --git a/lua/nvim-tree/actions/expand-all.lua b/lua/nvim-tree/actions/tree-modifiers/expand-all.lua similarity index 100% rename from lua/nvim-tree/actions/expand-all.lua rename to lua/nvim-tree/actions/tree-modifiers/expand-all.lua diff --git a/lua/nvim-tree/actions/toggles.lua b/lua/nvim-tree/actions/tree-modifiers/toggles.lua similarity index 90% rename from lua/nvim-tree/actions/toggles.lua rename to lua/nvim-tree/actions/tree-modifiers/toggles.lua index d761d2099f2..63c9e07c66c 100644 --- a/lua/nvim-tree/actions/toggles.lua +++ b/lua/nvim-tree/actions/tree-modifiers/toggles.lua @@ -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 = {} diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index 2cca941f29d..ff40339a282 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -69,7 +69,7 @@ end local function handle_buf_cwd(cwd) 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 @@ -107,18 +107,18 @@ function M.open(cwd) view.restore_tab_state() 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 -M.dir_up = require("nvim-tree.actions.dir-up").fn --- @deprecated: use nvim-tree.actions.change-dir.fn -M.change_dir = require("nvim-tree.actions.change-dir").fn --- @deprecated: use nvim-tree.actions.reloaders.reload_explorer -M.refresh_tree = require("nvim-tree.actions.reloaders").reload_explorer --- @deprecated: use nvim-tree.actions.reloaders.reload_git -M.reload_git = require("nvim-tree.actions.reloaders").reload_git --- @deprecated: use nvim-tree.actions.find-file.fn -M.set_index_and_redraw = require("nvim-tree.actions.find-file").fn +-- @deprecated: use nvim-tree.actions.tree-modifiers.collapse-all.fn +M.collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn +-- @deprecated: use nvim-tree.actions.root.dir-up.fn +M.dir_up = require("nvim-tree.actions.root.dir-up").fn +-- @deprecated: use nvim-tree.actions.root.change-dir.fn +M.change_dir = require("nvim-tree.actions.root.change-dir").fn +-- @deprecated: use nvim-tree.actions.reloaders.reloaders.reload_explorer +M.refresh_tree = require("nvim-tree.actions.reloaders.reloaders").reload_explorer +-- @deprecated: use nvim-tree.actions.reloaders.reloaders.reload_git +M.reload_git = require("nvim-tree.actions.reloaders.reloaders").reload_git +-- @deprecated: use nvim-tree.actions.finders.find-file.fn +M.set_index_and_redraw = require("nvim-tree.actions.finders.find-file").fn function M.setup(opts) M.hijack_unnamed_buffer_when_opening = opts.hijack_unnamed_buffer_when_opening diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index c189ccd0a4a..45cf92ea3be 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -404,7 +404,7 @@ function M._prevent_buffer_override() M.open { focus_tree = false } require("nvim-tree.renderer").draw() 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