Skip to content
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
67 changes: 57 additions & 10 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2765,6 +2765,13 @@ navigate.sibling.prev({node})
Parameters: ~
• {node} (`nvim_tree.api.Node?`) directory or file

open.drop({node}) *nvim_tree.api.node.open.drop()*
Switch to window with selected file if it exists, otherwise open, see
|:drop|

Parameters: ~
• {node} (`nvim_tree.api.Node?`) directory or file
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no quit_on_open and focus here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we had some logical or eventing problems with (tab_)drop and decided to exclude them.

#3054 (comment)


open.edit({node}, {opts}) *nvim_tree.api.node.open.edit()*
• file: open as per |nvim_tree.config.actions.open_file|
• directory: expand or collapse
Expand All @@ -2778,39 +2785,64 @@ open.edit({node}, {opts}) *nvim_tree.api.node.open.edit()*
• {focus}? (`boolean`, default: false) Keep focus in the tree
when opening the file.

open.horizontal({node}) *nvim_tree.api.node.open.horizontal()*
open.horizontal({node}, {opts}) *nvim_tree.api.node.open.horizontal()*
Open file in a new horizontal split.

Parameters: ~
• {node} (`nvim_tree.api.Node?`) file
• {opts} (`table?`) optional
• {quit_on_open}? (`boolean`, default: false) Quits the tree
when opening the file.
• {focus}? (`boolean`, default: false) Keep focus in the tree
when opening the file.

*nvim_tree.api.node.open.horizontal_no_picker()*
open.horizontal_no_picker({node})
open.horizontal_no_picker({node}, {opts})
Open file in a new horizontal split without using the window picker.

Parameters: ~
• {node} (`nvim_tree.api.Node?`) file
• {opts} (`table?`) optional
• {quit_on_open}? (`boolean`, default: false) Quits the tree
when opening the file.
• {focus}? (`boolean`, default: false) Keep focus in the tree
when opening the file.

*nvim_tree.api.node.open.no_window_picker()*
open.no_window_picker({node})
open.no_window_picker({node}, {opts})
Open file without using the window picker.

Parameters: ~
• {node} (`nvim_tree.api.Node?`) file
• {opts} (`table?`) optional
• {quit_on_open}? (`boolean`, default: false) Quits the tree
when opening the file.
• {focus}? (`boolean`, default: false) Keep focus in the tree
when opening the file.

open.preview({node}) *nvim_tree.api.node.open.preview()*
open.preview({node}, {opts}) *nvim_tree.api.node.open.preview()*
Open file with |'bufhidden'| set to `delete`.

Parameters: ~
• {node} (`nvim_tree.api.Node?`) directory or file
• {opts} (`table?`) optional
• {quit_on_open}? (`boolean`, default: false) Quits the tree
when opening the file.
• {focus}? (`boolean`, default: false) Keep focus in the tree
when opening the file.

*nvim_tree.api.node.open.preview_no_picker()*
open.preview_no_picker({node})
open.preview_no_picker({node}, {opts})
Open file with |'bufhidden'| set to `delete` without using the window
picker.

Parameters: ~
• {node} (`nvim_tree.api.Node?`) directory or file
• {opts} (`table?`) optional
• {quit_on_open}? (`boolean`, default: false) Quits the tree
when opening the file.
• {focus}? (`boolean`, default: false) Keep focus in the tree
when opening the file.

*nvim_tree.api.node.open.replace_tree_buffer()*
open.replace_tree_buffer({node})
Expand All @@ -2819,15 +2851,20 @@ open.replace_tree_buffer({node})
Parameters: ~
• {node} (`nvim_tree.api.Node?`) file

open.tab({node}) *nvim_tree.api.node.open.tab()*
open.tab({node}, {opts}) *nvim_tree.api.node.open.tab()*
Open file in a new tab.

Parameters: ~
• {node} (`nvim_tree.api.Node?`) directory or file
• {opts} (`table?`) optional
• {quit_on_open}? (`boolean`, default: false) Quits the tree
when opening the file.
• {focus}? (`boolean`, default: false) Keep focus in the tree
when opening the file.

open.tab_drop({node}) *nvim_tree.api.node.open.tab_drop()*
Switch to tab containing window with selected file if it exists. Open file
in new tab otherwise.
Switch to tab containing window with selected file if it exists, otherwise
open in new tab, see |:drop|

Parameters: ~
• {node} (`nvim_tree.api.Node?`) directory or file
Expand All @@ -2840,18 +2877,28 @@ open.toggle_group_empty({node})
Parameters: ~
• {node} (`nvim_tree.api.Node?`) directory

