Skip to content

Commit f852edf

Browse files
committed
Improve close button quitting process (#422)
1 parent ff86b87 commit f852edf

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

Diff for: editor/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ type editorConfig struct {
8484
IgnoreFirstMouseClickWhenAppInactivated bool
8585
HideTitlebar bool
8686
HideMouseWhenTyping bool
87+
IgnoreSaveConfirmationWithCloseButton bool
8788
}
8889

8990
type cursorConfig struct {

Diff for: editor/editor.go

+21-6
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,28 @@ func InitEditor(options Options, args []string) {
328328
// When an application is closed with the Close button
329329
e.window.ConnectCloseEvent(func(event *gui.QCloseEvent) {
330330
e.putLog("The application was closed outside of Neovim's commands, such as the Close button.")
331-
e.cleanup()
332-
e.saveSessions()
333-
if runtime.GOOS == "darwin" {
334-
e.app.DisconnectEvent()
331+
332+
// A request to exit the application via the close button has been issued,
333+
// intercept this request and send quit command to the nvim process.
334+
event.Ignore()
335+
336+
if e.config.Workspace.RestoreSession {
337+
e.cleanup()
338+
e.saveSessions()
335339
}
336-
e.saveAppWindowState()
337-
event.Accept()
340+
341+
var cmd string
342+
if e.config.Editor.IgnoreSaveConfirmationWithCloseButton {
343+
cmd = "qa!"
344+
} else {
345+
cmd = "confirm qa"
346+
}
347+
348+
for _, ws := range e.workspaces {
349+
go ws.nvim.Command(cmd)
350+
}
351+
352+
return
338353
})
339354

340355
// runs goroutine to detect stop events and quit the application

Diff for: runtime/doc/goneovim.txt

+15-11
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,17 @@ All Options are follows:
330330
## All of the following commented configuration items have default values.
331331
332332
[Editor]
333+
## If enabled, when the Close button of the application window is clicked,
334+
## the application will exit without confirmation, even if there are unsaved
335+
## updates.
336+
IgnoreSaveConfirmationWithCloseButton = false
337+
333338
## Makes the application window frameless.
334339
# BorderlessWindow = false
335340
336341
## Controls whether the title bar is displayed when the borderless
337-
## window setting is enabled.
338-
# HideTitlebar = false
342+
## window setting is enabled.
343+
# HideTitlebar = false
339344
340345
## Editor minimum window width (>= 400)
341346
# Width = 800
@@ -354,12 +359,12 @@ All Options are follows:
354359
# LineToScroll = 1
355360
356361
## MouseScrollingUnit sets the mode of mouse scrolling.
357-
## "line" scrolls in lines.
358-
## "pixel" scrolls in pixels.
359-
## "smart" scrolls in pixels when the amount of scrolling is small, and
360-
## scrolls in lines when the amount of scrolling is large.
361-
## The default value is "smart" on macos, and "line" on other operating systems.
362-
# MouseScrollingUnit = "line"
362+
## "line" scrolls in lines.
363+
## "pixel" scrolls in pixels.
364+
## "smart" scrolls in pixels when the amount of scrolling is small, and
365+
## scrolls in lines when the amount of scrolling is large.
366+
## The default value is "smart" on macos, and "line" on other operating systems.
367+
# MouseScrollingUnit = "line"
363368
364369
## This option makes the whole GUI window in semi-transparent.
365370
## This setting also implicitly enables the Drawborder setting
@@ -434,11 +439,10 @@ All Options are follows:
434439
## "normal", "insert", "replace", "visual", "visual_select",
435440
## "cmdline_normal", "cmdline_insert", "cmdline_replace", etc.
436441
# ModeEnablingIME = []
437-
438442
439443
## This option allows you to hide the mouse cursor in the gooneovim window
440-
## when you type a key, and to redisplay it when you move the mouse cursor again.
441-
# HideMouseWhenTyping = false
444+
## when you type a key, and to redisplay it when you move the mouse cursor again.
445+
# HideMouseWhenTyping = false
442446
443447
## Draw borders on the GUI side instead of the vertical border and status line that nvim draws.
444448
# DrawWindowSeparator = false

0 commit comments

Comments
 (0)