From: Kevin McCarthy Date: Sat, 2 Jul 2016 19:24:25 +0000 (-0700) Subject: Fix sidebar "unsorted" order to match Buffy list order. X-Git-Tag: neomutt-20160822~91 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed60d778751531793019f3e97f15e5135351272e;p=neomutt Fix sidebar "unsorted" order to match Buffy list order. Since the previous commit decoupled the sidebar from the Buffy list, we can now restore the order to match the buffy list when sidebar_sort_method is set (back) to "unsorted". --- diff --git a/sidebar.c b/sidebar.c index 0ddd33e4d..12971e521 100644 --- a/sidebar.c +++ b/sidebar.c @@ -29,7 +29,7 @@ #include "sort.h" /* Previous values for some sidebar config */ -static short PreviousSort = -1; /* sidebar_sort_method */ +static short PreviousSort = SORT_ORDER; /* sidebar_sort_method */ /** * struct sidebar_entry - Info about folders in the sidebar @@ -316,7 +316,36 @@ static void update_entries_visibility (void) } /** - * sort_entries - Sort an array of BUFFY pointers + * unsort_entries - Restore Entries array order to match Buffy list order + */ +static void unsort_entries (void) +{ + BUFFY *cur = Incoming; + int i = 0, j; + SBENTRY *tmp; + + while (cur && (i < EntryCount)) + { + j = i; + while ((j < EntryCount) && + (Entries[j]->buffy != cur)) + j++; + if (j < EntryCount) + { + if (j != i) + { + tmp = Entries[i]; + Entries[i] = Entries[j]; + Entries[j] = tmp; + } + i++; + } + cur = cur->next; + } +} + +/** + * sort_entries - Sort Entries array. * * Sort the Entries array according to the current sort config * option "sidebar_sort_method". This calls qsort to do the work which calls our @@ -334,6 +363,9 @@ static void sort_entries (void) (ssm == SORT_FLAGGED) || (ssm == SORT_PATH)) qsort (Entries, EntryCount, sizeof (*Entries), cb_qsort_sbe); + else if ((ssm == SORT_ORDER) && + (SidebarSortMethod != PreviousSort)) + unsort_entries (); } /**