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:
@@ -24,34 +24,40 @@ func NewConfirmationHelper(c *HelperCommon) *ConfirmationHelper {
|
|||||||
// This file is for the rendering of confirmation panels along with setting and handling associated
|
// This file is for the rendering of confirmation panels along with setting and handling associated
|
||||||
// keybindings.
|
// keybindings.
|
||||||
|
|
||||||
|
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
|
||||||
|
// will cause the entire pasted text to appear as a single line in the prompt. Hopefully
|
||||||
|
// the user knows that ctrl-u allows them to delete it again...
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
func (self *ConfirmationHelper) wrappedConfirmationFunction(cancel goContext.CancelFunc, function func() error) func() error {
|
||||||
return func() error {
|
return func() error {
|
||||||
if self.c.GocuiGui().IsPasting {
|
return self.closeAndCallConfirmationFunction(cancel, function)
|
||||||
// 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
|
|
||||||
// will cause the entire pasted text to appear as a single line in the prompt. Hopefully
|
|
||||||
// the user knows that ctrl-u allows them to delete it again...
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
cancel()
|
|
||||||
|
|
||||||
self.c.Context().Pop()
|
|
||||||
|
|
||||||
if function != nil {
|
|
||||||
if err := function(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) func() error {
|
||||||
return self.wrappedConfirmationFunction(cancel, func() error {
|
return func() error {
|
||||||
return function(getResponse())
|
return self.closeAndCallConfirmationFunction(cancel, func() error {
|
||||||
})
|
return function(getResponse())
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ConfirmationHelper) DeactivateConfirmation() {
|
func (self *ConfirmationHelper) DeactivateConfirmation() {
|
||||||
|
|||||||
Reference in New Issue
Block a user