diff --git a/Libraries/LibGUI/AbstractView.cpp b/Libraries/LibGUI/AbstractView.cpp index 634876a4c8..37990b77ce 100644 --- a/Libraries/LibGUI/AbstractView.cpp +++ b/Libraries/LibGUI/AbstractView.cpp @@ -234,16 +234,6 @@ 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(); } diff --git a/Libraries/LibGUI/AbstractView.h b/Libraries/LibGUI/AbstractView.h index 84f3a7689a..b2378b6029 100644 --- a/Libraries/LibGUI/AbstractView.h +++ b/Libraries/LibGUI/AbstractView.h @@ -104,8 +104,6 @@ public: NonnullRefPtr font_for_index(const ModelIndex&) const; - void set_last_valid_hovered_index(const ModelIndex&); - void set_key_column_and_sort_order(int column, SortOrder); int key_column() const { return m_key_column; } @@ -153,7 +151,6 @@ protected: bool m_might_drag { false }; ModelIndex m_hovered_index; - ModelIndex m_last_valid_hovered_index; int m_key_column { -1 }; SortOrder m_sort_order; diff --git a/Libraries/LibGUI/ComboBox.cpp b/Libraries/LibGUI/ComboBox.cpp index b45edcbf89..a4e722b789 100644 --- a/Libraries/LibGUI/ComboBox.cpp +++ b/Libraries/LibGUI/ComboBox.cpp @@ -196,9 +196,6 @@ void ComboBox::open() Gfx::IntRect list_window_rect { my_screen_rect.bottom_left(), size }; list_window_rect.intersect(Desktop::the().rect().shrunken(0, taskbar_height + menubar_height + offset)); - if (m_list_view->hover_highlighting()) - m_list_view->set_last_valid_hovered_index({}); - m_editor->set_has_visible_list(true); m_editor->set_focus(true); m_list_window->set_rect(list_window_rect); diff --git a/Libraries/LibGUI/ListView.cpp b/Libraries/LibGUI/ListView.cpp index c1d69fb3e9..50e3449f05 100644 --- a/Libraries/LibGUI/ListView.cpp +++ b/Libraries/LibGUI/ListView.cpp @@ -127,11 +127,7 @@ void ListView::paint_event(PaintEvent& event) int painted_item_index = 0; for (int row_index = 0; row_index < model()->row_count(); ++row_index) { - bool is_selected_row; - if (hover_highlighting() && m_last_valid_hovered_index.is_valid()) - is_selected_row = row_index == m_last_valid_hovered_index.row(); - else - is_selected_row = selection().contains_row(row_index); + bool is_selected_row = selection().contains_row(row_index); int y = painted_item_index * item_height(); @@ -185,20 +181,23 @@ int ListView::item_count() const return model()->row_count(); } +void ListView::mousemove_event(MouseEvent& event) +{ + auto previous_hovered_index = m_hovered_index; + AbstractView::mousemove_event(event); + if (hover_highlighting() && previous_hovered_index != m_hovered_index) + set_cursor(m_hovered_index, SelectionUpdate::Set); +} + void ListView::keydown_event(KeyEvent& event) { if (!model()) return; - auto& model = *this->model(); SelectionUpdate selection_update = SelectionUpdate::Set; ModelIndex new_index; if (event.key() == KeyCode::Key_Return) { - if (hover_highlighting() && m_last_valid_hovered_index.is_valid()) { - auto new_index = model.index(m_last_valid_hovered_index.row(), m_last_valid_hovered_index.column()); - selection().set(new_index); - } activate_selected(); return; } @@ -267,15 +266,11 @@ void ListView::move_cursor(CursorMovement movement, SelectionUpdate selection_up new_index = model.index(model.row_count() - 1, 0); break; case CursorMovement::PageUp: { - if (hover_highlighting()) - set_last_valid_hovered_index({}); int items_per_page = visible_content_rect().height() / item_height(); new_index = model.index(max(0, cursor_index().row() - items_per_page), cursor_index().column()); break; } case CursorMovement::PageDown: { - if (hover_highlighting()) - set_last_valid_hovered_index({}); int items_per_page = visible_content_rect().height() / item_height(); new_index = model.index(min(model.row_count() - 1, cursor_index().row() + items_per_page), cursor_index().column()); break; diff --git a/Libraries/LibGUI/ListView.h b/Libraries/LibGUI/ListView.h index 7b75067afc..4f81364a51 100644 --- a/Libraries/LibGUI/ListView.h +++ b/Libraries/LibGUI/ListView.h @@ -69,6 +69,7 @@ private: virtual void paint_event(PaintEvent&) override; virtual void keydown_event(KeyEvent&) override; virtual void resize_event(ResizeEvent&) override; + virtual void mousemove_event(MouseEvent&) override; Gfx::IntRect content_rect(int row) const; int item_count() const;