on main help sign in
fix(sessions): select the current session in dialog
commit098bc8abf07fd8dd0506669376c34e6445a07f10 authorKujtim Hoxha <kujtimii.h@gmail.com> dateSun 28 Dec 2025, 14:15 (1 year ago) parent9b26ea2
2 files changed+24−8
internal/ui/dialog/sessions.go+18−7 internal/ui/model/ui.go+6−1
internal/ui/dialog/sessions.go+18−7
@@ -16,11 +16,12 @@ const SessionsID = "session"
1616
1717// Session is a session selector dialog.
1818type Session struct {
19− width, height int
20− com *common.Common
21− help help.Model
22− list *list.FilterableList
23− input textinput.Model
19+ width, height int
20+ com *common.Common
21+ help help.Model
22+ list *list.FilterableList
23+ input textinput.Model
24+ selectedSessionInx int
2425
2526 keyMap struct {
2627 Select key.Binding
@@ -33,7 +34,7 @@ type Session struct {
3334var _ Dialog = (*Session)(nil)
3435
3536// NewSessions creates a new Session dialog.
36−func NewSessions(com *common.Common) (*Session, error) {
37+func NewSessions(com *common.Common, selectedSessionID string) (*Session, error) {
3738 s := new(Session)
3839 s.com = com
3940 sessions, err := com.App.Sessions.List(context.TODO())
@@ -41,13 +42,19 @@ func NewSessions(com *common.Common) (*Session, error) {
4142 return nil, err
4243 }
4344
45+ for i, sess := range sessions {
46+ if sess.ID == selectedSessionID {
47+ s.selectedSessionInx = i
48+ break
49+ }
50+ }
51+
4452 help := help.New()
4553 help.Styles = com.Styles.DialogHelpStyles()
4654
4755 s.help = help
4856 s.list = list.NewFilterableList(sessionItems(com.Styles, sessions...)...)
4957 s.list.Focus()
50− s.list.SetSelected(0)
5158
5259 s.input = textinput.New()
5360 s.input.SetVirtualCursor(false)
@@ -85,6 +92,10 @@ func (s *Session) SetSize(width, height int) {
8592 s.input.SetWidth(innerWidth - t.Dialog.InputPrompt.GetHorizontalFrameSize() - 1) // (1) cursor padding
8693 s.list.SetSize(innerWidth, height-heightOffset)
8794 s.help.SetWidth(width)
95+
96+ // Now that we know the height we can select the selected session and scroll to it.
97+ s.list.SetSelected(s.selectedSessionInx)
98+ s.list.ScrollToSelected()
8899}
89100
90101// ID implements Dialog.
internal/ui/model/ui.go+6−1
@@ -1440,7 +1440,12 @@ func (m *UI) openSessionsDialog() tea.Cmd {
14401440 return nil
14411441 }
14421442
1443− dialog, err := dialog.NewSessions(m.com)
1443+ selectedSessionID := ""
1444+ if m.session != nil {
1445+ selectedSessionID = m.session.ID
1446+ }
1447+
1448+ dialog, err := dialog.NewSessions(m.com, selectedSessionID)
14441449 if err != nil {
14451450 return uiutil.ReportError(err)
14461451 }