@@ -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.