feat: add winid parameter for api.tree.open, toggle, find_file (#2213)
* feat: add winid parameter for api.tree.open, toggle, find_file * feat: add winid parameter for api.tree.open, toggle, find_file
This commit is contained in:
committed by
GitHub
parent
736c7ff590
commit
b1e074d2b5
@@ -48,7 +48,7 @@ function M.fn(opts)
|
||||
end
|
||||
elseif opts.open then
|
||||
-- open
|
||||
lib.open { current_window = opts.current_window }
|
||||
lib.open { current_window = opts.current_window, winid = opts.winid }
|
||||
if not opts.focus then
|
||||
vim.cmd "noautocmd wincmd p"
|
||||
end
|
||||
|
||||
@@ -29,7 +29,7 @@ function M.fn(opts)
|
||||
view.focus()
|
||||
else
|
||||
-- open
|
||||
lib.open { path = opts.path, current_window = opts.current_window }
|
||||
lib.open { path = opts.path, current_window = opts.current_window, winid = opts.winid }
|
||||
end
|
||||
|
||||
-- find file
|
||||
|
||||
@@ -45,7 +45,7 @@ function M.fn(opts, no_focus, cwd, bang)
|
||||
view.close()
|
||||
else
|
||||
-- open
|
||||
lib.open { path = opts.path, current_window = opts.current_window }
|
||||
lib.open { path = opts.path, current_window = opts.current_window, winid = opts.winid }
|
||||
|
||||
-- find file
|
||||
if M.config.update_focused_file.enable or opts.find_file then
|
||||
|
||||
@@ -36,6 +36,7 @@ end
|
||||
---@class ApiTreeOpenOpts
|
||||
---@field path string|nil path
|
||||
---@field current_window boolean|nil default false
|
||||
---@field winid number|nil
|
||||
---@field find_file boolean|nil default false
|
||||
---@field update_root boolean|nil default false
|
||||
|
||||
@@ -44,6 +45,7 @@ Api.tree.open = wrap(require("nvim-tree.actions.tree.open").fn)
|
||||
---@class ApiTreeToggleOpts
|
||||
---@field path string|nil
|
||||
---@field current_window boolean|nil default false
|
||||
---@field winid number|nil
|
||||
---@field find_file boolean|nil default false
|
||||
---@field update_root boolean|nil default false
|
||||
---@field focus boolean|nil default true
|
||||
@@ -84,6 +86,7 @@ Api.tree.get_nodes = wrap(require("nvim-tree.lib").get_nodes)
|
||||
---@field buf string|number|nil
|
||||
---@field open boolean|nil default false
|
||||
---@field current_window boolean|nil default false
|
||||
---@field winid number|nil
|
||||
---@field update_root boolean|nil default false
|
||||
---@field focus boolean|nil default false
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ local events = require "nvim-tree.events"
|
||||
---@class LibOpenOpts
|
||||
---@field path string|nil path
|
||||
---@field current_window boolean|nil default false
|
||||
---@field winid number|nil
|
||||
|
||||
local M = {
|
||||
target_winid = nil,
|
||||
@@ -163,10 +164,13 @@ function M.open(opts)
|
||||
end
|
||||
if should_hijack_current_buf() then
|
||||
view.close_this_tab_only()
|
||||
view.open_in_current_win()
|
||||
view.open_in_win()
|
||||
renderer.draw()
|
||||
elseif opts.winid then
|
||||
view.open_in_win { hijack_current_buf = false, resize = false, winid = opts.winid }
|
||||
renderer.draw()
|
||||
elseif opts.current_window then
|
||||
view.open_in_current_win { hijack_current_buf = false, resize = false }
|
||||
view.open_in_win { hijack_current_buf = false, resize = false }
|
||||
renderer.draw()
|
||||
else
|
||||
open_view_and_draw()
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
local M = {}
|
||||
|
||||
local events = require "nvim-tree.events"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local log = require "nvim-tree.log"
|
||||
|
||||
---@class OpenInWinOpts
|
||||
---@field hijack_current_buf boolean|nil default true
|
||||
---@field resize boolean|nil default true
|
||||
---@field winid number|nil 0 or nil for current
|
||||
|
||||
local M = {}
|
||||
|
||||
local DEFAULT_MIN_WIDTH = 30
|
||||
local DEFAULT_MAX_WIDTH = -1
|
||||
local DEFAULT_PADDING = 1
|
||||
@@ -340,8 +345,13 @@ local function set_current_win()
|
||||
M.View.tabpages[current_tab].winnr = vim.api.nvim_get_current_win()
|
||||
end
|
||||
|
||||
function M.open_in_current_win(opts)
|
||||
---Open the tree in the a window
|
||||
---@param opts OpenInWinOpts|nil
|
||||
function M.open_in_win(opts)
|
||||
opts = opts or { hijack_current_buf = true, resize = true }
|
||||
if opts.winid and vim.api.nvim_win_is_valid(opts.winid) then
|
||||
vim.api.nvim_set_current_win(opts.winid)
|
||||
end
|
||||
create_buffer(opts.hijack_current_buf and vim.api.nvim_get_current_buf())
|
||||
setup_tabpage(vim.api.nvim_get_current_tabpage())
|
||||
set_current_win()
|
||||
|
||||
Reference in New Issue
Block a user