From d348976784a79fcab4cca26c1e8e374adc0a4296 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Mon, 25 Jan 2021 20:37:02 +0100 Subject: [PATCH] AbstractTableView: prevent setting an invalid index If you tried to move a cursor down when the last row is selected, the index becomes invalid without updating the selection. On the next cursor movement the invalid index is then reset to {0, 0}, selecting the first row instead. --- Userland/Libraries/LibGUI/AbstractTableView.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGUI/AbstractTableView.cpp b/Userland/Libraries/LibGUI/AbstractTableView.cpp index 129189db36..06597c90b7 100644 --- a/Userland/Libraries/LibGUI/AbstractTableView.cpp +++ b/Userland/Libraries/LibGUI/AbstractTableView.cpp @@ -235,7 +235,9 @@ void AbstractTableView::move_cursor_relative(int vertical_steps, int horizontal_ } else { new_index = model.index(0, 0); } - set_cursor(new_index, selection_update); + if (new_index.is_valid()) { + set_cursor(new_index, selection_update); + } } void AbstractTableView::scroll_into_view(const ModelIndex& index, bool scroll_horizontally, bool scroll_vertically)