diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index 83fa60676d13400179bdc1714ee26df6b1351a32..0ee9fc94b4915ecb0ca6732cf8c8b9431c5e0ca3 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -653,19 +653,15 @@ func (m *editorCmp) stepOverHistory(resolveHistoricMessages func(context.Context return messageHistory[0] } + // the first time we invoke scroll we need to start from top of the list if !m.previouslyScrollingPromptHistory { m.promptHistoryIndex = len(messageHistory) - 1 m.previouslyScrollingPromptHistory = true } - defer func() { - if !m.scrollingPromptHistory { - m.scrollingPromptHistory = m.promptHistoryIndex < len(messageHistory)-2 - } - }() - switch resolveDirection() { case previous: + m.scrollingPromptHistory = true return m.stepBack(messageHistory) case next: return m.stepForward(messageHistory) @@ -683,12 +679,12 @@ func (m *editorCmp) stepBack(history []string) string { func (m *editorCmp) stepForward(history []string) string { m.promptHistoryIndex += 1 - if m.promptHistoryIndex > len(history)-1 { - offset := 1 - if m.scrollingPromptHistory { - offset = 2 - } - m.promptHistoryIndex = len(history) - offset + maxIndex := len(history) - 1 + if m.scrollingPromptHistory { + maxIndex = len(history) - 2 + } + if m.promptHistoryIndex > maxIndex { + m.promptHistoryIndex = maxIndex } return history[m.promptHistoryIndex] }