open.vertical({node}) *nvim_tree.api.node.open.vertical()*
open.vertical({node}, {opts}) *nvim_tree.api.node.open.vertical()*
Open file in a new vertical split.

Parameters: ~
• {node} (`nvim_tree.api.Node?`) file
• {opts} (`table?`) optional
• {quit_on_open}? (`boolean`, default: false) Quits the tree
when opening the file.
• {focus}? (`boolean`, default: false) Keep focus in the tree
when opening the file.

*nvim_tree.api.node.open.vertical_no_picker()*
open.vertical_no_picker({node})
open.vertical_no_picker({node}, {opts})
Open file in a new vertical split without using the window picker.

Parameters: ~
• {node} (`nvim_tree.api.Node?`) file
• {opts} (`table?`) optional
• {quit_on_open}? (`boolean`, default: false) Quits the tree
when opening the file.
• {focus}? (`boolean`, default: false) Keep focus in the tree
when opening the file.

run.cmd({node}) *nvim_tree.api.node.run.cmd()*
Enter |cmdline| with the full path of the node and the cursor at the start
Expand Down
32 changes: 23 additions & 9 deletions lua/nvim-tree/_meta/api/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ nvim_tree.api.node.open = {}
---@field focus? boolean


---
---Switch to window with selected file if it exists, otherwise open, see [:drop]
---
---@param node? nvim_tree.api.Node directory or file
function nvim_tree.api.node.open.drop(node) end

---
---- file: open as per [nvim_tree.config.actions.open_file]
---- directory: expand or collapse
Expand All @@ -29,31 +35,36 @@ function nvim_tree.api.node.open.edit(node, opts) end
---Open file in a new horizontal split.
---
---@param node? nvim_tree.api.Node file
function nvim_tree.api.node.open.horizontal(node) end
---@param opts? nvim_tree.api.node.open.Opts optional
function nvim_tree.api.node.open.horizontal(node, opts) end

---
---Open file in a new horizontal split without using the window picker.
---
---@param node? nvim_tree.api.Node file
function nvim_tree.api.node.open.horizontal_no_picker(node) end
---@param opts? nvim_tree.api.node.open.Opts optional
function nvim_tree.api.node.open.horizontal_no_picker(node, opts) end

---
---Open file without using the window picker.
---
---@param node? nvim_tree.api.Node file
function nvim_tree.api.node.open.no_window_picker(node) end
---@param opts? nvim_tree.api.node.open.Opts optional
function nvim_tree.api.node.open.no_window_picker(node, opts) end

---
---Open file with ['bufhidden'] set to `delete`.
---
---@param node? nvim_tree.api.Node directory or file
function nvim_tree.api.node.open.preview(node) end
---@param opts? nvim_tree.api.node.open.Opts optional
function nvim_tree.api.node.open.preview(node, opts) end

---
---Open file with ['bufhidden'] set to `delete` without using the window picker.
---
---@param node? nvim_tree.api.Node directory or file
function nvim_tree.api.node.open.preview_no_picker(node) end
---@param opts? nvim_tree.api.node.open.Opts optional
function nvim_tree.api.node.open.preview_no_picker(node, opts) end

---
---Open file in place: in the nvim-tree window.
Expand All @@ -65,10 +76,11 @@ function nvim_tree.api.node.open.replace_tree_buffer(node) end
---Open file in a new tab.
---
---@param node? nvim_tree.api.Node directory or file
function nvim_tree.api.node.open.tab(node) end
---@param opts? nvim_tree.api.node.open.Opts optional
function nvim_tree.api.node.open.tab(node, opts) end

---
---Switch to tab containing window with selected file if it exists. Open file in new tab otherwise.
---Switch to tab containing window with selected file if it exists, otherwise open in new tab, see [:drop]
---
---@param node? nvim_tree.api.Node directory or file
function nvim_tree.api.node.open.tab_drop(node) end
Expand All @@ -83,13 +95,15 @@ function nvim_tree.api.node.open.toggle_group_empty(node) end
---Open file in a new vertical split.
---
---@param node? nvim_tree.api.Node file
function nvim_tree.api.node.open.vertical(node) end
---@param opts? nvim_tree.api.node.open.Opts optional
function nvim_tree.api.node.open.vertical(node, opts) end

---
---Open file in a new vertical split without using the window picker.
---
---@param node? nvim_tree.api.Node file
function nvim_tree.api.node.open.vertical_no_picker(node) end
---@param opts? nvim_tree.api.node.open.Opts optional
function nvim_tree.api.node.open.vertical_no_picker(node, opts) end

