Skip to content

Commit 31ba3c4

Browse files
fix: get_icon_color() is now case insensitive (#445)
Problem: get_icon_color() does not find icons for files whose names are completely capitalized, such as "LICENSE" or "COMMIT_EDITMSG". This is inconsistent with the functionality of get_icon(), which does lowercase the name parameter. Solution: Lowercase the name parameter in get_icon_color(). Coincidentally, get_icon() and get_icon_color() have a lot of duplicate functionality at the front of the function, specifically to get the entire icon data. Abstract this functionality out to a local function that can be shared by these two functions, which now are basically wrapper functions that return different data.
1 parent b346839 commit 31ba3c4

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

lua/nvim-web-devicons.lua

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ local function get_icon_by_extension(name, ext, opts)
461461
return iterate_multi_dotted_extension(name, icon_table)
462462
end
463463

464-
function M.get_icon(name, ext, opts)
464+
local function get_icon_data(name, ext, opts)
465465
if type(name) == "string" then
466466
name = name:lower()
467467
end
@@ -479,6 +479,12 @@ function M.get_icon(name, ext, opts)
479479
icon_data = icons[name] or get_icon_by_extension(name, ext, opts) or (has_default and default_icon)
480480
end
481481

482+
return icon_data
483+
end
484+
485+
function M.get_icon(name, ext, opts)
486+
local icon_data = get_icon_data(name, ext, opts)
487+
482488
if icon_data then
483489
return icon_data.icon, get_highlight_name(icon_data)
484490
end
@@ -496,18 +502,7 @@ function M.get_icon_by_filetype(ft, opts)
496502
end
497503

498504
function M.get_icon_colors(name, ext, opts)
499-
if not loaded then
500-
M.setup()
501-
end
502-
503-
local has_default = if_nil(opts and opts.default, global_opts.default)
504-
local is_strict = if_nil(opts and opts.strict, global_opts.strict)
505-
local icon_data
506-
if is_strict then
507-
icon_data = icons_by_filename[name] or get_icon_by_extension(name, ext, opts) or (has_default and default_icon)
508-
else
509-
icon_data = icons[name] or get_icon_by_extension(name, ext, opts) or (has_default and default_icon)
510-
end
505+
local icon_data = get_icon_data(name, ext, opts)
511506

512507
if icon_data then
513508
local color = icon_data.color

0 commit comments

Comments
 (0)