diff options
| author | Timo Clasen <[email protected]> | 2025-07-21 22:10:50 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-21 15:10:50 -0500 |
| commit | bec796e3c3c097bfc7bb9090729ec23573151d79 (patch) | |
| tree | 92cd1a7114f78ccbe4ae3f2c54e0d5774916237a | |
| parent | 0bd8b2c72f0ef91e18377550f118d0b1b1ef928b (diff) | |
| download | opencode-bec796e3c3c097bfc7bb9090729ec23573151d79.tar.gz opencode-bec796e3c3c097bfc7bb9090729ec23573151d79.zip | |
feat(tui): add ctrl+p and ctrl-n to history navigation (#1199)
| -rw-r--r-- | STATS.md | 1 | ||||
| -rw-r--r-- | packages/tui/internal/components/chat/editor.go | 18 |
2 files changed, 11 insertions, 8 deletions
@@ -22,3 +22,4 @@ | 2025-07-18 | 70,379 (+3,695) | 102,587 (+2,539) | 172,966 (+6,234) | | 2025-07-19 | 73,497 (+3,117) | 105,904 (+3,317) | 179,401 (+6,434) | | 2025-07-20 | 76,453 (+2,956) | 109,044 (+3,140) | 185,497 (+6,096) | +| 2025-07-21 | 80,197 (+3,744) | 113,537 (+4,493) | 193,734 (+8,237) | diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go index dbd4f3dbb..74401dc6a 100644 --- a/packages/tui/internal/components/chat/editor.go +++ b/packages/tui/internal/components/chat/editor.go @@ -75,11 +75,12 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.spinner, cmd = m.spinner.Update(msg) return m, cmd case tea.KeyPressMsg: - // Handle up/down arrows for history navigation + // Handle up/down arrows and ctrl+p/ctrl+n for history navigation switch msg.String() { - case "up": - // Only navigate history if cursor is at the first line and column - if m.textarea.Line() == 0 && m.textarea.CursorColumn() == 0 && len(m.app.State.MessageHistory) > 0 { + case "up", "ctrl+p": + // Only navigate history if cursor is at the first line and column (for arrow keys) + // or allow ctrl+p from anywhere + if (msg.String() == "ctrl+p" || (m.textarea.Line() == 0 && m.textarea.CursorColumn() == 0)) && len(m.app.State.MessageHistory) > 0 { if m.historyIndex == -1 { // Save current text before entering history m.currentText = m.textarea.Value() @@ -93,9 +94,10 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } return m, nil } - case "down": - // Only navigate history if cursor is at the last line and we're in history navigation - if m.textarea.IsCursorAtEnd() && m.historyIndex > -1 { + case "down", "ctrl+n": + // Only navigate history if cursor is at the last line and we're in history navigation (for arrow keys) + // or allow ctrl+n from anywhere if we're in history navigation + if (msg.String() == "ctrl+n" || m.textarea.IsCursorAtEnd()) && m.historyIndex > -1 { // Move down in history (newer messages) m.historyIndex-- if m.historyIndex == -1 { @@ -108,7 +110,7 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.textarea.MoveToEnd() } return m, nil - } else if m.historyIndex > -1 { + } else if m.historyIndex > -1 && msg.String() == "down" { m.textarea.MoveToEnd() return m, nil } |
