@@ -16,11 +16,12 @@ const SessionsID = "session"
17// Session is a session selector dialog.
17// Session is a session selector dialog.
18type Session struct {
18type Session struct {
19− width, height int
19+ width, height int
20− com *common.Common
20+ com *common.Common
21− help help.Model
21+ help help.Model
22− list *list.FilterableList
22+ list *list.FilterableList
23− input textinput.Model
23+ input textinput.Model
24+ selectedSessionInx int
25 keyMap struct {
26 keyMap struct {
26 Select key.Binding
27 Select key.Binding
@@ -33,7 +34,7 @@ type Session struct {
33var _ Dialog = (*Session)(nil)
34var _ Dialog = (*Session)(nil)
35// NewSessions creates a new Session dialog.
36// NewSessions creates a new Session dialog.
36−func NewSessions(com *common.Common) (*Session, error) {
37+func NewSessions(com *common.Common, selectedSessionID string) (*Session, error) {
37 s := new(Session)
38 s := new(Session)
38 s.com = com
39 s.com = com
39 sessions, err := com.App.Sessions.List(context.TODO())
40 sessions, err := com.App.Sessions.List(context.TODO())
@@ -41,13 +42,19 @@ func NewSessions(com *common.Common) (*Session, error) {
41 return nil, err
42 return nil, err
45+ for i, sess := range sessions {
46+ if sess.ID == selectedSessionID {
47+ s.selectedSessionInx = i
44 help := help.New()
52 help := help.New()
45 help.Styles = com.Styles.DialogHelpStyles()
53 help.Styles = com.Styles.DialogHelpStyles()
47 s.help = help
55 s.help = help
48 s.list = list.NewFilterableList(sessionItems(com.Styles, sessions...)...)
56 s.list = list.NewFilterableList(sessionItems(com.Styles, sessions...)...)
49 s.list.Focus()
57 s.list.Focus()
50− s.list.SetSelected(0)
52 s.input = textinput.New()
59 s.input = textinput.New()
53 s.input.SetVirtualCursor(false)
60 s.input.SetVirtualCursor(false)
@@ -85,6 +92,10 @@ func (s *Session) SetSize(width, height int) {
85 s.input.SetWidth(innerWidth - t.Dialog.InputPrompt.GetHorizontalFrameSize() - 1) // (1) cursor padding
92 s.input.SetWidth(innerWidth - t.Dialog.InputPrompt.GetHorizontalFrameSize() - 1) // (1) cursor padding
86 s.list.SetSize(innerWidth, height-heightOffset)
93 s.list.SetSize(innerWidth, height-heightOffset)
87 s.help.SetWidth(width)
94 s.help.SetWidth(width)
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()
90// ID implements Dialog.
101// ID implements Dialog.