Skip to content

Do not ignore right_aligned icons when computing max window width #3015

Closed
@simonmandlik

Description

@simonmandlik

Is your feature request related to a problem? Please describe.
I like the nvim-tree window to take as much width as needed as long as it doesn't cover over 60% of the screen. For this reason, I'm using

view.width = {
   min = -1,
   max=60%
}

This works very nice, but when used together with right_aligned icon extmarks, the longest paths are not always shown in full, even if there is plenty of width in the window. This is likely because the max width computation doesn't take these extmarks into account.

It would be great to have the width computation take extmarks into account.

I guess the modification could be done here?

local function grow()
local starts_at = M.is_root_folder_visible(require("nvim-tree.core").get_cwd()) and 1 or 0
local lines = vim.api.nvim_buf_get_lines(M.get_bufnr(), starts_at, -1, false)
-- number of columns of right-padding to indicate end of path
local padding = get_size(M.View.padding)
-- account for sign/number columns etc.
local wininfo = vim.fn.getwininfo(M.get_winnr())
if type(wininfo) == "table" and type(wininfo[1]) == "table" then
padding = padding + wininfo[1].textoff
end
local resizing_width = M.View.initial_width - padding
local max_width
-- maybe bound max
if M.View.max_width == -1 then
max_width = -1
else
max_width = get_width(M.View.max_width) - padding
end
for _, l in pairs(lines) do
local count = vim.fn.strchars(l)
if resizing_width < count then
resizing_width = count
end
if M.View.adaptive_size and max_width >= 0 and resizing_width >= max_width then
resizing_width = max_width
break
end
end
M.resize(resizing_width + padding)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    PR pleasenvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciatedbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions