refactor(#2826): multi instance nvim-tree.view

This commit is contained in:
Mateusz Russak
2024-08-04 13:31:11 +02:00
parent 0f2cda6ce0
commit fa051cf990
22 changed files with 390 additions and 297 deletions

View File

@@ -1,7 +1,6 @@
local core = require "nvim-tree.core"
local notify = require "nvim-tree.notify"
local utils = require "nvim-tree.utils"
local view = require "nvim-tree.view"
local DecoratorBookmarks = require "nvim-tree.renderer.decorator.bookmarks"
local DecoratorCopied = require "nvim-tree.renderer.decorator.copied"
@@ -408,14 +407,17 @@ end
---@private
function Builder:build_header()
local explorer = core.get_explorer()
if view.is_root_folder_visible(core.get_cwd()) then
if not explorer then
return
end
if explorer.view:is_root_folder_visible(core.get_cwd()) then
local root_name = self:format_root_name(M.opts.renderer.root_folder_label)
table.insert(self.lines, root_name)
self:insert_highlight({ "NvimTreeRootFolder" }, 0, string.len(root_name))
self.index = 1
end
if explorer and explorer.live_filter.filter then
if explorer.live_filter.filter then
local filter_line = string.format("%s/%s/", M.opts.live_filter.prefix, explorer.live_filter.filter)
table.insert(self.lines, filter_line)
local prefix_length = string.len(M.opts.live_filter.prefix)

View File

@@ -1,6 +1,5 @@
local core = require "nvim-tree.core"
local log = require "nvim-tree.log"
local view = require "nvim-tree.view"
local events = require "nvim-tree.events"
local _padding = require "nvim-tree.renderer.components.padding"
@@ -67,14 +66,18 @@ function M.render_hl(bufnr, hl)
end
function M.draw()
local bufnr = view.get_bufnr()
if not core.get_explorer() or not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
local explorer = core.get_explorer()
if not explorer then
return
end
local bufnr = explorer.view:get_bufnr()
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
return
end
local profile = log.profile_start "draw"
local cursor = vim.api.nvim_win_get_cursor(view.get_winnr() or 0)
local cursor = vim.api.nvim_win_get_cursor(explorer.view:get_winnr() or 0)
icon_component.reset_config()
local builder = Builder:new():build()
@@ -82,14 +85,14 @@ function M.draw()
_draw(bufnr, builder.lines, builder.hl_args, builder.signs, builder.extmarks)
if cursor and #builder.lines >= cursor[1] then
vim.api.nvim_win_set_cursor(view.get_winnr() or 0, cursor)
vim.api.nvim_win_set_cursor(explorer.view:get_winnr() or 0, cursor)
end
view.grow_from_content()
explorer.view:grow_from_content()
log.profile_end(profile)
events._dispatch_on_tree_rendered(bufnr, view.get_winnr())
events._dispatch_on_tree_rendered(bufnr, explorer.view:get_winnr())
end
function M.setup(opts)