1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:37:44 +00:00

LibGUI: Allow FilteringProxyModel to optionally sort results by score

When the `FilteringOptions::SortByScore` flag is set, filtered indices
are sorted by match score in descending order, meaning the most
relevant results should appear first.

The default behavior of FilteringProxyModel is unchanged.
This commit is contained in:
Tim Ledbetter 2023-04-26 17:23:08 +01:00 committed by Andrew Kaster
parent a042c4e93d
commit 556c4ac358
15 changed files with 89 additions and 51 deletions

View file

@ -135,16 +135,17 @@ public:
VERIFY_NOT_REACHED();
}
virtual TriState data_matches(GUI::ModelIndex const& index, GUI::Variant const& term) const override
virtual GUI::Model::MatchResult data_matches(GUI::ModelIndex const& index, GUI::Variant const& term) const override
{
auto needle = term.as_string();
if (needle.is_empty())
return TriState::True;
return { TriState::True };
auto haystack = DeprecatedString::formatted("{} {}", menu_name(index), action_text(index));
if (fuzzy_match(needle, haystack).score > 0)
return TriState::True;
return TriState::False;
auto match_result = fuzzy_match(needle, haystack);
if (match_result.score > 0)
return { TriState::True, match_result.score };
return { TriState::False };
}
static DeprecatedString action_text(ModelIndex const& index)