Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/gui/controllers/diffing_menu_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package controllers

import (
"fmt"
"strings"

"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
"github.com/jesseduffield/lazygit/pkg/gui/types"
Expand Down Expand Up @@ -38,7 +37,7 @@ func (self *DiffingMenuAction) Call() error {
Title: self.c.Tr.EnterRefName,
FindSuggestionsFunc: self.c.Helpers().Suggestions.GetRefsSuggestionsFunc(),
HandleConfirm: func(response string) error {
self.c.Modes().Diffing.Ref = strings.TrimSpace(response)
self.c.Modes().Diffing.Ref = response
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
},
Expand Down
1 change: 1 addition & 0 deletions pkg/gui/controllers/files_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}})
return nil
},
AllowEmptyInput: true,
})

return nil
Expand Down
5 changes: 2 additions & 3 deletions pkg/gui/controllers/filtering_menu_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package controllers

import (
"fmt"
"strings"

"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/types"
Expand Down Expand Up @@ -66,7 +65,7 @@ func (self *FilteringMenuAction) Call() error {
FindSuggestionsFunc: self.c.Helpers().Suggestions.GetFilePathSuggestionsFunc(),
Title: self.c.Tr.EnterFileName,
HandleConfirm: func(response string) error {
return self.setFilteringPath(strings.TrimSpace(response))
return self.setFilteringPath(response)
},
})

Expand All @@ -82,7 +81,7 @@ func (self *FilteringMenuAction) Call() error {
FindSuggestionsFunc: self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc(),
Title: self.c.Tr.EnterAuthor,
HandleConfirm: func(response string) error {
return self.setFilteringAuthor(strings.TrimSpace(response))
return self.setFilteringAuthor(response)
},
})

Expand Down
55 changes: 40 additions & 15 deletions pkg/gui/controllers/helpers/confirmation_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,33 @@ func NewConfirmationHelper(c *HelperCommon) *ConfirmationHelper {
// This file is for the rendering of confirmation panels along with setting and handling associated
// keybindings.

func (self *ConfirmationHelper) closeAndCallConfirmationFunction(cancel goContext.CancelFunc, function func() error) error {
cancel()

self.c.Context().Pop()

if function != nil {
if err := function(); err != nil {
return err
}
}

return nil
}

func (self *ConfirmationHelper) wrappedConfirmationFunction(cancel goContext.CancelFunc, function func() error) func() error {
return func() error {
return self.closeAndCallConfirmationFunction(cancel, function)
}
}

func (self *ConfirmationHelper) wrappedPromptConfirmationFunction(
cancel goContext.CancelFunc,
function func(string) error,
getResponse func() string,
allowEmptyInput bool,
preserveWhitespace 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
Expand All @@ -34,26 +60,22 @@ func (self *ConfirmationHelper) wrappedConfirmationFunction(cancel goContext.Can
return nil
}

cancel()

self.c.Context().Pop()
response := getResponse()
if !preserveWhitespace {
response = strings.TrimSpace(response)
}

if function != nil {
if err := function(); err != nil {
return err
}
if response == "" && !allowEmptyInput {
self.c.ErrorToast(self.c.Tr.PromptInputCannotBeEmptyToast)
return nil
}

return nil
return self.closeAndCallConfirmationFunction(cancel, func() error {
return function(response)
})
}
}

func (self *ConfirmationHelper) wrappedPromptConfirmationFunction(cancel goContext.CancelFunc, function func(string) error, getResponse func() string) func() error {
return self.wrappedConfirmationFunction(cancel, func() error {
return function(getResponse())
})
}

func (self *ConfirmationHelper) DeactivateConfirmation() {
self.c.Mutexes().PopupMutex.Lock()
self.c.State().GetRepoState().SetCurrentPopupOpts(nil)
Expand Down Expand Up @@ -229,12 +251,15 @@ 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, opts.PreserveWhitespace)

onSuggestionConfirm := self.wrappedPromptConfirmationFunction(
cancel,
opts.HandleConfirmPrompt,
self.getSelectedSuggestionValue,
opts.AllowEmptyInput,
opts.PreserveWhitespace,
)

onClose := self.wrappedConfirmationFunction(cancel, opts.HandleClose)
Expand Down
1 change: 1 addition & 0 deletions pkg/gui/controllers/helpers/credentials_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (self *CredentialsHelper) PromptUserForCredential(passOrUname oscommands.Cr

return nil
},
AllowEmptyInput: true,
})

