From 50e759685d05b193822dc5d12f3c8528043c62d7 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 8 Jul 2025 16:48:42 -0400 Subject: [PATCH] feat(tui): support adding newlines in chat editor This adds support for inserting newlines in the chat editor using `shift+enter` (when supported) and `ctrl+j`. This allows users to write multi-line messages more easily, enhancing the chat experience. --- internal/tui/components/chat/editor/editor.go | 6 +++++- internal/tui/components/chat/editor/keys.go | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index 30d3aeef80c57487e665952f699cd7b4522db214..f910efee3b0924ebf2c5f9e77fcf5233ef909d93 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -245,7 +245,11 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.deleteMode = false return m, nil } - // Hanlde Enter key + if key.Matches(msg, m.keyMap.Newline) { + m.textarea.InsertRune('\n') + return m, nil + } + // Handle Enter key if m.textarea.Focused() && key.Matches(msg, m.keyMap.SendMessage) { value := m.textarea.Value() if len(value) > 0 && value[len(value)-1] == '\\' { diff --git a/internal/tui/components/chat/editor/keys.go b/internal/tui/components/chat/editor/keys.go index c64a92d526a1a81e558909fe5500b2bf1d4e3990..738e575db220960b2a25b7cfe847901d978786d4 100644 --- a/internal/tui/components/chat/editor/keys.go +++ b/internal/tui/components/chat/editor/keys.go @@ -8,6 +8,7 @@ type EditorKeyMap struct { AddFile key.Binding SendMessage key.Binding OpenEditor key.Binding + Newline key.Binding } func DefaultEditorKeyMap() EditorKeyMap { @@ -24,6 +25,10 @@ func DefaultEditorKeyMap() EditorKeyMap { key.WithKeys("ctrl+e"), key.WithHelp("ctrl+e", "open editor"), ), + Newline: key.NewBinding( + key.WithKeys("shift+enter", "ctrl+j"), + key.WithHelp("shift+enter", "newline"), key.WithHelp("ctrl+j", "newline"), + ), } } @@ -33,6 +38,7 @@ func (k EditorKeyMap) KeyBindings() []key.Binding { k.AddFile, k.SendMessage, k.OpenEditor, + k.Newline, } }