Skip to content

Commit

Permalink
fix #2981: nvim-tree root changed when navigating with LSP
Browse files Browse the repository at this point in the history
  • Loading branch information
ljie-PI committed Nov 2, 2024
1 parent 82ab19e commit aa1e1ec
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lua/nvim-tree/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit aa1e1ec

Please sign in to comment.