Skip to content

Commit

Permalink
feat(files): add src and dest arguments to fs action callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
cseickel committed Jan 8, 2022
1 parent 6f96463 commit b112277
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
14 changes: 5 additions & 9 deletions lua/neo-tree/sources/common/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ M.add = function(state, callback)
if node.type == 'file' then
node = tree:get_node(node:get_parent_id())
end
fs_actions.create_node(node:get_id(), function()
fs_actions.create_node(node:get_id(), function(dir_path, new_path)
if callback then
callback(node)
callback(dir_path, new_path)
end
end)
end
Expand Down Expand Up @@ -97,15 +97,15 @@ M.paste_from_clipboard = function(state, callback)
state.clipboard = nil
local handle_next_paste, paste_complete

paste_complete = function()
paste_complete = function(source, destination)
-- open the folder so the user can see the new files
local node = state.tree:get_node(folder)
if not node then
print("Could not find node for " .. folder)
return
end
if callback then
callback()
callback(source, destination)
end
local next_item = table.remove(clipboard_list)
if next_item then
Expand Down Expand Up @@ -207,11 +207,7 @@ end
M.rename = function(state, callback)
local tree = state.tree
local node = tree:get_node()
fs_actions.rename_node(node.path, function()
if callback then
callback()
end
end)
fs_actions.rename_node(node.path, callback)
end


Expand Down
8 changes: 7 additions & 1 deletion lua/neo-tree/sources/filesystem/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ M.open_vsplit = function(state) cc.open_vsplit(state, fs.toggle_directory) end
M.refresh = fs.refresh

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

M.set_root = function(state)
Expand Down
18 changes: 13 additions & 5 deletions lua/neo-tree/sources/filesystem/lib/fs_actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ M.move_node = function(source, destination, callback)
return
end
if callback then
vim.schedule_wrap(callback)()
vim.schedule_wrap(function()
callback(source, dest)
end)()
end
end)
end)
Expand All @@ -64,7 +66,9 @@ M.copy_node = function(source, _destination, callback)
return
end
if callback then
vim.schedule_wrap(callback)()
vim.schedule_wrap(function()
callback(source, destination)
end)()
end
end)
end)
Expand Down Expand Up @@ -97,7 +101,9 @@ M.create_node = function(in_directory, callback)
end

if callback then
vim.schedule_wrap(callback)()
vim.schedule_wrap(function()
callback(in_directory, destination)
end)()
end
end)
end
Expand Down Expand Up @@ -178,7 +184,9 @@ M.delete_node = function(path, callback)
end

if callback then
vim.schedule_wrap(callback)()
vim.schedule_wrap(function()
callback(path)
end)()
end
end)
end
Expand All @@ -204,7 +212,7 @@ M.rename_node = function(path, callback)

local complete = vim.schedule_wrap( function()
if callback then
callback()
callback(path, destination)
end
print("Renamed " .. new_name .. " successfully")
end)
Expand Down

0 comments on commit b112277

Please sign in to comment.