fix(#2746): background and right aligned icons in floating windows (#3128)

* fix(#2746): fix cursorcolumn and right aligned icons in floating windows

* feat: remove right aligned icons from full name float, show float over right aligned icons

* refactoring: move `extmarks_length` to utils.lua

* fix: decrease `win_width` instead of increasing `text_width` when computing condition for full name float to show

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
Šimon Mandlík
2025-05-24 05:19:19 +02:00
committed by GitHub
parent bd54d1d33c
commit cbc3165e08
3 changed files with 29 additions and 11 deletions

View File

@@ -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,
})