From 2cbe29093083ccdcaf917d57e378749885f19cad Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 24 Aug 2020 21:02:46 +0200 Subject: [PATCH] LibGUI: Allow moving the TableView selection horizontally with keyboard --- Libraries/LibGUI/AbstractTableView.cpp | 4 ++-- Libraries/LibGUI/AbstractTableView.h | 2 +- Libraries/LibGUI/TableView.cpp | 12 ++++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Libraries/LibGUI/AbstractTableView.cpp b/Libraries/LibGUI/AbstractTableView.cpp index a06d6aa0fc..4e7433bf5f 100644 --- a/Libraries/LibGUI/AbstractTableView.cpp +++ b/Libraries/LibGUI/AbstractTableView.cpp @@ -435,7 +435,7 @@ int AbstractTableView::item_count() const return model()->row_count(); } -void AbstractTableView::move_selection(int steps) +void AbstractTableView::move_selection(int vertical_steps, int horizontal_steps) { if (!model()) return; @@ -443,7 +443,7 @@ void AbstractTableView::move_selection(int steps) ModelIndex new_index; if (!selection().is_empty()) { auto old_index = selection().first(); - new_index = model.index(old_index.row() + steps, old_index.column()); + new_index = model.index(old_index.row() + vertical_steps, old_index.column() + horizontal_steps); } else { new_index = model.index(0, 0); } diff --git a/Libraries/LibGUI/AbstractTableView.h b/Libraries/LibGUI/AbstractTableView.h index c405c64016..cfcbf7c9a7 100644 --- a/Libraries/LibGUI/AbstractTableView.h +++ b/Libraries/LibGUI/AbstractTableView.h @@ -78,7 +78,7 @@ public: virtual void select_all() override; - void move_selection(int steps); + void move_selection(int vertical_steps, int horizontal_steps); protected: virtual ~AbstractTableView() override; diff --git a/Libraries/LibGUI/TableView.cpp b/Libraries/LibGUI/TableView.cpp index 2dfd0c4443..306a26c42b 100644 --- a/Libraries/LibGUI/TableView.cpp +++ b/Libraries/LibGUI/TableView.cpp @@ -162,12 +162,20 @@ void TableView::keydown_event(KeyEvent& event) activate_selected(); return; } + if (event.key() == KeyCode::Key_Left) { + move_selection(0, -1); + return; + } + if (event.key() == KeyCode::Key_Right) { + move_selection(0, 1); + return; + } if (event.key() == KeyCode::Key_Up) { - move_selection(-1); + move_selection(-1, 0); return; } if (event.key() == KeyCode::Key_Down) { - move_selection(1); + move_selection(1, 0); return; } if (event.key() == KeyCode::Key_PageUp) {