Skip to content

Commit 7aff29d

Browse files
authored
feat(#2277): skip overwrite prompt when copy/cut paste into same directory (#2278)
1 parent c3c6544 commit 7aff29d

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

lua/nvim-tree/actions/fs/copy-paste.lua

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,30 @@ local function do_single_paste(source, dest, action_type, action_fn)
100100
end
101101

102102
if dest_stats then
103-
local prompt_select = "Overwrite " .. dest .. " ?"
104-
local prompt_input = prompt_select .. " y/n/r(ename): "
105-
lib.prompt(prompt_input, prompt_select, { "y", "n", "r" }, { "Yes", "No", "Rename" }, function(item_short)
106-
utils.clear_prompt()
107-
if item_short == "y" then
108-
on_process()
109-
elseif item_short == "r" then
110-
vim.ui.input({ prompt = "Rename to ", default = dest, completion = "dir" }, function(new_dest)
111-
utils.clear_prompt()
112-
if new_dest then
113-
do_single_paste(source, new_dest, action_type, action_fn)
114-
end
115-
end)
116-
end
117-
end)
103+
if source == dest then
104+
vim.ui.input({ prompt = "Rename to ", default = dest, completion = "dir" }, function(new_dest)
105+
utils.clear_prompt()
106+
if new_dest then
107+
do_single_paste(source, new_dest, action_type, action_fn)
108+
end
109+
end)
110+
else
111+
local prompt_select = "Overwrite " .. dest .. " ?"
112+
local prompt_input = prompt_select .. " y/n/r(ename): "
113+
lib.prompt(prompt_input, prompt_select, { "y", "n", "r" }, { "Yes", "No", "Rename" }, function(item_short)
114+
utils.clear_prompt()
115+
if item_short == "y" then
116+
on_process()
117+
elseif item_short == "r" then
118+
vim.ui.input({ prompt = "Rename to ", default = dest, completion = "dir" }, function(new_dest)
119+
utils.clear_prompt()
120+
if new_dest then
121+
do_single_paste(source, new_dest, action_type, action_fn)
122+
end
123+
end)
124+
end
125+
end)
126+
end
118127
else
119128
on_process()
120129
end

0 commit comments

Comments
 (0)