Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): Add new node selection action based on tab :drop command #2161

Merged
merged 2 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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