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.
This commit is contained in:
Tim Ledbetter 2023-01-17 19:59:08 +00:00 committed by Jelle Raaijmakers
parent d9aa7eacc6
commit 9c7f4bafdf
Notes: sideshowbarker 2024-07-17 01:35:42 +09:00

View file

@ -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;