Skip to content

Commit dc65651

Browse files
committed
add a guard clause in the key handlers for when len(m.groups) == 0
1 parent a4c25fc commit dc65651

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

model.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,43 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
7272
return m, tea.Quit
7373

7474
case "up", "k":
75+
if len(m.groups) == 0 {
76+
return m, nil
77+
}
7578
if m.currentFile > 0 {
7679
m.currentFile--
7780
}
7881

7982
case "down", "j":
83+
if len(m.groups) == 0 {
84+
return m, nil
85+
}
8086
if m.currentFile < len(m.groups[m.currentGroup])-1 {
8187
m.currentFile++
8288
}
8389

8490
case "left", "h":
91+
if len(m.groups) == 0 {
92+
return m, nil
93+
}
8594
if m.currentGroup > 0 {
8695
m.currentGroup--
8796
m.currentFile = 0
8897
}
8998

9099
case "right", "l":
100+
if len(m.groups) == 0 {
101+
return m, nil
102+
}
91103
if m.currentGroup < len(m.groups)-1 {
92104
m.currentGroup++
93105
m.currentFile = 0
94106
}
95107

96108
case " ":
109+
if len(m.groups) == 0 {
110+
return m, nil
111+
}
97112
group := m.currentGroup
98113
file := m.currentFile
99114

@@ -108,6 +123,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
108123
}
109124

110125
case "d":
126+
if len(m.groups) == 0 {
127+
return m, nil
128+
}
111129
m.toDelete = m.getSelectedFiles()
112130
if len(m.toDelete) > 0 {
113131
m.showConfirm = true

0 commit comments

Comments
 (0)