From 9c7f4bafdfb25da32978481639733707db7bdb9b Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Tue, 17 Jan 2023 19:59:08 +0000 Subject: 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. --- Userland/Applications/Assistant/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Userland/Applications') 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 #include #include +#include #include #include #include @@ -195,7 +196,7 @@ ErrorOr 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 serenity_main(Main::Arguments arguments) } db.search(text_box.text()); - }; + }, + 5); text_box.on_return_pressed = [&]() { if (!app_state.selected_index.has_value()) return; -- cgit v1.2.3