feat(remove-file): use vim.ui.select

This commit is contained in:
kiyan
2022-07-18 14:28:08 +02:00
parent 7cffe14743
commit 2d629cab78

View File

@@ -68,29 +68,28 @@ function M.fn(node)
return return
end end
print("Remove " .. node.name .. " ? y/n") vim.ui.select({ "y", "n" }, { prompt = "Remove " .. node.name .. " ?" }, function(choice)
local ans = utils.get_user_input_char() if choice == "y" then
utils.clear_prompt() if node.nodes ~= nil and not node.link_to then
if ans:match "^y" then local success = remove_dir(node.absolute_path)
if node.nodes ~= nil and not node.link_to then if not success then
local success = remove_dir(node.absolute_path) return utils.notify.error("Could not remove " .. node.name)
if not success then end
return utils.notify.error("Could not remove " .. node.name) events._dispatch_folder_removed(node.absolute_path)
else
local success = luv.fs_unlink(node.absolute_path)
if not success then
return utils.notify.error("Could not remove " .. node.name)
end
events._dispatch_file_removed(node.absolute_path)
clear_buffer(node.absolute_path)
end end
events._dispatch_folder_removed(node.absolute_path) utils.notify.info(node.absolute_path .. " was properly removed.")
else if M.enable_reload then
local success = luv.fs_unlink(node.absolute_path) require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
if not success then
return utils.notify.error("Could not remove " .. node.name)
end end
events._dispatch_file_removed(node.absolute_path)
clear_buffer(node.absolute_path)
end end
utils.notify.info(node.absolute_path .. " was properly removed.") end)
if M.enable_reload then
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
end
end end
function M.setup(opts) function M.setup(opts)