* 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:
parent
bd54d1d33c
commit
cbc3165e08
@ -1,6 +1,7 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local utils = require("nvim-tree.utils")
|
local utils = require("nvim-tree.utils")
|
||||||
|
local view = require("nvim-tree.view")
|
||||||
|
|
||||||
local function hide(win)
|
local function hide(win)
|
||||||
if win then
|
if win then
|
||||||
@ -32,7 +33,7 @@ local function effective_win_width()
|
|||||||
return win_width - win_info[1].textoff
|
return win_width - win_info[1].textoff
|
||||||
end
|
end
|
||||||
|
|
||||||
local function show()
|
local function show(opts)
|
||||||
local line_nr = vim.api.nvim_win_get_cursor(0)[1]
|
local line_nr = vim.api.nvim_win_get_cursor(0)[1]
|
||||||
if vim.wo.wrap then
|
if vim.wo.wrap then
|
||||||
return
|
return
|
||||||
@ -52,6 +53,11 @@ local function show()
|
|||||||
local text_width = vim.fn.strdisplaywidth(vim.fn.substitute(line, "[^[:print:]]*$", "", "g"))
|
local text_width = vim.fn.strdisplaywidth(vim.fn.substitute(line, "[^[:print:]]*$", "", "g"))
|
||||||
local win_width = effective_win_width()
|
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
|
if text_width < win_width then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -66,6 +72,7 @@ local function show()
|
|||||||
style = "minimal",
|
style = "minimal",
|
||||||
border = "none"
|
border = "none"
|
||||||
})
|
})
|
||||||
|
vim.wo[M.popup_win].winhl = view.View.winopts.winhl
|
||||||
|
|
||||||
local ns_id = vim.api.nvim_get_namespaces()["NvimTreeHighlights"]
|
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 })
|
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
|
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)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -114,7 +124,7 @@ M.setup = function(opts)
|
|||||||
pattern = { "NvimTree_*" },
|
pattern = { "NvimTree_*" },
|
||||||
callback = function()
|
callback = function()
|
||||||
if utils.is_nvim_tree_buf(0) then
|
if utils.is_nvim_tree_buf(0) then
|
||||||
show()
|
show(opts)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -172,6 +172,21 @@ function M.find_node_line(node)
|
|||||||
return -1
|
return -1
|
||||||
end
|
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
|
-- get the node in the tree state depending on the absolute path of the node
|
||||||
-- (grouped or hidden too)
|
-- (grouped or hidden too)
|
||||||
---@param path string
|
---@param path string
|
||||||
|
|||||||
@ -329,14 +329,7 @@ local function grow()
|
|||||||
local count = vim.fn.strchars(l)
|
local count = vim.fn.strchars(l)
|
||||||
-- also add space for right-aligned icons
|
-- 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 })
|
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
|
count = count + utils.extmarks_length(extmarks)
|
||||||
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
|
|
||||||
if resizing_width < count then
|
if resizing_width < count then
|
||||||
resizing_width = count
|
resizing_width = count
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user