mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-20 17:22:23 +03:00
Add AllowEmptyInput flag to PromptOpts
Most of our prompts don't (shouldn't) allow empty input, but most callers didn't check, and would run into cryptic errors when the user pressed enter at an empty prompt (e.g. when creating a new branch). Now we simply don't allow hitting enter in this case, and show an error toast instead. This behavior is opt-out, because there are a few cases where empty input is supported (e.g. creating a stash).
This commit is contained in:
@@ -1211,6 +1211,7 @@ func (self *FilesController) handleStashSave(stashFunc func(message string) erro
|
|||||||
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH, types.FILES}})
|
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH, types.FILES}})
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
AllowEmptyInput: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -44,7 +44,12 @@ func (self *ConfirmationHelper) wrappedConfirmationFunction(cancel goContext.Can
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ConfirmationHelper) wrappedPromptConfirmationFunction(cancel goContext.CancelFunc, function func(string) error, getResponse func() string) func() error {
|
func (self *ConfirmationHelper) wrappedPromptConfirmationFunction(
|
||||||
|
cancel goContext.CancelFunc,
|
||||||
|
function func(string) error,
|
||||||
|
getResponse func() string,
|
||||||
|
allowEmptyInput bool,
|
||||||
|
) func() error {
|
||||||
return func() error {
|
return func() error {
|
||||||
if self.c.GocuiGui().IsPasting {
|
if self.c.GocuiGui().IsPasting {
|
||||||
// The user is pasting multi-line text into a prompt; we don't want to handle the
|
// The user is pasting multi-line text into a prompt; we don't want to handle the
|
||||||
@@ -54,8 +59,15 @@ func (self *ConfirmationHelper) wrappedPromptConfirmationFunction(cancel goConte
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response := getResponse()
|
||||||
|
|
||||||
|
if response == "" && !allowEmptyInput {
|
||||||
|
self.c.ErrorToast(self.c.Tr.PromptInputCannotBeEmptyToast)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return self.closeAndCallConfirmationFunction(cancel, func() error {
|
return self.closeAndCallConfirmationFunction(cancel, func() error {
|
||||||
return function(getResponse())
|
return function(response)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,12 +247,14 @@ func (self *ConfirmationHelper) setConfirmationKeyBindings(cancel goContext.Canc
|
|||||||
|
|
||||||
func (self *ConfirmationHelper) setPromptKeyBindings(cancel goContext.CancelFunc, opts types.CreatePopupPanelOpts) {
|
func (self *ConfirmationHelper) setPromptKeyBindings(cancel goContext.CancelFunc, opts types.CreatePopupPanelOpts) {
|
||||||
onConfirm := self.wrappedPromptConfirmationFunction(cancel, opts.HandleConfirmPrompt,
|
onConfirm := self.wrappedPromptConfirmationFunction(cancel, opts.HandleConfirmPrompt,
|
||||||
func() string { return self.c.Views().Prompt.TextArea.GetContent() })
|
func() string { return self.c.Views().Prompt.TextArea.GetContent() },
|
||||||
|
opts.AllowEmptyInput)
|
||||||
|
|
||||||
onSuggestionConfirm := self.wrappedPromptConfirmationFunction(
|
onSuggestionConfirm := self.wrappedPromptConfirmationFunction(
|
||||||
cancel,
|
cancel,
|
||||||
opts.HandleConfirmPrompt,
|
opts.HandleConfirmPrompt,
|
||||||
self.getSelectedSuggestionValue,
|
self.getSelectedSuggestionValue,
|
||||||
|
opts.AllowEmptyInput,
|
||||||
)
|
)
|
||||||
|
|
||||||
onClose := self.wrappedConfirmationFunction(cancel, opts.HandleClose)
|
onClose := self.wrappedConfirmationFunction(cancel, opts.HandleClose)
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ func (self *CredentialsHelper) PromptUserForCredential(passOrUname oscommands.Cr
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
AllowEmptyInput: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo
|
|||||||
|
|
||||||
return f()
|
return f()
|
||||||
},
|
},
|
||||||
|
AllowEmptyInput: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -147,6 +148,7 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo
|
|||||||
|
|
||||||
return f()
|
return f()
|
||||||
},
|
},
|
||||||
|
AllowEmptyInput: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -209,6 +209,7 @@ func (self *StashController) handleRenameStashEntry(stashEntry *models.StashEntr
|
|||||||
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
|
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
AllowEmptyInput: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ func (self *PopupHandler) Prompt(opts types.PromptOpts) {
|
|||||||
HandleDeleteSuggestion: opts.HandleDeleteSuggestion,
|
HandleDeleteSuggestion: opts.HandleDeleteSuggestion,
|
||||||
FindSuggestionsFunc: opts.FindSuggestionsFunc,
|
FindSuggestionsFunc: opts.FindSuggestionsFunc,
|
||||||
AllowEditSuggestion: opts.AllowEditSuggestion,
|
AllowEditSuggestion: opts.AllowEditSuggestion,
|
||||||
|
AllowEmptyInput: opts.AllowEmptyInput,
|
||||||
Mask: opts.Mask,
|
Mask: opts.Mask,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ func (self *HandlerCreator) inputPrompt(prompt *config.CustomCommandPrompt, wrap
|
|||||||
HandleConfirm: func(str string) error {
|
HandleConfirm: func(str string) error {
|
||||||
return wrappedF(str)
|
return wrappedF(str)
|
||||||
},
|
},
|
||||||
|
AllowEmptyInput: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -172,6 +172,7 @@ type CreatePopupPanelOpts struct {
|
|||||||
FindSuggestionsFunc func(string) []*Suggestion
|
FindSuggestionsFunc func(string) []*Suggestion
|
||||||
Mask bool
|
Mask bool
|
||||||
AllowEditSuggestion bool
|
AllowEditSuggestion bool
|
||||||
|
AllowEmptyInput bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfirmOpts struct {
|
type ConfirmOpts struct {
|
||||||
@@ -190,6 +191,7 @@ type PromptOpts struct {
|
|||||||
FindSuggestionsFunc func(string) []*Suggestion
|
FindSuggestionsFunc func(string) []*Suggestion
|
||||||
HandleConfirm func(string) error
|
HandleConfirm func(string) error
|
||||||
AllowEditSuggestion bool
|
AllowEditSuggestion bool
|
||||||
|
AllowEmptyInput bool
|
||||||
// CAPTURE THIS
|
// CAPTURE THIS
|
||||||
HandleClose func() error
|
HandleClose func() error
|
||||||
HandleDeleteSuggestion func(int) error
|
HandleDeleteSuggestion func(int) error
|
||||||
|
|||||||
@@ -618,6 +618,7 @@ type TranslationSet struct {
|
|||||||
MustStashTitle string
|
MustStashTitle string
|
||||||
ConfirmationTitle string
|
ConfirmationTitle string
|
||||||
PromptTitle string
|
PromptTitle string
|
||||||
|
PromptInputCannotBeEmptyToast string
|
||||||
PrevPage string
|
PrevPage string
|
||||||
NextPage string
|
NextPage string
|
||||||
GotoTop string
|
GotoTop string
|
||||||
@@ -1713,6 +1714,7 @@ func EnglishTranslationSet() *TranslationSet {
|
|||||||
MustStashTitle: "Must stash",
|
MustStashTitle: "Must stash",
|
||||||
ConfirmationTitle: "Confirmation panel",
|
ConfirmationTitle: "Confirmation panel",
|
||||||
PromptTitle: "Input prompt",
|
PromptTitle: "Input prompt",
|
||||||
|
PromptInputCannotBeEmptyToast: "Empty input is not allowed",
|
||||||
PrevPage: "Previous page",
|
PrevPage: "Previous page",
|
||||||
NextPage: "Next page",
|
NextPage: "Next page",
|
||||||
GotoTop: "Scroll to top",
|
GotoTop: "Scroll to top",
|
||||||
|
|||||||
Reference in New Issue
Block a user