Skip to content

Commit

Permalink
fix(#3015): right-aligned icons are taken into account in grow
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmandlik committed Dec 8, 2024
1 parent db8d7ac commit 2879bd5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ local function get_size(size)
if type(size) == "number" then
return size
elseif type(size) == "function" then
return get_size(size())
return size()
end
local size_as_number = tonumber(size:sub(0, -2))
local percent_as_decimal = size_as_number / 100
Expand Down Expand Up @@ -321,8 +321,17 @@ local function grow()
max_width = get_width(M.View.max_width) - padding
end

for _, l in pairs(lines) do
local ns_id = vim.api.nvim_get_namespaces()["NvimTreeExtmarks"]
for line_nr, l in pairs(lines) do
local count = vim.fn.strchars(l)
-- also add space for right-aligned icons
local extmarks = vim.api.nvim_buf_get_extmarks(0, ns_id, { line_nr, 0 }, { line_nr, -1 }, { details = true } )
for _, extmark in ipairs(extmarks) do
local virt_texts = extmark[4].virt_text
for _, virt_text in ipairs(virt_texts) do
count = count + vim.fn.strchars(virt_text[1])
end
end
if resizing_width < count then
resizing_width = count
end
Expand Down

0 comments on commit 2879bd5

Please sign in to comment.