Skip to content

Commit d68b00a

Browse files
hinellgegoune
hinell
andauthored
feat(api): Add new node selection action based on tab :drop command (#2161)
Co-authored-by: gegoune <[email protected]>
1 parent 967865c commit d68b00a

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

doc/nvim-tree-lua.txt

+9
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,15 @@ node.open.horizontal() *nvim-tree-api.node.open.horizontal()*
15461546
node.open.tab() *nvim-tree-api.node.open.tab()*
15471547
|nvim-tree-api.node.edit()|, file will be opened in a new tab.
15481548

1549+
*nvim-tree-api.node.open.tab_drop()*
1550+
node.open.tab_drop()
1551+
Switch to tab containing window with selected file if it exists.
1552+
Open file in new tab otherwise.
1553+
1554+
File: open file using `tab :drop`
1555+
Folder: expand or collapse
1556+
Root: change directory up
1557+
15491558
node.open.preview() *nvim-tree-api.node.open.preview()*
15501559
|nvim-tree-api.node.edit()|, file buffer will have |bufhidden| set to `delete`.
15511560

lua/nvim-tree/actions/node/open-file.lua

+11
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ local function open_file_in_tab(filename)
148148
vim.cmd("tabe " .. vim.fn.fnameescape(filename))
149149
end
150150

151+
local function tab_drop(filename)
152+
if M.quit_on_open then
153+
view.close()
154+
end
155+
vim.cmd("tab :drop " .. vim.fn.fnameescape(filename))
156+
end
157+
151158
local function on_preview(buf_loaded)
152159
if not buf_loaded then
153160
vim.bo.bufhidden = "delete"
@@ -284,6 +291,10 @@ function M.fn(mode, filename)
284291
return open_file_in_tab(filename)
285292
end
286293

294+
if mode == "tab_drop" then
295+
return tab_drop(filename)
296+
end
297+
287298
if mode == "edit_in_place" then
288299
return edit_in_current_buf(filename)
289300
end

lua/nvim-tree/api.lua

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ local function open_preview(node)
162162
end
163163

164164
Api.node.open.edit = wrap_node(open_or_expand_or_dir_up "edit")
165+
Api.node.open.tab_drop = wrap_node(open_or_expand_or_dir_up "tab_drop")
165166
Api.node.open.replace_tree_buffer = wrap_node(open_or_expand_or_dir_up "edit_in_place")
166167
Api.node.open.no_window_picker = wrap_node(open_or_expand_or_dir_up "edit_no_picker")
167168
Api.node.open.vertical = wrap_node(open_or_expand_or_dir_up "vsplit")

0 commit comments

Comments
 (0)