@@ -181,19 +181,10 @@ local open_with_cmd = function(state, open_cmd, toggle_directory)
181181 return
182182 end
183183
184- local function open ()
185- local path = node :get_id ()
186- utils .open_file (state , path , open_cmd )
187- end
188-
189- if utils .is_expandable (node ) then
190- if toggle_directory and node .type == " directory" then
184+ if node .type == " directory" then
185+ if toggle_directory then
191186 toggle_directory (node )
192187 elseif node :has_children () then
193- if node :is_expanded () and node .type == " file" then
194- return open ()
195- end
196-
197188 local updated = false
198189 if node :is_expanded () then
199190 updated = node :collapse ()
@@ -205,7 +196,8 @@ local open_with_cmd = function(state, open_cmd, toggle_directory)
205196 end
206197 end
207198 else
208- open ()
199+ local path = node :get_id ()
200+ utils .open_file (state , path , open_cmd )
209201 end
210202end
211203
@@ -240,10 +232,10 @@ M.rename = function(state, callback)
240232end
241233
242234--- Expands or collapses the current node.
243- M .toggle_directory = function (state )
235+ M .toggle_node = function (state )
244236 local tree = state .tree
245237 local node = tree :get_node ()
246- if node . type ~= " directory " then
238+ if not utils . is_expandable ( node ) then
247239 return
248240 end
249241 if node .loaded == false then
@@ -263,4 +255,14 @@ M.toggle_directory = function(state)
263255 end
264256end
265257
258+ --- Expands or collapses the current node.
259+ M .toggle_directory = function (state )
260+ local tree = state .tree
261+ local node = tree :get_node ()
262+ if node .type ~= " directory" then
263+ return
264+ end
265+ M .toggle_node (state )
266+ end
267+
266268return M
0 commit comments