Generalize save prompt on close code into method

This slightly changes the open and term command to be similar with the
Quit action, where the buffer or pane is replaced after the prompts are
completed if "n" wasn't pressed after the 1st prompt.
This commit is contained in:
niten94
2025-04-18 19:21:27 +08:00
parent 0d5b2b73e3
commit c457ae421a
2 changed files with 17 additions and 23 deletions

View File

@@ -309,14 +309,7 @@ func (h *BufPane) OpenCmd(args []string) {
h.OpenBuffer(b)
}
if h.Buf.Modified() && !h.Buf.Shared() {
InfoBar.YNPrompt("Save changes to "+h.Buf.GetName()+" before closing? (y,n,esc)", func(yes, canceled bool) {
if !canceled && !yes {
open()
} else if !canceled && yes {
h.Save()
open()
}
})
h.closePrompt("Save", open)
} else {
open()
}
@@ -1122,13 +1115,8 @@ func (h *BufPane) TermCmd(args []string) {
for i, p := range ps {
if p.ID() == h.ID() {
if h.Buf.Modified() && !h.Buf.Shared() {
InfoBar.YNPrompt("Save changes to "+h.Buf.GetName()+" before closing? (y,n,esc)", func(yes, canceled bool) {
if !canceled && !yes {
term(i, false)
} else if !canceled && yes {
h.Save()
term(i, false)
}
h.closePrompt("Save", func() {
term(i, false)
})
} else {
term(i, false)