From 8231bd9bc3d725f8ba16508522c45e6d349a6a88 Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Mon, 28 Nov 2022 17:58:17 -0500 Subject: LibGUI: Add IncrementalSearchBanner Compared to traditional modal search, incremental search begins matching as soon as the user starts typing, highlighting results immediately. This refactors Itamar's work for HackStudio into a common LibGUI widget to be used in all multi-line TextEditors. --- .../Libraries/LibGUI/AbstractScrollableWidget.h | 2 +- Userland/Libraries/LibGUI/CMakeLists.txt | 3 + Userland/Libraries/LibGUI/Forward.h | 1 + .../Libraries/LibGUI/IncrementalSearchBanner.cpp | 136 +++++++++++++++++++++ .../Libraries/LibGUI/IncrementalSearchBanner.gml | 81 ++++++++++++ .../Libraries/LibGUI/IncrementalSearchBanner.h | 45 +++++++ 6 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 Userland/Libraries/LibGUI/IncrementalSearchBanner.cpp create mode 100644 Userland/Libraries/LibGUI/IncrementalSearchBanner.gml create mode 100644 Userland/Libraries/LibGUI/IncrementalSearchBanner.h diff --git a/Userland/Libraries/LibGUI/AbstractScrollableWidget.h b/Userland/Libraries/LibGUI/AbstractScrollableWidget.h index 7f16066093..6e33e2ceb4 100644 --- a/Userland/Libraries/LibGUI/AbstractScrollableWidget.h +++ b/Userland/Libraries/LibGUI/AbstractScrollableWidget.h @@ -56,6 +56,7 @@ public: void scroll_to_top(); void scroll_to_bottom(); + void update_scrollbar_ranges(); void set_automatic_scrolling_timer(bool active); virtual Gfx::IntPoint automatic_scroll_delta_from_position(Gfx::IntPoint const&) const; @@ -89,7 +90,6 @@ protected: virtual void on_automatic_scrolling_timer_fired() {}; int autoscroll_threshold() const { return m_autoscroll_threshold; } void update_scrollbar_visibility(); - void update_scrollbar_ranges(); private: class AbstractScrollableWidgetScrollbar final : public Scrollbar { diff --git a/Userland/Libraries/LibGUI/CMakeLists.txt b/Userland/Libraries/LibGUI/CMakeLists.txt index 65fd641497..ae8fa20e23 100644 --- a/Userland/Libraries/LibGUI/CMakeLists.txt +++ b/Userland/Libraries/LibGUI/CMakeLists.txt @@ -1,6 +1,7 @@ compile_gml(EmojiInputDialog.gml EmojiInputDialogGML.h emoji_input_dialog_gml) compile_gml(FontPickerDialog.gml FontPickerDialogGML.h font_picker_dialog_gml) compile_gml(FilePickerDialog.gml FilePickerDialogGML.h file_picker_dialog_gml) +compile_gml(IncrementalSearchBanner.gml IncrementalSearchBannerGML.h incremental_search_banner_gml) compile_gml(PasswordInputDialog.gml PasswordInputDialogGML.h password_input_dialog_gml) set(SOURCES @@ -57,6 +58,7 @@ set(SOURCES Icon.cpp IconView.cpp ImageWidget.cpp + IncrementalSearchBanner.cpp INILexer.cpp INISyntaxHighlighter.cpp InputBox.cpp @@ -133,6 +135,7 @@ set(GENERATED_SOURCES EmojiInputDialogGML.h FilePickerDialogGML.h FontPickerDialogGML.h + IncrementalSearchBannerGML.h PasswordInputDialogGML.h ) diff --git a/Userland/Libraries/LibGUI/Forward.h b/Userland/Libraries/LibGUI/Forward.h index 2a11e53283..0ad380d344 100644 --- a/Userland/Libraries/LibGUI/Forward.h +++ b/Userland/Libraries/LibGUI/Forward.h @@ -37,6 +37,7 @@ class HorizontalSlider; class Icon; class IconView; class ImageWidget; +class IncrementalSearchBanner; class JsonArrayModel; class KeyEvent; class Label; diff --git a/Userland/Libraries/LibGUI/IncrementalSearchBanner.cpp b/Userland/Libraries/LibGUI/IncrementalSearchBanner.cpp new file mode 100644 index 0000000000..eeab9a573c --- /dev/null +++ b/Userland/Libraries/LibGUI/IncrementalSearchBanner.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2022, Itamar S. + * Copyright (c) 2022, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace GUI { + +IncrementalSearchBanner::IncrementalSearchBanner(TextEditor& editor) + : m_editor(editor) +{ + load_from_gml(incremental_search_banner_gml); + m_index_label = find_descendant_of_type_named