Skip to content

Commit 0155ee2

Browse files
committed
Changed command suggestions / autocomplete to also work with aliases.
1 parent 504327f commit 0155ee2

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
- Changed command suggestions / autocomplete to also work with aliases.
89

910
## [0.1.9-alpha] - 2021-08-05
1011
- Added events for when the console is enabled/disabled, opened/closed and focused/unfocused.

Runtime/DevConsoleMono.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,18 +2045,34 @@ private void RefreshCommandSuggestions()
20452045
private string[] GetCommandSuggestions(string text)
20462046
{
20472047
// Get a list of command names that could fill in the missing text
2048+
// Store alias suggestions separately and add on end later (so the result contains real commands before aliases)
20482049
List<string> suggestions = new List<string>();
2050+
List<string> aliasSuggestions = new List<string>();
20492051
string textToLower = text.ToLower();
2050-
foreach (string commandName in _commands.Keys)
2052+
2053+
foreach (Command command in _commands.Values)
20512054
{
2052-
if (!commandName.StartsWith(textToLower))
2055+
// Check if the command name matches the text
2056+
if (command.Name.StartsWith(textToLower))
20532057
{
2054-
continue;
2058+
// Combine current input with suggestion so capitalisation remains
2059+
// Add to suggestions list
2060+
suggestions.Add(text + command.Name.Substring(text.Length));
20552061
}
20562062

2057-
// Combine current input with suggestion so capitalisation remains
2058-
suggestions.Add(text + commandName.Substring(text.Length));
2063+
// Iterate over the command aliases
2064+
foreach (string alias in command.Aliases)
2065+
{
2066+
// Check if this command alias matches the text
2067+
if (alias.StartsWith(textToLower))
2068+
{
2069+
// Combine current input with suggestion so capitalisation remains
2070+
// Add to alias suggestions list
2071+
aliasSuggestions.Add(text + alias.Substring(text.Length));
2072+
}
2073+
}
20592074
}
2075+
suggestions.AddRange(aliasSuggestions);
20602076
return suggestions.ToArray();
20612077
}
20622078

0 commit comments

Comments
 (0)