Skip to content

Commit 6656d82

Browse files
committed
refactoring: move extmarks_length to utils.lua
1 parent 29c88bb commit 6656d82

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

lua/nvim-tree/renderer/components/full-name.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ local function show(opts)
5656
-- windows width reduced by right aligned icons
5757
local icon_ns_id = vim.api.nvim_get_namespaces()["NvimTreeExtmarks"]
5858
local icon_extmarks = vim.api.nvim_buf_get_extmarks(0, icon_ns_id, { line_nr - 1, 0 }, { line_nr - 1, -1 }, { details = true })
59-
text_width = text_width + view.extmarks_length(icon_extmarks)
59+
text_width = text_width + utils.extmarks_length(icon_extmarks)
6060

6161
if text_width < win_width then
6262
return

lua/nvim-tree/utils.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,21 @@ function M.find_node_line(node)
172172
return -1
173173
end
174174

175+
---@param extmarks vim.api.keyset.get_extmark_item[] as per vim.api.nvim_buf_get_extmarks
176+
---@return number
177+
function M.extmarks_length(extmarks)
178+
local length = 0
179+
for _, extmark in ipairs(extmarks) do
180+
local details = extmark[4]
181+
if details and details.virt_text then
182+
for _, text in ipairs(details.virt_text) do
183+
length = length + vim.fn.strchars(text[1])
184+
end
185+
end
186+
end
187+
return length
188+
end
189+
175190
-- get the node in the tree state depending on the absolute path of the node
176191
-- (grouped or hidden too)
177192
---@param path string

lua/nvim-tree/view.lua

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -302,21 +302,6 @@ function M.open(options)
302302
log.profile_end(profile)
303303
end
304304

305-
---@param extmarks table
306-
---@return number
307-
function M.extmarks_length(extmarks)
308-
local length = 0
309-
for _, extmark in ipairs(extmarks) do
310-
local details = extmark[4]
311-
if details and details.virt_text then
312-
for _, text in ipairs(details.virt_text) do
313-
length = length + vim.fn.strchars(text[1])
314-
end
315-
end
316-
end
317-
return length
318-
end
319-
320305
local function grow()
321306
local starts_at = M.is_root_folder_visible(require("nvim-tree.core").get_cwd()) and 1 or 0
322307
local lines = vim.api.nvim_buf_get_lines(M.get_bufnr(), starts_at, -1, false)
@@ -344,7 +329,7 @@ local function grow()
344329
local count = vim.fn.strchars(l)
345330
-- also add space for right-aligned icons
346331
local extmarks = vim.api.nvim_buf_get_extmarks(M.get_bufnr(), ns_id, { line_nr, 0 }, { line_nr, -1 }, { details = true })
347-
count = count + M.extmarks_length(extmarks)
332+
count = count + utils.extmarks_length(extmarks)
348333
if resizing_width < count then
349334
resizing_width = count
350335
end

0 commit comments

Comments
 (0)