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' update: 'u'
bulkMenu: 'b' bulkMenu: 'b'
commitMessage: commitMessage:
switchToEditor: '<c-o>' commitMenu: '<c-o>'
amendAttribute: amendAttribute:
addCoAuthor: 'c' addCoAuthor: 'c'
resetAuthor: 'a' resetAuthor: 'a'

View File

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

View File

@ -115,8 +115,8 @@ func (self *CommitMessageContext) SetPanelState(
subtitleTemplate := lo.Ternary(onSwitchToEditor != nil, self.c.Tr.CommitDescriptionSubTitle, self.c.Tr.CommitDescriptionSubTitleNoSwitch) subtitleTemplate := lo.Ternary(onSwitchToEditor != nil, self.c.Tr.CommitDescriptionSubTitle, self.c.Tr.CommitDescriptionSubTitleNoSwitch)
self.c.Views().CommitDescription.Subtitle = utils.ResolvePlaceholderString(subtitleTemplate, self.c.Views().CommitDescription.Subtitle = utils.ResolvePlaceholderString(subtitleTemplate,
map[string]string{ map[string]string{
"togglePanelKeyBinding": keybindings.Label(self.c.UserConfig.Keybinding.Universal.TogglePanel), "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, Handler: self.confirm,
}, },
{ {
Key: opts.GetKey(opts.Config.CommitMessage.SwitchToEditor), Key: opts.GetKey(opts.Config.CommitMessage.CommitMenu),
Handler: self.switchToEditor, Handler: self.openCommitMenu,
}, },
} }
@ -64,6 +64,7 @@ func (self *CommitDescriptionController) confirm() error {
return self.c.Helpers().Commits.HandleCommitConfirm() return self.c.Helpers().Commits.HandleCommitConfirm()
} }
func (self *CommitDescriptionController) switchToEditor() error { func (self *CommitDescriptionController) openCommitMenu() error {
return self.c.Helpers().Commits.SwitchToEditor() 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, Handler: self.switchToCommitDescription,
}, },
{ {
Key: opts.GetKey(opts.Config.CommitMessage.SwitchToEditor), Key: opts.GetKey(opts.Config.CommitMessage.CommitMenu),
Handler: self.switchToEditor, Handler: self.openCommitMenu,
}, },
} }
@ -89,10 +89,6 @@ func (self *CommitMessageController) switchToCommitDescription() error {
return nil return nil
} }
func (self *CommitMessageController) switchToEditor() error {
return self.c.Helpers().Commits.SwitchToEditor()
}
func (self *CommitMessageController) handleCommitIndexChange(value int) error { func (self *CommitMessageController) handleCommitIndexChange(value int) error {
currentIndex := self.context().GetSelectedIndex() currentIndex := self.context().GetSelectedIndex()
newIndex := currentIndex + value newIndex := currentIndex + value
@ -134,3 +130,8 @@ func (self *CommitMessageController) confirm() error {
func (self *CommitMessageController) close() error { func (self *CommitMessageController) close() error {
return self.c.Helpers().Commits.CloseCommitMessagePanel() 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, 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 SearchTitle string
TagsTitle string TagsTitle string
MenuTitle string MenuTitle string
CommitMenuTitle string
RemotesTitle string RemotesTitle string
RemoteBranchesTitle string RemoteBranchesTitle string
PatchBuildingTitle string PatchBuildingTitle string
@ -1213,12 +1214,13 @@ func EnglishTranslationSet() TranslationSet {
RebaseOptionsTitle: "Rebase options", RebaseOptionsTitle: "Rebase options",
CommitSummaryTitle: "Commit summary", CommitSummaryTitle: "Commit summary",
CommitDescriptionTitle: "Commit description", 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", CommitDescriptionSubTitleNoSwitch: "Press {{.togglePanelKeyBinding}} to toggle focus",
LocalBranchesTitle: "Local branches", LocalBranchesTitle: "Local branches",
SearchTitle: "Search", SearchTitle: "Search",
TagsTitle: "Tags", TagsTitle: "Tags",
MenuTitle: "Menu", MenuTitle: "Menu",
CommitMenuTitle: "Commit Menu",
RemotesTitle: "Remotes", RemotesTitle: "Remotes",
RemoteBranchesTitle: "Remote branches", RemoteBranchesTitle: "Remote branches",
PatchBuildingTitle: "Main panel (patch building)", PatchBuildingTitle: "Main panel (patch building)",

View File

@ -69,7 +69,10 @@ func (self *CommitMessagePanelDriver) Cancel() {
} }
func (self *CommitMessagePanelDriver) SwitchToEditor() { 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 { func (self *CommitMessagePanelDriver) SelectPreviousMessage() *CommitMessagePanelDriver {
@ -81,3 +84,8 @@ func (self *CommitMessagePanelDriver) SelectNextMessage() *CommitMessagePanelDri
self.getViewDriver().SelectNextItem() self.getViewDriver().SelectNextItem()
return self return self
} }
func (self *CommitMessagePanelDriver) OpenCommitMenu() *CommitMessagePanelDriver {
self.t.press(self.t.keys.CommitMessage.CommitMenu)
return self
}

View File

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