1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00

LibGUI: Use fuzzy matching in CommandPalette

This patch changes the previously used contains method for matching the
user search term with all available commands to use the fuzzy match
algorithm, which makes it more typo tolerant.
This commit is contained in:
faxe1008 2022-04-16 22:02:10 +02:00 committed by Linus Groh
parent b8bd667782
commit 9e323241f8
Notes: sideshowbarker 2024-07-17 11:39:18 +09:00

View file

@ -6,6 +6,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/FuzzyMatch.h>
#include <AK/QuickSort.h>
#include <LibGUI/Action.h>
#include <LibGUI/ActionGroup.h>
@ -136,8 +137,12 @@ public:
virtual TriState data_matches(GUI::ModelIndex const& index, GUI::Variant const& term) const override
{
auto search = String::formatted("{} {}", menu_name(index), action_text(index));
if (search.contains(term.as_string(), CaseSensitivity::CaseInsensitive))
auto needle = term.as_string();
if (needle.is_empty())
return TriState::True;
auto haystack = String::formatted("{} {}", menu_name(index), action_text(index));
if (fuzzy_match(needle, haystack).score > 0)
return TriState::True;
return TriState::False;
}