Skip to content

Commit 0bb8c8e

Browse files
committed
prevent crash when there are no items in table
1 parent a6bba2d commit 0bb8c8e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tui/torrent.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,15 @@ func (tw *torrentWid) verify(s *core.Session) {
144144

145145
func (tw *torrentWid) setKeys(s *core.Session) {
146146
tw.widget.SetInputCapture(func(e *tcell.EventKey) *tcell.EventKey {
147-
switch e.Rune() {
147+
key := e.Rune()
148+
row, _ := tw.widget.GetSelection()
149+
count := tw.widget.GetRowCount()
150+
151+
if key != 'q' && (count == 1 || count == row) {
152+
return e
153+
}
154+
155+
switch key {
148156
case 'g':
149157
tw.widget.Select(1, 0)
150158
tw.widget.ScrollToBeginning()

0 commit comments

Comments
 (0)