1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-23 22:24:51 +02:00

Refactor: extract body of wrappedConfirmationFunction into a helper function

And call this new helper function from both wrappedConfirmationFunction and
wrappedPromptConfirmationFunction; this gives us more flexibility to do
different things in each of those.
This commit is contained in:
Stefan Haller
2025-11-15 14:04:45 +01:00
parent 3d5b22f804
commit 8d8cf42786

View File

@@ -24,8 +24,7 @@ func NewConfirmationHelper(c *HelperCommon) *ConfirmationHelper {
// This file is for the rendering of confirmation panels along with setting and handling associated
// keybindings.
func (self *ConfirmationHelper) wrappedConfirmationFunction(cancel goContext.CancelFunc, function func() error) func() error {
return func() error {
func (self *ConfirmationHelper) closeAndCallConfirmationFunction(cancel goContext.CancelFunc, function func() error) error {
if self.c.GocuiGui().IsPasting {
// The user is pasting multi-line text into a prompt; we don't want to handle the
// line feeds as "confirm" keybindings. Simply ignoring them is the best we can do; this
@@ -45,13 +44,20 @@ func (self *ConfirmationHelper) wrappedConfirmationFunction(cancel goContext.Can
}
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) func() error {
return self.wrappedConfirmationFunction(cancel, func() error {
return func() error {
return self.closeAndCallConfirmationFunction(cancel, func() error {
return function(getResponse())
})
}
}
func (self *ConfirmationHelper) DeactivateConfirmation() {