summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LibGUI/GItemView.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/LibGUI/GItemView.cpp b/LibGUI/GItemView.cpp
index 4acab7073a..db0499c121 100644
--- a/LibGUI/GItemView.cpp
+++ b/LibGUI/GItemView.cpp
@@ -144,6 +144,9 @@ void GItemView::keydown_event(GKeyEvent& event)
{
if (!model())
return;
+ if (!m_visual_row_count || !m_visual_column_count)
+ return;
+
auto& model = *this->model();
if (event.key() == KeyCode::Key_Return) {
model.activate(model.selected_index());
@@ -152,7 +155,7 @@ void GItemView::keydown_event(GKeyEvent& event)
if (event.key() == KeyCode::Key_Up) {
GModelIndex new_index;
if (model.selected_index().is_valid())
- new_index = { model.selected_index().row() - 1, model.selected_index().column() };
+ new_index = { model.selected_index().row() - m_visual_column_count, model.selected_index().column() };
else
new_index = { 0, 0 };
if (model.is_valid(new_index)) {
@@ -165,6 +168,32 @@ void GItemView::keydown_event(GKeyEvent& event)
if (event.key() == KeyCode::Key_Down) {
GModelIndex new_index;
if (model.selected_index().is_valid())
+ new_index = { model.selected_index().row() + m_visual_column_count, model.selected_index().column() };
+ else
+ new_index = { 0, 0 };
+ if (model.is_valid(new_index)) {
+ model.set_selected_index(new_index);
+ scroll_into_view(new_index, Orientation::Vertical);
+ update();
+ }
+ return;
+ }
+ if (event.key() == KeyCode::Key_Left) {
+ GModelIndex new_index;
+ if (model.selected_index().is_valid())
+ new_index = { model.selected_index().row() - 1, model.selected_index().column() };
+ else
+ new_index = { 0, 0 };
+ if (model.is_valid(new_index)) {
+ model.set_selected_index(new_index);
+ scroll_into_view(new_index, Orientation::Vertical);
+ update();
+ }
+ return;
+ }
+ if (event.key() == KeyCode::Key_Right) {
+ GModelIndex new_index;
+ if (model.selected_index().is_valid())
new_index = { model.selected_index().row() + 1, model.selected_index().column() };
else
new_index = { 0, 0 };