move folder specifics from icons to Directory

This commit is contained in:
Alexander Courtis 2024-11-02 14:13:58 +11:00
parent 8053244d98
commit 612f787d97
3 changed files with 33 additions and 14 deletions

View File

@ -41,6 +41,22 @@ function FileLinkNode:update_git_status(parent_ignored, project)
self.git_status = git_utils.git_status_file(parent_ignored, project, self.link_to, self.absolute_path)
end
---@return HighlightedString icon
function FileLinkNode:highlighted_icon()
return { str = icons.i.symlink, hl = { "NvimTreeSymlinkIcon" } }
end
---@return HighlightedString name
function FileLinkNode:highlighted_name()
local str = self.name
if self.explorer.opts.renderer.symlink_destination then
local link_to = utils.path_relative(self.link_to, self.explorer.absolute_path)
str = string.format("%s%s%s", str, icons.i.symlink_arrow, link_to)
end
return { str = str, hl = { "NvimTreeSymlink" } }
end
---Icon and name for the file link
---@return HighlightedString icon
---@return HighlightedString name

View File

@ -66,22 +66,25 @@ function FileNode:get_git_xy()
return self.git_status.file and { self.git_status.file }
end
---Icon and name for the file
---@return HighlightedString icon
---@return HighlightedString name
function FileNode:icon_name()
local name_hl
if vim.tbl_contains(self.explorer.opts.renderer.special_files, self.absolute_path) or vim.tbl_contains(self.explorer.opts.renderer.special_files, self.name) then
name_hl = "NvimTreeSpecialFile"
elseif self.executable then
name_hl = "NvimTreeExecFile"
elseif PICTURE_MAP[self.extension] then
name_hl = "NvimTreeImageFile"
end
function FileNode:highlighted_icon()
local icon_str, icon_hl = icons.get_file_icon(self.name, self.extension)
return { str = icon_str, hl = { icon_hl } }, { str = self.name, hl = { name_hl } }
return { str = icon_str, hl = { icon_hl } }
end
---@return HighlightedString name
function FileNode:highlighted_name()
local hl
if vim.tbl_contains(self.explorer.opts.renderer.special_files, self.absolute_path) or vim.tbl_contains(self.explorer.opts.renderer.special_files, self.name) then
hl = "NvimTreeSpecialFile"
elseif self.executable then
hl = "NvimTreeExecFile"
elseif PICTURE_MAP[self.extension] then
hl = "NvimTreeImageFile"
end
return { str = self.name, hl = { hl } }
end
---Create a sanitized partial copy of a node

View File

@ -252,7 +252,7 @@ function Builder:build_line(node, idx, num_children)
local arrows = pad.get_arrows(node)
-- main components
local icon, name = node:icon_name()
local icon, name = node:highlighted_icon(), node:highlighted_name()
-- highighting
local icon_hl_group, name_hl_group = self:add_highlights(node)