mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibGUI: Constrain relative cursor delta to valid range
This commit is contained in:
parent
0c57e16ce4
commit
eabbe03b97
Notes:
sideshowbarker
2024-07-19 00:19:07 +09:00
Author: https://github.com/tomuta Commit: https://github.com/SerenityOS/serenity/commit/eabbe03b973 Pull-request: https://github.com/SerenityOS/serenity/pull/4682 Issue: https://github.com/SerenityOS/serenity/issues/4657
1 changed files with 13 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue