Skip to content

feat: Rename child buffers when renaming directory #1095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions lua/nvim-tree/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,23 @@ function M.is_windows_exe(ext)
return pathexts[ext:upper()]
end

function M.rename_loaded_buffers(old_name, new_name)
function M.rename_loaded_buffers(old_path, new_path)
for _, buf in pairs(a.nvim_list_bufs()) do
if a.nvim_buf_is_loaded(buf) then
if a.nvim_buf_get_name(buf) == old_name then
a.nvim_buf_set_name(buf, new_name)
-- to avoid the 'overwrite existing file' error message on write
vim.api.nvim_buf_call(buf, function()
vim.cmd "silent! w!"
end)
local buf_name = a.nvim_buf_get_name(buf)
local exact_match = buf_name == old_path
local child_match = (
buf_name:sub(1, #old_path) == old_path and buf_name:sub(#old_path + 1, #old_path + 1) == path_separator
)
if exact_match or child_match then
a.nvim_buf_set_name(buf, new_path .. buf_name:sub(#old_path + 1))
-- to avoid the 'overwrite existing file' error message on write for
-- normal files
if a.nvim_buf_get_option(buf, "buftype") == "" then
a.nvim_buf_call(buf, function()
vim.cmd "silent! write!"
end)
end
end
end
end
Expand Down