From 8ae346787aaef5261acd0026b61a18883f2d0149 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 11 Aug 2018 13:24:05 +1000 Subject: [PATCH] revert use of stored values in confirmation panels --- branches_panel.go | 4 ++-- commits_panel.go | 2 +- confirmation_panel.go | 36 ++---------------------------------- stash_panel.go | 2 +- 4 files changed, 6 insertions(+), 38 deletions(-) diff --git a/branches_panel.go b/branches_panel.go index 00091ffb8..3102f0c28 100644 --- a/branches_panel.go +++ b/branches_panel.go @@ -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) } diff --git a/commits_panel.go b/commits_panel.go index e8ff68678..88c7b8ebe 100644 --- a/commits_panel.go +++ b/commits_panel.go @@ -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) } diff --git a/confirmation_panel.go b/confirmation_panel.go index 03e078155..563db72d8 100644 --- a/confirmation_panel.go +++ b/confirmation_panel.go @@ -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 { diff --git a/stash_panel.go b/stash_panel.go index a4a2207d8..33c7e297b 100644 --- a/stash_panel.go +++ b/stash_panel.go @@ -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) }