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()*
1698
1698
Return: ~
1699
1699
(boolean) nvim-tree is visible
1700
1700
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
+
1701
1713
==============================================================================
1702
1714
6.2 API FILE SYSTEM *nvim-tree-api.fs*
1703
1715
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)
145
145
146
146
Api .tree .is_visible = wrap (require (" nvim-tree.view" ).is_visible )
147
147
148
+ --- @class ApiTreeWinIdOpts
149
+ --- @field tabpage number | nil default nil
150
+
151
+ Api .tree .winid = wrap (require (" nvim-tree.view" ).winid )
152
+
148
153
Api .fs .create = wrap_node_or_nil (require (" nvim-tree.actions.fs.create-file" ).fn )
149
154
Api .fs .remove = wrap_node (require (" nvim-tree.actions.fs.remove-file" ).fn )
150
155
Api .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)
427
427
vim .api .nvim_set_current_win (wnr )
428
428
end
429
429
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
+
430
445
--- Restores the state of a NvimTree window if it was initialized before.
431
446
function M .restore_tab_state ()
432
447
local tabpage = vim .api .nvim_get_current_tabpage ()
You can’t perform that action at this time.
0 commit comments