refactor(#2826): View is an Explorer member
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
|
||||
local M = {}
|
||||
@@ -41,11 +40,12 @@ function M.fn(opts)
|
||||
return
|
||||
end
|
||||
|
||||
if view.View:is_visible() then
|
||||
local explorer = core.get_explorer()
|
||||
if explorer and explorer.view:is_visible() then
|
||||
-- focus
|
||||
if opts.focus then
|
||||
lib.set_target_win()
|
||||
view.View:focus()
|
||||
explorer.view:focus()
|
||||
end
|
||||
elseif opts.open then
|
||||
-- open
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
|
||||
local M = {}
|
||||
@@ -23,10 +23,12 @@ function M.fn(opts)
|
||||
opts.path = nil
|
||||
end
|
||||
|
||||
if view.View:is_visible() then
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
if explorer and explorer.view:is_visible() then
|
||||
-- focus
|
||||
lib.set_target_win()
|
||||
view.View:focus()
|
||||
explorer.view:focus()
|
||||
else
|
||||
-- open
|
||||
lib.open({
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
local view = require("nvim-tree.view")
|
||||
local core = require("nvim-tree.core")
|
||||
|
||||
local M = {}
|
||||
|
||||
---Resize the tree, persisting the new size.
|
||||
---@param opts ApiTreeResizeOpts|nil
|
||||
function M.fn(opts)
|
||||
local explorer = core.get_explorer()
|
||||
if not explorer then
|
||||
return
|
||||
end
|
||||
|
||||
if opts == nil then
|
||||
-- reset to config values
|
||||
view.View:configure_width()
|
||||
view.View:resize()
|
||||
explorer.view:configure_width()
|
||||
explorer.view:resize()
|
||||
return
|
||||
end
|
||||
|
||||
@@ -16,19 +21,19 @@ function M.fn(opts)
|
||||
local width_cfg = options.width
|
||||
|
||||
if width_cfg ~= nil then
|
||||
view.View:configure_width(width_cfg)
|
||||
view.View:resize()
|
||||
explorer.view:configure_width(width_cfg)
|
||||
explorer.view:resize()
|
||||
return
|
||||
end
|
||||
|
||||
if not view.View:is_width_determined() then
|
||||
if not explorer.view:is_width_determined() then
|
||||
-- {absolute} and {relative} do nothing when {width} is a function.
|
||||
return
|
||||
end
|
||||
|
||||
local absolute = options.absolute
|
||||
if type(absolute) == "number" then
|
||||
view.View:resize(absolute)
|
||||
explorer.view:resize(absolute)
|
||||
return
|
||||
end
|
||||
|
||||
@@ -39,7 +44,7 @@ function M.fn(opts)
|
||||
relative_size = "+" .. relative_size
|
||||
end
|
||||
|
||||
view.View:resize(relative_size)
|
||||
explorer.view:resize(relative_size)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local core = require("nvim-tree.core")
|
||||
local lib = require("nvim-tree.lib")
|
||||
local view = require("nvim-tree.view")
|
||||
local finders_find_file = require("nvim-tree.actions.finders.find-file")
|
||||
|
||||
local M = {}
|
||||
@@ -10,6 +10,8 @@ local M = {}
|
||||
---@param cwd boolean|nil legacy -> opts.path
|
||||
---@param bang boolean|nil legacy -> opts.update_root
|
||||
function M.fn(opts, no_focus, cwd, bang)
|
||||
local explorer = core.get_explorer()
|
||||
|
||||
-- legacy arguments
|
||||
if type(opts) == "boolean" then
|
||||
opts = {
|
||||
@@ -40,9 +42,9 @@ function M.fn(opts, no_focus, cwd, bang)
|
||||
opts.path = nil
|
||||
end
|
||||
|
||||
if view.View:is_visible() then
|
||||
if explorer and explorer.view:is_visible() then
|
||||
-- close
|
||||
view.View:close()
|
||||
explorer.view:close()
|
||||
else
|
||||
-- open
|
||||
lib.open({
|
||||
|
||||
Reference in New Issue
Block a user