From 9e323241f87efe4fda81437c431bac64bc46f874 Mon Sep 17 00:00:00 2001 From: faxe1008 Date: Sat, 16 Apr 2022 22:02:10 +0200 Subject: [PATCH] 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. --- Userland/Libraries/LibGUI/CommandPalette.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGUI/CommandPalette.cpp b/Userland/Libraries/LibGUI/CommandPalette.cpp index 41e6e6908e..2f5a096c19 100644 --- a/Userland/Libraries/LibGUI/CommandPalette.cpp +++ b/Userland/Libraries/LibGUI/CommandPalette.cpp @@ -6,6 +6,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -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; }