Skip to content

Commit 318a399

Browse files
authored
Fix enabling/disabling of ctrl-o in commit message panel (#3395)
- **PR Description** This fixes two minor regressions introduced in #3097 related to commands that open a commit message panel but don't set an onSwitchToEditor function (an example is the commit message panel that appears when moving a custom patch to a new commit): - the "Press <c-o> to open menu" hint was hidden. That's wrong, it is still possible to open the menu in this case. (And it still worked, we just wouldn't show the hint.) - invoking the "open in editor" menu item would silently do nothing. Now we set a DisabledReason for the item in this case.
2 parents 9a3db0d + 7764e6d commit 318a399

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

pkg/gui/context/commit_message_context.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
99
"github.com/jesseduffield/lazygit/pkg/gui/types"
1010
"github.com/jesseduffield/lazygit/pkg/utils"
11-
"github.com/samber/lo"
1211
)
1312

1413
type CommitMessageContext struct {
@@ -112,8 +111,7 @@ func (self *CommitMessageContext) SetPanelState(
112111
self.GetView().Title = summaryTitle
113112
self.c.Views().CommitDescription.Title = descriptionTitle
114113

115-
subtitleTemplate := lo.Ternary(onSwitchToEditor != nil, self.c.Tr.CommitDescriptionSubTitle, self.c.Tr.CommitDescriptionSubTitleNoSwitch)
116-
self.c.Views().CommitDescription.Subtitle = utils.ResolvePlaceholderString(subtitleTemplate,
114+
self.c.Views().CommitDescription.Subtitle = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionSubTitle,
117115
map[string]string{
118116
"togglePanelKeyBinding": keybindings.Label(self.c.UserConfig.Keybinding.Universal.TogglePanel),
119117
"commitMenuKeybinding": keybindings.Label(self.c.UserConfig.Keybinding.CommitMessage.CommitMenu),

pkg/gui/controllers/helpers/commits_helper.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ func TryRemoveHardLineBreaks(message string, autoWrapWidth int) string {
9191
}
9292

9393
func (self *CommitsHelper) SwitchToEditor() error {
94-
if !self.c.Contexts().CommitMessage.CanSwitchToEditor() {
95-
return nil
96-
}
97-
9894
message := lo.Ternary(len(self.getCommitDescription()) == 0,
9995
self.getCommitSummary(),
10096
self.getCommitSummary()+"\n\n"+self.getCommitDescription())
@@ -218,13 +214,21 @@ func (self *CommitsHelper) commitMessageContexts() []types.Context {
218214
}
219215

220216
func (self *CommitsHelper) OpenCommitMenu(suggestionFunc func(string) []*types.Suggestion) error {
217+
var disabledReasonForOpenInEditor *types.DisabledReason
218+
if !self.c.Contexts().CommitMessage.CanSwitchToEditor() {
219+
disabledReasonForOpenInEditor = &types.DisabledReason{
220+
Text: self.c.Tr.CommandDoesNotSupportOpeningInEditor,
221+
}
222+
}
223+
221224
menuItems := []*types.MenuItem{
222225
{
223226
Label: self.c.Tr.OpenInEditor,
224227
OnPress: func() error {
225228
return self.SwitchToEditor()
226229
},
227-
Key: 'e',
230+
Key: 'e',
231+
DisabledReason: disabledReasonForOpenInEditor,
228232
},
229233
{
230234
Label: self.c.Tr.AddCoAuthor,

pkg/i18n/english.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ type TranslationSet struct {
272272
CommitSummaryTitle string
273273
CommitDescriptionTitle string
274274
CommitDescriptionSubTitle string
275-
CommitDescriptionSubTitleNoSwitch string
276275
LocalBranchesTitle string
277276
SearchTitle string
278277
TagsTitle string
@@ -776,6 +775,7 @@ type TranslationSet struct {
776775
SelectedItemDoesNotHaveFiles string
777776
RangeSelectNotSupportedForSubmodules string
778777
OldCherryPickKeyWarning string
778+
CommandDoesNotSupportOpeningInEditor string
779779
Actions Actions
780780
Bisect Bisect
781781
Log Log
@@ -1229,7 +1229,6 @@ func EnglishTranslationSet() TranslationSet {
12291229
CommitSummaryTitle: "Commit summary",
12301230
CommitDescriptionTitle: "Commit description",
12311231
CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.commitMenuKeybinding}} to open menu",
1232-
CommitDescriptionSubTitleNoSwitch: "Press {{.togglePanelKeyBinding}} to toggle focus",
12331232
LocalBranchesTitle: "Local branches",
12341233
SearchTitle: "Search",
12351234
TagsTitle: "Tags",
@@ -1733,6 +1732,7 @@ func EnglishTranslationSet() TranslationSet {
17331732
SelectedItemDoesNotHaveFiles: "Selected item does not have files to view",
17341733
RangeSelectNotSupportedForSubmodules: "Range select not supported for submodules",
17351734
OldCherryPickKeyWarning: "The 'c' key is no longer the default key for copying commits to cherry pick. Please use `{{.copy}}` instead (and `{{.paste}}` to paste). The reason for this change is that the 'v' key for selecting a range of lines when staging is now also used for selecting a range of lines in any list view, meaning that we needed to find a new key for pasting commits, and if we're going to now use `{{.paste}}` for pasting commits, we may as well use `{{.copy}}` for copying them. If you want to configure the keybindings to get the old behaviour, set the following in your config:\n\nkeybinding:\n universal:\n toggleRangeSelect: <something other than v>\n commits:\n cherryPickCopy: 'c'\n pasteCommits: 'v'",
1735+
CommandDoesNotSupportOpeningInEditor: "This command doesn't support switching to the editor",
17361736

17371737
Actions: Actions{
17381738
// TODO: combine this with the original keybinding descriptions (those are all in lowercase atm)

pkg/i18n/polish.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ func polishTranslationSet() TranslationSet {
256256
CommitSummaryTitle: "Podsumowanie commita",
257257
CommitDescriptionTitle: "Opis commita",
258258
CommitDescriptionSubTitle: "Naciśnij {{.togglePanelKeyBinding}}, aby przełączyć fokus, {{.commitMenuKeybinding}}, aby otworzyć menu",
259-
CommitDescriptionSubTitleNoSwitch: "Naciśnij {{.togglePanelKeyBinding}}, aby przełączyć fokus",
260259
LocalBranchesTitle: "Lokalne gałęzie",
261260
SearchTitle: "Szukaj",
262261
TagsTitle: "Tagi",

0 commit comments

Comments
 (0)