Skip to content

Commit 2879bd5

Browse files
committed
fix(#3015): right-aligned icons are taken into account in grow
1 parent db8d7ac commit 2879bd5

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lua/nvim-tree/view.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ local function get_size(size)
119119
if type(size) == "number" then
120120
return size
121121
elseif type(size) == "function" then
122-
return get_size(size())
122+
return size()
123123
end
124124
local size_as_number = tonumber(size:sub(0, -2))
125125
local percent_as_decimal = size_as_number / 100
@@ -321,8 +321,17 @@ local function grow()
321321
max_width = get_width(M.View.max_width) - padding
322322
end
323323

324-
for _, l in pairs(lines) do
324+
local ns_id = vim.api.nvim_get_namespaces()["NvimTreeExtmarks"]
325+
for line_nr, l in pairs(lines) do
325326
local count = vim.fn.strchars(l)
327+
-- also add space for right-aligned icons
328+
local extmarks = vim.api.nvim_buf_get_extmarks(0, ns_id, { line_nr, 0 }, { line_nr, -1 }, { details = true } )
329+
for _, extmark in ipairs(extmarks) do
330+
local virt_texts = extmark[4].virt_text
331+
for _, virt_text in ipairs(virt_texts) do
332+
count = count + vim.fn.strchars(virt_text[1])
333+
end
334+
end
326335
if resizing_width < count then
327336
resizing_width = count
328337
end

0 commit comments

Comments
 (0)