refactor(renderer): remove set_folder_hl function from icons
This greatly simplifies the folder highlighting logic. It wasn't clear before and the code was probably doing more than it should. The logic with highlight_opened_file wasn't working at all, so i just removed it. This should allow us to greatly extend the order in which the components are rendered.
This commit is contained in:
parent
d8fe48a887
commit
0d6c0dda3d
@ -6,7 +6,7 @@ local icons = require "nvim-tree.renderer.components.icons"
|
||||
|
||||
-- TODO(refactor): the builder abstraction is not perfect yet. We shouldn't leak data in components.
|
||||
-- Components should return only and icon / highlight group pair at most.
|
||||
-- The code was mostly moved from renderer/init.lua and rearranged, so it's still under construction.
|
||||
-- Only missing git refactoring
|
||||
|
||||
local Builder = {}
|
||||
Builder.__index = Builder
|
||||
@ -84,39 +84,28 @@ function Builder:_build_folder(node, padding, git_hl)
|
||||
local has_children = #node.nodes ~= 0 or node.has_children
|
||||
local icon = icons.get_folder_icon(node.open, node.link_to ~= nil, has_children)
|
||||
local git_icon = git.get_icons(node, self.index, offset, #icon, self.highlights) or ""
|
||||
local line = padding .. icon .. git_icon .. name .. self.trailing_slash
|
||||
|
||||
local folder_hl = "NvimTreeFolderName"
|
||||
self:_insert_line(line)
|
||||
|
||||
if #icon > 0 then
|
||||
self:_insert_highlight("NvimTreeFolderIcon", offset, offset + #icon)
|
||||
end
|
||||
|
||||
local foldername_hl = "NvimTreeFolderName"
|
||||
if self.special_map[node.absolute_path] then
|
||||
folder_hl = "NvimTreeSpecialFolderName"
|
||||
foldername_hl = "NvimTreeSpecialFolderName"
|
||||
elseif node.open then
|
||||
folder_hl = "NvimTreeOpenedFolderName"
|
||||
foldername_hl = "NvimTreeOpenedFolderName"
|
||||
elseif not has_children then
|
||||
folder_hl = "NvimTreeEmptyFolderName"
|
||||
foldername_hl = "NvimTreeEmptyFolderName"
|
||||
end
|
||||
|
||||
icons.set_folder_hl(
|
||||
self.index,
|
||||
offset,
|
||||
#icon + #git_icon,
|
||||
#name,
|
||||
"NvimTreeFolderIcon",
|
||||
folder_hl,
|
||||
self.highlights,
|
||||
self.open_file_highlight
|
||||
)
|
||||
self:_insert_highlight(foldername_hl, offset + #icon + #git_icon, #line)
|
||||
|
||||
if git_hl then
|
||||
icons.set_folder_hl(
|
||||
self.index,
|
||||
offset,
|
||||
#icon + #git_icon,
|
||||
#name,
|
||||
git_hl,
|
||||
git_hl,
|
||||
self.highlights,
|
||||
self.open_file_highlight
|
||||
)
|
||||
self:_insert_highlight(git_hl, offset + #icon + #git_icon, #line)
|
||||
end
|
||||
self:_insert_line(padding .. icon .. git_icon .. name .. self.trailing_slash)
|
||||
end
|
||||
|
||||
-- TODO: missing git icon for symlinks
|
||||
|
||||
@ -11,14 +11,6 @@ local function empty()
|
||||
return ""
|
||||
end
|
||||
|
||||
local function get_trailing_length()
|
||||
return vim.g.nvim_tree_add_trailing and 1 or 0
|
||||
end
|
||||
|
||||
local function set_folder_hl_default(line, depth, git_icon_len, _, hl_group, _, hl)
|
||||
table.insert(hl, { hl_group, line, depth + git_icon_len, -1 })
|
||||
end
|
||||
|
||||
local function get_folder_icon(open, is_symlink, has_children)
|
||||
local n
|
||||
if is_symlink and open then
|
||||
@ -41,12 +33,6 @@ local function get_folder_icon(open, is_symlink, has_children)
|
||||
return n .. M.padding
|
||||
end
|
||||
|
||||
local function set_folder_hl(line, depth, icon_len, name_len, hl_icongroup, hl_fnamegroup, hl, should_hl_opened_files)
|
||||
local hl_icon = should_hl_opened_files and hl_icongroup or "NvimTreeFolderIcon"
|
||||
table.insert(hl, { hl_icon, line, depth, depth + icon_len })
|
||||
table.insert(hl, { hl_fnamegroup, line, depth + icon_len, depth + icon_len + name_len + get_trailing_length() })
|
||||
end
|
||||
|
||||
local function get_file_icon_default()
|
||||
local hl_group = "NvimTreeFileIcon"
|
||||
local icon = M.icons.default
|
||||
@ -95,10 +81,8 @@ end
|
||||
local function config_folder_icon()
|
||||
if M.configs.show_folder_icon then
|
||||
M.get_folder_icon = get_folder_icon
|
||||
M.set_folder_hl = set_folder_hl
|
||||
else
|
||||
M.get_folder_icon = empty
|
||||
M.set_folder_hl = set_folder_hl_default
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user