Merge branch 'master' into master

This commit is contained in:
Alexander Courtis 2025-02-22 11:34:21 +11:00 committed by GitHub
commit 7108587882
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 132 additions and 15 deletions

View File

@ -2007,43 +2007,99 @@ fs.print_clipboard() *nvim-tree-api.fs.print_clipboard()*
Parameters: ~
• {node} (Node|nil) file or folder
node.open.edit({node}) *nvim-tree-api.node.open.edit()*
node.open.edit({node}, {opts}) *nvim-tree-api.node.open.edit()*
File: open as per |nvim-tree.actions.open_file|
Folder: expand or collapse
Root: change directory up
Parameters: ~
• {node} (Node|nil) file or folder
• {opts} (table) optional parameters
Options: ~
• {quit_on_open} (boolean) quits the tree when opening the file
• {focus} (boolean) keep focus in the tree when opening the file
*nvim-tree-api.node.open.replace_tree_buffer()*
node.open.replace_tree_buffer({node})
|nvim-tree-api.node.edit()|, file will be opened in place: in the
nvim-tree window.
*nvim-tree-api.node.open.no_window_picker()*
node.open.no_window_picker({node})
node.open.no_window_picker({node}, {opts})
|nvim-tree-api.node.edit()|, window picker will never be used as per
|nvim-tree.actions.open_file.window_picker.enable| `false`
node.open.vertical({node}) *nvim-tree-api.node.open.vertical()*
Parameters: ~
• {node} (Node|nil) file or folder
• {opts} (table) optional parameters
Options: ~
• {quit_on_open} (boolean) quits the tree when opening the file
• {focus} (boolean) keep focus in the tree when opening the file
node.open.vertical({node}, {opts}) *nvim-tree-api.node.open.vertical()*
|nvim-tree-api.node.edit()|, file will be opened in a new vertical split.
Parameters: ~
• {node} (Node|nil) file or folder
• {opts} (table) optional parameters
Options: ~
• {quit_on_open} (boolean) quits the tree when opening the file
• {focus} (boolean) keep focus in the tree when opening the file
*nvim-tree-api.node.open.vertical_no_picker()*
node.open.vertical_no_picker({node})
node.open.vertical_no_picker({node}, {opts})
|nvim-tree-api.node.vertical()|, window picker will never be used as per
|nvim-tree.actions.open_file.window_picker.enable| `false`
node.open.horizontal({node}) *nvim-tree-api.node.open.horizontal()*
Parameters: ~
• {node} (Node|nil) file or folder
• {opts} (table) optional parameters
Options: ~
• {quit_on_open} (boolean) quits the tree when opening the file
• {focus} (boolean) keep focus in the tree when opening the file
node.open.horizontal({node}, {opts}) *nvim-tree-api.node.open.horizontal()*
|nvim-tree-api.node.edit()|, file will be opened in a new horizontal split.
Parameters: ~
• {node} (Node|nil) file or folder
• {opts} (table) optional parameters
Options: ~
• {quit_on_open} (boolean) quits the tree when opening the file
• {focus} (boolean) keep focus in the tree when opening the file
*nvim-tree-api.node.open.horizontal_no_picker()*
node.open.horizontal_no_picker({node})
node.open.horizontal_no_picker({node}, {opts})
|nvim-tree-api.node.horizontal()|, window picker will never be used as per
|nvim-tree.actions.open_file.window_picker.enable| `false`
Parameters: ~
• {node} (Node|nil) file or folder
• {opts} (table) optional parameters
Options: ~
• {quit_on_open} (boolean) quits the tree when opening the file
• {focus} (boolean) keep focus in the tree when opening the file
*nvim-tree-api.node.open.toggle_group_empty()*
node.open.toggle_group_empty({node})
node.open.toggle_group_empty({node}, {opts})
Toggle |nvim-tree.renderer.group_empty| for a specific folder.
Does nothing on files.
Needs |nvim-tree.renderer.group_empty| set.
Parameters: ~
• {node} (Node|nil) file or folder
• {opts} (table) optional parameters
Options: ~
• {quit_on_open} (boolean) quits the tree when opening the file
• {focus} (boolean) keep focus in the tree when opening the file
node.open.drop({node}) *nvim-tree-api.node.open.drop()*
Switch to window with selected file if it exists.
Open file otherwise.
@ -2053,9 +2109,17 @@ node.open.drop({node}) *nvim-tree-api.node.open.drop()*
Folder: expand or collapse
Root: change directory up
node.open.tab({node}) *nvim-tree-api.node.open.tab()*
node.open.tab({node}, {opts}) *nvim-tree-api.node.open.tab()*
|nvim-tree-api.node.edit()|, file will be opened in a new tab.
Parameters: ~
• {node} (Node|nil) file or folder
• {opts} (table) optional parameters
Options: ~
• {quit_on_open} (boolean) quits the tree when opening the file
• {focus} (boolean) keep focus in the tree when opening the file
*nvim-tree-api.node.open.tab_drop()*
node.open.tab_drop({node})
Switch to tab containing window with selected file if it exists.
@ -2065,15 +2129,31 @@ node.open.tab_drop({node})
Folder: expand or collapse
Root: change directory up
node.open.preview({node}) *nvim-tree-api.node.open.preview()*
node.open.preview({node}, {opts}) *nvim-tree-api.node.open.preview()*
|nvim-tree-api.node.edit()|, file buffer will have |bufhidden| set to `delete`.
Parameters: ~
• {node} (Node|nil) file or folder
• {opts} (table) optional parameters
Options: ~
• {quit_on_open} (boolean) quits the tree when opening the file
• {focus} (boolean) keep focus in the tree when opening the file
*nvim-tree-api.node.open.preview_no_picker()*
node.open.preview_no_picker({node})
node.open.preview_no_picker({node}, {opts})
|nvim-tree-api.node.edit()|, file buffer will have |bufhidden| set to `delete`.
window picker will never be used as per
|nvim-tree.actions.open_file.window_picker.enable| `false`
Parameters: ~
• {node} (Node|nil) file or folder
• {opts} (table) optional parameters
Options: ~
• {quit_on_open} (boolean) quits the tree when opening the file
• {focus} (boolean) keep focus in the tree when opening the file
node.navigate.git.next({node}) *nvim-tree-api.node.navigate.git.next()*
Navigate to the next item showing git status.

