@@ -21,9 +21,7 @@ type editorCmp struct {
21 textarea textarea.Model
21 textarea textarea.Model
24−type FocusEditorMsg bool
24+type EditorKeyMaps struct {
26−type focusedEditorKeyMaps struct {
27 Send key.Binding
25 Send key.Binding
28 OpenEditor key.Binding
26 OpenEditor key.Binding
@@ -34,10 +32,10 @@ type bluredEditorKeyMaps struct {
34 OpenEditor key.Binding
32 OpenEditor key.Binding
37−var KeyMaps = focusedEditorKeyMaps{
35+var editorMaps = EditorKeyMaps{
38 Send: key.NewBinding(
36 Send: key.NewBinding(
39− key.WithKeys("ctrl+s"),
37+ key.WithKeys("enter", "ctrl+s"),
40− key.WithHelp("ctrl+s", "send message"),
38+ key.WithHelp("enter", "send message"),
42 OpenEditor: key.NewBinding(
40 OpenEditor: key.NewBinding(
43 key.WithKeys("ctrl+e"),
41 key.WithKeys("ctrl+e"),
@@ -107,29 +105,24 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
107 m.session = msg
105 m.session = msg
109 return m, nil
107 return m, nil
110− case FocusEditorMsg:
113− return m, tea.Batch(textarea.Blink, util.CmdHandler(EditorFocusMsg(true)))
115 case tea.KeyMsg:
108 case tea.KeyMsg:
116 if key.Matches(msg, messageKeys.PageUp) || key.Matches(msg, messageKeys.PageDown) ||
109 if key.Matches(msg, messageKeys.PageUp) || key.Matches(msg, messageKeys.PageDown) ||
117 key.Matches(msg, messageKeys.HalfPageUp) || key.Matches(msg, messageKeys.HalfPageDown) {
110 key.Matches(msg, messageKeys.HalfPageUp) || key.Matches(msg, messageKeys.HalfPageDown) {
118 return m, nil
111 return m, nil
120− if key.Matches(msg, KeyMaps.OpenEditor) {
113+ if key.Matches(msg, editorMaps.OpenEditor) {
121 if m.app.CoderAgent.IsSessionBusy(m.session.ID) {
114 if m.app.CoderAgent.IsSessionBusy(m.session.ID) {
122 return m, util.ReportWarn("Agent is working, please wait...")
115 return m, util.ReportWarn("Agent is working, please wait...")
124 return m, openEditor()
117 return m, openEditor()
126 // if the key does not match any binding, return
119 // if the key does not match any binding, return
127− if m.textarea.Focused() && key.Matches(msg, KeyMaps.Send) {
120+ if m.textarea.Focused() && key.Matches(msg, editorMaps.Send) {
128 return m, m.send()
121 return m, m.send()
131 // Handle Enter key
124 // Handle Enter key
132− if m.textarea.Focused() && msg.String() == "enter" {
125+ if m.textarea.Focused() && key.Matches(msg, editorMaps.Send) {
133 value := m.textarea.Value()
126 value := m.textarea.Value()
134 if len(value) > 0 && value[len(value)-1] == '\\' {
127 if len(value) > 0 && value[len(value)-1] == '\\' {
135 // If the last character is a backslash, remove it and add a newline
128 // If the last character is a backslash, remove it and add a newline
@@ -163,7 +156,7 @@ func (m *editorCmp) GetSize() (int, int) {
164func (m *editorCmp) BindingKeys() []key.Binding {
157func (m *editorCmp) BindingKeys() []key.Binding {
165 bindings := []key.Binding{}
158 bindings := []key.Binding{}
166− bindings = append(bindings, layout.KeyMapToSlice(KeyMaps)...)
159+ bindings = append(bindings, layout.KeyMapToSlice(editorMaps)...)
167 return bindings
160 return bindings