Skip to content

Commit d3df304

Browse files
committed
fix(#2415): harden unicode signs
1 parent 9ee3783 commit d3df304

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

lua/nvim-tree/renderer/builder.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,8 @@ function Builder:_format_line(indent_markers, arrows, icon, name, node)
235235
return line
236236
end
237237

238-
function Builder:_build_line(node, idx, num_children)
239-
-- various components
240-
local indent_markers = pad.get_indent_markers(self.depth, idx, num_children, node, self.markers)
241-
local arrows = pad.get_arrows(node)
242-
243-
-- signs, use the highest priority
238+
function Builder:_build_signs(node)
239+
-- first in priority order
244240
local sign_name
245241
for _, d in ipairs(self.deco) do
246242
sign_name = d:sign_name(node)
@@ -249,6 +245,12 @@ function Builder:_build_line(node, idx, num_children)
249245
break
250246
end
251247
end
248+
end
249+
250+
function Builder:_build_line(node, idx, num_children)
251+
-- various components
252+
local indent_markers = pad.get_indent_markers(self.depth, idx, num_children, node, self.markers)
253+
local arrows = pad.get_arrows(node)
252254

253255
-- main components
254256
local is_folder = node.nodes ~= nil
@@ -302,6 +304,7 @@ function Builder:build(tree)
302304
local idx = 1
303305
for _, node in ipairs(tree.nodes) do
304306
if not node.hidden then
307+
self:_build_signs(node)
305308
self:_build_line(node, idx, num_children)
306309
idx = idx + 1
307310
end

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,20 @@ function Decorator:define_sign(icon)
103103
vim.fn.sign_undefine(name)
104104
end
105105

106-
if self.icon_placement ~= ICON_PLACEMENT.signcolumn or #icon.str < 1 then
106+
-- don't use sign if not defined
107+
if #icon.str < 1 then
108+
self.icon_placement = ICON_PLACEMENT.none
107109
return
108110
end
109111

112+
-- byte index of the next character, allowing for wide
113+
local bi = vim.fn.byteidx(icon.str, 1)
114+
115+
-- first (wide) character, falls back to empty string
116+
local text = string.sub(icon.str, 1, bi)
110117
vim.fn.sign_define(name, {
111-
text = string.sub(icon.str, 1, 1),
112-
texthl = icon.hl[1],
118+
text = text,
119+
texthl = name,
113120
})
114121
end
115122
end

0 commit comments

Comments
 (0)