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

fix(#3015): dynamic width no longer truncates on right_align icons #3022

Merged
merged 2 commits into from
Dec 13, 2024

Conversation

simonmandlik
Copy link
Contributor

Fixes #3015

@alex-courtis
Copy link
Member

Thanks for the fix, however I'm having trouble replicating and validating it.

Please provide a clean room configuration and instructions on how I can demonstrate the fix with it.

@simonmandlik
Copy link
Contributor Author

Instructions:

  1. run nvim -nu minimal.lua
  2. Edit the longest file in any git repo. Here, I use nvim-tree directly so I change something in .release-please-manifest.json so that it get a right-aligned icon
  3. This is the bug
image

Even though the max width is set to 100%, the whole filename is not shown due to the icon covering a part of it.

With this PR, it looks like this

image

minimal.lua:

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvt-min/site]])
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup({
    {
      "wbthomason/packer.nvim",
      -- "~/Downloads/nvim-tree.lua",
      "nvim-tree/nvim-tree.lua",
      "nvim-tree/nvim-web-devicons",
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  })
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing nvim-tree and dependencies.")
  vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()
vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]])
vim.opt.termguicolors = true
vim.opt.cursorline = true

_G.setup = function()
  require("nvim-tree").setup({
    view = {
      width = {
        min = -1,
        max = "100%",
        padding = 0
      }
    },
    renderer = {
      icons = {
        git_placement = "right_align"
      }
    }
  })
end

@simonmandlik
Copy link
Contributor Author

For what it's worth, this is not a solution I'm completely satisfied with. I placed the fix into View.grow and so upon every call of NvimTreeOpen the width is computed correctly. However, once I switch from the nvim-tree buffer to a different buffer, it gets resized back. This is because in such case, View.grow is called but for some reason there are no longer extmarks for right-aligned icons in the NvimTreeExtmarks namespace.

Screen.Recording.2024-12-11.at.19.11.49.mov

Another problem I could observe is that when nvim tree buffer is open and a new "after" icon is added (e.g. from LSP), the View.grow function doesn't have extmarks available either. Here I add both error diagnostic ("after") and git modified ("right_align") icon at the same time and the width is computed incorrectly. Only after I reopen the nvim tree buffer, it is correct again:

Screen.Recording.2024-12-11.at.19.27.07.mov

I don't know the internals of nvim-tree to be able to fix these, so I would appreciated some guidance here. Or I would be happy with merging this PR as is since I almost always close nvim tree rightaway and so the issues above do not bother me.

@simonmandlik simonmandlik force-pushed the master branch 2 times, most recently from 293d288 to 2c6dd75 Compare December 11, 2024 18:52
@simonmandlik
Copy link
Contributor Author

Addressed the CI issues

@alex-courtis
Copy link
Member

This change does address the issue for width whilst focused. Unfortunately the width when changing is a regression.

View is quite fragile. It is targeted for a refactor during https://github.com/orgs/nvim-tree/projects/1 however that will not address this issue.

A full solution is desirable, let's see what we can come up with.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works nicely for a variety of width cases.
Many thanks for resolving this one!

@alex-courtis alex-courtis changed the title fix(#3015): right-aligned icons are taken into account in grow fix(#3015): dynamic width no longer truncates on right_align icons Dec 13, 2024
@alex-courtis alex-courtis merged commit f7b76cd into nvim-tree:master Dec 13, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not ignore right_aligned icons when computing max window width
2 participants