feat(marks): add bulk move action (#1419)
This commit is contained in:
@@ -7,6 +7,26 @@ local events = require "nvim-tree.events"
|
||||
|
||||
local M = {}
|
||||
|
||||
local function err_fmt(from, to, reason)
|
||||
return string.format("Cannot rename %s -> %s: %s", from, to, reason)
|
||||
end
|
||||
|
||||
function M.rename(node, to)
|
||||
if utils.file_exists(to) then
|
||||
utils.warn(err_fmt(node.absolute_path, to, "file already exists"))
|
||||
return
|
||||
end
|
||||
|
||||
local success, err = uv.fs_rename(node.absolute_path, to)
|
||||
if not success then
|
||||
return utils.warn(err_fmt(node.absolute_path, to, err))
|
||||
end
|
||||
utils.clear_prompt()
|
||||
a.nvim_out_write(node.absolute_path .. " ➜ " .. to .. "\n")
|
||||
utils.rename_loaded_buffers(node.absolute_path, to)
|
||||
events._dispatch_node_renamed(node.absolute_path, to)
|
||||
end
|
||||
|
||||
function M.fn(with_sub)
|
||||
return function(node)
|
||||
node = lib.get_last_group_node(node)
|
||||
@@ -24,19 +44,7 @@ function M.fn(with_sub)
|
||||
return
|
||||
end
|
||||
|
||||
if utils.file_exists(new_file_path) then
|
||||
utils.warn "Cannot rename: file already exists"
|
||||
return
|
||||
end
|
||||
|
||||
local success = uv.fs_rename(node.absolute_path, new_file_path)
|
||||
if not success then
|
||||
return a.nvim_err_writeln("Could not rename " .. node.absolute_path .. " to " .. new_file_path)
|
||||
end
|
||||
utils.clear_prompt()
|
||||
a.nvim_out_write(node.absolute_path .. " ➜ " .. new_file_path .. "\n")
|
||||
utils.rename_loaded_buffers(node.absolute_path, new_file_path)
|
||||
events._dispatch_node_renamed(abs_path, new_file_path)
|
||||
M.rename(node, new_file_path)
|
||||
if M.enable_reload then
|
||||
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user