Skip to content

Commit

Permalink
Fix roll-over in file browser and archive (#2811)
Browse files Browse the repository at this point in the history
  • Loading branch information
Astrrra authored Jun 28, 2023
1 parent 6f1c46e commit bf975ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
19 changes: 11 additions & 8 deletions applications/main/archive/views/archive_browser_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
17 changes: 10 additions & 7 deletions applications/services/gui/modules/file_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit bf975ad

Please sign in to comment.