From aa1e1ec9a31ef4fd55251cfc4745e93f4461c6b9 Mon Sep 17 00:00:00 2001 From: ljie-PI Date: Sat, 2 Nov 2024 15:50:44 +0800 Subject: [PATCH] fix #2981: nvim-tree root changed when navigating with LSP --- lua/nvim-tree/utils.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree/utils.lua b/lua/nvim-tree/utils.lua index 936982ec0a7..54ebe2a042c 100644 --- a/lua/nvim-tree/utils.lua +++ b/lua/nvim-tree/utils.lua @@ -70,6 +70,18 @@ local function has_parentheses_and_brackets(path) return false end +--- Path normalizations for windows only +local function win_norm_path(path) + local norm_path = path + -- Normalize for issue #2862 and #2961 + if has_parentheses_and_brackets(norm_path) then + norm_path = norm_path:gsub("/", "\\") + end + -- Normalize the drive letter + norm_path = string.upper(string.sub(norm_path, 1, 1)) .. string.sub(norm_path, 2) + return norm_path +end + --- Get a path relative to another path. ---@param path string ---@param relative_to string|nil @@ -80,8 +92,8 @@ function M.path_relative(path, relative_to) end local norm_path = path - if M.is_windows and has_parentheses_and_brackets(path) then - norm_path = path:gsub("/", "\\") + if M.is_windows then + norm_path = win_norm_path(norm_path) end local _, r = norm_path:find(M.path_add_trailing(relative_to), 1, true)