refactoring: move extmarks_length to utils.lua
This commit is contained in:
parent
29c88bbd6f
commit
6656d82d63
@ -56,7 +56,7 @@ local function show(opts)
|
||||
-- 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 })
|
||||
text_width = text_width + view.extmarks_length(icon_extmarks)
|
||||
text_width = text_width + utils.extmarks_length(icon_extmarks)
|
||||
|
||||
if text_width < win_width then
|
||||
return
|
||||
|
||||
@ -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
|
||||
|
||||
@ -302,21 +302,6 @@ function M.open(options)
|
||||
log.profile_end(profile)
|
||||
end
|
||||
|
||||
---@param extmarks table
|
||||
---@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
|
||||
|
||||
local function grow()
|
||||
local starts_at = M.is_root_folder_visible(require("nvim-tree.core").get_cwd()) and 1 or 0
|
||||
local lines = vim.api.nvim_buf_get_lines(M.get_bufnr(), starts_at, -1, false)
|
||||
@ -344,7 +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 })
|
||||
count = count + M.extmarks_length(extmarks)
|
||||
count = count + utils.extmarks_length(extmarks)
|
||||
if resizing_width < count then
|
||||
resizing_width = count
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user