Skip to content

Commit a945502

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 167bbd3 commit a945502

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
@@ -276,7 +276,7 @@ keybinding:
276276
update: 'u'
277277
bulkMenu: 'b'
278278
commitMessage:
279-
switchToEditor: '<c-o>'
279+
commitMenu: '<c-o>'
280280
amendAttribute:
281281
addCoAuthor: 'c'
282282
resetAuthor: 'a'

pkg/config/user_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ type KeybindingSubmodulesConfig struct {
465465
}
466466

467467
type KeybindingCommitMessageConfig struct {
468-
SwitchToEditor string `yaml:"switchToEditor"`
468+
CommitMenu string `yaml:"commitMenu"`
469469
}
470470

471471
// OSConfig contains config on the level of the os
@@ -860,7 +860,7 @@ func GetDefaultConfig() *UserConfig {
860860
BulkMenu: "b",
861861
},
862862
CommitMessage: KeybindingCommitMessageConfig{
863-
SwitchToEditor: "<c-o>",
863+
CommitMenu: "<c-o>",
864864
},
865865
},
866866
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
@@ -47,8 +47,8 @@ func (self *CommitMessageController) GetKeybindings(opts types.KeybindingsOpts)
4747
Handler: self.switchToCommitDescription,
4848
},
4949
{
50-
Key: opts.GetKey(opts.Config.CommitMessage.SwitchToEditor),
51-
Handler: self.switchToEditor,
50+
Key: opts.GetKey(opts.Config.CommitMessage.CommitMenu),
51+
Handler: self.openCommitMenu,
5252
},
5353
}
5454

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

91-
func (self *CommitMessageController) switchToEditor() error {
92-
return self.c.Helpers().Commits.SwitchToEditor()
93-
}
94-
9591
func (self *CommitMessageController) handleCommitIndexChange(value int) error {
9692
currentIndex := self.context().GetSelectedIndex()
9793
newIndex := currentIndex + value
@@ -130,3 +126,8 @@ func (self *CommitMessageController) confirm() error {
130126
func (self *CommitMessageController) close() error {
131127
return self.c.Helpers().Commits.CloseCommitMessagePanel()
132128
}
129+
130+
func (self *CommitMessageController) openCommitMenu() error {
131+
authorSuggestion := self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc()
132+
return self.c.Helpers().Commits.OpenCommitMenu(authorSuggestion)
133+
}

pkg/gui/controllers/helpers/commits_helper.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,19 @@ func (self *CommitsHelper) commitMessageContexts() []types.Context {
186186
self.c.Contexts().CommitMessage,
187187
}
188188
}
189+
190+
func (self *CommitsHelper) OpenCommitMenu(suggestionFunc func(string) []*types.Suggestion) error {
191+
menuItems := []*types.MenuItem{
192+
{
193+
Label: self.c.Tr.OpenInEditor,
194+
OnPress: func() error {
195+
return self.SwitchToEditor()
196+
},
197+
Key: 'e',
198+
},
199+
}
200+
return self.c.Menu(types.CreateMenuOptions{
201+
Title: self.c.Tr.CommitMenuTitle,
202+
Items: menuItems,
203+
})
204+
}

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
@@ -1212,12 +1213,13 @@ func EnglishTranslationSet() TranslationSet {
12121213
RebaseOptionsTitle: "Rebase options",
12131214
CommitSummaryTitle: "Commit summary",
12141215
CommitDescriptionTitle: "Commit description",
1215-
CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.switchToEditorKeyBinding}} to switch to editor",
1216+
CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.commitMenuKeybinding}} to open menu",
12161217
CommitDescriptionSubTitleNoSwitch: "Press {{.togglePanelKeyBinding}} to toggle focus",
12171218
LocalBranchesTitle: "Local branches",
12181219
SearchTitle: "Search",
12191220
TagsTitle: "Tags",
12201221
MenuTitle: "Menu",
1222+
CommitMenuTitle: "Commit Menu",
12211223
RemotesTitle: "Remotes",
12221224
RemoteBranchesTitle: "Remote branches",
12231225
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
@@ -1233,7 +1233,7 @@
12331233
},
12341234
"commitMessage": {
12351235
"properties": {
1236-
"switchToEditor": {
1236+
"commitMenu": {
12371237
"type": "string",
12381238
"default": "\u003cc-o\u003e"
12391239
}

0 commit comments

Comments
 (0)