@@ -57,7 +57,6 @@ func NewSessions(com *common.Common, selectedSessionID string) (*Session, error)
5757 s.list = list.NewFilterableList(sessionItems(com.Styles, sessions...)...)
5858 s.list.Focus()
5959 s.list.SetSelected(s.selectedSessionInx)
60− s.list.ScrollToSelected()
6160
6261 s.input = textinput.New()
6362 s.input.SetVirtualCursor(false)
@@ -153,6 +152,14 @@ func (s *Session) Draw(scr uv.Screen, area uv.Rectangle) *tea.Cursor {
153152 s.list.SetSize(innerWidth, height-heightOffset)
154153 s.help.SetWidth(innerWidth)
155154
155+ // This makes it so we do not scroll the list if we don't have to
156+ start, end := s.list.VisibleItemIndices()
157+
158+ // if selected index is outside visible range, scroll to it
159+ if s.selectedSessionInx < start || s.selectedSessionInx > end {
160+ s.list.ScrollToSelected()
161+ }
162+
156163 rc := NewRenderContext(t, width)
157164 rc.Title = "Switch Session"
158165 inputView := t.Dialog.InputPrompt.Render(s.input.View())