refactor(#2826): singleton View class, WIP

This commit is contained in:
Alexander Courtis 2025-04-20 13:57:12 +10:00
parent 9d3d0d220f
commit b95b873626
2 changed files with 7 additions and 9 deletions

View File

@ -1,4 +1,4 @@
---TODO #2826 wrap all the view methods in explorer -- TODO #2826 wrap all the view methods in explorer
local core = require("nvim-tree.core") local core = require("nvim-tree.core")
local view = require("nvim-tree.view") local view = require("nvim-tree.view")

View File

@ -16,13 +16,13 @@ local DEFAULT_MIN_WIDTH = 30
local DEFAULT_MAX_WIDTH = -1 local DEFAULT_MAX_WIDTH = -1
local DEFAULT_PADDING = 1 local DEFAULT_PADDING = 1
--TODO attempt to type the tables, at least the options ones -- TODO #2826 attempt to type the tables, at least the options ones
---@class (exact) View: Class ---@class (exact) View: Class
---@field live_filter table ---@field live_filter table
---@field side string ---@field side string
---@field float table ---@field float table
---TODO private below here ---TODO #2826 private below here
---@field explorer Explorer ---@field explorer Explorer
---@field adaptive_size boolean ---@field adaptive_size boolean
---@field centralize_selection boolean ---@field centralize_selection boolean
@ -42,6 +42,7 @@ local View = Class:extend()
---@class View ---@class View
---@overload fun(args: ViewArgs): View ---@overload fun(args: ViewArgs): View
--TODO #2826 exact
---@class (exact) ViewArgs ---@class (exact) ViewArgs
---@field explorer Explorer ---@field explorer Explorer
@ -114,7 +115,7 @@ local tabinitial = {
winnr = nil, winnr = nil,
} }
-- TODO member -- TODO #2826 member
local BUFNR_PER_TAB = {} local BUFNR_PER_TAB = {}
---@type { name: string, value: any }[] ---@type { name: string, value: any }[]
@ -683,11 +684,8 @@ function View:configure_width(width)
end end
function M.setup(opts) function M.setup(opts)
M.View = View({ -- TODO #2826 move this to explorer constructor
explorer = { M.View = View({ explorer = { opts = opts } }) ---@diagnostic disable-line: missing-fields
opts = opts
}
})
end end
return M return M