on main help sign in
Merge remote-tracking branch 'origin/main' into onboarding
commitfda5f0f8e7242dd9331ceae8a455a4f8f5edd880 authorKujtim Hoxha <kujtimii.h@gmail.com> dateThu 10 Jul 2025, 09:56 (1 year ago) parent2794e4572f469e
4 files changed+36−2
internal/tui/components/chat/editor/editor.go+8−1 internal/tui/components/chat/editor/keys.go+16 internal/tui/page/chat/chat.go+4 internal/tui/tui.go+8−1
internal/tui/components/chat/editor/editor.go+8−1
@@ -157,6 +157,9 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
157157 var cmd tea.Cmd
158158 var cmds []tea.Cmd
159159 switch msg := msg.(type) {
160+ case tea.KeyboardEnhancementsMsg:
161+ m.keyMap.keyboard = msg
162+ return m, nil
160163 case filepicker.FilePickedMsg:
161164 if len(m.attachments) >= maxAttachments {
162165 return m, util.ReportError(fmt.Errorf("cannot add more than %d images", maxAttachments))
@@ -252,7 +255,11 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
252255 m.deleteMode = false
253256 return m, nil
254257 }
255− // Hanlde Enter key
258+ if key.Matches(msg, m.keyMap.Newline) {
259+ m.textarea.InsertRune('\n')
260+ return m, nil
261+ }
262+ // Handle Enter key
256263 if m.textarea.Focused() && key.Matches(msg, m.keyMap.SendMessage) {
257264 value := m.textarea.Value()
258265 if len(value) > 0 && value[len(value)-1] == '\\' {
internal/tui/components/chat/editor/keys.go+16
@@ -2,12 +2,16 @@ package editor
22
33import (
44 "github.com/charmbracelet/bubbles/v2/key"
5+ tea "github.com/charmbracelet/bubbletea/v2"
56)
67
78type EditorKeyMap struct {
89 AddFile key.Binding
910 SendMessage key.Binding
1011 OpenEditor key.Binding
12+ Newline key.Binding
13+
14+ keyboard tea.KeyboardEnhancementsMsg
1115}
1216
1317func DefaultEditorKeyMap() EditorKeyMap {
@@ -24,15 +28,27 @@ func DefaultEditorKeyMap() EditorKeyMap {
2428 key.WithKeys("ctrl+e"),
2529 key.WithHelp("ctrl+e", "open editor"),
2630 ),
31+ Newline: key.NewBinding(
32+ key.WithKeys("shift+enter", "ctrl+j"),
33+ // "ctrl+j" is a common keybinding for newline in many editors. If
34+ // the terminal supports "shift+enter", we substitute the help text
35+ // to reflect that.
36+ key.WithHelp("ctrl+j", "newline"),
37+ ),
2738 }
2839}
2940
3041// KeyBindings implements layout.KeyMapProvider
3142func (k EditorKeyMap) KeyBindings() []key.Binding {
43+ newline := k.Newline
44+ if k.keyboard.SupportsKeyDisambiguation() {
45+ newline.SetHelp("shift+enter", newline.Help().Desc)
46+ }
3247 return []key.Binding{
3348 k.AddFile,
3449 k.SendMessage,
3550 k.OpenEditor,
51+ newline,
3652 }
3753}
3854
internal/tui/page/chat/chat.go+4
@@ -152,6 +152,10 @@ func (p *chatPage) Init() tea.Cmd {
152152func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
153153 var cmds []tea.Cmd
154154 switch msg := msg.(type) {
155+ case tea.KeyboardEnhancementsMsg:
156+ m, cmd := p.editor.Update(msg)
157+ p.editor = m.(editor.Editor)
158+ return p, cmd
155159 case tea.WindowSizeMsg:
156160 return p, p.SetSize(msg.Width, msg.Height)
157161 case CancelTimerExpiredMsg:
internal/tui/tui.go+8−1
@@ -99,7 +99,14 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9999
100100 switch msg := msg.(type) {
101101 case tea.KeyboardEnhancementsMsg:
102− return a, nil
102+ for id, page := range a.pages {
103+ m, pageCmd := page.Update(msg)
104+ a.pages[id] = m.(util.Model)
105+ if pageCmd != nil {
106+ cmds = append(cmds, pageCmd)
107+ }
108+ }
109+ return a, tea.Batch(cmds...)
103110 case tea.WindowSizeMsg:
104111 return a, a.handleWindowResize(msg.Width, msg.Height)
105112