feat(marks): add bulk move action (#1419)
This commit is contained in:
@@ -46,6 +46,7 @@ local Actions = {
|
||||
toggle_file_info = require("nvim-tree.actions.node.file-popup").toggle_file_info,
|
||||
system_open = require("nvim-tree.actions.node.system-open").fn,
|
||||
toggle_mark = require("nvim-tree.marks").toggle_mark,
|
||||
bulk_move = require("nvim-tree.marks.bulk-move").bulk_move,
|
||||
}
|
||||
|
||||
local function handle_action_on_help_ui(action)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -231,6 +231,11 @@ local DEFAULT_MAPPINGS = {
|
||||
action = "toggle_mark",
|
||||
desc = "Toggle node in bookmarks",
|
||||
},
|
||||
{
|
||||
key = "bmv",
|
||||
action = "bulk_move",
|
||||
desc = "Move all bookmarked nodes into specified location",
|
||||
},
|
||||
}
|
||||
-- END_DEFAULT_MAPPINGS
|
||||
|
||||
|
||||
Reference in New Issue
Block a user