Skip to content

Commit 7745bbb

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 88e4581 commit 7745bbb

File tree

9 files changed

+43
-21
lines changed

9 files changed

+43
-21
lines changed

docs/Config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ keybinding:
271271
update: 'u'
272272
bulkMenu: 'b'
273273
commitMessage:
274-
switchToEditor: '<c-o>'
274+
commitMenu: '<c-o>'
275275
amendAttribute:
276276
addCoAuthor: 'c'
277277
resetAuthor: 'a'

pkg/config/user_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ type KeybindingSubmodulesConfig struct {
440440
}
441441

442442
type KeybindingCommitMessageConfig struct {
443-
SwitchToEditor string `yaml:"switchToEditor"`
443+
CommitMenu string `yaml:"commitMenu"`
444444
}
445445

446446
// OSConfig contains config on the level of the os
@@ -829,7 +829,7 @@ func GetDefaultConfig() *UserConfig {
829829
BulkMenu: "b",
830830
},
831831
CommitMessage: KeybindingCommitMessageConfig{
832-
SwitchToEditor: "<c-o>",
832+
CommitMenu: "<c-o>",
833833
},
834834
},
835835
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
@@ -191,3 +191,19 @@ func (self *CommitsHelper) commitMessageContexts() []types.Context {
191191
self.c.Contexts().CommitMessage,
192192
}
193193
}
194+
195+
func (self *CommitsHelper) OpenCommitMenu(suggestionFunc func(string) []*types.Suggestion) error {
196+
menuItems := []*types.MenuItem{
197+
{
198+
Label: self.c.Tr.OpenInEditor,
199+
OnPress: func() error {
200+
return self.SwitchToEditor()
201+
},
202+
Key: 'e',
203+
},
204+
}
205+
return self.c.Menu(types.CreateMenuOptions{
206+
Title: self.c.Tr.CommitMenuTitle,
207+
Items: menuItems,
208+
})
209+
}

pkg/i18n/english.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ type TranslationSet struct {
208208
SearchTitle string
209209
TagsTitle string
210210
MenuTitle string
211+
CommitMenuTitle string
211212
RemotesTitle string
212213
RemoteBranchesTitle string
213214
PatchBuildingTitle string
@@ -1000,12 +1001,13 @@ func EnglishTranslationSet() TranslationSet {
10001001
RebaseOptionsTitle: "Rebase options",
10011002
CommitSummaryTitle: "Commit summary",
10021003
CommitDescriptionTitle: "Commit description",
1003-
CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.switchToEditorKeyBinding}} to switch to editor",
1004+
CommitDescriptionSubTitle: "Toggle focus {{.togglePanelKeyBinding}}, Open menu {{.commitMenuKeybinding}}",
10041005
CommitDescriptionSubTitleNoSwitch: "Press {{.togglePanelKeyBinding}} to toggle focus",
10051006
LocalBranchesTitle: "Local branches",
10061007
SearchTitle: "Search",
10071008
TagsTitle: "Tags",
10081009
MenuTitle: "Menu",
1010+
CommitMenuTitle: "Commit Menu",
10091011
RemotesTitle: "Remotes",
10101012
RemoteBranchesTitle: "Remote branches",
10111013
PatchBuildingTitle: "Main panel (patch building)",

pkg/integration/components/commit_message_panel_driver.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ func (self *CommitMessagePanelDriver) Cancel() {
7474
self.getViewDriver().PressEscape()
7575
}
7676

77-
func (self *CommitMessagePanelDriver) SwitchToEditor() {
78-
self.getViewDriver().Press(self.t.keys.CommitMessage.SwitchToEditor)
79-
}
80-
8177
func (self *CommitMessagePanelDriver) SelectPreviousMessage() *CommitMessagePanelDriver {
8278
self.getViewDriver().SelectPreviousItem()
8379
return self
@@ -87,3 +83,8 @@ func (self *CommitMessagePanelDriver) SelectNextMessage() *CommitMessagePanelDri
8783
self.getViewDriver().SelectNextItem()
8884
return self
8985
}
86+
87+
func (self *CommitMessagePanelDriver) OpenCommitMenu() *CommitMessagePanelDriver {
88+
self.t.press(self.t.keys.CommitMessage.CommitMenu)
89+
return self
90+
}

pkg/integration/tests/commit/commit_switch_to_editor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ var CommitSwitchToEditor = NewIntegrationTest(NewIntegrationTestArgs{
3333
SwitchToDescription().
3434
Type("second line").
3535
SwitchToSummary().
36-
SwitchToEditor()
36+
OpenCommitMenu().
37+
Type("e")
3738
t.Views().Commits().
3839
Lines(
3940
Contains("first line"),

0 commit comments

Comments
 (0)