Skip to content

Commit 19a60c0

Browse files
committed
refactor(actions): move actions into semantic modules
1 parent 90bf140 commit 19a60c0

23 files changed

+85
-76
lines changed

lua/nvim-tree.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ local colors = require "nvim-tree.colors"
77
local renderer = require "nvim-tree.renderer"
88
local view = require "nvim-tree.view"
99
local utils = require "nvim-tree.utils"
10-
local change_dir = require "nvim-tree.actions.change-dir"
10+
local change_dir = require "nvim-tree.actions.root.change-dir"
1111
local legacy = require "nvim-tree.legacy"
1212
local core = require "nvim-tree.core"
13-
local reloaders = require "nvim-tree.actions.reloaders"
14-
local copy_paste = require "nvim-tree.actions.copy-paste"
15-
local collapse_all = require "nvim-tree.actions.collapse-all"
13+
local reloaders = require "nvim-tree.actions.reloaders.reloaders"
14+
local copy_paste = require "nvim-tree.actions.fs.copy-paste"
15+
local collapse_all = require "nvim-tree.actions.tree-modifiers.collapse-all"
1616
local git = require "nvim-tree.git"
1717

1818
local _config = {}
@@ -116,7 +116,7 @@ function M.open_replacing_current_buffer(cwd)
116116
end
117117
view.open_in_current_win { hijack_current_buf = false, resize = false }
118118
require("nvim-tree.renderer").draw()
119-
require("nvim-tree.actions.find-file").fn(bufname)
119+
require("nvim-tree.actions.finders.find-file").fn(bufname)
120120
end
121121

122122
function M.tab_change()
@@ -163,7 +163,7 @@ function M.find_file(with_open, bufnr, bang)
163163
if bang or _config.update_focused_file.update_root then
164164
M.change_root(filepath, bufnr)
165165
end
166-
require("nvim-tree.actions.find-file").fn(filepath)
166+
require("nvim-tree.actions.finders.find-file").fn(filepath)
167167
end)
168168
end
169169

lua/nvim-tree/actions/dispatch.lua

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,51 @@ local M = {}
55

