Skip to content

Commit 744519d

Browse files
2KAbhishekstefanhaller
authored andcommitted
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.
1 parent b8f4cd0 commit 744519d

File tree

9 files changed

+46
-18
lines changed

9 files changed

+46
-18
lines changed

docs/Config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ keybinding:
278278
update: 'u'
279279
bulkMenu: 'b'
280280
commitMessage:
281-
switchToEditor: '<c-o>'
281+
commitMenu: '<c-o>'
282282
amendAttribute:
283283
addCoAuthor: 'c'
284284
resetAuthor: 'a'

pkg/config/user_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ type KeybindingSubmodulesConfig struct {
469469
}
470470

471471
type KeybindingCommitMessageConfig struct {
472-
SwitchToEditor string `yaml:"switchToEditor"`
472+
CommitMenu string `yaml:"commitMenu"`
473473
}
474474

475475
// OSConfig contains config on the level of the os
@@ -866,7 +866,7 @@ func GetDefaultConfig() *UserConfig {
866866
BulkMenu: "b",
867867
},
868868
CommitMessage: KeybindingCommitMessageConfig{
869-
SwitchToEditor: "<c-o>",
869+
CommitMenu: "<c-o>",
870870
},
871871
},
872872
OS: OSConfig{},

pkg/gui/context/commit_message_context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ func (self *CommitMessageContext) SetPanelState(
115115
subtitleTemplate := lo.Ternary(onSwitchToEditor != nil, self.c.Tr.CommitDescriptionSubTitle, self.c.Tr.CommitDescriptionSubTitleNoSwitch)
116116
self.c.Views().CommitDescription.Subtitle = utils.ResolvePlaceholderString(subtitleTemplate,
117117
map[string]string{
118-
"togglePanelKeyBinding": keybindings.Label(self.c.UserConfig.Keybinding.Universal.TogglePanel),
119-
"switchToEditorKeyBinding": keybindings.Label(self.c.UserConfig.Keybinding.CommitMessage.SwitchToEditor),
118+
"togglePanelKeyBinding": keybindings.Label(self.c.UserConfig.Keybinding.Universal.TogglePanel),
119+
"commitMenuKeybinding": keybindings.Label(self.c.UserConfig.Keybinding.CommitMessage.CommitMenu),
120120
})
121121
}
122122

pkg/gui/controllers/commit_description_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func (self *CommitDescriptionController) GetKeybindings(opts types.KeybindingsOp
3636
Handler: self.confirm,
3737
},
3838
{
39-
Key: opts.GetKey(opts.Config.CommitMessage.SwitchToEditor),
40-
Handler: self.switchToEditor,
39+
Key: opts.GetKey(opts.Config.CommitMessage.CommitMenu),
40+
Handler: self.openCommitMenu,
4141
},
4242
}
4343

@@ -64,6 +64,7 @@ func (self *CommitDescriptionController) confirm() error {
6464
return self.c.Helpers().Commits.HandleCommitConfirm()
6565
}
6666

67-
func (self *CommitDescriptionController) switchToEditor() error {
68-
return self.c.Helpers().Commits.SwitchToEditor()
67+
func (self *CommitDescriptionController) openCommitMenu() error {
68+
authorSuggestion := self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc()
69+
return self.c.Helpers().Commits.OpenCommitMenu(authorSuggestion)
6970
}

pkg/gui/controllers/commit_message_controller.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func (self *CommitMessageController) GetKeybindings(opts types.KeybindingsOpts)
4848
Handler: self.switchToCommitDescription,
4949
},
5050
{
51-
Key: opts.GetKey(opts.Config.CommitMessage.SwitchToEditor),
52-
Handler: self.switchToEditor,
51+
Key: opts.GetKey(opts.Config.CommitMessage.CommitMenu),
52+
Handler: self.openCommitMenu,
5353
},
5454
}
5555

@@ -89,10 +89,6 @@ func (self *CommitMessageController) switchToCommitDescription() error {
8989
return nil
9090
}
9191

