From 345907914f3e7f131ff9a0fd054a6f772d050636 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Mon, 22 May 2023 23:20:40 +0200 Subject: dirstore: list the folders in arrival order List the folders in arrival order when dirstore.List() is called instead of returning it in an arbitrary order. If enable-folders-sort=false and dirlist-tree=false, the directory list will arbitrarly reshuffle when changing directories because the dirlist.dirs are generated from keys in a map in the dirstore. Fixes: https://todo.sr.ht/~rjarry/aerc/178 Signed-off-by: Koni Marti Acked-by: Robin Jarry --- lib/sort/sort.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/sort/sort.go') diff --git a/lib/sort/sort.go b/lib/sort/sort.go index c7e2b8ce..287f986c 100644 --- a/lib/sort/sort.go +++ b/lib/sort/sort.go @@ -70,3 +70,15 @@ func SortBy(toSort []uint32, sortBy []uint32) { return uidMap[toSort[i]] < uidMap[toSort[j]] }) } + +// SortStringBy sorts the string slice s according to the order given in the +// order string slice. +func SortStringBy(s []string, order []string) { + m := make(map[string]int) + for i, d := range order { + m[d] = i + } + sort.Slice(s, func(i, j int) bool { + return m[s[i]] < m[s[j]] + }) +} -- cgit