summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorTim Ledbetter <timledbetter@gmail.com>2023-01-17 19:59:08 +0000
committerJelle Raaijmakers <jelle@gmta.nl>2023-01-17 21:52:21 +0100
commit9c7f4bafdfb25da32978481639733707db7bdb9b (patch)
treed6838b982ac57a5b04f9070d15d804652a6158b5 /Userland/Applications
parentd9aa7eacc6b566412598ccf32d432037b4b8a434 (diff)
downloadserenity-9c7f4bafdfb25da32978481639733707db7bdb9b.zip
Assistant: Debounce text input on_change event
This prevents unnecessary queries being executed when pasting text or typing very quickly. The debounce timeout is 5ms, which is half the rate at which the UI is updated. Therefore, there should be no noticable impact on user experience.
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/Assistant/main.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/Userland/Applications/Assistant/main.cpp b/Userland/Applications/Assistant/main.cpp
index d2b4ea61ab..028893d0a1 100644
--- a/Userland/Applications/Assistant/main.cpp
+++ b/Userland/Applications/Assistant/main.cpp
@@ -12,6 +12,7 @@
#include <AK/LexicalPath.h>
#include <AK/QuickSort.h>
#include <AK/Try.h>
+#include <LibCore/Debounce.h>
#include <LibCore/LockFile.h>
#include <LibCore/System.h>
#include <LibDesktop/Launcher.h>
@@ -195,7 +196,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
};
- text_box.on_change = [&]() {
+ text_box.on_change = Core::debounce([&]() {
{
Threading::MutexLocker locker(app_state.lock);
if (app_state.last_query == text_box.text())
@@ -205,7 +206,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
db.search(text_box.text());
- };
+ },
+ 5);
text_box.on_return_pressed = [&]() {
if (!app_state.selected_index.has_value())
return;