@@ -85,8 +85,10 @@ func (c *Cmdline) Run() {
85
85
c .mu .Unlock ()
86
86
continue
87
87
case event .ExecuteCmdline :
88
- c .execute ()
89
- c .saveHistory ()
88
+ if c .execute () {
89
+ c .mu .Unlock ()
90
+ continue
91
+ }
90
92
default :
91
93
c .mu .Unlock ()
92
94
continue
@@ -199,16 +201,16 @@ func (c *Cmdline) complete(forward bool) {
199
201
c .cursor = len (c .cmdline )
200
202
}
201
203
202
- func (c * Cmdline ) execute () {
204
+ func (c * Cmdline ) execute () (finish bool ) {
205
+ defer c .saveHistory ()
203
206
switch c .typ {
204
207
case ':' :
205
208
cmd , r , bang , _ , arg , err := parse (string (c .cmdline ))
206
209
if err != nil {
207
210
c .eventCh <- event.Event {Type : event .Error , Error : err }
208
- return
209
- }
210
- if cmd .name != "" {
211
+ } else if cmd .name != "" {
211
212
c .eventCh <- event.Event {Type : cmd .eventType , Range : r , CmdName : cmd .name , Bang : bang , Arg : arg }
213
+ finish = cmd .eventType == event .QuitAll || cmd .eventType == event .QuitErr
212
214
}
213
215
case '/' :
214
216
c .eventCh <- event.Event {Type : event .ExecuteSearch , Arg : string (c .cmdline ), Rune : '/' }
@@ -217,10 +219,14 @@ func (c *Cmdline) execute() {
217
219
default :
218
220
panic ("cmdline.Cmdline.execute: unreachable" )
219
221
}
222
+ return
220
223
}
221
224
222
225
func (c * Cmdline ) saveHistory () {
223
226
cmdline := string (c .cmdline )
227
+ if cmdline == "" {
228
+ return
229
+ }
224
230
for i , h := range c .history {
225
231
if h == cmdline {
226
232
c .history = slices .Delete (c .history , i , i + 1 )
0 commit comments