1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 17:28:10 +00:00

LibGUI: Constrain relative cursor delta to valid range

This commit is contained in:
Tom 2020-12-30 22:15:41 -07:00 committed by Andreas Kling
parent 0c57e16ce4
commit eabbe03b97

View file

@ -213,7 +213,19 @@ void ListView::move_cursor_relative(int steps, SelectionUpdate selection_update)
auto& model = *this->model();
ModelIndex new_index;
if (cursor_index().is_valid()) {
new_index = model.index(cursor_index().row() + steps, cursor_index().column());
auto row = cursor_index().row();
if (steps > 0) {
if (row + steps >= model.row_count())
row = model.row_count() - 1;
else
row += steps;
} else if (steps < 0) {
if (row < -steps)
row = 0;
else
row += steps;
}
new_index = model.index(row, cursor_index().column());
} else {
new_index = model.index(0, 0);
}