neo-tree.nvim icon indicating copy to clipboard operation
neo-tree.nvim copied to clipboard

BUG: file names are truncated when relative line numbers are enabled

Open utrumo opened this issue 1 year ago • 5 comments
trafficstars

Did you check docs and existing issues?

  • [X] I have read all the docs.
  • [X] I have searched the existing issues.
  • [X] I have searched the existing discussions.

Neovim Version (nvim -v)

v0.9.5

Operating System / Version

Arch Linux

Describe the Bug

File names are truncated when relative line numbers are enabled.

Screenshots, Traceback

extension

Steps to Reproduce

  1. Adds to config event handler:
  auto_expand_width = true,
  event_handlers = {
      event = "neo_tree_buffer_enter",
      handler = function()
        vim.opt_local.relativenumber = true
      end,
   },
  1. Open neo-tree by hotkey <Leader>e.

Expected Behavior

file names are not truncated

Your Configuration

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  -- add any other plugins here
}

local neotree_config = {
  "nvim-neo-tree/neo-tree.nvim",
  dependencies = { "MunifTanjim/nui.nvim", "nvim-tree/nvim-web-devicons", "nvim-lua/plenary.nvim" },
  cmd = { "Neotree" },
  keys = {
    { "<Leader>e", "<Cmd>Neotree<CR>" }, -- change or remove this line if relevant.
  },
  opts = {
    -- Your config here
    -- ...
    auto_expand_width = true,
    event_handlers = {
      event = "neo_tree_buffer_enter",
      handler = function()
        vim.opt_local.relativenumber = true
      end,
    },
  },
}

table.insert(plugins, neotree_config)
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

utrumo avatar Jan 22 '24 20:01 utrumo

This is not a bug I guess. Your filename is bigger than the width of neo-tree buffer. So some of the name is hidden. You can use your mouse(click and hold, then drag) to change the width of neo-tree to see the full name. Check this video... Screencast from 2024-01-25 10-32-42.webm

Rid1FZ avatar Jan 25 '24 04:01 Rid1FZ

I forgot to add the option auto_expand_width = true to the bug report description from my config (now added it). I think the problem with auto_expand_width option is that it does not check that relativenumber is on and calculates the width less than necessary

utrumo avatar Feb 01 '24 12:02 utrumo

As far as I know, there is no way to know the real available width of a window (ref).

API calls such as nvim_win_get_width(0) returns a number that includes the width of nu, rnu, signcolumns so we cannot detect how long the line should be if you enable those columns, hence the content overflows. Due to this limitation we force set nonu nornu for neo-tree windows and forget about this difficult problem.

If you happen to know any good ways to detect the actual buffer width of a window, please please let me know. But until then labeling this as wontfix for now.

@cseickel Can we close this FR?

pysan3 avatar Mar 12 '24 10:03 pysan3

As far as I know, there is no way to know the real available width of a window (ref).

I do think it is possible to get the real width. I do it for some code in my winbar.

vim.fn.getwininfo(winid).textoff

Will give you the width of the sign/number columns.

cseickel avatar Mar 12 '24 12:03 cseickel