@@ -529,13 +529,18 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
529529 m.dialog.Update(msg)
530530 return m, tea.Batch(cmds...)
531531 }
532+
533+ if cmd := m.handleClickFocus(msg); cmd != nil {
534+ cmds = append(cmds, cmd)
535+ }
536+
532537 switch m.state {
533538 case uiChat:
534539 x, y := msg.X, msg.Y
535540 // Adjust for chat area position
536541 x -= m.layout.main.Min.X
537542 y -= m.layout.main.Min.Y
538− if m.chat.HandleMouseDown(x, y) {
543+ if !image.Pt(msg.X, msg.Y).In(m.layout.sidebar) && m.chat.HandleMouseDown(x, y) {
539544 m.lastClickTime = time.Now()
540545 }
541546 }
@@ -897,6 +902,24 @@ func (m *UI) appendSessionMessage(msg message.Message) tea.Cmd {
897902 return tea.Batch(cmds...)
898903}
899904
905+func (m *UI) handleClickFocus(msg tea.MouseClickMsg) (cmd tea.Cmd) {
906+ switch {
907+ case m.state != uiChat:
908+ return nil
909+ case image.Pt(msg.X, msg.Y).In(m.layout.sidebar):
910+ return nil
911+ case m.focus != uiFocusEditor && image.Pt(msg.X, msg.Y).In(m.layout.editor):
912+ m.focus = uiFocusEditor
913+ cmd = m.textarea.Focus()
914+ m.chat.Blur()
915+ case m.focus != uiFocusMain && image.Pt(msg.X, msg.Y).In(m.layout.main):
916+ m.focus = uiFocusMain
917+ m.textarea.Blur()
918+ m.chat.Focus()
919+ }
920+ return cmd
921+}
922+
900923// updateSessionMessage updates an existing message in the current session in the chat
901924// when an assistant message is updated it may include updated tool calls as well
902925// that is why we need to handle creating/updating each tool call message too