Skip to content

Commit 8598de6

Browse files
Sort by most used modifier group
1 parent 499b49a commit 8598de6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

internal/i3parse/group.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package i3parse
22

3+
import "sort"
4+
35
func compareSlices(a []string, b []string) bool {
46
if len(a) != len(b) {
57
return false
@@ -14,6 +16,14 @@ func compareSlices(a []string, b []string) bool {
1416
return true
1517
}
1618

19+
type sortByNumBindings []ModifierGroup
20+
21+
func (a sortByNumBindings) Len() int { return len(a) }
22+
func (a sortByNumBindings) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
23+
func (a sortByNumBindings) Less(i, j int) bool {
24+
return len(a[i].Bindings) > len(a[j].Bindings)
25+
}
26+
1727
//GetModifierGroups groups bindings that have the same modifiers
1828
func GetModifierGroups(bindings []Binding) []ModifierGroup {
1929
var groups []ModifierGroup
@@ -33,6 +43,7 @@ func GetModifierGroups(bindings []Binding) []ModifierGroup {
3343
})
3444
}
3545
}
46+
sort.Sort(sortByNumBindings(groups))
3647

3748
return groups
3849
}

0 commit comments

Comments
 (0)