Skip to content

Commit abfd1d1

Browse files
fix(#2813): macos: enable file renaming with changed capitalization (#2814)
* 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>
1 parent 2ede0de commit abfd1d1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lua/nvim-tree/actions/fs/rename-file.lua

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,25 @@ local function err_fmt(from, to, reason)
3030
return string.format("Cannot rename %s -> %s: %s", from, to, reason)
3131
end
3232

33+
local function rename_file_exists(node, to)
34+
if not utils.is_macos then
35+
return utils.file_exists(to)
36+
end
37+
38+
if string.lower(node) == string.lower(to) then
39+
return false
40+
end
41+
42+
return utils.file_exists(to)
43+
end
44+
3345
---@param node Node
3446
---@param to string
3547
function M.rename(node, to)
3648
local notify_from = notify.render_path(node.absolute_path)
3749
local notify_to = notify.render_path(to)
3850

39-
if utils.file_exists(to) then
51+
if rename_file_exists(notify_from, notify_to) then
4052
notify.warn(err_fmt(notify_from, notify_to, "file already exists"))
4153
return
4254
end
@@ -65,7 +77,7 @@ function M.rename(node, to)
6577
notify.warn(err_fmt(notify_from, notify_to, err))
6678
return
6779
end
68-
elseif not utils.file_exists(path_to_create) then
80+
elseif not rename_file_exists(notify_from, path_to_create) then
6981
local success = vim.loop.fs_mkdir(path_to_create, 493)
7082
if not success then
7183
notify.error("Could not create folder " .. notify.render_path(path_to_create))

0 commit comments

Comments
 (0)