From 21ba9c808eb23f89282340ab0008c830ce96f5a2 Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Mon, 28 Feb 2022 11:25:43 -0500 Subject: [PATCH] Help: Improve search ergonomics Up and down arrows now select search results. Matching index now displays in full before filtering. Searching from the command line focuses the query, and searches are now case insensitive. --- Userland/Applications/Help/MainWidget.cpp | 25 +++++++++++----------- Userland/Applications/Help/MainWidget.h | 2 ++ Userland/Applications/Help/ManualModel.cpp | 4 ++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Userland/Applications/Help/MainWidget.cpp b/Userland/Applications/Help/MainWidget.cpp index d23f872111..a375a4c4e4 100644 --- a/Userland/Applications/Help/MainWidget.cpp +++ b/Userland/Applications/Help/MainWidget.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -44,11 +43,13 @@ MainWidget::MainWidget() m_search_box = find_descendant_of_type_named("search_box"); m_search_box->on_change = [this] { - if (auto* model = m_search_view->model()) { - auto& search_model = *static_cast(model); - search_model.set_filter_term(m_search_box->text()); - search_model.invalidate(); - } + m_filter_model->set_filter_term(m_search_box->text()); + }; + m_search_box->on_down_pressed = [this] { + m_search_view->move_cursor(GUI::AbstractView::CursorMovement::Down, GUI::AbstractView::SelectionUpdate::Set); + }; + m_search_box->on_up_pressed = [this] { + m_search_view->move_cursor(GUI::AbstractView::CursorMovement::Up, GUI::AbstractView::SelectionUpdate::Set); }; m_search_view = find_descendant_of_type_named("search_view"); @@ -212,11 +213,10 @@ void MainWidget::set_start_page(String const& start_page, int section) // No match, so treat the input as a search query if (!set_start_page) { m_tab_widget->set_active_widget(m_search_container); + m_search_box->set_focus(true); m_search_box->set_text(start_page); - if (auto* model = m_search_view->model(); model) { - auto& search_model = *static_cast(model); - search_model.set_filter_term(m_search_box->text()); - } + m_search_box->select_all(); + m_filter_model->set_filter_term(m_search_box->text()); } } } @@ -260,8 +260,9 @@ ErrorOr MainWidget::initialize_fallibles(GUI::Window& window) m_manual_model = TRY(ManualModel::create()); m_browse_view->set_model(*m_manual_model); - m_search_view->set_model(TRY(GUI::FilteringProxyModel::create(*m_manual_model))); - m_search_view->model()->invalidate(); + m_filter_model = TRY(GUI::FilteringProxyModel::create(*m_manual_model)); + m_search_view->set_model(*m_filter_model); + m_filter_model->set_filter_term(""); return {}; } diff --git a/Userland/Applications/Help/MainWidget.h b/Userland/Applications/Help/MainWidget.h index bab7bc6fbb..73573313ce 100644 --- a/Userland/Applications/Help/MainWidget.h +++ b/Userland/Applications/Help/MainWidget.h @@ -8,6 +8,7 @@ #include "History.h" #include "ManualModel.h" +#include #include namespace Help { @@ -31,6 +32,7 @@ private: History m_history; RefPtr m_context_menu; RefPtr m_manual_model; + RefPtr m_filter_model; RefPtr m_go_back_action; RefPtr m_go_forward_action; diff --git a/Userland/Applications/Help/ManualModel.cpp b/Userland/Applications/Help/ManualModel.cpp index 5c7667de47..f5a99c702c 100644 --- a/Userland/Applications/Help/ManualModel.cpp +++ b/Userland/Applications/Help/ManualModel.cpp @@ -174,12 +174,12 @@ void ManualModel::update_section_node_on_toggle(const GUI::ModelIndex& index, co TriState ManualModel::data_matches(const GUI::ModelIndex& index, const GUI::Variant& term) const { auto name = page_name(index); - if (name.contains(term.as_string())) + if (name.contains(term.as_string(), CaseSensitivity::CaseInsensitive)) return TriState::True; auto view_result = page_view(page_path(index)); if (view_result.is_error() || view_result.value().is_empty()) return TriState::False; - return view_result.value().contains(term.as_string()) ? TriState::True : TriState::False; + return view_result.value().contains(term.as_string(), CaseSensitivity::CaseInsensitive) ? TriState::True : TriState::False; }