mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-08 23:56:15 +02:00
revert use of stored values in confirmation panels
This commit is contained in:
parent
fd13cf14b4
commit
8ae346787a
@ -30,7 +30,7 @@ func handleForceCheckout(g *gocui.Gui, v *gocui.View) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleCheckoutByName(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 {
|
if output, err := gitCheckout(trimmedContent(v), false); err != nil {
|
||||||
return createErrorPanel(g, output)
|
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 {
|
func handleNewBranch(g *gocui.Gui, v *gocui.View) error {
|
||||||
branch := state.Branches[0]
|
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 {
|
if output, err := gitNewBranch(trimmedContent(v)); err != nil {
|
||||||
return createErrorPanel(g, output)
|
return createErrorPanel(g, output)
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ func handleRenameCommit(g *gocui.Gui, v *gocui.View) error {
|
|||||||
if getItemPosition(v) != 0 {
|
if getItemPosition(v) != 0 {
|
||||||
return createErrorPanel(g, "Can only rename topmost commit")
|
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 {
|
if output, err := gitRenameCommit(v.Buffer()); err != nil {
|
||||||
return createErrorPanel(g, output)
|
return createErrorPanel(g, output)
|
||||||
}
|
}
|
||||||
|
@ -55,11 +55,8 @@ func getConfirmationPanelDimensions(g *gocui.Gui, prompt string) (int, int, int,
|
|||||||
height/2 + panelHeight/2
|
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")
|
g.SetViewOnBottom("commitMessage")
|
||||||
if initialValue == nil {
|
|
||||||
initialValue = &[]byte{}
|
|
||||||
}
|
|
||||||
// only need to fit one line
|
// only need to fit one line
|
||||||
x0, y0, x1, y1 := getConfirmationPanelDimensions(g, "")
|
x0, y0, x1, y1 := getConfirmationPanelDimensions(g, "")
|
||||||
if confirmationView, err := g.SetView("confirmation", x0, y0, x1, y1, 0); err != nil {
|
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
|
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.Editable = true
|
||||||
confirmationView.Title = title
|
confirmationView.Title = title
|
||||||
restorePreviousBuffer(confirmationView, initialValue)
|
|
||||||
switchFocus(g, currentView, confirmationView)
|
switchFocus(g, currentView, confirmationView)
|
||||||
return setKeyBindings(g, handleConfirm, handleClose)
|
return setKeyBindings(g, handleConfirm, nil)
|
||||||
}
|
}
|
||||||
return 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 {
|
func createConfirmationPanel(g *gocui.Gui, currentView *gocui.View, title, prompt string, handleConfirm, handleClose func(*gocui.Gui, *gocui.View) error) error {
|
||||||
g.SetViewOnBottom("commitMessage")
|
g.SetViewOnBottom("commitMessage")
|
||||||
g.Update(func(g *gocui.Gui) error {
|
g.Update(func(g *gocui.Gui) error {
|
||||||
|
@ -82,7 +82,7 @@ func stashDo(g *gocui.Gui, v *gocui.View, method string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleStashSave(g *gocui.Gui, filesView *gocui.View) 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 {
|
if output, err := gitStashSave(trimmedContent(v)); err != nil {
|
||||||
createErrorPanel(g, output)
|
createErrorPanel(g, output)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user