diff --git a/cursor.go b/cursor.go index 9444e0b..37abd15 100644 --- a/cursor.go +++ b/cursor.go @@ -16,8 +16,15 @@ func NewGridCursor() *GridCursor { } } -func (gc *GridCursor) Len() int { return len(gc.filtered) } -func (gc *GridCursor) Selected() *Container { return gc.filtered[gc.Idx()] } +func (gc *GridCursor) Len() int { return len(gc.filtered) } + +func (gc *GridCursor) Selected() *Container { + idx := gc.Idx() + if idx < gc.Len() { + return gc.filtered[idx] + } + return nil +} // Refresh containers from source func (gc *GridCursor) RefreshContainers() (lenChanged bool) { diff --git a/grid.go b/grid.go index 7704cf4..826844f 100644 --- a/grid.go +++ b/grid.go @@ -132,7 +132,10 @@ func Display() bool { return false } if expand { - ExpandView(cursor.Selected()) + c := cursor.Selected() + if c != nil { + ExpandView(c) + } return false } return true