Skip to content

Commit 99687f3

Browse files
committed
edit/edcore: Save the terminal restore callback once and reuse.
This fixes elves#706.
1 parent 14feeb8 commit 99687f3

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

edit/edcore/edit.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ type editor struct {
6060
navigation *navigation
6161
listing *listingMode
6262

63+
restoreTerminal func() error
64+
6365
editorState
6466
}
6567

6668
type editorState struct {
6769
// States used during ReadLine. Reset at the beginning of ReadLine.
68-
restoreTerminal func() error
69-
7070
notificationMutex sync.Mutex
7171

7272
notifications []string
@@ -313,7 +313,12 @@ func (ed *editor) startReadLine() error {
313313
}
314314
return err
315315
}
316-
ed.restoreTerminal = restoreTerminal
316+
// Save the restore callback when Readline is called for the first time, and
317+
// reuse that callback. This is guard against commands that misbehave and
318+
// put the terminal in a bad state when it quits.
319+
if ed.restoreTerminal == nil {
320+
ed.restoreTerminal = restoreTerminal
321+
}
317322

318323
return nil
319324
}
@@ -419,8 +424,7 @@ MainLoop:
419424
// Start over
420425
ed.mode.Teardown()
421426
ed.editorState = editorState{
422-
restoreTerminal: ed.restoreTerminal,
423-
isExternal: ed.isExternal,
427+
isExternal: ed.isExternal,
424428
}
425429
ed.SetModeInsert()
426430
fresh = true

0 commit comments

Comments
 (0)