diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-11-18 18:20:21 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-11-18 18:21:00 +0300 |
commit | 31afa1bb9abf6adcfcb0efc0e227076fa47d92ba (patch) | |
tree | 48a6ee7123564e9c59223a229c49cfc6c0e8e1ff /source/blender | |
parent | 0624acf0884e2998449e39f3774aadc962484203 (diff) |
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.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_file/filelist.c | 25 |
1 files changed, 2 insertions, 23 deletions
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index e6575316aec..481f1f8e240 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -922,19 +922,6 @@ static void prepare_filter_asset_library(const FileList *filelist, FileListFilte } /** - * 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 * filter string, this function searches for " tag ". Assumes the search filter @@ -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, |