]> git.lizzy.rs Git - micro.git/commitdiff
Only perform save callback if save was successful
authorZachary Yedidia <zyedidia@gmail.com>
Fri, 29 May 2020 19:02:38 +0000 (15:02 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Fri, 29 May 2020 19:02:38 +0000 (15:02 -0400)
Fixes #1684

internal/action/actions.go

index ae19a3f917dfe2d7b30432d9a70a91c9ceec7be8..6f2f0940d4d851387af9ef32c5374ac8198dcc87 100644 (file)
@@ -727,6 +727,7 @@ func (h *BufPane) Save() bool {
 }
 
 // SaveAsCB performs a save as and does a callback at the very end (after all prompts have been resolved)
+// The callback is only called if the save was successful
 func (h *BufPane) SaveAsCB(action string, callback func()) bool {
        InfoBar.Prompt("Filename: ", "", "Save", nil, func(resp string, canceled bool) {
                if !canceled {
@@ -757,6 +758,7 @@ func (h *BufPane) SaveAs() bool {
 
 // This function saves the buffer to `filename` and changes the buffer's path and name
 // to `filename` if the save is successful
+// The callback is only called if the save was successful
 func (h *BufPane) saveBufToFile(filename string, action string, callback func()) bool {
        err := h.Buf.SaveAs(filename)
        if err != nil {
@@ -769,6 +771,9 @@ func (h *BufPane) saveBufToFile(filename string, action string, callback func())
                                        h.Buf.Path = filename
                                        h.Buf.SetName(filename)
                                        InfoBar.Message("Saved " + filename)
+                                       if callback != nil {
+                                               callback()
+                                       }
                                }
                        }
                        if h.Buf.Settings["autosu"].(bool) {
@@ -779,9 +784,6 @@ func (h *BufPane) saveBufToFile(filename string, action string, callback func())
                                                saveWithSudo()
                                                h.completeAction(action)
                                        }
-                                       if callback != nil {
-                                               callback()
-                                       }
                                })
                                return false
                        }
@@ -792,9 +794,9 @@ func (h *BufPane) saveBufToFile(filename string, action string, callback func())
                h.Buf.Path = filename
                h.Buf.SetName(filename)
                InfoBar.Message("Saved " + filename)
-       }
-       if callback != nil {
-               callback()
+               if callback != nil {
+                       callback()
+               }
        }
        return true
 }