on main help sign in
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.

commit50e759685d05b193822dc5d12f3c8528043c62d7 authorAyman Bagabas <ayman.bagabas@gmail.com> dateTue 8 Jul 2025, 16:48 (1 year ago) parentf4c7c5c
2 files changed+11−1
internal/tui/components/chat/editor/editor.go+5−1 internal/tui/components/chat/editor/keys.go+6
internal/tui/components/chat/editor/editor.go+5−1
@@ -245,7 +245,11 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
245245 m.deleteMode = false
246246 return m, nil
247247 }
248− // Hanlde Enter key
248+ if key.Matches(msg, m.keyMap.Newline) {
249+ m.textarea.InsertRune('\n')
250+ return m, nil
251+ }
252+ // Handle Enter key
249253 if m.textarea.Focused() && key.Matches(msg, m.keyMap.SendMessage) {
250254 value := m.textarea.Value()
251255 if len(value) > 0 && value[len(value)-1] == '\\' {
internal/tui/components/chat/editor/keys.go+6
@@ -8,6 +8,7 @@ type EditorKeyMap struct {
88 AddFile key.Binding
99 SendMessage key.Binding
1010 OpenEditor key.Binding
11+ Newline key.Binding
1112}
1213
1314func DefaultEditorKeyMap() EditorKeyMap {
@@ -24,6 +25,10 @@ func DefaultEditorKeyMap() EditorKeyMap {
2425 key.WithKeys("ctrl+e"),
2526 key.WithHelp("ctrl+e", "open editor"),
2627 ),
28+ Newline: key.NewBinding(
29+ key.WithKeys("shift+enter", "ctrl+j"),
30+ key.WithHelp("shift+enter", "newline"), key.WithHelp("ctrl+j", "newline"),
31+ ),
2732 }
2833}
2934
@@ -33,6 +38,7 @@ func (k EditorKeyMap) KeyBindings() []key.Binding {
3338 k.AddFile,
3439 k.SendMessage,
3540 k.OpenEditor,
41+ k.Newline,
3642 }
3743}
3844