diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-12 10:55:00 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-12 10:55:00 +0300 |
| commit | 1d7c581957bc14c9feee22938997e29b5e236158 (patch) | |
| tree | 150007c063de231d930b500f2a45ba8517219957 /src/c/fastforge.c | |
| parent | ba9bf35f26538355de3e9613545bd5bdcdd9c95e (diff) | |
fix(c2): keep history chronological after edit saves
Diffstat (limited to 'src/c/fastforge.c')
| -rw-r--r-- | src/c/fastforge.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/c/fastforge.c b/src/c/fastforge.c index 8df5b33..add9578 100644 --- a/src/c/fastforge.c +++ b/src/c/fastforge.c @@ -1,4 +1,5 @@ #include <pebble.h> +#include <stdlib.h> #include <string.h> #include "fastforge.h" @@ -265,6 +266,31 @@ static int history_index_for_row(int row) { return history_count - 1 - row; } +static int compare_history_entries_by_end_time(const void *a, const void *b) { + const FastEntry *entry_a = a; + const FastEntry *entry_b = b; + if (entry_a->end_time < entry_b->end_time) { + return -1; + } + if (entry_a->end_time > entry_b->end_time) { + return 1; + } + if (entry_a->start_time < entry_b->start_time) { + return -1; + } + if (entry_a->start_time > entry_b->start_time) { + return 1; + } + return 0; +} + +static void sort_history_by_end_time(void) { + if (history_count <= 1) { + return; + } + qsort(history, (size_t)history_count, sizeof(FastEntry), compare_history_entries_by_end_time); +} + static void format_history_row(int row, char *title, size_t title_size, char *subtitle, size_t subtitle_size) { if (!title || !subtitle || title_size == 0 || subtitle_size == 0) { return; @@ -856,6 +882,7 @@ static void history_edit_save_click_handler(ClickRecognizerRef recognizer, void } s_history_edit_draft.max_stage_reached = stage_level_for_elapsed(entry_duration_seconds(&s_history_edit_draft)); history[s_history_edit_index] = s_history_edit_draft; + sort_history_by_end_time(); save_all_data(); s_history_edit_dirty = false; refresh_history_row_cache(); |
