summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-08-10 22:49:54 +1000
committerJesse Duffield <jessedduffield@gmail.com>2018-08-10 22:49:54 +1000
commitaa4160d57ae460a7735fb2beb2ab7904151de50e (patch)
tree65bdcf95d11d55dd5f951ee5978a87babbc86b92
parent8bc68325460382d84c1a6139308aa9f5fb925964 (diff)
merge feature/clearing-commit-panel into master
-rw-r--r--branches_panel.go4
-rw-r--r--commits_panel.go2
-rw-r--r--confirmation_panel.go17
-rw-r--r--files_panel.go7
-rw-r--r--stash_panel.go2
5 files changed, 22 insertions, 10 deletions
diff --git a/branches_panel.go b/branches_panel.go
index 3102f0c28..00091ffb8 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:", func(g *gocui.Gui, v *gocui.View) error {
+ createPromptPanel(g, v, "Branch Name:", nil, 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+")", func(g *gocui.Gui, v *gocui.View) error {
+ createPromptPanel(g, v, "New Branch Name (Branch is off of "+branch.Name+")", nil, 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 88c7b8ebe..e8ff68678 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", func(g *gocui.Gui, v *gocui.View) error {
+ createPromptPanel(g, v, "Rename Commit", nil, 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 362b75c49..520c8b593 100644
--- a/confirmation_panel.go
+++ b/confirmation_panel.go
@@ -55,7 +55,7 @@ func getConfirmationPanelDimensions(g *gocui.Gui, prompt string) (int, int, int,
height/2 + panelHeight/2
}
-func createPromptPanel(g *gocui.Gui, currentView *gocui.View, title string, handleConfirm func(*gocui.Gui, *gocui.View) error) error {
+func createPromptPanel(g *gocui.Gui, currentView *gocui.View, title string, initialValue *[]byte, handleConfirm func(*gocui.Gui, *gocui.View) error) error {
// 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 {
@@ -65,11 +65,22 @@ func createPromptPanel(g *gocui.Gui, currentView *gocui.View, title string, hand
g.Cursor = true
+ handleConfirmAndClear := func(gui *gocui.Gui, view *gocui.View) error {
+ *initialValue = nil
+ return handleConfirm(g, view)
+ }
+
+ handleClose := func(gui *gocui.Gui, view *gocui.View) error {
+ *initialValue = []byte(strings.TrimSpace(view.Buffer()))
+ return nil
+ }
+
confirmationView.Editable = true
confirmationView.Title = title
- confirmationView.FgColor = gocui.ColorWhite
+ confirmationView.Write(*initialValue)
+ confirmationView.SetCursor(len(*initialValue), 0)
switchFocus(g, currentView, confirmationView)
- return setKeyBindings(g, handleConfirm, nil)
+ return setKeyBindings(g, handleConfirmAndClear, handleClose)
}
return nil
}
diff --git a/files_panel.go b/files_panel.go
index 32ed36ad4..b2de2c226 100644
--- a/files_panel.go
+++ b/files_panel.go
@@ -15,8 +15,9 @@ import (
)
var (
- errNoFiles = errors.New("No changed files")
- errNoUsername = errors.New(`No username set. Please do: git config --global user.name "Your Name"`)
+ savedCommitMessage = &[]byte{}
+ errNoFiles = errors.New("No changed files")
+ errNoUsername = errors.New(`No username set. Please do: git config --global user.name "Your Name"`)
)
func stagedFiles(files []GitFile) []GitFile {
@@ -177,7 +178,7 @@ func handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
if len(stagedFiles(state.GitFiles)) == 0 && !state.HasMergeConflicts {
return createErrorPanel(g, "There are no staged files to commit")
}
- createPromptPanel(g, filesView, "Commit message", func(g *gocui.Gui, v *gocui.View) error {
+ createPromptPanel(g, filesView, "Commit message", savedCommitMessage, func(g *gocui.Gui, v *gocui.View) error {
message := trimmedContent(v)
if message == "" {
return createErrorPanel(g, "You cannot commit without a commit message")
diff --git a/stash_panel.go b/stash_panel.go
index 33c7e297b..a4a2207d8 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", func(g *gocui.Gui, v *gocui.View) error {
+ createPromptPanel(g, filesView, "Stash changes", nil, func(g *gocui.Gui, v *gocui.View) error {
if output, err := gitStashSave(trimmedContent(v)); err != nil {
createErrorPanel(g, output)
}