From f381c73a21d3095e64657fab4fe02aa4ac320a14 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Sat, 19 Mar 2022 09:23:05 -0700 Subject: Fix T95257: Filter files on "name" and "relpath" When filtering File Browser items by name, use entry's "name" field as well as the "relpath" field since they can vary. See D13940 for details. Differential Revision: https://developer.blender.org/D13940 Reviewed by Bastien Montagne --- source/blender/editors/space_file/filelist.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'source/blender/editors/space_file/filelist.c') diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 363e19a8905..180e30a11d4 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -851,6 +851,20 @@ static bool is_filtered_file_relpath(const FileListInternEntry *file, const File return fnmatch(filter->filter_search, file->relpath, FNM_CASEFOLD) == 0; } +/** + * Apply the filter string as matching pattern on file name. + * \return true when the file should be in the result set, false if it should be filtered out. + */ +static bool is_filtered_file_name(const FileListInternEntry *file, const FileListFilter *filter) +{ + if (filter->filter_search[0] == '\0') { + return true; + } + + /* If there's a filter string, apply it as filter even if FLF_DO_FILTER is not set. */ + return fnmatch(filter->filter_search, file->name, FNM_CASEFOLD) == 0; +} + /** \return true when the file should be in the result set, false if it should be filtered out. */ static bool is_filtered_file_type(const FileListInternEntry *file, const FileListFilter *filter) { @@ -890,7 +904,8 @@ static bool is_filtered_file(FileListInternEntry *file, const char *UNUSED(root), FileListFilter *filter) { - return is_filtered_file_type(file, filter) && is_filtered_file_relpath(file, filter); + return is_filtered_file_type(file, filter) && + (is_filtered_file_relpath(file, filter) || is_filtered_file_name(file, filter)); } static bool is_filtered_id_file_type(const FileListInternEntry *file, -- cgit v1.2.3