66
local Actions = {
77
close = view.close,
8-
close_node = require("nvim-tree.actions.movements").parent_node(true),
9-
collapse_all = require("nvim-tree.actions.collapse-all").fn,
10-
expand_all = require("nvim-tree.actions.expand-all").fn,
11-
copy_absolute_path = require("nvim-tree.actions.copy-paste").copy_absolute_path,
12-
copy_name = require("nvim-tree.actions.copy-paste").copy_filename,
13-
copy_path = require("nvim-tree.actions.copy-paste").copy_path,
14-
copy = require("nvim-tree.actions.copy-paste").copy,
15-
create = require("nvim-tree.actions.create-file").fn,
16-
cut = require("nvim-tree.actions.copy-paste").cut,
17-
dir_up = require("nvim-tree.actions.dir-up").fn,
18-
first_sibling = require("nvim-tree.actions.movements").sibling(-math.huge),
19-
full_rename = require("nvim-tree.actions.rename-file").fn(true),
20-
last_sibling = require("nvim-tree.actions.movements").sibling(math.huge),
21-
next_diag_item = require("nvim-tree.actions.movements").find_item("next", "diag"),
22-
next_git_item = require("nvim-tree.actions.movements").find_item("next", "git"),
23-
next_sibling = require("nvim-tree.actions.movements").sibling(1),
24-
parent_node = require("nvim-tree.actions.movements").parent_node(false),
25-
paste = require("nvim-tree.actions.copy-paste").paste,
26-
prev_diag_item = require("nvim-tree.actions.movements").find_item("prev", "diag"),
27-
prev_git_item = require("nvim-tree.actions.movements").find_item("prev", "git"),
28-
prev_sibling = require("nvim-tree.actions.movements").sibling(-1),
29-
refresh = require("nvim-tree.actions.reloaders").reload_explorer,
30-
remove = require("nvim-tree.actions.remove-file").fn,
31-
rename = require("nvim-tree.actions.rename-file").fn(false),
32-
run_file_command = require("nvim-tree.actions.run-command").run_file_command,
33-
search_node = require("nvim-tree.actions.search-node").fn,
34-
toggle_file_info = require("nvim-tree.actions.file-popup").toggle_file_info,
35-
system_open = require("nvim-tree.actions.system-open").fn,
36-
toggle_dotfiles = require("nvim-tree.actions.toggles").dotfiles,
37-
toggle_custom = require("nvim-tree.actions.toggles").custom,
38-
toggle_git_ignored = require("nvim-tree.actions.toggles").git_ignored,
39-
trash = require("nvim-tree.actions.trash").fn,
8+
9+
-- Tree modifiers
10+
collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn,
11+
expand_all = require("nvim-tree.actions.tree-modifiers.expand-all").fn,
12+
toggle_dotfiles = require("nvim-tree.actions.tree-modifiers.toggles").dotfiles,
13+
toggle_custom = require("nvim-tree.actions.tree-modifiers.toggles").custom,
14+
toggle_git_ignored = require("nvim-tree.actions.tree-modifiers.toggles").git_ignored,
15+
16+
-- Filesystem operations
17+
copy_absolute_path = require("nvim-tree.actions.fs.copy-paste").copy_absolute_path,
18+
copy_name = require("nvim-tree.actions.fs.copy-paste").copy_filename,
19+
copy_path = require("nvim-tree.actions.fs.copy-paste").copy_path,
20+
copy = require("nvim-tree.actions.fs.copy-paste").copy,
21+
create = require("nvim-tree.actions.fs.create-file").fn,
22+
cut = require("nvim-tree.actions.fs.copy-paste").cut,
23+
full_rename = require("nvim-tree.actions.fs.rename-file").fn(true),
24+
paste = require("nvim-tree.actions.fs.copy-paste").paste,
25+
trash = require("nvim-tree.actions.fs.trash").fn,
26+
remove = require("nvim-tree.actions.fs.remove-file").fn,
27+
rename = require("nvim-tree.actions.fs.rename-file").fn(false),
28+
29+
-- Movements in tree
30+
close_node = require("nvim-tree.actions.moves.movements").parent_node(true),
31+
first_sibling = require("nvim-tree.actions.moves.movements").sibling(-math.huge),
32+
last_sibling = require("nvim-tree.actions.moves.movements").sibling(math.huge),
33+
next_diag_item = require("nvim-tree.actions.moves.movements").find_item("next", "diag"),
34+
next_git_item = require("nvim-tree.actions.moves.movements").find_item("next", "git"),
35+
next_sibling = require("nvim-tree.actions.moves.movements").sibling(1),
36+
parent_node = require("nvim-tree.actions.moves.movements").parent_node(false),
37+
prev_diag_item = require("nvim-tree.actions.moves.movements").find_item("prev", "diag"),
38+
prev_git_item = require("nvim-tree.actions.moves.movements").find_item("prev", "git"),
39+
prev_sibling = require("nvim-tree.actions.moves.movements").sibling(-1),
40+
41+
-- Other types
42+
refresh = require("nvim-tree.actions.reloaders.reloaders").reload_explorer,
43+
dir_up = require("nvim-tree.actions.root.dir-up").fn,
44+
search_node = require("nvim-tree.actions.finders.search-node").fn,
45+
run_file_command = require("nvim-tree.actions.node.run-command").run_file_command,
46+
toggle_file_info = require("nvim-tree.actions.node.file-popup").toggle_file_info,
47+
system_open = require("nvim-tree.actions.node.system-open").fn,
4048
}
4149

4250
local function handle_action_on_help_ui(action)
4351
if action == "close" or action == "toggle_help" then
44-
require("nvim-tree.actions.toggles").help()
52+
require("nvim-tree.actions.tree-modifiers.toggles").help()
4553
end
4654
end
4755

@@ -55,9 +63,9 @@ end
5563

5664
local function change_dir_action(node)
5765
if node.name == ".." then
58-
require("nvim-tree.actions.change-dir").fn ".."
66+
require("nvim-tree.actions.root.change-dir").fn ".."
5967
elseif node.nodes ~= nil then
60-
require("nvim-tree.actions.change-dir").fn(lib.get_last_group_node(node).absolute_path)
68+
require("nvim-tree.actions.root.change-dir").fn(lib.get_last_group_node(node).absolute_path)
6169
end
6270
end
6371

@@ -66,7 +74,7 @@ local function open_file(action, node)
6674
if node.link_to and not node.nodes then
6775
path = node.link_to
6876
end
69-
require("nvim-tree.actions.open-file").fn(action, path)
77+
require("nvim-tree.actions.node.open-file").fn(action, path)
7078
end
7179

