fix: preserve devicons highlight groups in nonicons icon provider
Problem: when the nonicons direct API was detected, all icons were returned with the generic 'OilFileIcon' highlight group, losing per-filetype colors from nvim-web-devicons. Solution: resolve highlight groups from devicons when available so nonicons glyphs retain their per-filetype colors.
This commit is contained in:
parent
c51e3168de
commit
60bfbe05da
1 changed files with 6 additions and 3 deletions
|
|
@ -947,23 +947,26 @@ M.get_icon_provider = function()
|
||||||
|
|
||||||
local has_nonicons, nonicons = pcall(require, 'nonicons')
|
local has_nonicons, nonicons = pcall(require, 'nonicons')
|
||||||
if has_nonicons and nonicons.get_icon then
|
if has_nonicons and nonicons.get_icon then
|
||||||
|
local _, devicons = pcall(require, 'nvim-web-devicons')
|
||||||
return function(type, name, conf, ft)
|
return function(type, name, conf, ft)
|
||||||
if type == 'directory' then
|
if type == 'directory' then
|
||||||
local icon = nonicons.get('file-directory')
|
local icon = nonicons.get('file-directory')
|
||||||
return icon or (conf and conf.directory or ''), 'OilDirIcon'
|
return icon or (conf and conf.directory or ''), 'OilDirIcon'
|
||||||
end
|
end
|
||||||
|
local hl = devicons and select(2, devicons.get_icon(name)) or 'OilFileIcon'
|
||||||
if ft then
|
if ft then
|
||||||
local ft_icon = nonicons.get_icon_by_filetype(ft)
|
local ft_icon = nonicons.get_icon_by_filetype(ft)
|
||||||
if ft_icon then
|
if ft_icon then
|
||||||
return ft_icon, 'OilFileIcon'
|
local ft_hl = devicons and select(2, devicons.get_icon_by_filetype(ft))
|
||||||
|
return ft_icon, ft_hl or hl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local icon = nonicons.get_icon(name)
|
local icon = nonicons.get_icon(name)
|
||||||
if icon then
|
if icon then
|
||||||
return icon, 'OilFileIcon'
|
return icon, hl
|
||||||
end
|
end
|
||||||
local fallback = nonicons.get('file')
|
local fallback = nonicons.get('file')
|
||||||
return fallback or (conf and conf.default_file or ''), 'OilFileIcon'
|
return fallback or (conf and conf.default_file or ''), hl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue