Skip to content

Commit b112277

Browse files
committed
feat(files): add src and dest arguments to fs action callbacks
1 parent 6f96463 commit b112277

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

Diff for: lua/neo-tree/sources/common/commands.lua

+5-9
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ M.add = function(state, callback)
1616
if node.type == 'file' then
1717
node = tree:get_node(node:get_parent_id())
1818
end
19-
fs_actions.create_node(node:get_id(), function()
19+
fs_actions.create_node(node:get_id(), function(dir_path, new_path)
2020
if callback then
21-
callback(node)
21+
callback(dir_path, new_path)
2222
end
2323
end)
2424
end
@@ -97,15 +97,15 @@ M.paste_from_clipboard = function(state, callback)
9797
state.clipboard = nil
9898
local handle_next_paste, paste_complete
9999

100-
paste_complete = function()
100+
paste_complete = function(source, destination)
101101
-- open the folder so the user can see the new files
102102
local node = state.tree:get_node(folder)
103103
if not node then
104104
print("Could not find node for " .. folder)
105105
return
106106
end
107107
if callback then
108-
callback()
108+
callback(source, destination)
109109
end
110110
local next_item = table.remove(clipboard_list)
111111
if next_item then
@@ -207,11 +207,7 @@ end
207207
M.rename = function(state, callback)
208208
local tree = state.tree
209209
local node = tree:get_node()
210-
fs_actions.rename_node(node.path, function()
211-
if callback then
212-
callback()
213-
end
214-
end)
210+
fs_actions.rename_node(node.path, callback)
215211
end
216212

217213

Diff for: lua/neo-tree/sources/filesystem/commands.lua

+7-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ M.open_vsplit = function(state) cc.open_vsplit(state, fs.toggle_directory) end
6666
M.refresh = fs.refresh
6767

6868
M.rename = function(state)
69-
cc.rename(state, fs.refresh)
69+
cc.rename(state, function(original_path, new_path)
70+
-- This is where you would do something like fix references to the file
71+
-- with an LSP server.
72+
-- <YOUR CODE HERE>
73+
-- Don't forget to call fs.refresh() after you're done.
74+
fs.refresh()
75+
end)
7076
end
7177

7278
M.set_root = function(state)

Diff for: lua/neo-tree/sources/filesystem/lib/fs_actions.lua

+13-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ M.move_node = function(source, destination, callback)
4646
return
4747
end
4848
if callback then
49-
vim.schedule_wrap(callback)()
49+
vim.schedule_wrap(function()
50+
callback(source, dest)
51+
end)()
5052
end
5153
end)
5254
end)
@@ -64,7 +66,9 @@ M.copy_node = function(source, _destination, callback)
6466
return
6567
end
6668
if callback then
67-
vim.schedule_wrap(callback)()
69+
vim.schedule_wrap(function()
70+
callback(source, destination)
71+
end)()
6872
end
6973
end)
7074
end)
@@ -97,7 +101,9 @@ M.create_node = function(in_directory, callback)
97101
end
98102

99103
if callback then
100-
vim.schedule_wrap(callback)()
104+
vim.schedule_wrap(function()
105+
callback(in_directory, destination)
106+
end)()
101107
end
102108
end)
103109
end
@@ -178,7 +184,9 @@ M.delete_node = function(path, callback)
178184
end
179185

180186
if callback then
181-
vim.schedule_wrap(callback)()
187+
vim.schedule_wrap(function()
188+
callback(path)
189+
end)()
182190
end
183191
end)
184192
end
@@ -204,7 +212,7 @@ M.rename_node = function(path, callback)
204212

205213
local complete = vim.schedule_wrap( function()
206214
if callback then
207-
callback()
215+
callback(path, destination)
208216
end
209217
print("Renamed " .. new_name .. " successfully")
210218
end)

0 commit comments

Comments
 (0)