feat(tui): support adding newlines in chat editor

Ayman Bagabas created

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.

Change summary

internal/tui/components/chat/editor/editor.go | 6 +++++-
internal/tui/components/chat/editor/keys.go   | 6 ++++++
2 files changed, 11 insertions(+), 1 deletion(-)

Detailed changes

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] == '\\' {

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,
 	}
 }