From a1baa5cb0084d15aeaee11021b0fc374d46025dc Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Sun, 5 Mar 2023 15:00:54 +0000 Subject: [PATCH] CharacterMap: Make the search happen as you type --- .../CharacterMap/CharacterSearchWidget.cpp | 5 ++--- .../CharacterMap/CharacterSearchWidget.h | 3 +-- .../CharacterMap/CharacterSearchWindow.gml | 16 ++-------------- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/Userland/Applications/CharacterMap/CharacterSearchWidget.cpp b/Userland/Applications/CharacterMap/CharacterSearchWidget.cpp index 29e8736563..35803cf1d5 100644 --- a/Userland/Applications/CharacterMap/CharacterSearchWidget.cpp +++ b/Userland/Applications/CharacterMap/CharacterSearchWidget.cpp @@ -8,6 +8,7 @@ #include "CharacterSearchWidget.h" #include "SearchCharacters.h" #include +#include struct SearchResult { u32 code_point; @@ -56,14 +57,12 @@ CharacterSearchWidget::CharacterSearchWidget() load_from_gml(character_search_window_gml).release_value_but_fixme_should_propagate_errors(); m_search_input = find_descendant_of_type_named("search_input"); - m_search_button = find_descendant_of_type_named("search_button"); m_results_table = find_descendant_of_type_named("results_table"); m_search_input->on_up_pressed = [this] { m_results_table->move_cursor(GUI::AbstractView::CursorMovement::Up, GUI::AbstractView::SelectionUpdate::Set); }; m_search_input->on_down_pressed = [this] { m_results_table->move_cursor(GUI::AbstractView::CursorMovement::Down, GUI::AbstractView::SelectionUpdate::Set); }; - m_search_input->on_return_pressed = [this] { search(); }; - m_search_button->on_click = [this](auto) { search(); }; + m_search_input->on_change = Core::debounce([this] { search(); }, 100); m_results_table->horizontal_scrollbar().set_visible(false); m_results_table->set_column_headers_visible(false); diff --git a/Userland/Applications/CharacterMap/CharacterSearchWidget.h b/Userland/Applications/CharacterMap/CharacterSearchWidget.h index ca0fcce39a..e3745ab1a5 100644 --- a/Userland/Applications/CharacterMap/CharacterSearchWidget.h +++ b/Userland/Applications/CharacterMap/CharacterSearchWidget.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Sam Atkins + * Copyright (c) 2022-2023, Sam Atkins * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause @@ -26,6 +26,5 @@ private: void search(); RefPtr m_search_input; - RefPtr m_search_button; RefPtr m_results_table; }; diff --git a/Userland/Applications/CharacterMap/CharacterSearchWindow.gml b/Userland/Applications/CharacterMap/CharacterSearchWindow.gml index 6ac9bf4f5a..a6815e3b5f 100644 --- a/Userland/Applications/CharacterMap/CharacterSearchWindow.gml +++ b/Userland/Applications/CharacterMap/CharacterSearchWindow.gml @@ -4,20 +4,8 @@ } fill_with_background_color: true - @GUI::Widget { - layout: @GUI::HorizontalBoxLayout {} - preferred_height: "fit" - - @GUI::TextBox { - name: "search_input" - } - - @GUI::Button { - name: "search_button" - icon: "/res/icons/16x16/find.png" - button_style: "Coolbar" - fixed_width: 22 - } + @GUI::TextBox { + name: "search_input" } @GUI::TableView {