7280
local function handle_tree_actions(action)

lua/nvim-tree/actions/search-node.lua renamed to lua/nvim-tree/actions/finders/search-node.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
local api = vim.api
22
local uv = vim.loop
3+
34
local utils = require "nvim-tree.utils"
45
local core = require "nvim-tree.core"
56
local filters = require "nvim-tree.explorer.filters"
6-
local find_file = require("nvim-tree.actions.find-file").fn
7+
local find_file = require("nvim-tree.actions.finders.find-file").fn
78

89
local M = {}
910

lua/nvim-tree/actions/copy-paste.lua renamed to lua/nvim-tree/actions/fs/copy-paste.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ local function do_paste(node, action_type, action_fn)
166166

167167
clipboard[action_type] = {}
168168
if M.enable_reload then
169-
return require("nvim-tree.actions.reloaders").reload_explorer()
169+
return require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
170170
end
171171
end
172172

lua/nvim-tree/actions/create-file.lua renamed to lua/nvim-tree/actions/fs/create-file.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function M.fn(node)
108108
end
109109
events._dispatch_folder_created(new_file_path)
110110
if M.enable_reload then
111-
require("nvim-tree.actions.reloaders").reload_explorer()
111+
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
112112
end
113113
-- INFO: defer needed when reload is automatic (watchers)
114114
vim.defer_fn(function()

lua/nvim-tree/actions/remove-file.lua renamed to lua/nvim-tree/actions/fs/remove-file.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function M.fn(node)
8787
clear_buffer(node.absolute_path)
8888
end
8989
if M.enable_reload then
90-
require("nvim-tree.actions.reloaders").reload_explorer()
90+
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
9191
end
9292
end
9393
end

lua/nvim-tree/actions/rename-file.lua renamed to lua/nvim-tree/actions/fs/rename-file.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function M.fn(with_sub)
3838
utils.rename_loaded_buffers(node.absolute_path, new_file_path)
3939
events._dispatch_node_renamed(abs_path, new_file_path)
4040
if M.enable_reload then
41-
require("nvim-tree.actions.reloaders").reload_explorer()
41+
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
4242
end
4343
end)
4444
end

lua/nvim-tree/actions/trash.lua renamed to lua/nvim-tree/actions/fs/trash.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function M.fn(node)
8888
end
8989
events._dispatch_folder_removed(node.absolute_path)
9090
if M.enable_reload then
91-
require("nvim-tree.actions.reloaders").reload_explorer()
91+
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
9292
end
9393
end)
9494
else
@@ -100,7 +100,7 @@ function M.fn(node)
100100
events._dispatch_file_removed(node.absolute_path)
101101
clear_buffer(node.absolute_path)
102102
if M.enable_reload then
103-
require("nvim-tree.actions.reloaders").reload_explorer()
103+
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
104104
end
105105
end)
106106
end

lua/nvim-tree/actions/init.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,15 @@ local DEFAULT_MAPPING_CONFIG = {
342342
}
343343

344344
function M.setup(opts)
345-
require("nvim-tree.actions.system-open").setup(opts)
346-
require("nvim-tree.actions.trash").setup(opts)
347-
require("nvim-tree.actions.open-file").setup(opts)
348-
require("nvim-tree.actions.change-dir").setup(opts)
349-
require("nvim-tree.actions.create-file").setup(opts)
350-
require("nvim-tree.actions.rename-file").setup(opts)
351-
require("nvim-tree.actions.remove-file").setup(opts)
352-
require("nvim-tree.actions.copy-paste").setup(opts)
353-
require("nvim-tree.actions.expand-all").setup(opts)
345+
require("nvim-tree.actions.fs.trash").setup(opts)
346+
require("nvim-tree.actions.node.system-open").setup(opts)
347+
require("nvim-tree.actions.node.open-file").setup(opts)
348+
require("nvim-tree.actions.root.change-dir").setup(opts)
349+
require("nvim-tree.actions.fs.create-file").setup(opts)
350+
require("nvim-tree.actions.fs.rename-file").setup(opts)
351+
require("nvim-tree.actions.fs.remove-file").setup(opts)
352+
require("nvim-tree.actions.fs.copy-paste").setup(opts)
353+
require("nvim-tree.actions.tree-modifiers.expand-all").setup(opts)
354354

