From c4e8132630b0ad00891914ba9d3f8b7b934b2dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Mandl=C3=ADk?= Date: Sun, 8 Dec 2024 10:54:37 +0100 Subject: [PATCH] fix(#3015): right-aligned icons are taken into account in `grow` --- lua/nvim-tree/view.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 21c4c6305aa..c62b491ef2e 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -321,8 +321,19 @@ 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(M.get_bufnr(), ns_id, { line_nr, 0 }, { line_nr, -1 }, { details = true }) + for _, extmark in ipairs(extmarks) do + local virt_texts = extmark[4].virt_text + if virt_texts then + for _, virt_text in ipairs(virt_texts) do + count = count + vim.fn.strchars(virt_text[1]) + end + end + end if resizing_width < count then resizing_width = count end