mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-22 04:42:37 +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:
@@ -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 {
|
||||
if self.c.GocuiGui().IsPasting {
|
||||
// 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
|
||||
}
|
||||
|
||||
response := getResponse()
|
||||
|
||||
if response == "" && !allowEmptyInput {
|
||||
self.c.ErrorToast(self.c.Tr.PromptInputCannotBeEmptyToast)
|
||||
return nil
|
||||
}
|
||||
|
||||
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) {
|
||||
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(
|
||||
cancel,
|
||||
opts.HandleConfirmPrompt,
|
||||
self.getSelectedSuggestionValue,
|
||||
opts.AllowEmptyInput,
|
||||
)
|
||||
|
||||
onClose := self.wrappedConfirmationFunction(cancel, opts.HandleClose)
|
||||
|
||||
Reference in New Issue
Block a user