Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cda815b

Browse files
committedOct 17, 2024·
skip redraw when cmdline emits an event to finish the editor
1 parent ecaa702 commit cda815b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed
 

‎cmdline/cmdline.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ func (c *Cmdline) Run() {
8585
c.mu.Unlock()
8686
continue
8787
case event.ExecuteCmdline:
88-
c.execute()
89-
c.saveHistory()
88+
if c.execute() {
89+
c.mu.Unlock()
90+
continue
91+
}
9092
default:
9193
c.mu.Unlock()
9294
continue
@@ -199,16 +201,16 @@ func (c *Cmdline) complete(forward bool) {
199201
c.cursor = len(c.cmdline)
200202
}
201203

202-
func (c *Cmdline) execute() {
204+
func (c *Cmdline) execute() (finish bool) {
205+
defer c.saveHistory()
203206
switch c.typ {
204207
case ':':
205208
cmd, r, bang, _, arg, err := parse(string(c.cmdline))
206209
if err != nil {
207210
c.eventCh <- event.Event{Type: event.Error, Error: err}
208-
return
209-
}
210-
if cmd.name != "" {
211+
} else if cmd.name != "" {
211212
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
212214
}
213215
case '/':
214216
c.eventCh <- event.Event{Type: event.ExecuteSearch, Arg: string(c.cmdline), Rune: '/'}
@@ -217,10 +219,14 @@ func (c *Cmdline) execute() {
217219
default:
218220
panic("cmdline.Cmdline.execute: unreachable")
219221
}
222+
return
220223
}
221224

222225
func (c *Cmdline) saveHistory() {
223226
cmdline := string(c.cmdline)
227+
if cmdline == "" {
228+
return
229+
}
224230
for i, h := range c.history {
225231
if h == cmdline {
226232
c.history = slices.Delete(c.history, i, i+1)

0 commit comments

Comments
 (0)
Please sign in to comment.