Fix T93519: handle prefix names in autocompletes

Autocomplete entires keep track of the length of the prefix
in `name_prefix_offset`. However, the name matching logic
was comparing the string including the prefix which resulted
in tab-completion not working (when the user didn't also type
in the prefix, typically two whitespaces).

This is fixed by passing in a char pointer after the end of
the prefix.

Additionally, some searchbox logic is moved. Previously,
`ui_searchbox_apply` would clear the entry which would mean
that `ui_searchbox_find_index` would never succeed. Now the
search box is only cleared if no match was found.

Differential Revision: https://developer.blender.org/D13483
This commit is contained in:
Azeem Bande-Ali 2021-12-09 11:09:50 +01:00 committed by Jacques Lucke
parent 65de17ece4
commit b8bad3549d
Notes: blender-bot 2023-02-14 07:45:38 +01:00
Referenced by issue #93519, Auto-complete not working for ID templates
2 changed files with 7 additions and 8 deletions

View File

@ -3551,6 +3551,12 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
if ((ui_searchbox_apply(but, data->searchbox) == false) &&
(ui_searchbox_find_index(data->searchbox, but->editstr) == -1) &&
!but_search->results_are_suggestions) {
if (but->flag & UI_BUT_VALUE_CLEAR) {
/* It is valid for _VALUE_CLEAR flavor to have no active element
* (it's a valid way to unlink). */
but->editstr[0] = '\0';
}
data->cancel = true;
/* ensure menu (popup) too is closed! */

View File

@ -115,7 +115,7 @@ bool UI_search_item_add(uiSearchItems *items,
{
/* hijack for autocomplete */
if (items->autocpl) {
UI_autocomplete_update_name(items->autocpl, name);
UI_autocomplete_update_name(items->autocpl, name + name_prefix_offset);
return true;
}
@ -313,13 +313,6 @@ bool ui_searchbox_apply(uiBut *but, ARegion *region)
return true;
}
if (but->flag & UI_BUT_VALUE_CLEAR) {
/* It is valid for _VALUE_CLEAR flavor to have no active element
* (it's a valid way to unlink). */
but->editstr[0] = '\0';
return true;
}
return false;
}