summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-09-18 13:48:04 -0400
committerSam Atkins <atkinssj@gmail.com>2022-09-20 11:08:54 +0100
commita203e714ec9493935dfb03161fda33b04c4a5a0d (patch)
treeb84c0baf671947d875d0169d7457d61a39e7e3ff /Userland
parent11bd6c3d68f6fbe5ca538dc3d0b8224544bf3f9c (diff)
downloadserenity-a203e714ec9493935dfb03161fda33b04c4a5a0d.zip
LibGUI: Use fuzzy matching when searching for emoji by name
This allows the user to have slight typos in their search query.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/EmojiInputDialog.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGUI/EmojiInputDialog.cpp b/Userland/Libraries/LibGUI/EmojiInputDialog.cpp
index 95b96fc97f..85b4db6a60 100644
--- a/Userland/Libraries/LibGUI/EmojiInputDialog.cpp
+++ b/Userland/Libraries/LibGUI/EmojiInputDialog.cpp
@@ -5,6 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/FuzzyMatch.h>
#include <AK/LexicalPath.h>
#include <AK/QuickSort.h>
#include <AK/ScopeGuard.h>
@@ -221,6 +222,8 @@ void EmojiInputDialog::update_displayed_emoji()
size_t rows = ceil_div(m_emojis.size(), columns);
size_t index = 0;
+ auto query = m_search_box->text();
+
for (size_t row = 0; row < rows && index < m_emojis.size(); ++row) {
auto& horizontal_container = m_emojis_widget->add<Widget>();
horizontal_container.set_preferred_height(SpecialDimension::Fit);
@@ -237,10 +240,12 @@ void EmojiInputDialog::update_displayed_emoji()
if (m_selected_category.has_value() && emoji.emoji.group != m_selected_category)
continue;
- if (!emoji.emoji.name.is_empty())
- found_match = emoji.emoji.name.contains(m_search_box->text(), CaseSensitivity::CaseInsensitive);
- else
- found_match = m_search_box->text().is_empty();
+ if (query.is_empty()) {
+ found_match = true;
+ } else if (!emoji.emoji.name.is_empty()) {
+ auto result = fuzzy_match(query, emoji.emoji.name);
+ found_match = result.score > 0;
+ }
if (found_match)
horizontal_container.add_child(*emoji.button);