diff --git a/lua/nvim-tree/renderer/components/full-name.lua b/lua/nvim-tree/renderer/components/full-name.lua index 17ed2e31f60..6c41f3909d9 100644 --- a/lua/nvim-tree/renderer/components/full-name.lua +++ b/lua/nvim-tree/renderer/components/full-name.lua @@ -1,6 +1,7 @@ local M = {} local utils = require("nvim-tree.utils") +local view = require("nvim-tree.view") local function hide(win) if win then @@ -32,7 +33,7 @@ local function effective_win_width() return win_width - win_info[1].textoff end -local function show() +local function show(opts) local line_nr = vim.api.nvim_win_get_cursor(0)[1] if vim.wo.wrap then return @@ -52,6 +53,11 @@ local function show() local text_width = vim.fn.strdisplaywidth(vim.fn.substitute(line, "[^[:print:]]*$", "", "g")) local win_width = effective_win_width() + -- windows width reduced by right aligned icons + local icon_ns_id = vim.api.nvim_get_namespaces()["NvimTreeExtmarks"] + local icon_extmarks = vim.api.nvim_buf_get_extmarks(0, icon_ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = true }) + win_width = win_width - utils.extmarks_length(icon_extmarks) + if text_width < win_width then return end @@ -66,6 +72,7 @@ local function show() style = "minimal", border = "none" }) + vim.wo[M.popup_win].winhl = view.View.winopts.winhl local ns_id = vim.api.nvim_get_namespaces()["NvimTreeHighlights"] local extmarks = vim.api.nvim_buf_get_extmarks(0, ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = true }) @@ -88,7 +95,10 @@ local function show() end end end - vim.cmd([[ setlocal nowrap cursorline noswapfile nobuflisted buftype=nofile bufhidden=wipe ]]) + vim.cmd([[ setlocal nowrap noswapfile nobuflisted buftype=nofile bufhidden=wipe ]]) + if opts.view.cursorline then + vim.cmd([[ setlocal cursorline cursorlineopt=both ]]) + end end) end @@ -114,7 +124,7 @@ M.setup = function(opts) pattern = { "NvimTree_*" }, callback = function() if utils.is_nvim_tree_buf(0) then - show() + show(opts) end end, }) diff --git a/lua/nvim-tree/utils.lua b/lua/nvim-tree/utils.lua index d1bf6bb9a33..9396ba9d52f 100644 --- a/lua/nvim-tree/utils.lua +++ b/lua/nvim-tree/utils.lua @@ -172,6 +172,21 @@ function M.find_node_line(node) return -1 end +---@param extmarks vim.api.keyset.get_extmark_item[] as per vim.api.nvim_buf_get_extmarks +---@return number +function M.extmarks_length(extmarks) + local length = 0 + for _, extmark in ipairs(extmarks) do + local details = extmark[4] + if details and details.virt_text then + for _, text in ipairs(details.virt_text) do + length = length + vim.fn.strchars(text[1]) + end + end + end + return length +end + -- get the node in the tree state depending on the absolute path of the node -- (grouped or hidden too) ---@param path string diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 41b98873ee2..4ce95bfb6f4 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -329,14 +329,7 @@ local function grow() 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 + count = count + utils.extmarks_length(extmarks) if resizing_width < count then resizing_width = count end