fix(ai): reset provider autocomplete state on search string change
Some checks failed
CI Code / Code Coverage (pull_request) Failing after 12m29s
CI Code / Check spelling (pull_request) Failing after 13m4s
CI Code / Check coding style (pull_request) Failing after 13m36s
CI Code / Linux (ubuntu) (pull_request) Failing after 14m13s
CI Code / Linux (debian) (pull_request) Failing after 14m48s
CI Code / Linux (arch) (pull_request) Failing after 15m25s
Some checks failed
CI Code / Code Coverage (pull_request) Failing after 12m29s
CI Code / Check spelling (pull_request) Failing after 13m4s
CI Code / Check coding style (pull_request) Failing after 13m36s
CI Code / Linux (ubuntu) (pull_request) Failing after 14m13s
CI Code / Linux (debian) (pull_request) Failing after 14m48s
CI Code / Linux (arch) (pull_request) Failing after 15m25s
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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user