355355
cleanup_existing_mappings()
356356
M.mappings = vim.deepcopy(DEFAULT_MAPPINGS)

lua/nvim-tree/actions/dir-up.lua renamed to lua/nvim-tree/actions/root/dir-up.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ local M = {}
55

66
function M.fn(node)
77
if not node or node.name == ".." then
8-
return require("nvim-tree.actions.change-dir").fn ".."
8+
return require("nvim-tree.actions.root.change-dir").fn ".."
99
else
1010
local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(core.get_cwd()), ":h")
11-
require("nvim-tree.actions.change-dir").fn(newdir)
12-
return require("nvim-tree.actions.find-file").fn(node.absolute_path)
11+
require("nvim-tree.actions.root.change-dir").fn(newdir)
12+
return require("nvim-tree.actions.finders.find-file").fn(node.absolute_path)
1313
end
1414
end
1515

lua/nvim-tree/actions/toggles.lua renamed to lua/nvim-tree/actions/tree-modifiers/toggles.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local view = require "nvim-tree.view"
22
local filters = require "nvim-tree.explorer.filters"
33
local renderer = require "nvim-tree.renderer"
4-
local reloaders = require "nvim-tree.actions.reloaders"
4+
local reloaders = require "nvim-tree.actions.reloaders.reloaders"
55

66
local M = {}
77

lua/nvim-tree/lib.lua

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ end
6969

7070
local function handle_buf_cwd(cwd)
7171
if M.respect_buf_cwd and cwd ~= core.get_cwd() then
72-
require("nvim-tree.actions.change-dir").fn(cwd)
72+
require("nvim-tree.actions.root.change-dir").fn(cwd)
7373
end
7474
end
7575

@@ -107,18 +107,18 @@ function M.open(cwd)
107107
view.restore_tab_state()
108108
end
109109

110-
-- @deprecated: use nvim-tree.actions.collapse-all.fn
111-
M.collapse_all = require("nvim-tree.actions.collapse-all").fn
112-
-- @deprecated: use nvim-tree.actions.dir-up.fn
113-
M.dir_up = require("nvim-tree.actions.dir-up").fn
114-
-- @deprecated: use nvim-tree.actions.change-dir.fn
115-
M.change_dir = require("nvim-tree.actions.change-dir").fn
116-
-- @deprecated: use nvim-tree.actions.reloaders.reload_explorer
117-
M.refresh_tree = require("nvim-tree.actions.reloaders").reload_explorer
118-
-- @deprecated: use nvim-tree.actions.reloaders.reload_git
119-
M.reload_git = require("nvim-tree.actions.reloaders").reload_git
120-
-- @deprecated: use nvim-tree.actions.find-file.fn
121-
M.set_index_and_redraw = require("nvim-tree.actions.find-file").fn
110+
-- @deprecated: use nvim-tree.actions.tree-modifiers.collapse-all.fn
111+
M.collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn
112+
-- @deprecated: use nvim-tree.actions.root.dir-up.fn
113+
M.dir_up = require("nvim-tree.actions.root.dir-up").fn
114+
-- @deprecated: use nvim-tree.actions.root.change-dir.fn
115+
M.change_dir = require("nvim-tree.actions.root.change-dir").fn
116+
-- @deprecated: use nvim-tree.actions.reloaders.reloaders.reload_explorer
117+
M.refresh_tree = require("nvim-tree.actions.reloaders.reloaders").reload_explorer
118+
-- @deprecated: use nvim-tree.actions.reloaders.reloaders.reload_git
119+
M.reload_git = require("nvim-tree.actions.reloaders.reloaders").reload_git
120+
-- @deprecated: use nvim-tree.actions.finders.find-file.fn
121+
M.set_index_and_redraw = require("nvim-tree.actions.finders.find-file").fn
122122

123123
function M.setup(opts)
124124
M.hijack_unnamed_buffer_when_opening = opts.hijack_unnamed_buffer_when_opening

lua/nvim-tree/view.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ function M._prevent_buffer_override()
404404
M.open { focus_tree = false }
405405
require("nvim-tree.renderer").draw()
406406
pcall(a.nvim_win_close, curwin, { force = true })
407-
require("nvim-tree.actions.open-file").fn("edit", bufname)
407+
require("nvim-tree.actions.node.open-file").fn("edit", bufname)
408408
end)
409409
end
410410

0 commit comments

Comments
 (0)