View File

@ -80,6 +80,14 @@ local function pick_win_id()
local win_map = {}
local laststatus = vim.o.laststatus
vim.o.laststatus = 2
local fillchars = vim.opt.fillchars:get()
local stl = fillchars.stl
local stlnc = fillchars.stlnc
fillchars.stl = nil
fillchars.stlnc = nil
vim.opt.fillchars = fillchars
fillchars.stl = stl
fillchars.stlnc = stlnc
local tabpage = vim.api.nvim_get_current_tabpage()
local win_ids = vim.api.nvim_tabpage_list_wins(tabpage)
@ -179,6 +187,7 @@ local function pick_win_id()
end
vim.o.laststatus = laststatus
vim.opt.fillchars = fillchars
if not vim.tbl_contains(vim.split(M.window_picker.chars, ""), resp) then
return

View File

@ -222,21 +222,46 @@ Api.fs.copy.absolute_path = wrap_node(wrap_explorer_member("clipboard", "copy_ab
Api.fs.copy.filename = wrap_node(wrap_explorer_member("clipboard", "copy_filename"))
Api.fs.copy.basename = wrap_node(wrap_explorer_member("clipboard", "copy_basename"))
Api.fs.copy.relative_path = wrap_node(wrap_explorer_member("clipboard", "copy_path"))
---
---@class NodeEditOpts
---@field quit_on_open boolean|nil default false
---@field focus boolean|nil default true
---@param mode string
---@param node Node
local function edit(mode, node)
---@param edit_opts NodeEditOpts?
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
local cur_tabpage = vim.api.nvim_get_current_tabpage()
actions.node.open_file.fn(mode, path)
edit_opts = edit_opts or {}
local mode_unsupported_quit_on_open = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
if not mode_unsupported_quit_on_open and edit_opts.quit_on_open then
view.close(cur_tabpage)
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
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
vim.cmd(":tabprev")
end
view.focus()
end
end
---@param mode string
---@param toggle_group boolean?
---@return fun(node: Node)
---@return fun(node: Node, edit_opts: NodeEditOpts?)
local function open_or_expand_or_dir_up(mode, toggle_group)
---@param node Node
return function(node)
---@param edit_opts NodeEditOpts?
return function(node, edit_opts)
local root = node:as(RootNode)
local dir = node:as(DirectoryNode)
@ -245,7 +270,7 @@ local function open_or_expand_or_dir_up(mode, toggle_group)
elseif dir then
dir:expand_or_collapse(toggle_group)
elseif not toggle_group then
edit(mode, node)
edit(mode, node, edit_opts)
end
end
end

View File

@ -270,9 +270,12 @@ function M.close_all_tabs()
end
end
function M.close()
---@param tabpage integer|nil
function M.close(tabpage)
if M.View.tab.sync.close then
M.close_all_tabs()
elseif tabpage then
close(tabpage)
else
M.close_this_tab_only()
end