diff --git a/Libraries/LibGUI/AbstractView.cpp b/Libraries/LibGUI/AbstractView.cpp index ab6199d55d..6635f2d0ea 100644 --- a/Libraries/LibGUI/AbstractView.cpp +++ b/Libraries/LibGUI/AbstractView.cpp @@ -225,6 +225,16 @@ void AbstractView::set_hovered_index(const ModelIndex& index) if (m_hovered_index == index) return; m_hovered_index = index; + if (m_hovered_index.is_valid()) + m_last_valid_hovered_index = m_hovered_index; + update(); +} + +void AbstractView::set_last_valid_hovered_index(const ModelIndex& index) +{ + if (m_last_valid_hovered_index == index) + return; + m_last_valid_hovered_index = index; update(); } @@ -325,6 +335,9 @@ void AbstractView::mouseup_event(MouseEvent& event) m_might_drag = false; update(); } + + if (activates_on_selection()) + activate_selected(); } void AbstractView::doubleclick_event(MouseEvent& event) diff --git a/Libraries/LibGUI/AbstractView.h b/Libraries/LibGUI/AbstractView.h index 295efa546e..7910871952 100644 --- a/Libraries/LibGUI/AbstractView.h +++ b/Libraries/LibGUI/AbstractView.h @@ -74,6 +74,8 @@ public: NonnullRefPtr font_for_index(const ModelIndex&) const; + void set_last_valid_hovered_index(const ModelIndex&); + protected: AbstractView(); virtual ~AbstractView() override; @@ -107,6 +109,7 @@ protected: bool m_might_drag { false }; ModelIndex m_hovered_index; + ModelIndex m_last_valid_hovered_index; private: RefPtr m_model; diff --git a/Libraries/LibGUI/ComboBox.cpp b/Libraries/LibGUI/ComboBox.cpp index 42a0bdf61e..ae6a236edb 100644 --- a/Libraries/LibGUI/ComboBox.cpp +++ b/Libraries/LibGUI/ComboBox.cpp @@ -49,6 +49,8 @@ private: virtual void mousewheel_event(MouseEvent& event) override { + if (!is_focused()) + set_focus(true); if (on_mousewheel) on_mousewheel(event.wheel_delta()); } @@ -57,6 +59,7 @@ private: ComboBox::ComboBox() { m_editor = add(); + m_editor->set_has_open_button(true); m_editor->on_change = [this] { if (on_change) on_change(m_editor->text(), m_list_view->selection().first()); @@ -65,6 +68,27 @@ ComboBox::ComboBox() if (on_return_pressed) on_return_pressed(); }; + m_editor->on_up_pressed = [this] { + m_list_view->move_selection(-1); + }; + m_editor->on_down_pressed = [this] { + m_list_view->move_selection(1); + }; + m_editor->on_pageup_pressed = [this] { + m_list_view->move_selection(-m_list_view->selection().first().row()); + }; + m_editor->on_pagedown_pressed = [this] { + if (model()) + m_list_view->move_selection((model()->row_count() - 1) - m_list_view->selection().first().row()); + }; + m_editor->on_mousewheel = [this](int delta) { + m_list_view->move_selection(delta); + }; + m_editor->on_mousedown = [this] { + if (only_allow_values_from_model()) + m_open_button->click(); + }; + m_open_button = add