* fix(#2813): enable file renaming in `nvim-tree` with changed capitalization * fix(#2813): check if is macos --------- Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
parent
2ede0de67b
commit
abfd1d1b67
@ -30,13 +30,25 @@ local function err_fmt(from, to, reason)
|
|||||||
return string.format("Cannot rename %s -> %s: %s", from, to, reason)
|
return string.format("Cannot rename %s -> %s: %s", from, to, reason)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function rename_file_exists(node, to)
|
||||||
|
if not utils.is_macos then
|
||||||
|
return utils.file_exists(to)
|
||||||
|
end
|
||||||
|
|
||||||
|
if string.lower(node) == string.lower(to) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
return utils.file_exists(to)
|
||||||
|
end
|
||||||
|
|
||||||
---@param node Node
|
---@param node Node
|
||||||
---@param to string
|
---@param to string
|
||||||
function M.rename(node, to)
|
function M.rename(node, to)
|
||||||
local notify_from = notify.render_path(node.absolute_path)
|
local notify_from = notify.render_path(node.absolute_path)
|
||||||
local notify_to = notify.render_path(to)
|
local notify_to = notify.render_path(to)
|
||||||
|
|
||||||
if utils.file_exists(to) then
|
if rename_file_exists(notify_from, notify_to) then
|
||||||
notify.warn(err_fmt(notify_from, notify_to, "file already exists"))
|
notify.warn(err_fmt(notify_from, notify_to, "file already exists"))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -65,7 +77,7 @@ function M.rename(node, to)
|
|||||||
notify.warn(err_fmt(notify_from, notify_to, err))
|
notify.warn(err_fmt(notify_from, notify_to, err))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
elseif not utils.file_exists(path_to_create) then
|
elseif not rename_file_exists(notify_from, path_to_create) then
|
||||||
local success = vim.loop.fs_mkdir(path_to_create, 493)
|
local success = vim.loop.fs_mkdir(path_to_create, 493)
|
||||||
if not success then
|
if not success then
|
||||||
notify.error("Could not create folder " .. notify.render_path(path_to_create))
|
notify.error("Could not create folder " .. notify.render_path(path_to_create))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user