From f979ca4ba4919053f34c2888dd7f640db79a5b76 Mon Sep 17 00:00:00 2001 From: tauraamui Date: Wed, 15 Oct 2025 16:56:14 +0100 Subject: [PATCH] fix: restore users previous prompt content when scrolled back down --- internal/tui/components/chat/editor/editor.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index 69434773b184b65d6fdfb3caa11c2b29646e9030..c962e1f45cb028ebdea7dcc1e07c5d0c97535171 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -77,6 +77,7 @@ type editorCmp struct { previouslyScrollingPromptHistory bool scrollingPromptHistory bool promptHistoryIndex int + historyCache []string } var DeleteKeyMaps = DeleteAttachmentKeyMaps{ @@ -148,6 +149,9 @@ func (m *editorCmp) Init() tea.Cmd { } func (m *editorCmp) send() tea.Cmd { + defer func() { + m.resetHistory() + }() value := m.textarea.Value() value = strings.TrimSpace(value) @@ -611,6 +615,9 @@ func yoloPromptFunc(info textarea.PromptInfo) string { } func (m *editorCmp) getUserMessagesAsText(ctx context.Context) ([]string, error) { + if len(m.historyCache) > 0 { + return m.historyCache, nil + } allMessages, err := m.app.Messages.List(ctx, m.session.ID) if err != nil { return nil, err @@ -624,6 +631,7 @@ func (m *editorCmp) getUserMessagesAsText(ctx context.Context) ([]string, error) } userMessages = append(userMessages, m.textarea.Value()) + m.historyCache = userMessages return userMessages, nil } @@ -688,6 +696,13 @@ func (m *editorCmp) stepForward(history []string) string { return history[m.promptHistoryIndex] } +func (m *editorCmp) resetHistory() { + m.historyCache = nil + m.promptHistoryIndex = 0 + m.previouslyScrollingPromptHistory = false + m.scrollingPromptHistory = false +} + func (m *editorCmp) handleMessageHistory(msg tea.KeyMsg) string { ctx := context.Background() userMessages, err := m.getUserMessagesAsText(ctx)