File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -1698,6 +1698,18 @@ tree.is_visible({opts}) *nvim-tree-api.tree.is_visible()*
16981698 Return: ~
16991699 (boolean) nvim-tree is visible
17001700
1701+ tree.winid({opts} ) *nvim-tree-api.tree.winid()*
1702+ Retrieve the winid of the open tree.
1703+
1704+ Parameters: ~
1705+ • {opts} (table) optional parameters
1706+
1707+ Options: ~
1708+ • {tabpage} (number|nil) tabpage, 0 or nil for current, default nil
1709+
1710+ Return: ~
1711+ (number) winid or nil if tree is not visible
1712+
17011713==============================================================================
17021714 6.2 API FILE SYSTEM *nvim-tree-api.fs*
17031715
Original file line number Diff line number Diff line change @@ -145,6 +145,11 @@ Api.tree.is_tree_buf = wrap(require("nvim-tree.utils").is_nvim_tree_buf)
145145
146146Api .tree .is_visible = wrap (require (" nvim-tree.view" ).is_visible )
147147
148+ --- @class ApiTreeWinIdOpts
149+ --- @field tabpage number | nil default nil
150+
151+ Api .tree .winid = wrap (require (" nvim-tree.view" ).winid )
152+
148153Api .fs .create = wrap_node_or_nil (require (" nvim-tree.actions.fs.create-file" ).fn )
149154Api .fs .remove = wrap_node (require (" nvim-tree.actions.fs.remove-file" ).fn )
150155Api .fs .trash = wrap_node (require (" nvim-tree.actions.fs.trash" ).fn )
Original file line number Diff line number Diff line change @@ -427,6 +427,21 @@ function M.focus(winnr, open_if_closed)
427427 vim .api .nvim_set_current_win (wnr )
428428end
429429
430+ --- Retrieve the winid of the open tree.
431+ --- @param opts ApiTreeWinIdOpts | nil
432+ --- @return number | nil winid unlike get_winnr (), this returns nil if the nvim-tree window is not visible
433+ function M .winid (opts )
434+ local tabpage = opts and opts .tabpage
435+ if tabpage == 0 then
436+ tabpage = vim .api .nvim_get_current_tabpage ()
437+ end
438+ if M .is_visible { tabpage = tabpage } then
439+ return M .get_winnr (tabpage )
440+ else
441+ return nil
442+ end
443+ end
444+
430445--- Restores the state of a NvimTree window if it was initialized before.
431446function M .restore_tab_state ()
432447 local tabpage = vim .api .nvim_get_current_tabpage ()
You can’t perform that action at this time.
0 commit comments