refactor(renderer): return hl group from get_file_icon

this allows to not pass private data from builder to component
This commit is contained in:
kiyan
2022-04-26 21:50:34 +02:00
parent 2934370fa3
commit d8fe48a887
2 changed files with 12 additions and 11 deletions

View File

@@ -137,7 +137,10 @@ function Builder:_build_file_icons(node, offset)
self:_insert_highlight("NvimTreeSpecialFile", offset + #git_icons) self:_insert_highlight("NvimTreeSpecialFile", offset + #git_icons)
return icons.i.special, git_icons return icons.i.special, git_icons
else else
local icon = icons.get_file_icon(node.name, node.extension, self.index, offset, self.highlights) local icon, hl_group = icons.get_file_icon(node.name, node.extension)
if hl_group then
self:_insert_highlight(hl_group, offset, offset + #icon)
end
return icon, git.get_icons(node, self.index, offset, #icon, self.highlights) return icon, git.get_icons(node, self.index, offset, #icon, self.highlights)
end end
end end

View File

@@ -47,30 +47,28 @@ local function set_folder_hl(line, depth, icon_len, name_len, hl_icongroup, hl_f
table.insert(hl, { hl_fnamegroup, line, depth + icon_len, depth + icon_len + name_len + get_trailing_length() }) table.insert(hl, { hl_fnamegroup, line, depth + icon_len, depth + icon_len + name_len + get_trailing_length() })
end end
local function get_file_icon_default(_, _, line, depth, hl) local function get_file_icon_default()
local hl_group = "NvimTreeFileIcon" local hl_group = "NvimTreeFileIcon"
local icon = M.icons.default local icon = M.icons.default
if #icon > 0 then if #icon > 0 then
table.insert(hl, { hl_group, line, depth, depth + #icon + 1 }) return icon .. M.padding, hl_group
else
return ""
end end
return #icon > 0 and icon .. M.padding or ""
end end
local function get_file_icon_webdev(fname, extension, line, depth, hl) local function get_file_icon_webdev(fname, extension)
local icon, hl_group = M.devicons.get_icon(fname, extension) local icon, hl_group = M.devicons.get_icon(fname, extension)
if not M.webdev_colors then if not M.webdev_colors then
hl_group = "NvimTreeFileIcon" hl_group = "NvimTreeFileIcon"
end end
if icon and hl_group ~= "DevIconDefault" then if icon and hl_group ~= "DevIconDefault" then
if hl_group then return icon .. M.padding, hl_group
table.insert(hl, { hl_group, line, depth, depth + #icon + 1 })
end
return icon .. M.padding
elseif string.match(extension, "%.(.*)") then elseif string.match(extension, "%.(.*)") then
-- If there are more extensions to the file, try to grab the icon for them recursively -- If there are more extensions to the file, try to grab the icon for them recursively
return M.get_file_icon(fname, string.match(extension, "%.(.*)"), line, depth, hl) return get_file_icon_webdev(fname, string.match(extension, "%.(.*)"))
else else
return get_file_icon_default(fname, extension, line, depth, hl) return get_file_icon_default()
end end
end end