92-
func (self *CommitMessageController) switchToEditor() error {
93-
return self.c.Helpers().Commits.SwitchToEditor()
94-
}
95-
9692
func (self *CommitMessageController) handleCommitIndexChange(value int) error {
9793
currentIndex := self.context().GetSelectedIndex()
9894
newIndex := currentIndex + value
@@ -134,3 +130,8 @@ func (self *CommitMessageController) confirm() error {
134130
func (self *CommitMessageController) close() error {
135131
return self.c.Helpers().Commits.CloseCommitMessagePanel()
136132
}
133+
134+
func (self *CommitMessageController) openCommitMenu() error {
135+
authorSuggestion := self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc()
136+
return self.c.Helpers().Commits.OpenCommitMenu(authorSuggestion)
137+
}

pkg/gui/controllers/helpers/commits_helper.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,19 @@ func (self *CommitsHelper) commitMessageContexts() []types.Context {
215215
self.c.Contexts().CommitMessage,
216216
}
217217
}
218+
219+
func (self *CommitsHelper) OpenCommitMenu(suggestionFunc func(string) []*types.Suggestion) error {
220+
menuItems := []*types.MenuItem{
221+
{
222+
Label: self.c.Tr.OpenInEditor,
223+
OnPress: func() error {
224+
return self.SwitchToEditor()
225+
},
226+
Key: 'e',
227+
},
228+
}
229+
return self.c.Menu(types.CreateMenuOptions{
230+
Title: self.c.Tr.CommitMenuTitle,
231+
Items: menuItems,
232+
})
233+
}

pkg/i18n/english.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ type TranslationSet struct {
272272
SearchTitle string
273273
TagsTitle string
274274
MenuTitle string
275+
CommitMenuTitle string
275276
RemotesTitle string
276277
RemoteBranchesTitle string
277278
PatchBuildingTitle string
@@ -1213,12 +1214,13 @@ func EnglishTranslationSet() TranslationSet {
12131214
RebaseOptionsTitle: "Rebase options",
12141215
CommitSummaryTitle: "Commit summary",
12151216
CommitDescriptionTitle: "Commit description",
1216-
CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.switchToEditorKeyBinding}} to switch to editor",
1217+
CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.commitMenuKeybinding}} to open menu",
12171218
CommitDescriptionSubTitleNoSwitch: "Press {{.togglePanelKeyBinding}} to toggle focus",
12181219
LocalBranchesTitle: "Local branches",
12191220
SearchTitle: "Search",
12201221
TagsTitle: "Tags",
12211222
MenuTitle: "Menu",
1223+
CommitMenuTitle: "Commit Menu",
12221224
RemotesTitle: "Remotes",
12231225
RemoteBranchesTitle: "Remote branches",
12241226
PatchBuildingTitle: "Main panel (patch building)",

pkg/integration/components/commit_message_panel_driver.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ func (self *CommitMessagePanelDriver) Cancel() {
6969
}
7070

7171
func (self *CommitMessagePanelDriver) SwitchToEditor() {
72-
self.getViewDriver().Press(self.t.keys.CommitMessage.SwitchToEditor)
72+
self.OpenCommitMenu()
73+
self.t.ExpectPopup().Menu().Title(Equals("Commit Menu")).
74+
Select(Contains("Open in editor")).
75+
Confirm()
7376
}
7477

7578
func (self *CommitMessagePanelDriver) SelectPreviousMessage() *CommitMessagePanelDriver {
@@ -81,3 +84,8 @@ func (self *CommitMessagePanelDriver) SelectNextMessage() *CommitMessagePanelDri
8184
self.getViewDriver().SelectNextItem()
8285
return self
8386
}
87+
88+
func (self *CommitMessagePanelDriver) OpenCommitMenu() *CommitMessagePanelDriver {
89+
self.t.press(self.t.keys.CommitMessage.CommitMenu)
90+
return self
91+
}

schema/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@
12431243
},
12441244
"commitMessage": {
12451245
"properties": {
1246-
"switchToEditor": {
1246+
"commitMenu": {
12471247
"type": "string",
12481248
"default": "\u003cc-o\u003e"
12491249
}

0 commit comments

Comments
 (0)