Skip to content

Commit

Permalink
feat(api): Add new node selection action based on tab :drop command (#…
Browse files Browse the repository at this point in the history
…2161)

Co-authored-by: gegoune <dev@clog.rocks>
  • Loading branch information
hinell and gegoune authored Apr 22, 2023
1 parent 967865c commit d68b00a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
11 changes: 11 additions & 0 deletions lua/nvim-tree/actions/node/open-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/nvim-tree/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d68b00a

Please sign in to comment.