feat(api): api.tree.open feature parity with api.tree.toggle (#1955)
This commit is contained in:
parent
f3b73725c5
commit
215b29bfad
@ -1256,6 +1256,8 @@ api.tree.open({opts}) *nvim-tree.api.tree.open()*
|
||||
Options: ~
|
||||
• {path} (string) root directory for the tree
|
||||
• {current_window} (boolean, false) open the tree in the current window
|
||||
• {find_file} (boolean, false) find the current buffer
|
||||
• {update_root} (boolean, false) see |nvim-tree.update_focused_file.update_root|
|
||||
|
||||
api.tree.toggle({opts}) *nvim-tree.api.tree.toggle()*
|
||||
Open or close the tree.
|
||||
@ -1266,9 +1268,9 @@ api.tree.toggle({opts}) *nvim-tree.api.tree.toggle()*
|
||||
Options: ~
|
||||
• {path} (string) root directory for the tree
|
||||
• {current_window} (boolean, false) open the tree in the current window
|
||||
• {focus} (boolean, true) focus the tree when opening
|
||||
• {find_file} (boolean, false) find the current buffer
|
||||
• {update_root} (boolean, false) see |nvim-tree.update_focused_file.update_root|
|
||||
• {focus} (boolean, true) focus the tree when opening
|
||||
|
||||
api.tree.close() *nvim-tree.api.tree.close()*
|
||||
Close the tree, affecting all tabs as per |nvim-tree.tab.sync.close|
|
||||
|
||||
@ -71,31 +71,6 @@ end
|
||||
---@deprecated
|
||||
M.on_keypress = require("nvim-tree.actions.dispatch").dispatch
|
||||
|
||||
---Open the tree, focusing if already open.
|
||||
---@param opts ApiTreeOpenOpts|nil|string
|
||||
function M.open(opts)
|
||||
-- legacy arguments
|
||||
if type(opts) == "string" then
|
||||
opts = {
|
||||
path = opts,
|
||||
}
|
||||
end
|
||||
|
||||
opts = opts or {}
|
||||
|
||||
-- sanitise path
|
||||
if type(opts.path) ~= "string" or vim.fn.isdirectory(opts.path) == 0 then
|
||||
opts.path = nil
|
||||
end
|
||||
|
||||
if view.is_visible() then
|
||||
lib.set_target_win()
|
||||
view.focus()
|
||||
else
|
||||
lib.open(opts)
|
||||
end
|
||||
end
|
||||
|
||||
function M.open_replacing_current_buffer(cwd)
|
||||
if view.is_visible() then
|
||||
return
|
||||
@ -180,6 +155,37 @@ function M.find_file(with_open, bufnr, bang)
|
||||
find_file(with_open, bufnr, bang)
|
||||
end
|
||||
|
||||
---Open the tree, focusing if already open.
|
||||
---@param opts ApiTreeOpenOpts|nil|string
|
||||
function M.open(opts)
|
||||
-- legacy arguments
|
||||
if type(opts) == "string" then
|
||||
opts = {
|
||||
path = opts,
|
||||
}
|
||||
end
|
||||
|
||||
opts = opts or {}
|
||||
|
||||
local previous_buf = vim.api.nvim_get_current_buf()
|
||||
|
||||
-- sanitise path
|
||||
if type(opts.path) ~= "string" or vim.fn.isdirectory(opts.path) == 0 then
|
||||
opts.path = nil
|
||||
end
|
||||
|
||||
if view.is_visible() then
|
||||
lib.set_target_win()
|
||||
view.focus()
|
||||
else
|
||||
lib.open(opts)
|
||||
end
|
||||
|
||||
if _config.update_focused_file.enable or opts.find_file then
|
||||
find_file(false, previous_buf, opts.update_root)
|
||||
end
|
||||
end
|
||||
|
||||
---Toggle the tree.
|
||||
---@param opts ApiTreeToggleOpts|nil|boolean
|
||||
function M.toggle(opts, no_focus, cwd, bang)
|
||||
|
||||
@ -19,15 +19,17 @@ end
|
||||
---@class ApiTreeOpenOpts
|
||||
---@field path string|nil path
|
||||
---@field current_window boolean|nil default false
|
||||
---@field find_file boolean|nil default false
|
||||
---@field update_root boolean|nil default false
|
||||
|
||||
Api.tree.open = require("nvim-tree").open
|
||||
|
||||
---@class ApiTreeToggleOpts
|
||||
---@field path string|nil
|
||||
---@field current_window boolean|nil default false
|
||||
---@field focus boolean|nil default true
|
||||
---@field find_file boolean|nil default false
|
||||
---@field update_root boolean|nil default false
|
||||
---@field focus boolean|nil default true
|
||||
|
||||
Api.tree.toggle = require("nvim-tree").toggle
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user