Console: Include aliases in tab completion

This commit is contained in:
Jonathan G Rennison
2021-04-25 02:22:25 +01:00
parent 253772e9af
commit a1c735999c

View File

@@ -534,13 +534,10 @@ static void IConsoleTabCompletion()
char *b = buffer; char *b = buffer;
uint matches = 0; uint matches = 0;
std::string common_prefix; std::string common_prefix;
for (auto &it : IConsole::Commands()) { auto check_candidate = [&](const std::string &cmd_name_str) {
const char *cmd_name = it.first.c_str(); const char *cmd_name = cmd_name_str.c_str();
const IConsoleCmd *cmd = &it.second;
if (strncmp(cmd_name, prefix.c_str(), prefix_length) == 0) {
if ((_settings_client.gui.console_show_unlisted || !cmd->unlisted) && (cmd->hook == nullptr || cmd->hook(false) != CHR_HIDE)) {
if (matches == 0) { if (matches == 0) {
common_prefix = it.first; common_prefix = cmd_name_str;
} else { } else {
const char *cp = common_prefix.c_str(); const char *cp = common_prefix.c_str();
const char *cmdp = cmd_name; const char *cmdp = cmd_name;
@@ -556,9 +553,22 @@ static void IConsoleTabCompletion()
} }
matches++; matches++;
b += seprintf(b, lastof(buffer), "%s ", cmd_name); b += seprintf(b, lastof(buffer), "%s ", cmd_name);
};
for (auto &it : IConsole::Commands()) {
const char *cmd_name = it.first.c_str();
const IConsoleCmd *cmd = &it.second;
if (strncmp(cmd_name, prefix.c_str(), prefix_length) == 0) {
if ((_settings_client.gui.console_show_unlisted || !cmd->unlisted) && (cmd->hook == nullptr || cmd->hook(false) != CHR_HIDE)) {
check_candidate(it.first);
} }
} }
} }
for (auto &it : IConsole::Aliases()) {
const char *cmd_name = it.first.c_str();
if (strncmp(cmd_name, prefix.c_str(), prefix_length) == 0) {
check_candidate(it.first);
}
}
if (matches > 0) { if (matches > 0) {
_iconsole_cmdline.Assign(common_prefix.c_str()); _iconsole_cmdline.Assign(common_prefix.c_str());
if (matches > 1) { if (matches > 1) {