summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbhishek Keshri <iam2kabhishek@gmail.com>2023-10-28 23:13:13 +0530
committerStefan Haller <stefan@haller-berlin.de>2024-03-11 09:18:40 +0100
commit744519de6016e2d65ca28129e3ad9d6accc76fb8 (patch)
treed49e119d6a0bdcaaad45ed083ad0e75c929b7c82
parentb8f4cd0ef67c9d7842cc20fd346c8decdb65be2f (diff)
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.
-rw-r--r--docs/Config.md2
-rw-r--r--pkg/config/user_config.go4
-rw-r--r--pkg/gui/context/commit_message_context.go4
-rw-r--r--pkg/gui/controllers/commit_description_controller.go9
-rw-r--r--pkg/gui/controllers/commit_message_controller.go13
-rw-r--r--pkg/gui/controllers/helpers/commits_helper.go16
-rw-r--r--pkg/i18n/english.go4
-rw-r--r--pkg/integration/components/commit_message_panel_driver.go10
-rw-r--r--schema/config.json2
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: '<c-o>'
+ commitMenu: '<c-o>'
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: "<c-o>",
+ CommitMenu: "<c-o>",
},
},
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"
}