From 42a12fd60da256d28531189c20a4641c64656a5f Mon Sep 17 00:00:00 2001 From: ras0q Date: Sat, 26 Jul 2025 13:25:49 +0900 Subject: [PATCH] fix: Delegate unhandled messages to the focused model Currently, chatPage does not handle anything other than special events. As a result, API/command responses from child models are passed to the parent and processed without being communicated to the child (for example, it is currently possible to open an external editor, but the new text after closing the editor is not reflected in Crush's editor). As an alternative solution, it is possible to export the child's tea.Msg to the parent to address this issue, but we would prefer to handle the logic closed in the child without communicating the details to the parent as much as possible. --- internal/tui/page/chat/chat.go | 48 ++++++++++++---------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/internal/tui/page/chat/chat.go b/internal/tui/page/chat/chat.go index c03a369ae371c0b9fadb9cd170e35618aa5e5b40..fd2f7849358b2b48961776dc2f7d7cb5bc1488b5 100644 --- a/internal/tui/page/chat/chat.go +++ b/internal/tui/page/chat/chat.go @@ -299,40 +299,24 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { p.toggleDetails() return p, nil } + } - switch p.focusedPane { - case PanelTypeChat: - u, cmd := p.chat.Update(msg) - p.chat = u.(chat.MessageListCmp) - cmds = append(cmds, cmd) - case PanelTypeEditor: - u, cmd := p.editor.Update(msg) - p.editor = u.(editor.Editor) - cmds = append(cmds, cmd) - case PanelTypeSplash: - u, cmd := p.splash.Update(msg) - p.splash = u.(splash.Splash) - cmds = append(cmds, cmd) - } - case tea.PasteMsg: - switch p.focusedPane { - case PanelTypeEditor: - u, cmd := p.editor.Update(msg) - p.editor = u.(editor.Editor) - cmds = append(cmds, cmd) - return p, tea.Batch(cmds...) - case PanelTypeChat: - u, cmd := p.chat.Update(msg) - p.chat = u.(chat.MessageListCmp) - cmds = append(cmds, cmd) - return p, tea.Batch(cmds...) - case PanelTypeSplash: - u, cmd := p.splash.Update(msg) - p.splash = u.(splash.Splash) - cmds = append(cmds, cmd) - return p, tea.Batch(cmds...) - } + // Delegate other messages to the focused pane model + switch p.focusedPane { + case PanelTypeEditor: + u, cmd := p.editor.Update(msg) + p.editor = u.(editor.Editor) + cmds = append(cmds, cmd) + case PanelTypeChat: + u, cmd := p.chat.Update(msg) + p.chat = u.(chat.MessageListCmp) + cmds = append(cmds, cmd) + case PanelTypeSplash: + u, cmd := p.splash.Update(msg) + p.splash = u.(splash.Splash) + cmds = append(cmds, cmd) } + return p, tea.Batch(cmds...) }