---
---@class nvim_tree.api.node.buffer.RemoveOpts
Expand Down
55 changes: 30 additions & 25 deletions lua/nvim-tree/actions/node/open-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ local DirectoryNode = require("nvim-tree.node.directory")
local FileLinkNode = require("nvim-tree.node.file-link")
local RootNode = require("nvim-tree.node.root")

---@class NodeEditOpts
---@field quit_on_open boolean|nil default false
---@field focus boolean|nil default true

---@alias NodeOpenFileMode ""|"change_dir"|"drop"|"edit"|"edit_in_place"|"edit_no_picker"|"preview"|"preview_no_picker"|"split"|"split_no_picker"|"tab_drop"|"tabnew"|"toggle_group_empty"|"vsplit"|"vsplit_no_picker"

local M = {}
Expand Down Expand Up @@ -416,7 +412,7 @@ end

---@param mode string
---@param node Node
---@param edit_opts NodeEditOpts?
---@param edit_opts nvim_tree.api.node.open.Opts?
local function edit(mode, node, edit_opts)
local file_link = node:as(FileLinkNode)
local path = file_link and file_link.link_to or node.absolute_path
Expand All @@ -432,7 +428,7 @@ local function edit(mode, node, edit_opts)
end

local mode_unsupported_focus = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
local focus = edit_opts.focus == nil or edit_opts.focus == true
local focus = edit_opts.focus == nil or edit_opts.focus == false
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was incorrect. Fixed to match doc.

if not mode_unsupported_focus and not focus then
-- if mode == "tabnew" a new tab will be opened and we need to focus back to the previous tab
if mode == "tabnew" then
Expand All @@ -445,7 +441,7 @@ end
---@param node Node
---@param mode NodeOpenFileMode
---@param toggle_group boolean?
---@param edit_opts NodeEditOpts?
---@param edit_opts nvim_tree.api.node.open.Opts?
local function open_or_expand_or_dir_up(node, mode, toggle_group, edit_opts)
local root = node:as(RootNode)
local dir = node:as(DirectoryNode)
Expand All @@ -468,18 +464,21 @@ function M.toggle_group_empty(node)
end

---@param node Node
function M.preview(node)
open_or_expand_or_dir_up(node, "preview")
---@param opts nvim_tree.api.node.open.Opts?
function M.preview(node, opts)
open_or_expand_or_dir_up(node, "preview", false, opts)
end

---@param node Node
function M.preview_no_picker(node)
open_or_expand_or_dir_up(node, "preview_no_picker")
---@param opts nvim_tree.api.node.open.Opts?
function M.preview_no_picker(node, opts)
open_or_expand_or_dir_up(node, "preview_no_picker", false, opts)
end

---@param node Node
function M.edit(node)
open_or_expand_or_dir_up(node, "edit")
---@param opts nvim_tree.api.node.open.Opts?
function M.edit(node, opts)
open_or_expand_or_dir_up(node, "edit", false, opts)
end

---@param node Node
Expand All @@ -498,33 +497,39 @@ function M.replace_tree_buffer(node)
end

---@param node Node
function M.no_window_picker(node)
open_or_expand_or_dir_up(node, "edit_no_picker")
---@param opts nvim_tree.api.node.open.Opts?
function M.no_window_picker(node, opts)
open_or_expand_or_dir_up(node, "edit_no_picker", false, opts)
end

---@param node Node
function M.vertical(node)
open_or_expand_or_dir_up(node, "vsplit")
---@param opts nvim_tree.api.node.open.Opts?
function M.vertical(node, opts)
open_or_expand_or_dir_up(node, "vsplit", false, opts)
end

---@param node Node
function M.vertical_no_picker(node)
open_or_expand_or_dir_up(node, "vsplit_no_picker")
---@param opts nvim_tree.api.node.open.Opts?
function M.vertical_no_picker(node, opts)
open_or_expand_or_dir_up(node, "vsplit_no_picker", false, opts)
end

---@param node Node
function M.horizontal(node)
open_or_expand_or_dir_up(node, "split")
---@param opts nvim_tree.api.node.open.Opts?
function M.horizontal(node, opts)
open_or_expand_or_dir_up(node, "split", false, opts)
end

---@param node Node
function M.horizontal_no_picker(node)
open_or_expand_or_dir_up(node, "split_no_picker")
---@param opts nvim_tree.api.node.open.Opts?
function M.horizontal_no_picker(node, opts)
open_or_expand_or_dir_up(node, "split_no_picker", false, opts)
end

---@param node Node
function M.tab(node)
open_or_expand_or_dir_up(node, "tabnew")
---@param opts nvim_tree.api.node.open.Opts?
function M.tab(node, opts)
open_or_expand_or_dir_up(node, "tabnew", false, opts)
end

return M
Loading
Loading