Skip to content

Commit d8fe48a

Browse files
committed
refactor(renderer): return hl group from get_file_icon
this allows to not pass private data from builder to component
1 parent 2934370 commit d8fe48a

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

lua/nvim-tree/renderer/builder.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ function Builder:_build_file_icons(node, offset)
137137
self:_insert_highlight("NvimTreeSpecialFile", offset + #git_icons)
138138
return icons.i.special, git_icons
139139
else
140-
local icon = icons.get_file_icon(node.name, node.extension, self.index, offset, self.highlights)
140+
local icon, hl_group = icons.get_file_icon(node.name, node.extension)
141+
if hl_group then
142+
self:_insert_highlight(hl_group, offset, offset + #icon)
143+
end
141144
return icon, git.get_icons(node, self.index, offset, #icon, self.highlights)
142145
end
143146
end

lua/nvim-tree/renderer/components/icons.lua

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,28 @@ local function set_folder_hl(line, depth, icon_len, name_len, hl_icongroup, hl_f
4747
table.insert(hl, { hl_fnamegroup, line, depth + icon_len, depth + icon_len + name_len + get_trailing_length() })
4848
end
4949

50-
local function get_file_icon_default(_, _, line, depth, hl)
50+
local function get_file_icon_default()
5151
local hl_group = "NvimTreeFileIcon"
5252
local icon = M.icons.default
5353
if #icon > 0 then
54-
table.insert(hl, { hl_group, line, depth, depth + #icon + 1 })
54+
return icon .. M.padding, hl_group
55+
else
56+
return ""
5557
end
56-
return #icon > 0 and icon .. M.padding or ""
5758
end
5859

59-
local function get_file_icon_webdev(fname, extension, line, depth, hl)
60+
local function get_file_icon_webdev(fname, extension)
6061
local icon, hl_group = M.devicons.get_icon(fname, extension)
6162
if not M.webdev_colors then
6263
hl_group = "NvimTreeFileIcon"
6364
end
6465
if icon and hl_group ~= "DevIconDefault" then
65-
if hl_group then
66-
table.insert(hl, { hl_group, line, depth, depth + #icon + 1 })
67-
end
68-
return icon .. M.padding
66+
return icon .. M.padding, hl_group
6967
elseif string.match(extension, "%.(.*)") then
7068
-- If there are more extensions to the file, try to grab the icon for them recursively
71-
return M.get_file_icon(fname, string.match(extension, "%.(.*)"), line, depth, hl)
69+
return get_file_icon_webdev(fname, string.match(extension, "%.(.*)"))
7270
else
73-
return get_file_icon_default(fname, extension, line, depth, hl)
71+
return get_file_icon_default()
7472
end
7573
end
7674

0 commit comments

Comments
 (0)