From 35dd75c945079d9e5a9bbc51e9921ba551b3f607 Mon Sep 17 00:00:00 2001 From: aligator Date: Mon, 2 Dec 2024 23:11:18 +0100 Subject: [PATCH] Sort colors in .Filter in a stable way, even with duplicate names --- gamut.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gamut.go b/gamut.go index b229ba0..835f36e 100644 --- a/gamut.go +++ b/gamut.go @@ -107,7 +107,10 @@ func (g Palette) Filter(name string) Colors { } } - sort.Slice(c, func(i, j int) bool { + sort.SliceStable(c, func(i, j int) bool { + if c[i].Name == c[j].Name { + return ToHex(c[i].Color) < ToHex(c[j].Color) + } di := smetrics.WagnerFischer(strings.ToLower(c[i].Name), s, 1, 1, 2) dj := smetrics.WagnerFischer(strings.ToLower(c[j].Name), s, 1, 1, 2) return di < dj