mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +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
Notes:
sideshowbarker
2024-07-17 01:35:42 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/9c7f4bafdf Pull-request: https://github.com/SerenityOS/serenity/pull/17065 Reviewed-by: https://github.com/gmta ✅
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…
Reference in a new issue