@@ -24,7 +24,33 @@ func NewConfirmationHelper(c *HelperCommon) *ConfirmationHelper {
2424// This file is for the rendering of confirmation panels along with setting and handling associated
2525// keybindings.
2626
27+ func (self * ConfirmationHelper ) closeAndCallConfirmationFunction (cancel goContext.CancelFunc , function func () error ) error {
28+ cancel ()
29+
30+ self .c .Context ().Pop ()
31+
32+ if function != nil {
33+ if err := function (); err != nil {
34+ return err
35+ }
36+ }
37+
38+ return nil
39+ }
40+
2741func (self * ConfirmationHelper ) wrappedConfirmationFunction (cancel goContext.CancelFunc , function func () error ) func () error {
42+ return func () error {
43+ return self .closeAndCallConfirmationFunction (cancel , function )
44+ }
45+ }
46+
47+ func (self * ConfirmationHelper ) wrappedPromptConfirmationFunction (
48+ cancel goContext.CancelFunc ,
49+ function func (string ) error ,
50+ getResponse func () string ,
51+ allowEmptyInput bool ,
52+ preserveWhitespace bool ,
53+ ) func () error {
2854 return func () error {
2955 if self .c .GocuiGui ().IsPasting {
3056 // The user is pasting multi-line text into a prompt; we don't want to handle the
@@ -34,26 +60,22 @@ func (self *ConfirmationHelper) wrappedConfirmationFunction(cancel goContext.Can
3460 return nil
3561 }
3662
37- cancel ()
38-
39- self .c .Context ().Pop ()
63+ response := getResponse ()
64+ if ! preserveWhitespace {
65+ response = strings .TrimSpace (response )
66+ }
4067
41- if function != nil {
42- if err := function (); err != nil {
43- return err
44- }
68+ if response == "" && ! allowEmptyInput {
69+ self .c .ErrorToast (self .c .Tr .PromptInputCannotBeEmptyToast )
70+ return nil
4571 }
4672
47- return nil
73+ return self .closeAndCallConfirmationFunction (cancel , func () error {
74+ return function (response )
75+ })
4876 }
4977}
5078
51- func (self * ConfirmationHelper ) wrappedPromptConfirmationFunction (cancel goContext.CancelFunc , function func (string ) error , getResponse func () string ) func () error {
52- return self .wrappedConfirmationFunction (cancel , func () error {
53- return function (getResponse ())
54- })
55- }
56-
5779func (self * ConfirmationHelper ) DeactivateConfirmation () {
5880 self .c .Mutexes ().PopupMutex .Lock ()
5981 self .c .State ().GetRepoState ().SetCurrentPopupOpts (nil )
@@ -229,12 +251,15 @@ func (self *ConfirmationHelper) setConfirmationKeyBindings(cancel goContext.Canc
229251
230252func (self * ConfirmationHelper ) setPromptKeyBindings (cancel goContext.CancelFunc , opts types.CreatePopupPanelOpts ) {
231253 onConfirm := self .wrappedPromptConfirmationFunction (cancel , opts .HandleConfirmPrompt ,
232- func () string { return self .c .Views ().Prompt .TextArea .GetContent () })
254+ func () string { return self .c .Views ().Prompt .TextArea .GetContent () },
255+ opts .AllowEmptyInput , opts .PreserveWhitespace )
233256
234257 onSuggestionConfirm := self .wrappedPromptConfirmationFunction (
235258 cancel ,
236259 opts .HandleConfirmPrompt ,
237260 self .getSelectedSuggestionValue ,
261+ opts .AllowEmptyInput ,
262+ opts .PreserveWhitespace ,
238263 )
239264
240265 onClose := self .wrappedConfirmationFunction (cancel , opts .HandleClose )
0 commit comments