Skip to content

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

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

Merged
merged 2 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,13 @@ node.open.edit() *nvim-tree-api.node.open.edit()*
Folder: expand or collapse
Root: change directory up

*nvim-tree-api.node.open.tab_drop()*
node.open.tab_drop()
Like edit(), but reuse already-opened window in tab. See also: |:drop|
File: open already-opened as per |nvim-tree.actions.open_file|
Folder: expand or collapse
Root: change directory up

*nvim-tree-api.node.open.replace_tree_buffer()*
node.open.replace_tree_buffer()
|nvim-tree-api.node.edit()|, file will be opened in place: in the
Expand Down
13 changes: 13 additions & 0 deletions lua/nvim-tree/actions/node/open-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,22 @@ local function pick_win_id()
return win_map[resp]
end


local function open_file_in_tab(filename)
if M.quit_on_open then
view.close()
end
vim.cmd("tabe " .. vim.fn.fnameescape(filename))
end

-- See :drop command. This will always focus already-opened tab
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 +293,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