fix(ai): move generic subcommand autocomplete outside nested conditionals

The generic `/ai <subcommand>` tab-completion was nested inside conditional
blocks that prevented it from firing in common cases — for example,
`/ai<tab>` or `/ai <tab>` would never match subcommands because the
`autocomplete_param_with_ac()` call was guarded by argument count checks
and nested inside the explicit handler branches.

Move the fallback subcommand autocomplete to execute unconditionally after
all explicit handler branches, ensuring `/ai <tab>` always lists available
subcommands regardless of argument count or which subcommand was typed.

Also move the `/ai set` subcommand fallback outside the inner else-block
so it runs whenever args[0] is "set", not only when num_args >= 2.
This commit is contained in:
2026-04-30 22:51:07 +00:00
parent da0bf43d73
commit dc75f16221

View File

@@ -4454,12 +4454,6 @@ _ai_autocomplete(ProfWin* window, const char* const input, gboolean previous)
/* Top-level /ai <subcommand> autocomplete (e.g., /ai s<tab> -> /ai set) */
if (num_args >= 1) {
/* Try to match subcommand prefix first */
result = autocomplete_param_with_ac(input, "/ai", ai_subcommands_ac, FALSE, previous);
if (result) {
return result;
}
if (g_strcmp0(args[0], "set") == 0) {
if (num_args >= 2) {
if (g_strcmp0(args[1], "provider") == 0) {
@@ -4481,12 +4475,11 @@ _ai_autocomplete(ProfWin* window, const char* const input, gboolean previous)
return result;
}
}
} else {
// /ai set <subcommand> - autocomplete subcommands
result = autocomplete_param_with_ac(input, "/ai set", ai_set_subcommands_ac, TRUE, previous);
if (result) {
return result;
}
}
// /ai set <subcommand> - autocomplete subcommands
result = autocomplete_param_with_ac(input, "/ai set", ai_set_subcommands_ac, TRUE, previous);
if (result) {
return result;
}
} else if (g_strcmp0(args[0], "remove") == 0) {
if (num_args >= 2 && g_strcmp0(args[1], "provider") == 0) {
@@ -4524,6 +4517,11 @@ _ai_autocomplete(ProfWin* window, const char* const input, gboolean previous)
return NULL;
}
}
result = autocomplete_param_with_ac(input, "/ai", ai_subcommands_ac, FALSE, previous);
if (result) {
return result;
}
}
return result;