on main help sign in
fix: fix sidebar init, fix focus
b78bf05Kujtim Hoxha
internal/tui/components/chat/sidebar/sidebar.go+8−4
@@ -52,6 +52,7 @@ type SessionFilesMsg struct {
52type Sidebar interface {
52type Sidebar interface {
53 util.Model
53 util.Model
54 layout.Sizeable
54 layout.Sizeable
55+ SetSession(session session.Session) tea.Cmd
55}
56}
56
57
57type sidebarCmp struct {
58type sidebarCmp struct {
@@ -83,10 +84,7 @@ func (m *sidebarCmp) Init() tea.Cmd {
83func (m *sidebarCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
84func (m *sidebarCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
84 switch msg := msg.(type) {
85 switch msg := msg.(type) {
85 case chat.SessionSelectedMsg:
86 case chat.SessionSelectedMsg:
86− if msg.ID != m.session.ID {
87+ return m, m.SetSession(msg)
87− m.session = msg
88− }
89− return m, m.loadSessionFiles
90 case SessionFilesMsg:
88 case SessionFilesMsg:
91 m.files = sync.Map{}
89 m.files = sync.Map{}
92 for _, file := range msg.Files {
90 for _, file := range msg.Files {
@@ -506,6 +504,12 @@ func (s *sidebarCmp) currentModelBlock() string {
506 )
504 )
507}
505}
508
506
507+// SetSession implements Sidebar.
508+func (m *sidebarCmp) SetSession(session session.Session) tea.Cmd {
509+ m.session = session
510+ return m.loadSessionFiles
511+}
512+
509func cwd() string {
513func cwd() string {
510 cwd := config.WorkingDirectory()
514 cwd := config.WorkingDirectory()
511 t := styles.CurrentTheme()
515 t := styles.CurrentTheme()
internal/tui/page/chat/chat.go+12−5
@@ -167,6 +167,8 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
167 p.clearMessages(),
167 p.clearMessages(),
168 util.CmdHandler(chat.SessionClearedMsg{}),
168 util.CmdHandler(chat.SessionClearedMsg{}),
169 p.setCompactMode(false),
169 p.setCompactMode(false),
170+ p.layout.FocusPanel(layout.BottomPanel),
171+ util.CmdHandler(ChatFocusedMsg{Focused: false}),
170 )
172 )
171 case key.Matches(msg, p.keyMap.AddAttachment):
173 case key.Matches(msg, p.keyMap.AddAttachment):
172 cfg := config.Get()
174 cfg := config.Get()
@@ -238,7 +240,7 @@ func (p *chatPage) setMessages() tea.Cmd {
238}
240}
239
241
240func (p *chatPage) setSidebar() tea.Cmd {
242func (p *chatPage) setSidebar() tea.Cmd {
241− sidebarContainer := sidebarCmp(p.app, false)
243+ sidebarContainer := sidebarCmp(p.app, false, p.session)
242 sidebarContainer.Init()
244 sidebarContainer.Init()
243 return p.layout.SetRightPanel(sidebarContainer)
245 return p.layout.SetRightPanel(sidebarContainer)
244}
246}
@@ -378,13 +380,18 @@ func (p *chatPage) Bindings() []key.Binding {
378 return bindings
380 return bindings
379}
381}
380
382
381−func sidebarCmp(app *app.App, compact bool) layout.Container {
383+func sidebarCmp(app *app.App, compact bool, session session.Session) layout.Container {
382 padding := layout.WithPadding(1, 1, 1, 1)
384 padding := layout.WithPadding(1, 1, 1, 1)
383 if compact {
385 if compact {
384 padding = layout.WithPadding(0, 1, 1, 1)
386 padding = layout.WithPadding(0, 1, 1, 1)
385 }
387 }
388+ sidebar := sidebar.NewSidebarCmp(app.History, app.LSPClients, compact)
389+ if session.ID != "" {
390+ sidebar.SetSession(session)
391+ }
392+
386 return layout.NewContainer(
393 return layout.NewContainer(
387− sidebar.NewSidebarCmp(app.History, app.LSPClients, compact),
394+ sidebar,
388 padding,
395 padding,
389 )
396 )
390}
397}
@@ -396,12 +403,12 @@ func NewChatPage(app *app.App) ChatPage {
396 return &chatPage{
403 return &chatPage{
397 app: app,
404 app: app,
398 layout: layout.NewSplitPane(
405 layout: layout.NewSplitPane(
399− layout.WithRightPanel(sidebarCmp(app, false)),
406+ layout.WithRightPanel(sidebarCmp(app, false, session.Session{})),
400 layout.WithBottomPanel(editorContainer),
407 layout.WithBottomPanel(editorContainer),
401 layout.WithFixedBottomHeight(5),
408 layout.WithFixedBottomHeight(5),
402 layout.WithFixedRightWidth(31),
409 layout.WithFixedRightWidth(31),
403 ),
410 ),
404− compactSidebar: sidebarCmp(app, true),
411+ compactSidebar: sidebarCmp(app, true, session.Session{}),
405 keyMap: DefaultKeyMap(),
412 keyMap: DefaultKeyMap(),
406 header: header.New(app.LSPClients),
413 header: header.New(app.LSPClients),
407 }
414 }