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