Skip to content

Commit b2ba6de

Browse files
authored
feat: optional path argument for NvimTreeToggle and NvimTreeFindFileToggle (#1276)
1 parent 73ab312 commit b2ba6de

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

doc/nvim-tree-lua.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ closes the tree
3131

3232
|:NvimTreeToggle| *:NvimTreeToggle*
3333

34-
open or close the tree
34+
open or close the tree. Takes an optional path argument.
3535

3636
|:NvimTreeFocus| *:NvimTreeFocus*
3737

@@ -52,7 +52,8 @@ It will also open the leafs of the tree leading to the file in the buffer
5252
|:NvimTreeFindFileToggle| *:NvimTreeFindFileToggle*
5353

5454
close the tree or change the cursor in the tree for the current bufname,
55-
similar to combination of |:NvimTreeToggle| and |:NvimTreeFindFile|
55+
similar to combination of |:NvimTreeToggle| and |:NvimTreeFindFile|. Takes an
56+
optional path argument.
5657

5758
|:NvimTreeClipboard| *:NvimTreeClipboard*
5859

@@ -233,7 +234,7 @@ Will ignore the buffer, when deciding to open the tree on setup.
233234
Type: `boolean`, Default: `false`
234235

235236
*nvim-tree.ignore_ft_on_setup*
236-
List of filetypes that will make `open_on_setup` not open.
237+
List of filetypes that will make `open_on_setup` not open.
237238
You can use this option if you don't want the tree to open
238239
in some scenarios (eg using vim startify).
239240
Type: {string}, Default: {}
@@ -411,7 +412,7 @@ Window / buffer setup.
411412
Will use only the provided user mappings and not the default otherwise,
412413
extends the default mappings with the provided user mappings.
413414
Type: `boolean`, Default: `false`
414-
415+
415416
*nvim-tree.view.mappings.list*
416417
A list of keymaps that will extend or override the default keymaps.
417418
Type: list of { key: table of strings or string, mode: string (vim-mode), cb: callback function as a string }

lua/nvim-tree.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ end
2626
---@deprecated
2727
M.on_keypress = require("nvim-tree.actions").on_keypress
2828

29-
function M.toggle(find_file, no_focus)
29+
function M.toggle(find_file, no_focus, cwd)
3030
if view.is_visible() then
3131
view.close()
3232
else
3333
local previous_buf = api.nvim_get_current_buf()
34-
M.open()
34+
M.open(cwd)
3535
if _config.update_focused_file.enable or find_file then
3636
M.find_file(false, previous_buf)
3737
end
@@ -259,18 +259,18 @@ local function setup_vim_commands()
259259
M.open(res.args)
260260
end, { nargs = "?", complete = "dir" })
261261
api.nvim_create_user_command("NvimTreeClose", view.close, {})
262-
api.nvim_create_user_command("NvimTreeToggle", function()
263-
M.toggle(false)
264-
end, {})
262+
api.nvim_create_user_command("NvimTreeToggle", function(res)
263+
M.toggle(false, false, res.args)
264+
end, { nargs = "?", complete = "dir" })
265265
api.nvim_create_user_command("NvimTreeFocus", M.focus, {})
266266
api.nvim_create_user_command("NvimTreeRefresh", reloaders.reload_explorer, {})
267267
api.nvim_create_user_command("NvimTreeClipboard", copy_paste.print_clipboard, {})
268268
api.nvim_create_user_command("NvimTreeFindFile", function()
269269
M.find_file(true)
270270
end, {})
271-
api.nvim_create_user_command("NvimTreeFindFileToggle", function()
272-
M.toggle(true)
273-
end, {})
271+
api.nvim_create_user_command("NvimTreeFindFileToggle", function(res)
272+
M.toggle(true, false, res.args)
273+
end, { nargs = "?", complete = "dir" })
274274
api.nvim_create_user_command("NvimTreeResize", function(res)
275275
M.resize(res.args)
276276
end, { nargs = 1 })

0 commit comments

Comments
 (0)