mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
Add key binding for switching from the commit message panel to an editor
This is useful for when you begin to type the message in lazygit's commit panel, and then realize that you'd rather use your editor's more powerful editing capabilities. Pressing <c-o> will take you right there.
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
type ICommitsHelper interface {
|
||||
@ -62,6 +65,28 @@ func (self *CommitsHelper) JoinCommitMessageAndDescription() string {
|
||||
return self.getCommitSummary() + "\n" + self.getCommitDescription()
|
||||
}
|
||||
|
||||
func (self *CommitsHelper) SwitchToEditor() error {
|
||||
if !self.c.Contexts().CommitMessage.CanSwitchToEditor() {
|
||||
return nil
|
||||
}
|
||||
|
||||
message := lo.Ternary(len(self.getCommitDescription()) == 0,
|
||||
self.getCommitSummary(),
|
||||
self.getCommitSummary()+"\n\n"+self.getCommitDescription())
|
||||
filepath := filepath.Join(self.c.OS().GetTempDir(), self.c.Git().RepoPaths.RepoName(), time.Now().Format("Jan _2 15.04.05.000000000")+".msg")
|
||||
err := self.c.OS().CreateFileWithContent(filepath, message)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = self.CloseCommitMessagePanel()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return self.c.Contexts().CommitMessage.SwitchToEditor(filepath)
|
||||
}
|
||||
|
||||
func (self *CommitsHelper) UpdateCommitPanelView(message string) {
|
||||
if message != "" {
|
||||
self.SetMessageAndDescriptionInView(message)
|
||||
@ -83,6 +108,7 @@ type OpenCommitMessagePanelOpts struct {
|
||||
DescriptionTitle string
|
||||
PreserveMessage bool
|
||||
OnConfirm func(summary string, description string) error
|
||||
OnSwitchToEditor func(string) error
|
||||
InitialMessage string
|
||||
}
|
||||
|
||||
@ -101,6 +127,7 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp
|
||||
opts.DescriptionTitle,
|
||||
opts.PreserveMessage,
|
||||
onConfirm,
|
||||
opts.OnSwitchToEditor,
|
||||
)
|
||||
|
||||
self.UpdateCommitPanelView(opts.InitialMessage)
|
||||
|
Reference in New Issue
Block a user