Skip to content

Commit 8f48426

Browse files
authored
feat(#2316): add NvimTreeFolderArrowClosed NvimTreeFolderArrowOpen (#2408)
1 parent 33c3bc5 commit 8f48426

File tree

3 files changed

+55
-39
lines changed

3 files changed

+55
-39
lines changed

doc/nvim-tree-lua.txt

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2142,27 +2142,29 @@ Icon: >
21422142
NvimTreeOpenedFolderIcon NvimTreeFolderIcon
21432143
NvimTreeClosedFolderIcon NvimTreeFolderIcon
21442144
NvimTreeBookmark
2145+
NvimTreeFolderArrowClosed NvimTreeIndentMarker
2146+
NvimTreeFolderArrowOpen NvimTreeIndentMarker
21452147
<
21462148
Indent: >
21472149
NvimTreeIndentMarker
21482150
<
21492151
Standard: >
2150-
NvimTreeNormal Normal
2151-
NvimTreeNormalFloat NormalFloat
2152-
NvimTreeNormalNC NormalFloat
2153-
2154-
NvimTreeLineNr LineNr
2155-
NvimTreeWinSeparator WinSeparator
2156-
NvimTreeEndOfBuffer EndOfBuffer
2157-
NvimTreePopup Normal
2158-
NvimTreeSignColumn NvimTreeNormal
2159-
2160-
NvimTreeCursorColumn CursorColumn
2161-
NvimTreeCursorLine CursorLine
2162-
NvimTreeCursorLineNr CursorLineNr
2163-
2164-
NvimTreeStatusLine StatusLine
2165-
NvimTreeStatusLineNC StatusLineNC
2152+
NvimTreeNormal Normal
2153+
NvimTreeNormalFloat NormalFloat
2154+
NvimTreeNormalNC NormalFloat
2155+
2156+
NvimTreeLineNr LineNr
2157+
NvimTreeWinSeparator WinSeparator
2158+
NvimTreeEndOfBuffer EndOfBuffer
2159+
NvimTreePopup Normal
2160+
NvimTreeSignColumn NvimTreeNormal
2161+
2162+
NvimTreeCursorColumn CursorColumn
2163+
NvimTreeCursorLine CursorLine
2164+
NvimTreeCursorLineNr CursorLineNr
2165+
2166+
NvimTreeStatusLine StatusLine
2167+
NvimTreeStatusLineNC StatusLineNC
21662168
<
21672169
Picker: >
21682170
NvimTreeWindowPicker

lua/nvim-tree/renderer/builder.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,15 @@ function Builder:_get_highlight_override(node, unloaded_bufnr)
290290
return icon_hl, name_hl
291291
end
292292

293-
---@param padding HighlightedString
293+
---@param indent_markers HighlightedString[]
294+
---@param arrows HighlightedString[]|nil
294295
---@param icon HighlightedString
295296
---@param name HighlightedString
296297
---@param git_icons HighlightedString[]|nil
297298
---@param diagnostics_icon HighlightedString|nil
298299
---@param modified_icon HighlightedString|nil
299300
---@return HighlightedString[]
300-
function Builder:_format_line(padding, icon, name, git_icons, diagnostics_icon, modified_icon)
301+
function Builder:_format_line(indent_markers, arrows, icon, name, git_icons, diagnostics_icon, modified_icon)
301302
local added_len = 0
302303
local function add_to_end(t1, t2)
303304
for _, v in ipairs(t2) do
@@ -315,7 +316,7 @@ function Builder:_format_line(padding, icon, name, git_icons, diagnostics_icon,
315316
end
316317
end
317318

318-
local line = { padding }
319+
local line = { indent_markers, arrows }
319320
add_to_end(line, { icon })
320321
if git_icons and self.git_placement == "before" then
321322
add_to_end(line, git_icons)
@@ -344,7 +345,8 @@ end
344345

345346
function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
346347
-- various components
347-
local padding = pad.get_padding(self.depth, idx, num_children, node, self.markers)
348+
local indent_markers = pad.get_indent_markers(self.depth, idx, num_children, node, self.markers)
349+
local arrows = pad.get_arrows(node)
348350
local git_icons = self:_get_git_icons(node)
349351
local modified_icon = self:_get_modified_icon(node)
350352
local diagnostics_icon = self:_get_diagnostics_icon(node)
@@ -370,7 +372,7 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
370372
name.hl = name_hl
371373
end
372374

373-
local line = self:_format_line(padding, icon, name, git_icons, diagnostics_icon, modified_icon)
375+
local line = self:_format_line(indent_markers, arrows, icon, name, git_icons, diagnostics_icon, modified_icon)
374376
self:_insert_line(self:_unwrap_highlighted_strings(line))
375377

376378
self.index = self.index + 1

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

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,41 +58,53 @@ local function get_padding_indent_markers(depth, idx, nodes_number, markers, wit
5858
return padding
5959
end
6060

61-
local function get_padding_arrows(node, indent)
62-
if node.nodes then
63-
return M.config.icons.glyphs.folder[node.open and "arrow_open" or "arrow_closed"] .. " "
64-
elseif indent then
65-
return " "
66-
else
67-
return ""
68-
end
69-
end
70-
7161
---@param depth integer
7262
---@param idx integer
7363
---@param nodes_number integer
7464
---@param node table
7565
---@param markers table
76-
---@return HighlightedString
77-
function M.get_padding(depth, idx, nodes_number, node, markers)
78-
local padding = ""
66+
---@return HighlightedString[]
67+
function M.get_indent_markers(depth, idx, nodes_number, node, markers)
68+
local str = ""
7969

8070
local show_arrows = M.config.icons.show.folder_arrow
8171
local show_markers = M.config.indent_markers.enable
8272
local inline_arrows = M.config.indent_markers.inline_arrows
8373
local indent_width = M.config.indent_width
8474

8575
if show_markers then
86-
padding = padding .. get_padding_indent_markers(depth, idx, nodes_number, markers, show_arrows, inline_arrows, node)
76+
str = str .. get_padding_indent_markers(depth, idx, nodes_number, markers, show_arrows, inline_arrows, node)
8777
else
88-
padding = padding .. string.rep(" ", depth * indent_width)
78+
str = str .. string.rep(" ", depth * indent_width)
79+
end
80+
81+
return { str = str, hl = "NvimTreeIndentMarker" }
82+
end
83+
84+
---@param node table
85+
---@return HighlightedString[]|nil
86+
function M.get_arrows(node)
87+
if not M.config.icons.show.folder_arrow then
88+
return
8989
end
9090

91-
if show_arrows then
92-
padding = padding .. get_padding_arrows(node, not show_markers)
91+
local str
92+
local hl = "NvimTreeFolderArrowClosed"
93+
94+
if node.nodes then
95+
if node.open then
96+
str = M.config.icons.glyphs.folder["arrow_open"] .. " "
97+
hl = "NvimTreeFolderArrowOpen"
98+
else
99+
str = M.config.icons.glyphs.folder["arrow_closed"] .. " "
100+
end
101+
elseif M.config.indent_markers.enable then
102+
str = ""
103+
else
104+
str = " "
93105
end
94106

95-
return { str = padding, hl = "NvimTreeIndentMarker" }
107+
return { str = str, hl = hl }
96108
end
97109

98110
function M.setup(opts)

0 commit comments

Comments
 (0)