From 744519de6016e2d65ca28129e3ad9d6accc76fb8 Mon Sep 17 00:00:00 2001 From: Abhishek Keshri Date: Sat, 28 Oct 2023 23:13:13 +0530 Subject: 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. --- docs/Config.md | 2 +- pkg/config/user_config.go | 4 ++-- pkg/gui/context/commit_message_context.go | 4 ++-- pkg/gui/controllers/commit_description_controller.go | 9 +++++---- pkg/gui/controllers/commit_message_controller.go | 13 +++++++------ pkg/gui/controllers/helpers/commits_helper.go | 16 ++++++++++++++++ pkg/i18n/english.go | 4 +++- .../components/commit_message_panel_driver.go | 10 +++++++++- schema/config.json | 2 +- 9 files changed, 46 insertions(+), 18 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index 676be2173..6998b2296 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -278,7 +278,7 @@ keybinding: update: 'u' bulkMenu: 'b' commitMessage: - switchToEditor: '' + commitMenu: '' amendAttribute: addCoAuthor: 'c' resetAuthor: 'a' diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 6045edbe8..2cbb15ce4 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -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: "", + CommitMenu: "", }, }, OS: OSConfig{}, diff --git a/pkg/gui/context/commit_message_context.go b/pkg/gui/context/commit_message_context.go index 1ac158839..0cea8e6b3 100644 --- a/pkg/gui/context/commit_message_context.go +++ b/pkg/gui/context/commit_message_context.go @@ -115,8 +115,8 @@ func (self *CommitMessageContext) SetPanelState( subtitleTemplate := lo.Ternary(onSwitchToEditor != nil, self.c.Tr.CommitDescriptionSubTitle, self.c.Tr.CommitDescriptionSubTitleNoSwitch) 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), + "togglePanelKeyBinding": keybindings.Label(self.c.UserConfig.Keybinding.Universal.TogglePanel), + "commitMenuKeybinding": keybindings.Label(self.c.UserConfig.Keybinding.CommitMessage.CommitMenu), }) } diff --git a/pkg/gui/controllers/commit_description_controller.go b/pkg/gui/controllers/commit_description_controller.go index 8f07cecfc..0c078382b 100644 --- a/pkg/gui/controllers/commit_description_controller.go +++ b/pkg/gui/controllers/commit_description_controller.go @@ -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) } diff --git a/pkg/gui/controllers/commit_message_controller.go b/pkg/gui/controllers/commit_message_controller.go index 756b240e6..84e553d87 100644 --- a/pkg/gui/controllers/commit_message_controller.go +++ b/pkg/gui/controllers/commit_message_controller.go @@ -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) +} diff --git a/pkg/gui/controllers/helpers/commits_helper.go b/pkg/gui/controllers/helpers/commits_helper.go index 0801d5742..31658f423 100644 --- a/pkg/gui/controllers/helpers/commits_helper.go +++ b/pkg/gui/controllers/helpers/commits_helper.go @@ -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, + }) +} diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index efc278ada..818783e93 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -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)", diff --git a/pkg/integration/components/commit_message_panel_driver.go b/pkg/integration/components/commit_message_panel_driver.go index b3dda6a04..68e1c639b 100644 --- a/pkg/integration/components/commit_message_panel_driver.go +++ b/pkg/integration/components/commit_message_panel_driver.go @@ -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 +} diff --git a/schema/config.json b/schema/config.json index bbb5ce61f..3816dcea6 100644 --- a/schema/config.json +++ b/schema/config.json @@ -1243,7 +1243,7 @@ }, "commitMessage": { "properties": { - "switchToEditor": { + "commitMenu": { "type": "string", "default": "\u003cc-o\u003e" } -- cgit v1.2.3