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
This commit is contained in:
Harley Acheson 2022-03-19 09:23:05 -07:00
parent 82c852f387
commit f381c73a21
Notes: blender-bot 2023-02-14 05:50:03 +01:00
Referenced by issue #95257, Blender File View search behaves unpredictably when searching for fonts
1 changed files with 16 additions and 1 deletions

View File

@ -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,