diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-11-28 13:35:58 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-11-28 20:48:17 +1100 |
commit | 5671ec5f5867c3c2b083563bac309c8616b322ae (patch) | |
tree | f0cd4ed218be9a4a87b9e60782a2fc97ba2d81cb /pkg/gui/branches_panel.go | |
parent | da3b0bf7c8aa6202d5eb9c8178f6648bc695336a (diff) |
refactor prompt opts
Diffstat (limited to 'pkg/gui/branches_panel.go')
-rw-r--r-- | pkg/gui/branches_panel.go | 90 |
1 files changed, 51 insertions, 39 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 523ecd0c2..00d0c5875 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -207,20 +207,24 @@ func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions) } func (gui *Gui) handleCheckoutByName(g *gocui.Gui, v *gocui.View) error { - return gui.prompt(gui.Tr.BranchName+":", "", func(response string) error { - return gui.handleCheckoutRef(response, handleCheckoutRefOptions{ - onRefNotFound: func(ref string) error { - - return gui.ask(askOpts{ - title: gui.Tr.BranchNotFoundTitle, - prompt: fmt.Sprintf("%s %s%s", gui.Tr.BranchNotFoundPrompt, ref, "?"), - handleConfirm: func() error { - return gui.createNewBranchWithName(ref) - }, - }) - }, - }) - }) + return gui.prompt(promptOpts{ + title: gui.Tr.BranchName + ":", + showSuggestions: true, + handleConfirm: func(response string) error { + return gui.handleCheckoutRef(response, handleCheckoutRefOptions{ + onRefNotFound: func(ref string) error { + + return gui.ask(askOpts{ + title: gui.Tr.BranchNotFoundTitle, + prompt: fmt.Sprintf("%s %s%s", gui.Tr.BranchNotFoundPrompt, ref, "?"), + handleConfirm: func() error { + return gui.createNewBranchWithName(ref) + }, + }) + }, + }) + }}, + ) } func (gui *Gui) getCheckedOutBranch() *models.Branch { @@ -427,17 +431,20 @@ func (gui *Gui) handleRenameBranch(g *gocui.Gui, v *gocui.View) error { // way to get it to show up in the reflog) promptForNewName := func() error { - return gui.prompt(gui.Tr.NewBranchNamePrompt+" "+branch.Name+":", "", func(newBranchName string) error { - if err := gui.GitCommand.RenameBranch(branch.Name, newBranchName); err != nil { - return gui.surfaceError(err) - } - // need to checkout so that the branch shows up in our reflog and therefore - // doesn't get lost among all the other branches when we switch to something else - if err := gui.GitCommand.Checkout(newBranchName, commands.CheckoutOptions{Force: false}); err != nil { - return gui.surfaceError(err) - } + return gui.prompt(promptOpts{ + title: gui.Tr.NewBranchNamePrompt + " " + branch.Name + ":", + handleConfirm: func(newBranchName string) error { + if err := gui.GitCommand.RenameBranch(branch.Name, newBranchName); err != nil { + return gui.surfaceError(err) + } + // need to checkout so that the branch shows up in our reflog and therefore + // doesn't get lost among all the other branches when we switch to something else + if err := gui.GitCommand.Checkout(newBranchName, commands.CheckoutOptions{Force: false}); err != nil { + return gui.surfaceError(err) + } - return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + }, }) } @@ -483,25 +490,30 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error { // will set to the remote's existing name prefilledName = item.ID() } - return gui.prompt(message, prefilledName, func(response string) error { - if err := gui.GitCommand.NewBranch(response, item.ID()); err != nil { - return err - } - - // if we're currently in the branch commits context then the selected commit - // is about to go to the top of the list - if context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY { - context.GetPanelState().SetSelectedLineIdx(0) - } - if context.GetKey() != gui.Contexts.Branches.Context.GetKey() { - if err := gui.pushContext(gui.Contexts.Branches.Context); err != nil { + return gui.prompt(promptOpts{ + title: message, + initialContent: prefilledName, + handleConfirm: func(response string) error { + if err := gui.GitCommand.NewBranch(response, item.ID()); err != nil { return err } - } - gui.State.Panels.Branches.SelectedLineIdx = 0 + // if we're currently in the branch commits context then the selected commit + // is about to go to the top of the list + if context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY { + context.GetPanelState().SetSelectedLineIdx(0) + } - return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + if context.GetKey() != gui.Contexts.Branches.Context.GetKey() { + if err := gui.pushContext(gui.Contexts.Branches.Context); err != nil { + return err + } + } + + gui.State.Panels.Branches.SelectedLineIdx = 0 + + return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + }, }) } |