mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-25 15:56:21 +00:00
fix(ai): reset provider autocomplete state on search string change
When typing /ai start <prefix><tab>, the autocomplete was not properly handling search string changes. For example, typing "/ai start o<tab>" would return "openai", but then typing "/ai start p<tab>" would still return "openai" because the autocomplete state was not reset. This commit: - Adds ai_providers_reset_ac() function to reset provider autocomplete state, following the same pattern as accounts_reset_all_search() - Integrates ai_providers_reset_ac() into cmd_ac_reset() for proper state cleanup when user presses Ctrl+C or switches contexts
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user