From e753d09af1e9279302388f7d4a15a7e7135b4396 Mon Sep 17 00:00:00 2001 From: Kujtim Hoxha Date: Thu, 22 Jan 2026 11:51:25 +0100 Subject: [PATCH] chore: do not scroll sessions if not neccessary 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. --- internal/ui/dialog/sessions.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/ui/dialog/sessions.go b/internal/ui/dialog/sessions.go index a70d13ce58fed2ddf1b292d30e405362cf093569..9f7023a44e005c4d6ab735206824519e5b91e5bf 100644 --- a/internal/ui/dialog/sessions.go +++ b/internal/ui/dialog/sessions.go @@ -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())