Skip to content

Commit

Permalink
fix(actions): correctly rename open (dir) buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
fdschmidt93 committed Nov 15, 2023
1 parent da2a20c commit bb8d54e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lua/telescope/_extensions/file_browser/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,25 @@ 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 }
-- use vim.fs rather than plenary to fetch basename, more battle-tested
local old_path_absolute = selection:absolute()
local basename = vim.fs.basename(old_path_absolute)
local new_path = Path:new { target_dir, basename }
if new_path:exists() then
table.insert(skipped, filename)
table.insert(skipped, basename)
else
local new_path_absolute = new_path:absolute()
selection:rename {
new_name = new_path.filename,
new_name = new_path_absolute,
}
table.insert(moved, filename)
if not selection:is_dir() then
fb_utils.rename_buf(old_path_absolute, new_path_absolute)
else
fb_utils.rename_dir_buf(old_path_absolute, new_path_absolute)
end
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
Expand Down

0 comments on commit bb8d54e

Please sign in to comment.