From dc75f16221c9f03403a0692b36ec127d7cf650ab Mon Sep 17 00:00:00 2001 From: Jabber Developer Date: Thu, 30 Apr 2026 22:51:07 +0000 Subject: [PATCH] fix(ai): move generic subcommand autocomplete outside nested conditionals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The generic `/ai ` tab-completion was nested inside conditional blocks that prevented it from firing in common cases — for example, `/ai` or `/ai ` 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 ` 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. --- src/command/cmd_ac.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 21887004..5c3b7486 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -4454,12 +4454,6 @@ _ai_autocomplete(ProfWin* window, const char* const input, gboolean previous) /* Top-level /ai autocomplete (e.g., /ai s -> /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 - autocomplete subcommands - result = autocomplete_param_with_ac(input, "/ai set", ai_set_subcommands_ac, TRUE, previous); - if (result) { - return result; - } + } + // /ai set - 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;