Skip to content

Commit b3772ad

Browse files
authored
fix(##3288): restore single-item paste conflict prompts (#3289)
1 parent 9197f3e commit b3772ad

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

lua/nvim-tree/actions/fs/clipboard.lua

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,57 @@ function Clipboard:finish_paste(action)
208208
self.explorer:reload_explorer()
209209
end
210210

211-
---Resolve conflicting paste items with a single batch prompt.
211+
---Resolve conflicting paste items.
212+
---Single conflict: per-file prompt with full-path rename (pre-visual-mode behavior).
213+
---Multiple conflicts: batch prompt with suffix rename.
212214
---@private
213215
---@param conflict {node: Node, dest: string}[]
214216
---@param destination string
215217
---@param action ClipboardAction
216218
---@param action_fn ClipboardActionFn
217219
function Clipboard:resolve_conflicts(conflict, destination, action, action_fn)
220+
if #conflict == 1 then
221+
local source = conflict[1].node.absolute_path
222+
local dest = conflict[1].dest
223+
224+
local function rename_prompt(default_dest)
225+
vim.ui.input({ prompt = "Rename to ", default = default_dest, completion = "dir" }, function(new_dest)
226+
utils.clear_prompt()
227+
if not new_dest or new_dest == "" then
228+
self:finish_paste(action)
229+
return
230+
end
231+
if vim.loop.fs_stat(new_dest) then
232+
self:resolve_conflicts({ { node = conflict[1].node, dest = new_dest } }, destination, action, action_fn)
233+
else
234+
do_paste_one(source, new_dest, action, action_fn)
235+
self:finish_paste(action)
236+
end
237+
end)
238+
end
239+
240+
if source == dest then
241+
rename_prompt(dest)
242+
else
243+
local prompt_select = "Overwrite " .. dest .. " ?"
244+
lib.prompt(prompt_select .. " R(ename)/y/n: ", prompt_select,
245+
{ "", "y", "n" }, { "Rename", "Yes", "No" },
246+
"nvimtree_overwrite_rename",
247+
function(item_short)
248+
utils.clear_prompt()
249+
if item_short == "y" then
250+
do_paste_one(source, dest, action, action_fn)
251+
self:finish_paste(action)
252+
elseif item_short == "" or item_short == "r" then
253+
rename_prompt(dest)
254+
else
255+
self:finish_paste(action)
256+
end
257+
end)
258+
end
259+
return
260+
end
261+
218262
local prompt_select = #conflict .. " file(s) already exist"
219263
local prompt_input = prompt_select .. ". R(ename suffix)/y/n: "
220264

0 commit comments

Comments
 (0)