diff --git a/lua/telescope/_extensions/file_browser/actions.lua b/lua/telescope/_extensions/file_browser/actions.lua index 024e3a4f..e438bdc5 100644 --- a/lua/telescope/_extensions/file_browser/actions.lua +++ b/lua/telescope/_extensions/file_browser/actions.lua @@ -332,24 +332,33 @@ fb_actions.move = function(prompt_bufnr) local skipped = {} for idx, selection in ipairs(selections) do - local filename = selection.filename:sub(#selection:parent().filename + 2) - local new_path = Path:new { target_dir, filename } - if new_path:exists() then - table.insert(skipped, filename) + local old_path_absolute = selection:absolute() + local basename = vim.fs.basename(old_path_absolute) + local new_path = Path:new { target_dir, basename } + -- vim.iter unstable and tbl_map not much less verbose here + local parent_dir_in_selections = false + local parent_dir = fb_utils.sanitize_dir(selection:parent():absolute(), true) + for _, s in ipairs(selections) do + if fb_utils.sanitize_dir(s:absolute(), true) == parent_dir then + parent_dir_in_selections = true + break + end + end + if new_path:exists() or parent_dir_in_selections then + table.insert(skipped, basename) else - local old_path = selection:absolute() + local new_path_absolute = new_path:absolute() selection:rename { - new_name = new_path.filename, + new_name = new_path_absolute, } if not selection:is_dir() then - fb_utils.rename_buf(old_path, new_path:absolute()) + fb_utils.rename_buf(old_path_absolute, new_path_absolute) else - fb_utils.rename_dir_buf(old_path, new_path:absolute()) + fb_utils.rename_dir_buf(old_path_absolute, new_path_absolute) end - fb_utils.rename_buf(old_path, new_path:absolute()) - table.insert(moved, filename) + table.insert(moved, basename) if idx == 1 and #selections == 1 then - fb_utils.selection_callback(current_picker, new_path:absolute()) + fb_utils.selection_callback(current_picker, new_path_absolute) end end end