on main help sign in
fix(ui): switch focus on click (#2055)
6c26f2aAndrey Nering
internal/ui/model/ui.go+24−1
@@ -529,13 +529,18 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
529 m.dialog.Update(msg)
529 m.dialog.Update(msg)
530 return m, tea.Batch(cmds...)
530 return m, tea.Batch(cmds...)
531 }
531 }
532+
533+ if cmd := m.handleClickFocus(msg); cmd != nil {
534+ cmds = append(cmds, cmd)
535+ }
536+
532 switch m.state {
537 switch m.state {
533 case uiChat:
538 case uiChat:
534 x, y := msg.X, msg.Y
539 x, y := msg.X, msg.Y
535 // Adjust for chat area position
540 // Adjust for chat area position
536 x -= m.layout.main.Min.X
541 x -= m.layout.main.Min.X
537 y -= m.layout.main.Min.Y
542 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) {
539 m.lastClickTime = time.Now()
544 m.lastClickTime = time.Now()
540 }
545 }
541 }
546 }
@@ -897,6 +902,24 @@ func (m *UI) appendSessionMessage(msg message.Message) tea.Cmd {
897 return tea.Batch(cmds...)
902 return tea.Batch(cmds...)
898}
903}
899
904
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+
900// updateSessionMessage updates an existing message in the current session in the chat
923// updateSessionMessage updates an existing message in the current session in the chat
901// when an assistant message is updated it may include updated tool calls as well
924// when an assistant message is updated it may include updated tool calls as well
902// that is why we need to handle creating/updating each tool call message too
925// that is why we need to handle creating/updating each tool call message too