Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ What to show. Can be one of:
| filesystem | Show a file browser. DEFAULT |
| buffers | Show a list of currently open buffers. |
| git_status | Show the output of `git status` in a tree layout. |
| last | Equivalent to the last source used |

#### `position`
Where to show it, can be one of:
Expand Down
23 changes: 23 additions & 0 deletions lua/neo-tree/command/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ local M = {
complete_args = completion.complete_args,
}

-- Store the last source used for `M.execute`
M._last = {
source = nil,
position = nil,
}

---Executes a Neo-tree action from outside of a Neo-tree window,
---such as show, hide, navigate, etc.
---@param args table The action to execute. The table can have the following keys:
Expand Down Expand Up @@ -61,6 +67,23 @@ M.execute = function(args)
-- The rest of the actions require a source
args.source = args.source or nt.config.default_source

-- Handle source=last
if args.source == "last" then
args.source = M._last.source or nt.config.default_source

-- Restore last position if it was not specified
if args.position == nil then
args.position = M._last.position
end

-- Prevent the default source from being set to "last"
if args.source == "last" then
args.source = nt.config.sources[1]
end
end
M._last.source = args.source
M._last.position = args.position

-- If position=current was requested, but we are currently in a neo-tree window,
-- then we need to override that.
if args.position == "current" and vim.bo.filetype == "neo-tree" then
Expand Down
3 changes: 3 additions & 0 deletions lua/neo-tree/command/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ M.setup = function(all_source_names)
local source_names = utils.table_copy(all_source_names)
table.insert(source_names, "migrations")

-- A special source referring to the last used source.
table.insert(source_names, "last")

-- For lists, the first value is the default value.
local arguments = {
action = {
Expand Down
2 changes: 1 addition & 1 deletion lua/neo-tree/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ local config = {
-- popup_border_style is for input and confirmation dialogs.
-- Configurtaion of floating window is done in the individual source sections.
-- "NC" is a special style that works well with NormalNC set
default_source = "filesystem",
default_source = "filesystem", -- you can choose a specific source `last` here which indicates the last used source
enable_diagnostics = true,
enable_git_status = true,
enable_modified_markers = true, -- Show markers for files with unsaved changes.
Expand Down
2 changes: 1 addition & 1 deletion lua/neo-tree/setup/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ M.merge_config = function(user_config, is_auto_config)
break
end
end
if not match then
if not match and M.config.default_source ~= "last" then
M.config.default_source = M.config.sources[1]
log.warn(string.format("Invalid default source found in configuration. Using first available source: %s", M.config.default_source))
end
Expand Down