diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 7c29ef58c0c..d3deb629f93 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1546,6 +1546,15 @@ node.open.horizontal() *nvim-tree-api.node.open.horizontal()* node.open.tab() *nvim-tree-api.node.open.tab()* |nvim-tree-api.node.edit()|, file will be opened in a new tab. + *nvim-tree-api.node.open.tab_drop()* +node.open.tab_drop() + Switch to tab containing window with selected file if it exists. + Open file in new tab otherwise. + + File: open file using `tab :drop` + Folder: expand or collapse + Root: change directory up + node.open.preview() *nvim-tree-api.node.open.preview()* |nvim-tree-api.node.edit()|, file buffer will have |bufhidden| set to `delete`. diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 41302d92f54..00908576aca 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -148,6 +148,13 @@ local function open_file_in_tab(filename) vim.cmd("tabe " .. vim.fn.fnameescape(filename)) end +local function tab_drop(filename) + if M.quit_on_open then + view.close() + end + vim.cmd("tab :drop " .. vim.fn.fnameescape(filename)) +end + local function on_preview(buf_loaded) if not buf_loaded then vim.bo.bufhidden = "delete" @@ -284,6 +291,10 @@ function M.fn(mode, filename) return open_file_in_tab(filename) end + if mode == "tab_drop" then + return tab_drop(filename) + end + if mode == "edit_in_place" then return edit_in_current_buf(filename) end diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index 49dc05c13cf..a4614eee5d0 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -162,6 +162,7 @@ local function open_preview(node) end Api.node.open.edit = wrap_node(open_or_expand_or_dir_up "edit") +Api.node.open.tab_drop = wrap_node(open_or_expand_or_dir_up "tab_drop") Api.node.open.replace_tree_buffer = wrap_node(open_or_expand_or_dir_up "edit_in_place") Api.node.open.no_window_picker = wrap_node(open_or_expand_or_dir_up "edit_no_picker") Api.node.open.vertical = wrap_node(open_or_expand_or_dir_up "vsplit")