1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-19 12:12:42 +02:00

Add a commit menu to the commit message panel

And move the "switch to editor" command into this menu. So far this is the only
entry, but we'll add another one in the next commit.
This commit is contained in:
Abhishek Keshri 2023-10-28 23:13:13 +05:30 committed by Stefan Haller
parent b8f4cd0ef6
commit 744519de60
9 changed files with 46 additions and 18 deletions

View File

@ -278,7 +278,7 @@ keybinding:
update: 'u'
bulkMenu: 'b'
commitMessage:
switchToEditor: '<c-o>'
commitMenu: '<c-o>'
amendAttribute:
addCoAuthor: 'c'
resetAuthor: 'a'

View File

@ -469,7 +469,7 @@ type KeybindingSubmodulesConfig struct {
}
type KeybindingCommitMessageConfig struct {
SwitchToEditor string `yaml:"switchToEditor"`
CommitMenu string `yaml:"commitMenu"`
}
// OSConfig contains config on the level of the os
@ -866,7 +866,7 @@ func GetDefaultConfig() *UserConfig {
BulkMenu: "b",
},
CommitMessage: KeybindingCommitMessageConfig{
SwitchToEditor: "<c-o>",
CommitMenu: "<c-o>",
},
},
OS: OSConfig{},

View File

@ -116,7 +116,7 @@ func (self *CommitMessageContext) SetPanelState(
self.c.Views().CommitDescription.Subtitle = utils.ResolvePlaceholderString(subtitleTemplate,
map[string]string{
"togglePanelKeyBinding": keybindings.Label(self.c.UserConfig.Keybinding.Universal.TogglePanel),
"switchToEditorKeyBinding": keybindings.Label(self.c.UserConfig.Keybinding.CommitMessage.SwitchToEditor),
"commitMenuKeybinding": keybindings.Label(self.c.UserConfig.Keybinding.CommitMessage.CommitMenu),
})
}

View File

@ -36,8 +36,8 @@ func (self *CommitDescriptionController) GetKeybindings(opts types.KeybindingsOp
Handler: self.confirm,
},
{
Key: opts.GetKey(opts.Config.CommitMessage.SwitchToEditor),
Handler: self.switchToEditor,
Key: opts.GetKey(opts.Config.CommitMessage.CommitMenu),
Handler: self.openCommitMenu,
},
}
@ -64,6 +64,7 @@ func (self *CommitDescriptionController) confirm() error {
return self.c.Helpers().Commits.HandleCommitConfirm()
}
func (self *CommitDescriptionController) switchToEditor() error {
return self.c.Helpers().Commits.SwitchToEditor()
func (self *CommitDescriptionController) openCommitMenu() error {
authorSuggestion := self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc()
return self.c.Helpers().Commits.OpenCommitMenu(authorSuggestion)
}

View File

@ -48,8 +48,8 @@ func (self *CommitMessageController) GetKeybindings(opts types.KeybindingsOpts)
Handler: self.switchToCommitDescription,
},
{
Key: opts.GetKey(opts.Config.CommitMessage.SwitchToEditor),
Handler: self.switchToEditor,
Key: opts.GetKey(opts.Config.CommitMessage.CommitMenu),
Handler: self.openCommitMenu,
},
}
@ -89,10 +89,6 @@ func (self *CommitMessageController) switchToCommitDescription() error {
return nil
}
func (self *CommitMessageController) switchToEditor() error {
return self.c.Helpers().Commits.SwitchToEditor()
}
func (self *CommitMessageController) handleCommitIndexChange(value int) error {
currentIndex := self.context().GetSelectedIndex()
newIndex := currentIndex + value
@ -134,3 +130,8 @@ func (self *CommitMessageController) confirm() error {
func (self *CommitMessageController) close() error {
return self.c.Helpers().Commits.CloseCommitMessagePanel()
}
func (self *CommitMessageController) openCommitMenu() error {
authorSuggestion := self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc()
return self.c.Helpers().Commits.OpenCommitMenu(authorSuggestion)
}

View File

@ -215,3 +215,19 @@ func (self *CommitsHelper) commitMessageContexts() []types.Context {
self.c.Contexts().CommitMessage,
}
}
func (self *CommitsHelper) OpenCommitMenu(suggestionFunc func(string) []*types.Suggestion) error {
menuItems := []*types.MenuItem{
{
Label: self.c.Tr.OpenInEditor,
OnPress: func() error {
return self.SwitchToEditor()
},
Key: 'e',
},
}
return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.CommitMenuTitle,
Items: menuItems,
})
}

View File

@ -272,6 +272,7 @@ type TranslationSet struct {
SearchTitle string
TagsTitle string
MenuTitle string
CommitMenuTitle string
RemotesTitle string
RemoteBranchesTitle string
PatchBuildingTitle string
@ -1213,12 +1214,13 @@ func EnglishTranslationSet() TranslationSet {
RebaseOptionsTitle: "Rebase options",
CommitSummaryTitle: "Commit summary",
CommitDescriptionTitle: "Commit description",
CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.switchToEditorKeyBinding}} to switch to editor",
CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.commitMenuKeybinding}} to open menu",
CommitDescriptionSubTitleNoSwitch: "Press {{.togglePanelKeyBinding}} to toggle focus",
LocalBranchesTitle: "Local branches",
SearchTitle: "Search",
TagsTitle: "Tags",
MenuTitle: "Menu",
CommitMenuTitle: "Commit Menu",
RemotesTitle: "Remotes",
RemoteBranchesTitle: "Remote branches",
PatchBuildingTitle: "Main panel (patch building)",

View File

@ -69,7 +69,10 @@ func (self *CommitMessagePanelDriver) Cancel() {
}
func (self *CommitMessagePanelDriver) SwitchToEditor() {
self.getViewDriver().Press(self.t.keys.CommitMessage.SwitchToEditor)
self.OpenCommitMenu()
self.t.ExpectPopup().Menu().Title(Equals("Commit Menu")).
Select(Contains("Open in editor")).
Confirm()
}
func (self *CommitMessagePanelDriver) SelectPreviousMessage() *CommitMessagePanelDriver {
@ -81,3 +84,8 @@ func (self *CommitMessagePanelDriver) SelectNextMessage() *CommitMessagePanelDri
self.getViewDriver().SelectNextItem()
return self
}
func (self *CommitMessagePanelDriver) OpenCommitMenu() *CommitMessagePanelDriver {
self.t.press(self.t.keys.CommitMessage.CommitMenu)
return self
}

View File

@ -1243,7 +1243,7 @@
},
"commitMessage": {
"properties": {
"switchToEditor": {
"commitMenu": {
"type": "string",
"default": "\u003cc-o\u003e"
}