return nil
Expand Down
8 changes: 3 additions & 5 deletions pkg/gui/controllers/helpers/worktree_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,21 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo

return f()
},
AllowEmptyInput: true,
})

return nil
}

// prompt for the new branch name where a blank means we just check out the branch
// prompt for the new branch name
self.c.Prompt(types.PromptOpts{
Title: self.c.Tr.NewBranchName,
HandleConfirm: func(branchName string) error {
if branchName == "" {
return errors.New(self.c.Tr.BranchNameCannotBeBlank)
}

opts.Branch = branchName

return f()
},
AllowEmptyInput: false,
})

return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/gui/controllers/shell_command_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (self *ShellCommandAction) Call() error {
Title: self.c.Tr.ShellCommand,
FindSuggestionsFunc: self.GetShellCommandsHistorySuggestionsFunc(),
AllowEditSuggestion: true,
PreserveWhitespace: true,
HandleConfirm: func(command string) error {
if self.shouldSaveCommand(command) {
self.c.GetAppState().ShellCommandsHistory = utils.Limit(
Expand Down
1 change: 1 addition & 0 deletions pkg/gui/controllers/stash_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func (self *StashController) handleRenameStashEntry(stashEntry *models.StashEntr
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
return nil
},
AllowEmptyInput: true,
})

return nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/gui/popup/popup_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ func (self *PopupHandler) Prompt(opts types.PromptOpts) {
HandleDeleteSuggestion: opts.HandleDeleteSuggestion,
FindSuggestionsFunc: opts.FindSuggestionsFunc,
AllowEditSuggestion: opts.AllowEditSuggestion,
AllowEmptyInput: opts.AllowEmptyInput,
PreserveWhitespace: opts.PreserveWhitespace,
Mask: opts.Mask,
})
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/gui/services/custom_commands/handler_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ func (self *HandlerCreator) inputPrompt(prompt *config.CustomCommandPrompt, wrap
HandleConfirm: func(str string) error {
return wrappedF(str)
},
AllowEmptyInput: true,
PreserveWhitespace: true,
})

return nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/gui/types/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ type CreatePopupPanelOpts struct {
FindSuggestionsFunc func(string) []*Suggestion
Mask bool
AllowEditSuggestion bool
AllowEmptyInput bool
PreserveWhitespace bool
}

type ConfirmOpts struct {
Expand All @@ -190,6 +192,8 @@ type PromptOpts struct {
FindSuggestionsFunc func(string) []*Suggestion
HandleConfirm func(string) error
AllowEditSuggestion bool
AllowEmptyInput bool
PreserveWhitespace bool
// CAPTURE THIS
HandleClose func() error
HandleDeleteSuggestion func(int) error
Expand Down
4 changes: 2 additions & 2 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ type TranslationSet struct {
MustStashTitle string
ConfirmationTitle string
PromptTitle string
PromptInputCannotBeEmptyToast string
PrevPage string
NextPage string
GotoTop string
Expand Down Expand Up @@ -861,7 +862,6 @@ type TranslationSet struct {
NewWorktreePath string
NewWorktreeBase string
RemoveWorktreeTooltip string
BranchNameCannotBeBlank string
NewBranchName string
NewBranchNameLeaveBlank string
ViewWorktreeOptions string
Expand Down Expand Up @@ -1713,6 +1713,7 @@ func EnglishTranslationSet() *TranslationSet {
MustStashTitle: "Must stash",
ConfirmationTitle: "Confirmation panel",
PromptTitle: "Input prompt",
PromptInputCannotBeEmptyToast: "Empty input is not allowed",
PrevPage: "Previous page",
NextPage: "Next page",
GotoTop: "Scroll to top",
Expand Down Expand Up @@ -1954,7 +1955,6 @@ func EnglishTranslationSet() *TranslationSet {
NewWorktreePath: "New worktree path",
NewWorktreeBase: "New worktree base ref",
RemoveWorktreeTooltip: "Remove the selected worktree. This will both delete the worktree's directory, as well as metadata about the worktree in the .git directory.",
BranchNameCannotBeBlank: "Branch name cannot be blank",
NewBranchName: "New branch name",
NewBranchNameLeaveBlank: "New branch name (leave blank to checkout {{.default}})",
ViewWorktreeOptions: "View worktree options",
Expand Down