fix: modal pastes (#1677)
This commit is contained in:
@@ -131,10 +131,28 @@ func (s *SearchDialog) Init() tea.Cmd {
|
|||||||
return textinput.Blink
|
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) {
|
func (s *SearchDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
var cmds []tea.Cmd
|
var cmds []tea.Cmd
|
||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
|
case tea.PasteMsg, tea.ClipboardMsg:
|
||||||
|
cmds = append(cmds, s.updateTextInput(msg)...)
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "ctrl+c":
|
case "ctrl+c":
|
||||||
@@ -183,17 +201,7 @@ func (s *SearchDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
oldValue := s.textInput.Value()
|
cmds = append(cmds, s.updateTextInput(msg)...)
|
||||||
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}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -612,6 +612,17 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
a.editor.SetExitKeyInDebounce(false)
|
a.editor.SetExitKeyInDebounce(false)
|
||||||
case dialog.FindSelectedMsg:
|
case dialog.FindSelectedMsg:
|
||||||
return a.openFile(msg.FilePath)
|
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
|
// API
|
||||||
case api.Request:
|
case api.Request:
|
||||||
@@ -679,17 +690,17 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
cmds = append(cmds, cmd)
|
cmds = append(cmds, cmd)
|
||||||
a.status = s.(status.StatusComponent)
|
a.status = s.(status.StatusComponent)
|
||||||
|
|
||||||
u, cmd := a.editor.Update(msg)
|
updatedEditor, cmd := a.editor.Update(msg)
|
||||||
a.editor = u.(chat.EditorComponent)
|
a.editor = updatedEditor.(chat.EditorComponent)
|
||||||
cmds = append(cmds, cmd)
|
cmds = append(cmds, cmd)
|
||||||
|
|
||||||
u, cmd = a.messages.Update(msg)
|
updatedMessages, cmd := a.messages.Update(msg)
|
||||||
a.messages = u.(chat.MessagesComponent)
|
a.messages = updatedMessages.(chat.MessagesComponent)
|
||||||
cmds = append(cmds, cmd)
|
cmds = append(cmds, cmd)
|
||||||
|
|
||||||
if a.modal != nil {
|
if a.modal != nil {
|
||||||
u, cmd := a.modal.Update(msg)
|
updatedModal, cmd := a.modal.Update(msg)
|
||||||
a.modal = u.(layout.Modal)
|
a.modal = updatedModal.(layout.Modal)
|
||||||
cmds = append(cmds, cmd)
|
cmds = append(cmds, cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user