From e673fc41837e003f8b787c57a852c202f0cd26e6 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Wed, 28 Dec 2022 00:35:30 +0100 Subject: LibGUI: Determine model index from a content position in ColumnsView We didn't take the scroll value into account when we were converting a position to an index, which basically prevented us from selecting a desired file if a list wasn't small enough to fit entirely in the widget box. --- Userland/Libraries/LibGUI/ColumnsView.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'Userland') diff --git a/Userland/Libraries/LibGUI/ColumnsView.cpp b/Userland/Libraries/LibGUI/ColumnsView.cpp index 53cf83f687..f5ec502982 100644 --- a/Userland/Libraries/LibGUI/ColumnsView.cpp +++ b/Userland/Libraries/LibGUI/ColumnsView.cpp @@ -241,13 +241,11 @@ void ColumnsView::update_column_sizes() set_content_size({ total_width, total_height }); } -Optional ColumnsView::column_at_event_position(Gfx::IntPoint a_position) const +Optional ColumnsView::column_at_event_position(Gfx::IntPoint position) const { if (!model()) return {}; - auto position = a_position.translated(horizontal_scrollbar().value() - frame_thickness(), vertical_scrollbar().value() - frame_thickness()); - int column_x = 0; for (auto const& column : m_columns) { @@ -288,8 +286,9 @@ ModelIndex ColumnsView::index_at_event_position_in_column(Gfx::IntPoint position return model()->index(row, m_model_column, column.parent_index); } -ModelIndex ColumnsView::index_at_event_position(Gfx::IntPoint position) const +ModelIndex ColumnsView::index_at_event_position(Gfx::IntPoint widget_position) const { + auto position = to_content_position(widget_position); auto const& column = column_at_event_position(position); if (!column.has_value()) return {}; @@ -307,11 +306,12 @@ void ColumnsView::mousedown_event(MouseEvent& event) if (event.button() != MouseButton::Primary) return; - auto column = column_at_event_position(event.position()); + auto position = to_content_position(event.position()); + auto column = column_at_event_position(position); if (!column.has_value()) return; - auto index = index_at_event_position_in_column(event.position(), *column); + auto index = index_at_event_position_in_column(position, *column); if (index.is_valid() && !(event.modifiers() & Mod_Ctrl)) { if (model()->row_count(index)) push_column(index); @@ -321,8 +321,8 @@ void ColumnsView::mousedown_event(MouseEvent& event) if (selection_mode() == SelectionMode::MultiSelection) { m_rubber_banding = true; m_rubber_band_origin_column = *column; - m_rubber_band_origin = event.position().y(); - m_rubber_band_current = event.position().y(); + m_rubber_band_origin = position.y(); + m_rubber_band_current = position.y(); } } -- cgit v1.2.3