Skip to content

Commit 0042f7d

Browse files
committed
perf(#3257): remove padding setup
1 parent f495542 commit 0042f7d

File tree

4 files changed

+33
-47
lines changed

4 files changed

+33
-47
lines changed

lua/nvim-tree.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ function M.setup(config_user)
289289
end
290290

291291
require("nvim-tree.appearance").setup()
292-
require("nvim-tree.renderer.components").setup(config.g)
293292

294293
require("nvim-tree.view-state").initialize()
295294

lua/nvim-tree/config.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,21 @@ local function process_config(g)
511511
-- Open
512512
--
513513
g.actions.open_file.window_picker.chars = tostring(g.actions.open_file.window_picker.chars):upper()
514+
515+
--
516+
-- Padding
517+
--
518+
if g.renderer.indent_width < 1 then
519+
g.renderer.indent_width = 1
520+
end
521+
for k, v in pairs(g.renderer.indent_markers.icons) do
522+
if #v == 0 then
523+
g.renderer.indent_markers.icons[k] = " "
524+
else
525+
-- return the first character from the UTF-8 encoded string; we may use utf8.codes from Lua 5.3 when available
526+
g.renderer.indent_markers.icons[k] = v:match("[%z\1-\127\194-\244][\128-\191]*")
527+
end
528+
end
514529
end
515530

516531
---Validate user config and migrate legacy.

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

Lines changed: 0 additions & 9 deletions
This file was deleted.

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

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local config = require("nvim-tree.config")
12
local DirectoryNode = require("nvim-tree.node.directory")
23

34
local M = {}
@@ -27,21 +28,21 @@ local function get_padding_indent_markers(depth, idx, nodes_number, markers, wit
2728

2829
if depth > 0 then
2930
local has_folder_sibling = check_siblings_for_folder(node, with_arrows)
30-
local indent = string.rep(" ", M.config.indent_width - 1)
31+
local indent = string.rep(" ", config.g.renderer.indent_width - 1)
3132
markers[depth] = idx ~= nodes_number
3233
for i = 1, depth - early_stop do
3334
local glyph
3435
if idx == nodes_number and i == depth then
35-
local bottom_width = M.config.indent_width - 2 + (with_arrows and not inline_arrows and has_folder_sibling and 2 or 0)
36-
glyph = M.config.indent_markers.icons.corner
37-
.. string.rep(M.config.indent_markers.icons.bottom, bottom_width)
38-
.. (M.config.indent_width > 1 and " " or "")
36+
local bottom_width = config.g.renderer.indent_width - 2 + (with_arrows and not inline_arrows and has_folder_sibling and 2 or 0)
37+
glyph = config.g.renderer.indent_markers.icons.corner
38+
.. string.rep(config.g.renderer.indent_markers.icons.bottom, bottom_width)
39+
.. (config.g.renderer.indent_width > 1 and " " or "")
3940
elseif markers[i] and i == depth then
40-
glyph = M.config.indent_markers.icons.item .. indent
41+
glyph = config.g.renderer.indent_markers.icons.item .. indent
4142
elseif markers[i] then
42-
glyph = M.config.indent_markers.icons.edge .. indent
43+
glyph = config.g.renderer.indent_markers.icons.edge .. indent
4344
else
44-
glyph = M.config.indent_markers.icons.none .. indent
45+
glyph = config.g.renderer.indent_markers.icons.none .. indent
4546
end
4647

4748
if not with_arrows or (inline_arrows and (depth ~= i or not node.nodes)) then
@@ -68,10 +69,10 @@ end
6869
function M.get_indent_markers(depth, idx, nodes_number, node, markers, early_stop)
6970
local str = ""
7071

71-
local show_arrows = M.config.icons.show.folder_arrow
72-
local show_markers = M.config.indent_markers.enable
73-
local inline_arrows = M.config.indent_markers.inline_arrows
74-
local indent_width = M.config.indent_width
72+
local show_arrows = config.g.renderer.icons.show.folder_arrow
73+
local show_markers = config.g.renderer.indent_markers.enable
74+
local inline_arrows = config.g.renderer.indent_markers.inline_arrows
75+
local indent_width = config.g.renderer.indent_width
7576

7677
if show_markers then
7778
str = str .. get_padding_indent_markers(depth, idx, nodes_number, markers, show_arrows, inline_arrows, node, early_stop or 0)
@@ -85,7 +86,7 @@ end
8586
---@param node Node
8687
---@return nvim_tree.api.highlighted_string[]?
8788
function M.get_arrows(node)
88-
if not M.config.icons.show.folder_arrow then
89+
if not config.g.renderer.icons.show.folder_arrow then
8990
return
9091
end
9192

@@ -95,38 +96,18 @@ function M.get_arrows(node)
9596
local dir = node:as(DirectoryNode)
9697
if dir then
9798
if dir.open then
98-
str = M.config.icons.glyphs.folder["arrow_open"] .. M.config.icons.padding.folder_arrow
99+
str = config.g.renderer.icons.glyphs.folder["arrow_open"] .. config.g.renderer.icons.padding.folder_arrow
99100
hl = "NvimTreeFolderArrowOpen"
100101
else
101-
str = M.config.icons.glyphs.folder["arrow_closed"] .. M.config.icons.padding.folder_arrow
102+
str = config.g.renderer.icons.glyphs.folder["arrow_closed"] .. config.g.renderer.icons.padding.folder_arrow
102103
end
103-
elseif M.config.indent_markers.enable then
104+
elseif config.g.renderer.indent_markers.enable then
104105
str = ""
105106
else
106-
str = " " .. string.rep(" ", #M.config.icons.padding.folder_arrow)
107+
str = " " .. string.rep(" ", #config.g.renderer.icons.padding.folder_arrow)
107108
end
108109

109110
return { str = str, hl = { hl } }
110111
end
111112

112-
function M.setup(opts)
113-
M.config = opts.renderer
114-
115-
if M.config.indent_width < 1 then
116-
M.config.indent_width = 1
117-
end
118-
119-
local function check_marker(symbol)
120-
if #symbol == 0 then
121-
return " "
122-
end
123-
-- return the first character from the UTF-8 encoded string; we may use utf8.codes from Lua 5.3 when available
124-
return symbol:match("[%z\1-\127\194-\244][\128-\191]*")
125-
end
126-
127-
for k, v in pairs(M.config.indent_markers.icons) do
128-
M.config.indent_markers.icons[k] = check_marker(v)
129-
end
130-
end
131-
132113
return M

0 commit comments

Comments
 (0)