From 6b21789417430d392a43772cefb38ab620873ac9 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 22 Jul 2020 16:32:07 +0200 Subject: [PATCH] Ensure sorting is stable: type -> timestamp -> path/ID --- ui/stash.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ui/stash.go b/ui/stash.go index caef982..b671904 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -74,7 +74,17 @@ func (m markdownsByLocalFirst) Less(i, j int) bool { } // Both or neither are local files so sort by date descending - return m[i].CreatedAt.After(*m[j].CreatedAt) + if !m[i].CreatedAt.Equal(*m[j].CreatedAt) { + return m[i].CreatedAt.After(*m[j].CreatedAt) + } + + // If the timestamps also match, sort by ID/path + if iType != localMarkdown { + // non-local items have an ID + return m[i].ID > m[j].ID + } + + return strings.Compare(m[i].localPath, m[j].localPath) == -1 } type loadedState byte