1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-31 23:19:40 +02:00

revert use of stored values in confirmation panels

This commit is contained in:
Jesse Duffield 2018-08-11 13:24:05 +10:00
parent fd13cf14b4
commit 8ae346787a
4 changed files with 6 additions and 38 deletions

View File

@ -30,7 +30,7 @@ func handleForceCheckout(g *gocui.Gui, v *gocui.View) error {
}
func handleCheckoutByName(g *gocui.Gui, v *gocui.View) error {
createPromptPanel(g, v, "Branch Name:", nil, func(g *gocui.Gui, v *gocui.View) error {
createPromptPanel(g, v, "Branch Name:", func(g *gocui.Gui, v *gocui.View) error {
if output, err := gitCheckout(trimmedContent(v), false); err != nil {
return createErrorPanel(g, output)
}
@ -41,7 +41,7 @@ func handleCheckoutByName(g *gocui.Gui, v *gocui.View) error {
func handleNewBranch(g *gocui.Gui, v *gocui.View) error {
branch := state.Branches[0]
createPromptPanel(g, v, "New Branch Name (Branch is off of "+branch.Name+")", nil, func(g *gocui.Gui, v *gocui.View) error {
createPromptPanel(g, v, "New Branch Name (Branch is off of "+branch.Name+")", func(g *gocui.Gui, v *gocui.View) error {
if output, err := gitNewBranch(trimmedContent(v)); err != nil {
return createErrorPanel(g, output)
}

View File

@ -109,7 +109,7 @@ func handleRenameCommit(g *gocui.Gui, v *gocui.View) error {
if getItemPosition(v) != 0 {
return createErrorPanel(g, "Can only rename topmost commit")
}
createPromptPanel(g, v, "Rename Commit", nil, func(g *gocui.Gui, v *gocui.View) error {
createPromptPanel(g, v, "Rename Commit", func(g *gocui.Gui, v *gocui.View) error {
if output, err := gitRenameCommit(v.Buffer()); err != nil {
return createErrorPanel(g, output)
}

View File

@ -55,11 +55,8 @@ func getConfirmationPanelDimensions(g *gocui.Gui, prompt string) (int, int, int,
height/2 + panelHeight/2
}
func createPromptPanel(g *gocui.Gui, currentView *gocui.View, title string, initialValue *[]byte, handleConfirm func(*gocui.Gui, *gocui.View) error) error {
func createPromptPanel(g *gocui.Gui, currentView *gocui.View, title string, handleConfirm func(*gocui.Gui, *gocui.View) error) error {
g.SetViewOnBottom("commitMessage")
if initialValue == nil {
initialValue = &[]byte{}
}
// only need to fit one line
x0, y0, x1, y1 := getConfirmationPanelDimensions(g, "")
if confirmationView, err := g.SetView("confirmation", x0, y0, x1, y1, 0); err != nil {
@ -67,43 +64,14 @@ func createPromptPanel(g *gocui.Gui, currentView *gocui.View, title string, init
return err
}
handleConfirm := func(gui *gocui.Gui, view *gocui.View) error {
*initialValue = nil
return handleConfirm(g, view)
}
handleClose := func(gui *gocui.Gui, view *gocui.View) error {
// FIXME: trimming a newline that is no doubt caused by the enter keybinding
// on the editor. We should just define a new editor that doesn't do that
*initialValue = []byte(strings.TrimSpace(view.Buffer()))
return nil
}
confirmationView.Editable = true
confirmationView.Title = title
restorePreviousBuffer(confirmationView, initialValue)
switchFocus(g, currentView, confirmationView)
return setKeyBindings(g, handleConfirm, handleClose)
return setKeyBindings(g, handleConfirm, nil)
}
return nil
}
func restorePreviousBuffer(confirmationView *gocui.View, initialValue *[]byte) {
confirmationView.Write(*initialValue)
x, y := getCursorPositionFromBuffer(initialValue)
devLog("New cursor position:", x, y)
confirmationView.SetCursor(0, 0)
confirmationView.MoveCursor(x, y, false)
}
func getCursorPositionFromBuffer(initialValue *[]byte) (int, int) {
split := strings.Split(string(*initialValue), "\n")
lastLine := split[len(split)-1]
x := len(lastLine)
y := len(split)
return x, y
}
func createConfirmationPanel(g *gocui.Gui, currentView *gocui.View, title, prompt string, handleConfirm, handleClose func(*gocui.Gui, *gocui.View) error) error {
g.SetViewOnBottom("commitMessage")
g.Update(func(g *gocui.Gui) error {

View File

@ -82,7 +82,7 @@ func stashDo(g *gocui.Gui, v *gocui.View, method string) error {
}
func handleStashSave(g *gocui.Gui, filesView *gocui.View) error {
createPromptPanel(g, filesView, "Stash changes", nil, func(g *gocui.Gui, v *gocui.View) error {
createPromptPanel(g, filesView, "Stash changes", func(g *gocui.Gui, v *gocui.View) error {
if output, err := gitStashSave(trimmedContent(v)); err != nil {
createErrorPanel(g, output)
}