Asset tags: include partial tag matches

When filtering the asset browser, also include results that have partial
tag matches. So searching for "xite" will include results tagged with
"excited".

This brings the tag filtering in line with other search boxes in
Blender. Later we might want to provide users with more options for
prefix-only ("excite" would match "excited", but "xited" would not) or
only exact matches.
This commit is contained in:
Sybren A. Stüvel 2021-11-18 16:20:21 +01:00
parent 0624acf088
commit 31afa1bb9a
1 changed files with 2 additions and 23 deletions

View File

@ -921,19 +921,6 @@ static void prepare_filter_asset_library(const FileList *filelist, FileListFilte
file_ensure_updated_catalog_filter_data(filter->asset_catalog_filter, filelist->asset_library);
}
/**
* Copy a string from source to `dest`, but prefix and suffix it with a single space.
* Assumes `dest` has at least space enough for the two spaces.
*/
static void tag_copy_with_spaces(char *dest, const char *source, const size_t dest_size)
{
BLI_assert(dest_size > 2);
const size_t source_length = BLI_strncpy_rlen(dest + 1, source, dest_size - 2);
dest[0] = ' ';
dest[source_length + 1] = ' ';
dest[source_length + 2] = '\0';
}
/**
* Return whether at least one tag matches the search filter.
* Tags are searched as "entire words", so instead of searching for "tag" in the
@ -949,9 +936,7 @@ static void tag_copy_with_spaces(char *dest, const char *source, const size_t de
static bool asset_tag_matches_filter(const char *filter_search, const AssetMetaData *asset_data)
{
LISTBASE_FOREACH (const AssetTag *, asset_tag, &asset_data->tags) {
char tag_name[MAX_NAME + 2]; /* sizeof(AssetTag::name) + 2 */
tag_copy_with_spaces(tag_name, asset_tag->name, sizeof(tag_name));
if (BLI_strcasestr(filter_search, tag_name) != NULL) {
if (BLI_strcasestr(asset_tag->name, filter_search) != NULL) {
return true;
}
}
@ -982,13 +967,7 @@ static bool is_filtered_asset(FileListInternEntry *file, FileListFilter *filter)
if (BLI_strcasestr(file->name, filter_search + 1) != NULL) {
return true;
}
/* Replace the asterisks with spaces, so that we can do matching on " sometag "; that way
* an artist searching for "redder" doesn't result in a match for the tag "red". */
filter_search[string_length - 1] = ' ';
filter_search[0] = ' ';
return asset_tag_matches_filter(filter_search, asset_data);
return asset_tag_matches_filter(filter_search + 1, asset_data);
}
static bool is_filtered_lib_type(FileListInternEntry *file,