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:
parent
b8bd667782
commit
9e323241f8
Notes:
sideshowbarker
2024-07-17 11:39:18 +09:00
Author: https://github.com/faxe1008
Commit: 9e323241f8
Pull-request: https://github.com/SerenityOS/serenity/pull/13709
Reviewed-by: https://github.com/linusg ✅
1 changed files with 7 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue