@@ -11,6 +11,12 @@ local M = {
1111 complete_args = completion .complete_args ,
1212}
1313
14+ -- Store the last source used for `M.execute`
15+ M ._last = {
16+ source = nil ,
17+ position = nil ,
18+ }
19+
1420--- Executes a Neo-tree action from outside of a Neo-tree window,
1521--- such as show, hide, navigate, etc.
1622--- @param args table The action to execute. The table can have the following keys :
@@ -61,6 +67,23 @@ M.execute = function(args)
6167 -- The rest of the actions require a source
6268 args .source = args .source or nt .config .default_source
6369
70+ -- Handle source=last
71+ if args .source == " last" then
72+ args .source = M ._last .source or nt .config .default_source
73+
74+ -- Restore last position if it was not specified
75+ if args .position == nil then
76+ args .position = M ._last .position
77+ end
78+
79+ -- Prevent the default source from being set to "last"
80+ if args .source == " last" then
81+ args .source = nt .config .sources [1 ]
82+ end
83+ end
84+ M ._last .source = args .source
85+ M ._last .position = args .position
86+
6487 -- If position=current was requested, but we are currently in a neo-tree window,
6588 -- then we need to override that.
6689 if args .position == " current" and vim .bo .filetype == " neo-tree" then
0 commit comments