mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-13 01:30:53 +02:00
merge feature/clearing-commit-panel into master
This commit is contained in:
@ -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:", 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 {
|
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+")", 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 {
|
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", 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 {
|
if output, err := gitRenameCommit(v.Buffer()); err != nil {
|
||||||
return createErrorPanel(g, output)
|
return createErrorPanel(g, output)
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ 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, 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
|
// 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 {
|
||||||
@ -65,11 +65,22 @@ func createPromptPanel(g *gocui.Gui, currentView *gocui.View, title string, hand
|
|||||||
|
|
||||||
g.Cursor = true
|
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.Editable = true
|
||||||
confirmationView.Title = title
|
confirmationView.Title = title
|
||||||
confirmationView.FgColor = gocui.ColorWhite
|
confirmationView.Write(*initialValue)
|
||||||
|
confirmationView.SetCursor(len(*initialValue), 0)
|
||||||
switchFocus(g, currentView, confirmationView)
|
switchFocus(g, currentView, confirmationView)
|
||||||
return setKeyBindings(g, handleConfirm, nil)
|
return setKeyBindings(g, handleConfirmAndClear, handleClose)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
savedCommitMessage = &[]byte{}
|
||||||
errNoFiles = errors.New("No changed files")
|
errNoFiles = errors.New("No changed files")
|
||||||
errNoUsername = errors.New(`No username set. Please do: git config --global user.name "Your Name"`)
|
errNoUsername = errors.New(`No username set. Please do: git config --global user.name "Your Name"`)
|
||||||
)
|
)
|
||||||
@ -177,7 +178,7 @@ func handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
|
|||||||
if len(stagedFiles(state.GitFiles)) == 0 && !state.HasMergeConflicts {
|
if len(stagedFiles(state.GitFiles)) == 0 && !state.HasMergeConflicts {
|
||||||
return createErrorPanel(g, "There are no staged files to commit")
|
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)
|
message := trimmedContent(v)
|
||||||
if message == "" {
|
if message == "" {
|
||||||
return createErrorPanel(g, "You cannot commit without a commit message")
|
return createErrorPanel(g, "You cannot commit without a commit message")
|
||||||
|
@ -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", 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 {
|
if output, err := gitStashSave(trimmedContent(v)); err != nil {
|
||||||
createErrorPanel(g, output)
|
createErrorPanel(g, output)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user