diff --git a/internal/tui/components/chat/editor/history.go b/internal/tui/components/chat/editor/history.go index f90810ec61e3fa31f391ca8c26207c105a2c86c0..eb707f3b94884c476b080c23a8649fb57d2b69d1 100644 --- a/internal/tui/components/chat/editor/history.go +++ b/internal/tui/components/chat/editor/history.go @@ -3,7 +3,6 @@ package editor type historyState struct { previouslyScrollingPromptHistory bool promptHistoryIndex int - existingValue string historyCache []string } @@ -15,22 +14,27 @@ type History interface { } func InitialiseHistory(existingValue string, messages []string) History { + msgs := messages + msgs = append(msgs, existingValue) return &historyState{ - existingValue: existingValue, - historyCache: messages, - promptHistoryIndex: len(messages) - 1, + historyCache: msgs, + promptHistoryIndex: len(msgs) - 1, } } func (h *historyState) Value() string { - if len(h.historyCache) == 0 { - return h.existingValue + if len(h.historyCache) > 1 { + return h.historyCache[h.promptHistoryIndex] } - return h.historyCache[h.promptHistoryIndex] + return h.ExistingValue() } func (h *historyState) ExistingValue() string { - return h.existingValue + index := len(h.historyCache) - 1 + if index < 0 { + return "" + } + return h.historyCache[index] } func (h *historyState) ScrollUp() {