Skip to content

Commit 0df384b

Browse files
feat(api): add node.open.drop() (#2164)
Co-authored-by: Alexander Courtis <alex@courtis.org>
1 parent 9c60947 commit 0df384b

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

doc/nvim-tree-lua.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,15 @@ node.open.vertical() *nvim-tree-api.node.open.vertical()*
16081608
node.open.horizontal() *nvim-tree-api.node.open.horizontal()*
16091609
|nvim-tree-api.node.edit()|, file will be opened in a new horizontal split.
16101610

1611+
node.open.drop() *nvim-tree-api.node.open.drop()*
1612+
Switch to window with selected file if it exists.
1613+
Open file otherwise.
1614+
See: `:h :drop`.
1615+
1616+
File: open file using `:drop`
1617+
Folder: expand or collapse
1618+
Root: change directory up
1619+
16111620
node.open.tab() *nvim-tree-api.node.open.tab()*
16121621
|nvim-tree-api.node.edit()|, file will be opened in a new tab.
16131622

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ local function open_file_in_tab(filename)
160160
vim.cmd("tabe " .. vim.fn.fnameescape(filename))
161161
end
162162

163+
local function drop(filename)
164+
if M.quit_on_open then
165+
view.close()
166+
end
167+
vim.cmd("drop " .. vim.fn.fnameescape(filename))
168+
end
169+
163170
local function tab_drop(filename)
164171
if M.quit_on_open then
165172
view.close()
@@ -303,6 +310,10 @@ function M.fn(mode, filename)
303310
return open_file_in_tab(filename)
304311
end
305312

313+
if mode == "drop" then
314+
return drop(filename)
315+
end
316+
306317
if mode == "tab_drop" then
307318
return tab_drop(filename)
308319
end

lua/nvim-tree/api.lua

Lines changed: 1 addition & 0 deletions
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.drop = wrap_node(open_or_expand_or_dir_up "drop")
165166
Api.node.open.tab_drop = wrap_node(open_or_expand_or_dir_up "tab_drop")
166167
Api.node.open.replace_tree_buffer = wrap_node(open_or_expand_or_dir_up "edit_in_place")
167168
Api.node.open.no_window_picker = wrap_node(open_or_expand_or_dir_up "edit_no_picker")

0 commit comments

Comments
 (0)