Skip to content

Commit 4f4e39f

Browse files
Merge pull request #9 from RasmusLindroth/bugfix
Bugfix for web output with empty modes. Sort by most used group
2 parents 5c56afb + bc2f590 commit 4f4e39f

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

i3keys.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/RasmusLindroth/i3keys/internal/web"
1212
)
1313

14-
const version string = "0.0.6"
14+
const version string = "0.0.7"
1515

1616
func helpText(exitCode int) {
1717
fmt.Printf("Usage:\n\n\ti3keys <command> [arguments]\n\n")

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
}

internal/web/template.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,13 @@ function generateKeyboard(layout, generated, modes) {
229229
headingEl.innerHTML = "Mode: Default";
230230
keyboardHolder.appendChild(headingEl);
231231
232-
for (let i = 0; i < generated.length; i++) {
232+
for (let i = 0; generated !== null && i < generated.length; i++) {
233233
let newKeyboardGroup = generateKeyboardGroup(kbLayout, generated[i]);
234234
keyboardHolder.appendChild(newKeyboardGroup);
235235
}
236236
237237
238-
for (let i = 0; i < modes.length; i++) {
238+
for (let i = 0; modes !== null && i < modes.length; i++) {
239239
let headingEl = document.createElement('h2');
240240
headingEl.innerHTML = "Mode: " + modes[i].Name;
241241
keyboardHolder.appendChild(headingEl);

0 commit comments

Comments
 (0)