1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +00:00

LibGUI: Allow moving the TableView selection horizontally with keyboard

This commit is contained in:
Andreas Kling 2020-08-24 21:02:46 +02:00
parent e5a6e297bf
commit 2cbe290930
3 changed files with 13 additions and 5 deletions

View file

@ -435,7 +435,7 @@ int AbstractTableView::item_count() const
return model()->row_count(); return model()->row_count();
} }
void AbstractTableView::move_selection(int steps) void AbstractTableView::move_selection(int vertical_steps, int horizontal_steps)
{ {
if (!model()) if (!model())
return; return;
@ -443,7 +443,7 @@ void AbstractTableView::move_selection(int steps)
ModelIndex new_index; ModelIndex new_index;
if (!selection().is_empty()) { if (!selection().is_empty()) {
auto old_index = selection().first(); 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 { } else {
new_index = model.index(0, 0); new_index = model.index(0, 0);
} }

View file

@ -78,7 +78,7 @@ public:
virtual void select_all() override; virtual void select_all() override;
void move_selection(int steps); void move_selection(int vertical_steps, int horizontal_steps);
protected: protected:
virtual ~AbstractTableView() override; virtual ~AbstractTableView() override;

View file

@ -162,12 +162,20 @@ void TableView::keydown_event(KeyEvent& event)
activate_selected(); activate_selected();
return; 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) { if (event.key() == KeyCode::Key_Up) {
move_selection(-1); move_selection(-1, 0);
return; return;
} }
if (event.key() == KeyCode::Key_Down) { if (event.key() == KeyCode::Key_Down) {
move_selection(1); move_selection(1, 0);
return; return;
} }
if (event.key() == KeyCode::Key_PageUp) { if (event.key() == KeyCode::Key_PageUp) {