on main help sign in
Merge remote-tracking branch 'origin/main' into onboarding
fda5f0fKujtim Hoxha
internal/tui/components/chat/editor/editor.go+8−1
@@ -157,6 +157,9 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
157 var cmd tea.Cmd
157 var cmd tea.Cmd
158 var cmds []tea.Cmd
158 var cmds []tea.Cmd
159 switch msg := msg.(type) {
159 switch msg := msg.(type) {
160+ case tea.KeyboardEnhancementsMsg:
161+ m.keyMap.keyboard = msg
162+ return m, nil
160 case filepicker.FilePickedMsg:
163 case filepicker.FilePickedMsg:
161 if len(m.attachments) >= maxAttachments {
164 if len(m.attachments) >= maxAttachments {
162 return m, util.ReportError(fmt.Errorf("cannot add more than %d images", maxAttachments))
165 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) {
252 m.deleteMode = false
255 m.deleteMode = false
253 return m, nil
256 return m, nil
254 }
257 }
258+ if key.Matches(msg, m.keyMap.Newline) {
259+ m.textarea.InsertRune('\n')
260+ return m, nil
261+ }
255− // Hanlde Enter key
262+ // Handle Enter key
256 if m.textarea.Focused() && key.Matches(msg, m.keyMap.SendMessage) {
263 if m.textarea.Focused() && key.Matches(msg, m.keyMap.SendMessage) {
257 value := m.textarea.Value()
264 value := m.textarea.Value()
258 if len(value) > 0 && value[len(value)-1] == '\\' {
265 if len(value) > 0 && value[len(value)-1] == '\\' {
internal/tui/components/chat/editor/keys.go+16
@@ -2,12 +2,16 @@ package editor
2
2
3import (
3import (
4 "github.com/charmbracelet/bubbles/v2/key"
4 "github.com/charmbracelet/bubbles/v2/key"
5+ tea "github.com/charmbracelet/bubbletea/v2"
5)
6)
6
7
7type EditorKeyMap struct {
8type EditorKeyMap struct {
8 AddFile key.Binding
9 AddFile key.Binding
9 SendMessage key.Binding
10 SendMessage key.Binding
10 OpenEditor key.Binding
11 OpenEditor key.Binding
12+ Newline key.Binding
13+
14+ keyboard tea.KeyboardEnhancementsMsg
11}
15}
12
16
13func DefaultEditorKeyMap() EditorKeyMap {
17func DefaultEditorKeyMap() EditorKeyMap {
@@ -24,15 +28,27 @@ func DefaultEditorKeyMap() EditorKeyMap {
24 key.WithKeys("ctrl+e"),
28 key.WithKeys("ctrl+e"),
25 key.WithHelp("ctrl+e", "open editor"),
29 key.WithHelp("ctrl+e", "open editor"),
26 ),
30 ),
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+ ),
27 }
38 }
28}
39}
29
40
30// KeyBindings implements layout.KeyMapProvider
41// KeyBindings implements layout.KeyMapProvider
31func (k EditorKeyMap) KeyBindings() []key.Binding {
42func (k EditorKeyMap) KeyBindings() []key.Binding {
43+ newline := k.Newline
44+ if k.keyboard.SupportsKeyDisambiguation() {
45+ newline.SetHelp("shift+enter", newline.Help().Desc)
46+ }
32 return []key.Binding{
47 return []key.Binding{
33 k.AddFile,
48 k.AddFile,
34 k.SendMessage,
49 k.SendMessage,
35 k.OpenEditor,
50 k.OpenEditor,
51+ newline,
36 }
52 }
37}
53}
38
54
internal/tui/page/chat/chat.go+4
@@ -152,6 +152,10 @@ func (p *chatPage) Init() tea.Cmd {
152func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
152func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
153 var cmds []tea.Cmd
153 var cmds []tea.Cmd
154 switch msg := msg.(type) {
154 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
155 case tea.WindowSizeMsg:
159 case tea.WindowSizeMsg:
156 return p, p.SetSize(msg.Width, msg.Height)
160 return p, p.SetSize(msg.Width, msg.Height)
157 case CancelTimerExpiredMsg:
161 case CancelTimerExpiredMsg:
internal/tui/tui.go+8−1
@@ -99,7 +99,14 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
99
99
100 switch msg := msg.(type) {
100 switch msg := msg.(type) {
101 case tea.KeyboardEnhancementsMsg:
101 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...)
103 case tea.WindowSizeMsg:
110 case tea.WindowSizeMsg:
104 return a, a.handleWindowResize(msg.Width, msg.Height)
111 return a, a.handleWindowResize(msg.Width, msg.Height)
105
112