check buffer is valid when renaming
This commit is contained in:
parent
5080c5c44c
commit
2e7118ca17
@ -146,14 +146,14 @@ local function do_single_paste(source, dest, action_type, action_fn)
|
|||||||
local should_process = true
|
local should_process = true
|
||||||
local should_rename = false
|
local should_rename = false
|
||||||
if dest_stats then
|
if dest_stats then
|
||||||
ans = vim.fn.input(dest..' already exists, overwrite ? y/n/r(ename): ')
|
local ans = vim.fn.input(dest..' already exists, overwrite ? y/n/r(ename): ')
|
||||||
clear_prompt()
|
clear_prompt()
|
||||||
should_process = ans:match('^y')
|
should_process = ans:match('^y')
|
||||||
should_rename = ans:match('^r')
|
should_rename = ans:match('^r')
|
||||||
end
|
end
|
||||||
|
|
||||||
if should_rename then
|
if should_rename then
|
||||||
new_dest = vim.fn.input('New name: ', dest)
|
local new_dest = vim.fn.input('New name: ', dest)
|
||||||
return do_single_paste(source, new_dest, action_type, action_fn)
|
return do_single_paste(source, new_dest, action_type, action_fn)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -245,14 +245,16 @@ function M.rename(node)
|
|||||||
clear_prompt()
|
clear_prompt()
|
||||||
if not new_name or #new_name == 0 then return end
|
if not new_name or #new_name == 0 then return end
|
||||||
|
|
||||||
local success = luv.fs_rename(node.absolute_path, new_name) --, vim.schedule_wrap(rename_callback(node, ans)))
|
local success = luv.fs_rename(node.absolute_path, new_name)
|
||||||
if not success then
|
if not success then
|
||||||
return api.nvim_err_writeln('Could not rename '..node.absolute_path..' to '..new_name)
|
return api.nvim_err_writeln('Could not rename '..node.absolute_path..' to '..new_name)
|
||||||
end
|
end
|
||||||
api.nvim_out_write(node.absolute_path..' ➜ '..new_name..'\n')
|
api.nvim_out_write(node.absolute_path..' ➜ '..new_name..'\n')
|
||||||
for _, buf in pairs(api.nvim_list_bufs()) do
|
for _, buf in pairs(api.nvim_list_bufs()) do
|
||||||
if api.nvim_buf_get_name(buf) == node.absolute_path then
|
if api.nvim_buf_is_loaded(buf) then
|
||||||
api.nvim_buf_set_name(buf, new_name)
|
if api.nvim_buf_get_name(buf) == node.absolute_path then
|
||||||
|
api.nvim_buf_set_name(buf, new_name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
refresh_tree()
|
refresh_tree()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user