diff --git a/src/ai/ai_client.c b/src/ai/ai_client.c index 70dbfd03..88c340bd 100644 --- a/src/ai/ai_client.c +++ b/src/ai/ai_client.c @@ -395,22 +395,15 @@ ai_list_providers(void) * Provider autocomplete state * ======================================================================== */ -/* Stateful provider name finder with case-sensitive matching. - * Maintains position in sorted list for deterministic tab-completion cycling. - * The autocomplete is kept in sync via ai_add_provider/ai_remove_provider. */ gchar* ai_providers_find(const char* const search_str, gboolean previous, void* context) { - /* Initialize autocomplete on first use */ if (!providers_ac) { - providers_ac = autocomplete_new(); + log_debug("[AI-AC] Uninitialized call to ai_providers_find"); + return NULL; } - /* NULL search_str is treated as empty string for cycling */ - const char* effective_search = (search_str != NULL) ? search_str : ""; - - /* Use stateful autocomplete */ - return autocomplete_complete(providers_ac, effective_search, FALSE, previous); + return autocomplete_complete(providers_ac, search_str, FALSE, previous); } /* Stateful model name finder for autocomplete. @@ -444,6 +437,17 @@ ai_models_find(const char* const search_str, gboolean previous, void* context) return result; } +/* Reset the provider autocomplete state. + * Called from cmd_ac_reset() to clear autocomplete state when the user presses Ctrl+C. */ +void +ai_providers_reset_ac(void) +{ + if (!providers_ac) { + return; + } + autocomplete_reset(providers_ac); +} + gchar* ai_get_provider_key(const gchar* provider_name) { diff --git a/src/ai/ai_client.h b/src/ai/ai_client.h index afcfab10..97ea8a9b 100644 --- a/src/ai/ai_client.h +++ b/src/ai/ai_client.h @@ -115,6 +115,12 @@ gchar* ai_providers_find(const char* const search_str, gboolean previous, void* */ gchar* ai_models_find(const char* const search_str, gboolean previous, void* context); +/** + * Reset the provider autocomplete state. + * Called from cmd_ac_reset() to clear autocomplete state. + */ +void ai_providers_reset_ac(void); + /** * Get the API key for a provider. * @param provider_name The provider name diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 6160468b..f0806e41 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1697,6 +1697,7 @@ cmd_ac_reset(ProfWin* window) win_reset_search_attempts(); win_close_reset_search_attempts(); plugins_reset_autocomplete(); + ai_providers_reset_ac(); } void