mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:47:34 +00:00
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:
parent
d9aa7eacc6
commit
9c7f4bafdf
1 changed files with 4 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue