this makes it so we only scroll if the selected item is not in the view,
this was driving me nuts that it was always putting my last session at
the top.
@@ -57,7 +57,6 @@ func NewSessions(com *common.Common, selectedSessionID string) (*Session, error)
s.list = list.NewFilterableList(sessionItems(com.Styles, sessions...)...)
s.list.Focus()
s.list.SetSelected(s.selectedSessionInx)
- s.list.ScrollToSelected()
s.input = textinput.New()
s.input.SetVirtualCursor(false)
@@ -153,6 +152,14 @@ func (s *Session) Draw(scr uv.Screen, area uv.Rectangle) *tea.Cursor {
s.list.SetSize(innerWidth, height-heightOffset)
s.help.SetWidth(innerWidth)
+ // This makes it so we do not scroll the list if we don't have to
+ start, end := s.list.VisibleItemIndices()
+
+ // if selected index is outside visible range, scroll to it
+ if s.selectedSessionInx < start || s.selectedSessionInx > end {
+ s.list.ScrollToSelected()
+ }
+
rc := NewRenderContext(t, width)
rc.Title = "Switch Session"
inputView := t.Dialog.InputPrompt.Render(s.input.View())