Skip to content

Commit 8afd209

Browse files
committed
fix: use case-insensitive indexing for paths on Windows
1 parent e80dea9 commit 8afd209

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lua/neo-tree/sources/common/components.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ end
115115

116116
M.diagnostics = function(config, node, state)
117117
local diag = state.diagnostics_lookup or {}
118-
local diag_state = diag[node:get_id()]
118+
local diag_state = utils.index_by_path(diag, node:get_id())
119119
if config.hide_when_expanded and node.type == "directory" and node:is_expanded() then
120120
return {}
121121
end
@@ -322,7 +322,7 @@ end
322322

323323
M.modified = function(config, node, state)
324324
local opened_buffers = state.opened_buffers or {}
325-
local buf_info = opened_buffers[node.path]
325+
local buf_info = utils.index_by_path(opened_buffers, node.path)
326326

327327
if buf_info and buf_info.modified then
328328
return {

lua/neo-tree/utils/init.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,4 +1220,33 @@ M.brace_expand = function(s)
12201220
return result
12211221
end
12221222

1223+
---Indexes a table that uses paths as keys. Case-insensitive logic is used when
1224+
---running on Windows.
1225+
---
1226+
---Consideration should be taken before using this function, because it is a
1227+
---bit expensive on Windows. However, this function helps when trying to index
1228+
---with absolute path keys, which can have inconsistent casing on Windows (such
1229+
---as with drive letters).
1230+
---@param tbl table
1231+
---@param key string
1232+
---@return unknown
1233+
M.index_by_path = function(tbl, key)
1234+
local value = tbl[key]
1235+
if value ~= nil then
1236+
return value
1237+
end
1238+
1239+
-- on windows, paths that differ only by case are considered equal
1240+
if M.is_windows then
1241+
local key_lower = key:lower()
1242+
for k, v in pairs(tbl) do
1243+
if key_lower == k:lower() then
1244+
return v
1245+
end
1246+
end
1247+
end
1248+
1249+
return value
1250+
end
1251+
12231252
return M

0 commit comments

Comments
 (0)