Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ local function setup_autocommands(opts)
end

local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
file_deletion_confirmation = true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor this to ui.confirm.remove.

auto_reload_on_write = true,
disable_netrw = false,
hijack_cursor = false,
Expand Down
55 changes: 33 additions & 22 deletions lua/nvim-tree/actions/fs/remove-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,36 +73,47 @@ function M.fn(node)
if node.name == ".." then
return
end
local prompt_select = "Remove " .. node.name .. " ?"
local prompt_input = prompt_select .. " y/n: "
lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short)
utils.clear_prompt()
if item_short == "y" then
if node.nodes ~= nil and not node.link_to then
local success = remove_dir(node.absolute_path)
if not success then
return notify.error("Could not remove " .. node.name)
end
events._dispatch_folder_removed(node.absolute_path)
else
local success = vim.loop.fs_unlink(node.absolute_path)
if not success then
return notify.error("Could not remove " .. node.name)
end
events._dispatch_file_removed(node.absolute_path)
clear_buffer(node.absolute_path)

local function do_remove()
if node.nodes ~= nil and not node.link_to then
local success = remove_dir(node.absolute_path)
if not success then
return notify.error("Could not remove " .. node.name)
end
notify.info(node.absolute_path .. " was properly removed.")
if M.enable_reload then
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
events._dispatch_folder_removed(node.absolute_path)
else
local success = vim.loop.fs_unlink(node.absolute_path)
if not success then
return notify.error("Could not remove " .. node.name)
end
events._dispatch_file_removed(node.absolute_path)
clear_buffer(node.absolute_path)
end
end)
notify.info(node.absolute_path .. " was properly removed.")
if M.enable_reload then
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
end


if M.file_deletion_confirmation then
local prompt_select = "Remove " .. node.name .. " ?"
local prompt_input = prompt_select .. " y/n: "
lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short)
utils.clear_prompt()
if item_short == "y" then
do_remove()
end
end)
else
do_remove()
end
end

function M.setup(opts)
M.enable_reload = not opts.filesystem_watchers.enable
M.close_window = opts.actions.remove_file.close_window
M.file_deletion_confirmation = opts.file_deletion_confirmation
end

return M