Skip to content

Commit

Permalink
fix(#2415): harden unicode signs
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Nov 26, 2023
1 parent 9ee3783 commit d3df304
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
15 changes: 9 additions & 6 deletions lua/nvim-tree/renderer/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,8 @@ function Builder:_format_line(indent_markers, arrows, icon, name, node)
return line
end

function Builder:_build_line(node, idx, num_children)
-- various components
local indent_markers = pad.get_indent_markers(self.depth, idx, num_children, node, self.markers)
local arrows = pad.get_arrows(node)

-- signs, use the highest priority
function Builder:_build_signs(node)
-- first in priority order
local sign_name
for _, d in ipairs(self.deco) do
sign_name = d:sign_name(node)
Expand All @@ -249,6 +245,12 @@ function Builder:_build_line(node, idx, num_children)
break
end
end
end

function Builder:_build_line(node, idx, num_children)
-- various components
local indent_markers = pad.get_indent_markers(self.depth, idx, num_children, node, self.markers)
local arrows = pad.get_arrows(node)

-- main components
local is_folder = node.nodes ~= nil
Expand Down Expand Up @@ -302,6 +304,7 @@ function Builder:build(tree)
local idx = 1
for _, node in ipairs(tree.nodes) do
if not node.hidden then
self:_build_signs(node)
self:_build_line(node, idx, num_children)
idx = idx + 1
end
Expand Down
13 changes: 10 additions & 3 deletions lua/nvim-tree/renderer/decorator/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,20 @@ function Decorator:define_sign(icon)
vim.fn.sign_undefine(name)
end

if self.icon_placement ~= ICON_PLACEMENT.signcolumn or #icon.str < 1 then
-- don't use sign if not defined
if #icon.str < 1 then
self.icon_placement = ICON_PLACEMENT.none
return
end

-- byte index of the next character, allowing for wide
local bi = vim.fn.byteidx(icon.str, 1)

-- first (wide) character, falls back to empty string
local text = string.sub(icon.str, 1, bi)
vim.fn.sign_define(name, {
text = string.sub(icon.str, 1, 1),
texthl = icon.hl[1],
text = text,
texthl = name,
})
end
end
Expand Down

0 comments on commit d3df304

Please sign in to comment.