Skip to content

Commit

Permalink
feat(open-file): Add new node selection action based on :drop command
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinell committed Apr 22, 2023
1 parent 967865c commit 6040689
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
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

0 comments on commit 6040689

Please sign in to comment.