Fix roll-over in file browser and archive (#2811)

This commit is contained in:
Astra 2023-06-28 14:46:42 +03:00 committed by GitHub
parent 6f1c46e11d
commit bf975ad786
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 15 deletions

View file

@ -345,11 +345,13 @@ static bool archive_view_input(InputEvent* event, void* context) {
if(event->key == InputKeyUp) {
if(model->item_idx < scroll_speed) {
scroll_speed = model->item_idx;
model->button_held_for_ticks = 0;
model->item_idx = model->item_cnt - 1;
} else {
model->item_idx =
((model->item_idx - scroll_speed) + model->item_cnt) %
model->item_cnt;
}
model->item_idx =
((model->item_idx - scroll_speed) + model->item_cnt) % model->item_cnt;
if(is_file_list_load_required(model)) {
model->list_loading = true;
browser->callback(ArchiveBrowserEventLoadPrevItems, browser->context);
@ -361,11 +363,12 @@ static bool archive_view_input(InputEvent* event, void* context) {
model->button_held_for_ticks += 1;
} else if(event->key == InputKeyDown) {
int32_t count = model->item_cnt;
if(model->item_idx >= (count - scroll_speed)) {
scroll_speed = model->item_cnt - model->item_idx - 1;
if(model->item_idx + scroll_speed >= count) {
model->button_held_for_ticks = 0;
model->item_idx = 0;
} else {
model->item_idx = (model->item_idx + scroll_speed) % model->item_cnt;
}
model->item_idx = (model->item_idx + scroll_speed) % model->item_cnt;
if(is_file_list_load_required(model)) {
model->list_loading = true;
browser->callback(ArchiveBrowserEventLoadNextItems, browser->context);

View file

@ -602,11 +602,13 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
if(event->key == InputKeyUp) {
if(model->item_idx < scroll_speed) {
scroll_speed = model->item_idx;
model->button_held_for_ticks = 0;
model->item_idx = model->item_cnt - 1;
} else {
model->item_idx =
((model->item_idx - scroll_speed) + model->item_cnt) %
model->item_cnt;
}
model->item_idx =
((model->item_idx - scroll_speed) + model->item_cnt) % model->item_cnt;
if(browser_is_list_load_required(model)) {
model->list_loading = true;
int32_t load_offset = CLAMP(
@ -622,10 +624,11 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
} else if(event->key == InputKeyDown) {
int32_t count = model->item_cnt;
if(model->item_idx + scroll_speed >= count) {
scroll_speed = count - model->item_idx - 1;
model->button_held_for_ticks = 0;
model->item_idx = 0;
} else {
model->item_idx = (model->item_idx + scroll_speed) % model->item_cnt;
}
model->item_idx = (model->item_idx + scroll_speed) % model->item_cnt;
if(browser_is_list_load_required(model)) {
model->list_loading = true;
int32_t load_offset = CLAMP(