Skip to content

Commit be8f0eb

Browse files
committed
refactor(#2875): multi instance renderer
1 parent 2dde0df commit be8f0eb

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

Diff for: lua/nvim-tree/renderer/init.lua

+15-15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ local namespace_highlights_id = vim.api.nvim_create_namespace "NvimTreeHighlight
1616
local namespace_extmarks_id = vim.api.nvim_create_namespace "NvimTreeExtmarks"
1717
local namespace_virtual_lines_id = vim.api.nvim_create_namespace "NvimTreeVirtualLines"
1818

19+
local function render_hl(bufnr, hl)
20+
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
21+
return
22+
end
23+
vim.api.nvim_buf_clear_namespace(bufnr, namespace_highlights_id, 0, -1)
24+
for _, data in ipairs(hl) do
25+
if type(data[1]) == "table" then
26+
for _, group in ipairs(data[1]) do
27+
vim.api.nvim_buf_add_highlight(bufnr, namespace_highlights_id, group, data[2], data[3], data[4])
28+
end
29+
end
30+
end
31+
end
32+
1933
---@param bufnr number
2034
---@param lines string[]
2135
---@param hl_args AddHighlightArgs[]
@@ -28,7 +42,7 @@ local function _draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
2842
end
2943

3044
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
31-
M.render_hl(bufnr, hl_args)
45+
render_hl(bufnr, hl_args)
3246

3347
if vim.fn.has "nvim-0.10" == 1 then
3448
vim.api.nvim_set_option_value("modifiable", false, { buf = bufnr })
@@ -62,20 +76,6 @@ local function _draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
6276
end
6377
end
6478

65-
function M.render_hl(bufnr, hl)
66-
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
67-
return
68-
end
69-
vim.api.nvim_buf_clear_namespace(bufnr, namespace_highlights_id, 0, -1)
70-
for _, data in ipairs(hl) do
71-
if type(data[1]) == "table" then
72-
for _, group in ipairs(data[1]) do
73-
vim.api.nvim_buf_add_highlight(bufnr, namespace_highlights_id, group, data[2], data[3], data[4])
74-
end
75-
end
76-
end
77-
end
78-
7979
function M.draw()
8080
local explorer = core.get_explorer()
8181

0 commit comments

Comments
 (0)