summaryrefslogtreecommitdiff
path: root/LibGUI/GTableView.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-04 10:57:26 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-04 10:57:26 +0100
commit06bd2fb2d5f39eb5d6344c87954981bee94758ad (patch)
tree095e52be56e6c77a543d5d113aa37d132812ef69 /LibGUI/GTableView.cpp
parent7e955f7b60f4f91da2d9f2817635a6d773257a88 (diff)
downloadserenity-06bd2fb2d5f39eb5d6344c87954981bee94758ad.zip
GTableView: Allow initiating keyboard navigation with no current selection.
Diffstat (limited to 'LibGUI/GTableView.cpp')
-rw-r--r--LibGUI/GTableView.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/LibGUI/GTableView.cpp b/LibGUI/GTableView.cpp
index 3734adfda6..ea6c76fcda 100644
--- a/LibGUI/GTableView.cpp
+++ b/LibGUI/GTableView.cpp
@@ -198,7 +198,11 @@ void GTableView::keydown_event(GKeyEvent& event)
return;
}
if (event.key() == KeyCode::Key_Up) {
- GModelIndex new_index(model.selected_index().row() - 1, model.selected_index().column());
+ 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);
@@ -207,7 +211,11 @@ void GTableView::keydown_event(GKeyEvent& event)
return;
}
if (event.key() == KeyCode::Key_Down) {
- GModelIndex new_index(model.selected_index().row() + 1, model.selected_index().column());
+ 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);