Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
simonmandlik opened this issue Dec 3, 2024 · 2 comments · Fixed by #3022
Closed

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

simonmandlik opened this issue Dec 3, 2024 · 2 comments · Fixed by #3022
Labels
bug Something isn't working PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated

Comments

@simonmandlik
Copy link
Contributor

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

@alex-courtis
Copy link
Member

I guess the modification could be done here?

That looks correct, a pull request would be most gratefully appreciated, see CONTRIBUTING.md

max=60%

Should this be max="60%"

@alex-courtis alex-courtis added bug Something isn't working PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated and removed feature request labels Dec 6, 2024
simonmandlik added a commit to simonmandlik/nvim-tree.lua that referenced this issue Dec 8, 2024
@simonmandlik
Copy link
Contributor Author

a pull request would be most gratefully appreciated

Here #3022

Should this be max="60%"

Sure, sorry, made a typo here :)

simonmandlik added a commit to simonmandlik/nvim-tree.lua that referenced this issue Dec 8, 2024
simonmandlik added a commit to simonmandlik/nvim-tree.lua that referenced this issue Dec 11, 2024
simonmandlik added a commit to simonmandlik/nvim-tree.lua that referenced this issue Dec 11, 2024
simonmandlik added a commit to simonmandlik/nvim-tree.lua that referenced this issue Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants