Skip to content

Commit

Permalink
fix(#502): always use lowercase icons by filename (#526)
Browse files Browse the repository at this point in the history
* fix(#502): always use lowercase icons by filename

* fix(#502): always use lowercase icons by filename

* fix(#502): always use lowercase icons by filename
  • Loading branch information
alex-courtis authored Dec 16, 2024
1 parent 1736cb8 commit 0eb18da
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions lua/nvim-web-devicons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ local global_opts = {
variant = nil,
}

---Change all keys in a table to lowercase
---Remove entry when lowercase entry already exists
---@param t table
local function lowercase_keys(t)
if not t then
return
end

for k, v in pairs(t) do
if type(k) == "string" then
local lower_k = k:lower()
if lower_k ~= k then
if not t[lower_k] then
t[lower_k] = v
end
t[k] = nil
end
end
end
end

-- Set the current icons tables, depending on variant option, then &background
local function refresh_icons()
local theme
Expand All @@ -63,6 +84,10 @@ local function refresh_icons()
icons_by_operating_system = theme.icons_by_operating_system
icons_by_desktop_environment = theme.icons_by_desktop_environment
icons_by_window_manager = theme.icons_by_window_manager

-- filename matches are case insensitive
lowercase_keys(icons_by_filename)

icons = vim.tbl_extend(
"keep",
{},
Expand Down Expand Up @@ -354,27 +379,6 @@ local function get_highlight_ctermfg(icon_data)
return nvim_get_hl_by_name(get_highlight_name(icon_data), false).foreground
end

---Change all keys in a table to lowercase
---Remove entry when lowercase entry already exists
---@param t table
local function lowercase_keys(t)
if not t then
return
end

for k, v in pairs(t) do
if type(k) == "string" then
local lower_k = k:lower()
if lower_k ~= k then
if not t[lower_k] then
t[lower_k] = v
end
t[k] = nil
end
end
end
end

local loaded = false

function M.has_loaded()
Expand Down

0 comments on commit 0eb18da

Please sign in to comment.