Skip to content

Commit 79c0a46

Browse files
committed
Sort displayed keys
1 parent 2c883d7 commit 79c0a46

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

go/optionsui/ui.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package optionsui
1919
import (
2020
"encoding/base64"
2121
"fmt"
22+
"sort"
2223

2324
"github.com/google/chrome-ssh-agent/go/dom"
2425
"github.com/google/chrome-ssh-agent/go/keys"
@@ -423,7 +424,23 @@ func mergeKeys(configured []*keys.ConfiguredKey, loaded []*keys.LoadedKey) []*di
423424
})
424425
}
425426

426-
// TODO(ralimi) Sort displayed items to ensure consitent ordering over time
427+
// Sort to ensure consistent ordering.
428+
sort.Slice(result, func (i, j int) bool {
429+
a, b := result[i], result[j]
430+
if a.Name < b.Name {
431+
return true
432+
}
433+
if a.Name > b.Name {
434+
return false
435+
}
436+
if a.Blob < b.Blob {
437+
return true
438+
}
439+
if a.Blob > b.Blob {
440+
return false
441+
}
442+
return a.ID < b.ID
443+
})
427444

428445
return result
429446
}

0 commit comments

Comments
 (0)