From 69aec67edb046aa94c6a2a7aef7ec83bbcfb36b5 Mon Sep 17 00:00:00 2001 From: kiyan Date: Mon, 18 Jul 2022 14:17:25 +0200 Subject: [PATCH] feat(copy-paste): use vim.ui from prompting --- lua/nvim-tree/actions/fs/copy-paste.lua | 34 ++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lua/nvim-tree/actions/fs/copy-paste.lua b/lua/nvim-tree/actions/fs/copy-paste.lua index 7b8fbe14..f48d03c2 100644 --- a/lua/nvim-tree/actions/fs/copy-paste.lua +++ b/lua/nvim-tree/actions/fs/copy-paste.lua @@ -85,29 +85,29 @@ local function do_single_paste(source, dest, action_type, action_fn) return false, errmsg end - local should_process = true - local should_rename = false - - if dest_stats then - print(dest .. " already exists. Overwrite? y/n/r(ename)") - local ans = utils.get_user_input_char() - utils.clear_prompt() - should_process = ans:match "^y" - should_rename = ans:match "^r" - end - - if should_rename then - local new_dest = vim.fn.input("New name: ", dest) - return do_single_paste(source, new_dest, action_type, action_fn) - end - - if should_process then + local function on_process() success, errmsg = action_fn(source, dest) if not success then utils.notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???")) return false, errmsg end end + + if dest_stats then + vim.ui.select({ "y", "n", "rename" }, { prompt = dest .. " already exists. Overwrite?" }, function(choice) + if choice == "y" then + on_process() + elseif choice == "rename" then + vim.ui.input({ prompt = "New name: ", default = dest, completion = "dir" }, function(new_dest) + if new_dest then + do_single_paste(source, new_dest, action_type, action_fn) + end + end) + end + end) + else + on_process() + end end local function add_to_clipboard(node, clip)