diff options
author | networkException <git@nwex.de> | 2022-07-24 00:06:27 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-24 13:40:31 +0100 |
commit | 2d681279d4d4d7a0548a0c0c9161ffe4fd94f4a5 (patch) | |
tree | c67e5bb4336fddf95590fd3c999a509de180d784 | |
parent | 30d68d71b4a8d8aad71096c5824a84615e14190f (diff) | |
download | serenity-2d681279d4d4d7a0548a0c0c9161ffe4fd94f4a5.zip |
LibGUI: Properly handle range selections in ColumnsView
Previously we would always select the left most column when selecting a
range of rows.
This patch fixes this issue by always applying a selection to the column
in which the selection ends.
-rw-r--r-- | Userland/Libraries/LibGUI/ColumnsView.cpp | 14 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/ColumnsView.h | 2 |
2 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/ColumnsView.cpp b/Userland/Libraries/LibGUI/ColumnsView.cpp index afd04ca201..502dff973c 100644 --- a/Userland/Libraries/LibGUI/ColumnsView.cpp +++ b/Userland/Libraries/LibGUI/ColumnsView.cpp @@ -234,6 +234,20 @@ ModelIndex ColumnsView::index_at_event_position(Gfx::IntPoint const& a_position) return {}; } +void ColumnsView::select_range(ModelIndex const& index) +{ + auto min_row = min(selection_start_index().row(), index.row()); + auto max_row = max(selection_start_index().row(), index.row()); + auto parent = index.parent(); + + clear_selection(); + for (auto row = min_row; row <= max_row; ++row) { + auto new_index = model()->index(row, m_model_column, parent); + if (new_index.is_valid()) + toggle_selection(new_index); + } +} + void ColumnsView::mousedown_event(MouseEvent& event) { AbstractView::mousedown_event(event); diff --git a/Userland/Libraries/LibGUI/ColumnsView.h b/Userland/Libraries/LibGUI/ColumnsView.h index f0d1ffea14..0fe157e8a6 100644 --- a/Userland/Libraries/LibGUI/ColumnsView.h +++ b/Userland/Libraries/LibGUI/ColumnsView.h @@ -37,6 +37,8 @@ private: virtual void paint_event(PaintEvent&) override; virtual void mousedown_event(MouseEvent& event) override; + virtual void select_range(ModelIndex const&) override; + void move_cursor(CursorMovement, SelectionUpdate) override; virtual void select_all() override; |