Skip to content

Commit 383c8c8

Browse files
committed
feat(api): add node.open.drop()
1 parent 061a05b commit 383c8c8

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
@@ -1545,6 +1545,15 @@ node.open.vertical() *nvim-tree-api.node.open.vertical()*
15451545
node.open.horizontal() *nvim-tree-api.node.open.horizontal()*
15461546
|nvim-tree-api.node.edit()|, file will be opened in a new horizontal split.
15471547

1548+
node.open.drop() *nvim-tree-api.node.open.tab()*
1549+
Switch to window with selected file if it exists.
1550+
Open file in current window otherwise.
1551+
See: `:h :drop`.
1552+
1553+
File: open file using `:drop`
1554+
Folder: expand or collapse
1555+
Root: change directory up
1556+
15481557
node.open.tab() *nvim-tree-api.node.open.tab()*
15491558
|nvim-tree-api.node.edit()|, file will be opened in a new tab.
15501559

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

Lines changed: 11 additions & 0 deletions
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 drop(filename)
152+
if M.quit_on_open then
153+
view.close()
154+
end
155+
vim.cmd("drop " .. vim.fn.fnameescape(filename))
156+
end
157+
151158
local function tab_drop(filename)
152159
if M.quit_on_open then
153160
view.close()
@@ -291,6 +298,10 @@ function M.fn(mode, filename)
291298
return open_file_in_tab(filename)
292299
end
293300

301+
if mode == "drop" then
302+
return drop(filename)
303+
end
304+
294305
if mode == "tab_drop" then
295306
return tab_drop(filename)
296307
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)