@@ -121,6 +121,45 @@ local function wrap_explorer_member(explorer_member, member_method)
121121 end )
122122end
123123
124+ ---
125+ --- @class NodeEditOpts
126+ --- @field quit_on_open boolean | nil default false
127+ --- @field focus boolean | nil default true
128+
129+ --- @param mode string
130+ --- @param node Node
131+ --- @param edit_opts NodeEditOpts ?
132+ local function edit (mode , node , edit_opts )
133+ local file_link = node :as (FileLinkNode )
134+ local path = file_link and file_link .link_to or node .absolute_path
135+ local cur_tabpage = vim .api .nvim_get_current_tabpage ()
136+
137+ local explorer = core .get_explorer ()
138+
139+ actions .node .open_file .fn (mode , path )
140+
141+ edit_opts = edit_opts or {}
142+
143+ local mode_unsupported_quit_on_open = mode == " drop" or mode == " tab_drop" or mode == " edit_in_place"
144+ if not mode_unsupported_quit_on_open and edit_opts .quit_on_open then
145+ if explorer then
146+ explorer .view :close (cur_tabpage , " api.edit " .. mode )
147+ end
148+ end
149+
150+ local mode_unsupported_focus = mode == " drop" or mode == " tab_drop" or mode == " edit_in_place"
151+ local focus = edit_opts .focus == nil or edit_opts .focus == true
152+ if not mode_unsupported_focus and not focus then
153+ -- if mode == "tabnew" a new tab will be opened and we need to focus back to the previous tab
154+ if mode == " tabnew" then
155+ vim .cmd (" :tabprev" )
156+ end
157+ if explorer then
158+ explorer .view :focus ()
159+ end
160+ end
161+ end
162+
124163--- @class ApiTreeOpenOpts
125164--- @field path string | nil path
126165--- @field current_window boolean | nil default false
@@ -186,7 +225,25 @@ Api.tree.search_node = wrap(actions.finders.search_node.fn)
186225--- @field keep_buffers boolean | nil default false
187226
188227Api .tree .collapse_all = wrap (actions .tree .modifiers .collapse .all )
228+
229+ --- @class ApiTreeExpandAllOpts
230+ --- @field descend_until (fun ( expansion_count : integer , node : Node ): boolean )| nil
231+
189232Api .tree .expand_all = wrap_node (actions .tree .modifiers .expand .all )
233+
234+ Api .tree .toggle_descend_until = wrap_node (function (node , descend_until )
235+ if node .open then
236+ local dir = node :as (DirectoryNode )
237+ dir :expand_or_collapse (" edit" )
238+ else
239+ if node .nodes then
240+ actions .tree .modifiers .expand .all (node , { descend_until = descend_until })
241+ else
242+ edit (" edit" , node )
243+ end
244+ end
245+ end )
246+
190247Api .tree .toggle_enable_filters = wrap_explorer_member (" filters" , " toggle" )
191248Api .tree .toggle_gitignore_filter = wrap_explorer_member_args (" filters" , " toggle" , " git_ignored" )
192249Api .tree .toggle_git_clean_filter = wrap_explorer_member_args (" filters" , " toggle" , " git_clean" )
@@ -225,44 +282,6 @@ Api.fs.copy.absolute_path = wrap_node(wrap_explorer_member("clipboard", "copy_ab
225282Api .fs .copy .filename = wrap_node (wrap_explorer_member (" clipboard" , " copy_filename" ))
226283Api .fs .copy .basename = wrap_node (wrap_explorer_member (" clipboard" , " copy_basename" ))
227284Api .fs .copy .relative_path = wrap_node (wrap_explorer_member (" clipboard" , " copy_path" ))
228- ---
229- --- @class NodeEditOpts
230- --- @field quit_on_open boolean | nil default false
231- --- @field focus boolean | nil default true
232-
233- --- @param mode string
234- --- @param node Node
235- --- @param edit_opts NodeEditOpts ?
236- local function edit (mode , node , edit_opts )
237- local file_link = node :as (FileLinkNode )
238- local path = file_link and file_link .link_to or node .absolute_path
239- local cur_tabpage = vim .api .nvim_get_current_tabpage ()
240-
241- local explorer = core .get_explorer ()
242-
243- actions .node .open_file .fn (mode , path )
244-
245- edit_opts = edit_opts or {}
246-
247- local mode_unsupported_quit_on_open = mode == " drop" or mode == " tab_drop" or mode == " edit_in_place"
248- if not mode_unsupported_quit_on_open and edit_opts .quit_on_open then
249- if explorer then
250- explorer .view :close (cur_tabpage , " api.edit " .. mode )
251- end
252- end
253-
254- local mode_unsupported_focus = mode == " drop" or mode == " tab_drop" or mode == " edit_in_place"
255- local focus = edit_opts .focus == nil or edit_opts .focus == true
256- if not mode_unsupported_focus and not focus then
257- -- if mode == "tabnew" a new tab will be opened and we need to focus back to the previous tab
258- if mode == " tabnew" then
259- vim .cmd (" :tabprev" )
260- end
261- if explorer then
262- explorer .view :focus ()
263- end
264- end
265- end
266285
267286--- @param mode string
268287--- @param toggle_group boolean ?
0 commit comments