Skip to content

Commit

Permalink
Improve close button quitting process (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
akiyosi committed Nov 6, 2022
1 parent 5aa2c0f commit 6754452
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions editor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type editorConfig struct {
IgnoreFirstMouseClickWhenAppInactivated bool
HideTitlebar bool
HideMouseWhenTyping bool
IgnoreSaveConfirmationWithCloseButton bool
}

type cursorConfig struct {
Expand Down
27 changes: 21 additions & 6 deletions editor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,28 @@ func InitEditor(options Options, args []string) {
// When an application is closed with the Close button
e.window.ConnectCloseEvent(func(event *gui.QCloseEvent) {
e.putLog("The application was closed outside of Neovim's commands, such as the Close button.")
e.cleanup()
e.saveSessions()
if runtime.GOOS == "darwin" {
e.app.DisconnectEvent()

// A request to exit the application via the close button has been issued,
// intercept this request and send quit command to the nvim process.
event.Ignore()

if e.config.Workspace.RestoreSession {
e.cleanup()
e.saveSessions()
}
e.saveAppWindowState()
event.Accept()

var cmd string
if e.config.Editor.IgnoreSaveConfirmationWithCloseButton {
cmd = "qa!"
} else {
cmd = "confirm qa"
}

for _, ws := range e.workspaces {
go ws.nvim.Command(cmd)
}

return
})

// runs goroutine to detect stop events and quit the application
Expand Down

0 comments on commit 6754452

Please sign in to comment.