Skip to content

Commit 671eedf

Browse files
committed
feat: add quit_on_open opt to api.node.open.edit
1 parent fee1da8 commit 671eedf

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lua/nvim-tree/api.lua

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,29 @@ Api.fs.copy.absolute_path = wrap_node(wrap_explorer_member("clipboard", "copy_ab
222222
Api.fs.copy.filename = wrap_node(wrap_explorer_member("clipboard", "copy_filename"))
223223
Api.fs.copy.basename = wrap_node(wrap_explorer_member("clipboard", "copy_basename"))
224224
Api.fs.copy.relative_path = wrap_node(wrap_explorer_member("clipboard", "copy_path"))
225+
---
226+
---@class NodeEditOpts
227+
---@field quit_on_open boolean|nil default false
225228

226229
---@param mode string
227230
---@param node Node
228-
local function edit(mode, node)
231+
---@param edit_opts NodeEditOpts?
232+
local function edit(mode, node, edit_opts)
229233
local file_link = node:as(FileLinkNode)
230234
local path = file_link and file_link.link_to or node.absolute_path
231235
actions.node.open_file.fn(mode, path)
236+
237+
if edit_opts and edit_opts.quit_on_open then
238+
view.close()
239+
end
232240
end
233241

234242
---@param mode string
235243
---@param toggle_group boolean?
236-
---@return fun(node: Node)
244+
---@return fun(node: Node, edit_opts: NodeEditOpts?)
237245
local function open_or_expand_or_dir_up(mode, toggle_group)
238246
---@param node Node
239-
return function(node)
247+
return function(node, edit_opts)
240248
local root = node:as(RootNode)
241249
local dir = node:as(DirectoryNode)
242250

@@ -245,7 +253,7 @@ local function open_or_expand_or_dir_up(mode, toggle_group)
245253
elseif dir then
246254
dir:expand_or_collapse(toggle_group)
247255
elseif not toggle_group then
248-
edit(mode, node)
256+
edit(mode, node, edit_opts)
249257
end
250258
end
251259
end

0 commit comments

Comments
 (0)