diff --git a/packages/tui/internal/components/dialog/search.go b/packages/tui/internal/components/dialog/search.go index cdb2b824..b8fefd8b 100644 --- a/packages/tui/internal/components/dialog/search.go +++ b/packages/tui/internal/components/dialog/search.go @@ -131,10 +131,28 @@ func (s *SearchDialog) Init() tea.Cmd { return textinput.Blink } +func (s *SearchDialog) updateTextInput(msg tea.Msg) []tea.Cmd { + var cmds []tea.Cmd + oldValue := s.textInput.Value() + var cmd tea.Cmd + s.textInput, cmd = s.textInput.Update(msg) + if cmd != nil { + cmds = append(cmds, cmd) + } + if newValue := s.textInput.Value(); newValue != oldValue { + cmds = append(cmds, func() tea.Msg { + return SearchQueryChangedMsg{Query: newValue} + }) + } + return cmds +} + func (s *SearchDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmds []tea.Cmd switch msg := msg.(type) { + case tea.PasteMsg, tea.ClipboardMsg: + cmds = append(cmds, s.updateTextInput(msg)...) case tea.KeyMsg: switch msg.String() { case "ctrl+c": @@ -183,17 +201,7 @@ func (s *SearchDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } default: - oldValue := s.textInput.Value() - var cmd tea.Cmd - s.textInput, cmd = s.textInput.Update(msg) - if cmd != nil { - cmds = append(cmds, cmd) - } - if newValue := s.textInput.Value(); newValue != oldValue { - cmds = append(cmds, func() tea.Msg { - return SearchQueryChangedMsg{Query: newValue} - }) - } + cmds = append(cmds, s.updateTextInput(msg)...) } } diff --git a/packages/tui/internal/tui/tui.go b/packages/tui/internal/tui/tui.go index f108971d..7f5b4871 100644 --- a/packages/tui/internal/tui/tui.go +++ b/packages/tui/internal/tui/tui.go @@ -612,6 +612,17 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { a.editor.SetExitKeyInDebounce(false) case dialog.FindSelectedMsg: return a.openFile(msg.FilePath) + case tea.PasteMsg, tea.ClipboardMsg: + // Paste events: prioritize modal if active, otherwise editor + if a.modal != nil { + updatedModal, cmd := a.modal.Update(msg) + a.modal = updatedModal.(layout.Modal) + return a, cmd + } else { + updatedEditor, cmd := a.editor.Update(msg) + a.editor = updatedEditor.(chat.EditorComponent) + return a, cmd + } // API case api.Request: @@ -679,17 +690,17 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds = append(cmds, cmd) a.status = s.(status.StatusComponent) - u, cmd := a.editor.Update(msg) - a.editor = u.(chat.EditorComponent) + updatedEditor, cmd := a.editor.Update(msg) + a.editor = updatedEditor.(chat.EditorComponent) cmds = append(cmds, cmd) - u, cmd = a.messages.Update(msg) - a.messages = u.(chat.MessagesComponent) + updatedMessages, cmd := a.messages.Update(msg) + a.messages = updatedMessages.(chat.MessagesComponent) cmds = append(cmds, cmd) if a.modal != nil { - u, cmd := a.modal.Update(msg) - a.modal = u.(layout.Modal) + updatedModal, cmd := a.modal.Update(msg) + a.modal = updatedModal.(layout.Modal) cmds = append(cmds, cmd) }