Add menuKey helper to reduce noise on menu item literals

Constructing a menu item key from a literal character requires
gocui.NewKeyRune('r'), which is a bit noisy. Add a private menuKey helper in
both the controllers and helpers packages so the common case in either reads as
menuKey('r'). Duplicating the one-liner is cheaper than a cross-package import
dependency and avoids forcing every controller file to qualify the call.

The reason for doing this now is that we are going to change MenuItem.Key to a
slice of keys later in the branch, which means we'd have to add `[]gocui.Key{`
at each call site, making them even more noisy. With the menuKey helper we can
just change its signature and leave all clients unchanged.
This commit is contained in:
Stefan Haller
2026-05-25 15:18:18 +02:00
parent 12cfb9be1f
commit 22a508fdba
17 changed files with 136 additions and 118 deletions
@@ -6,7 +6,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/context/traits"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
@@ -164,14 +163,14 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e
OnPress: func() error {
return self.copyCommitSubjectToClipboard(commit)
},
Key: gocui.NewKeyRune('s'),
Key: menuKey('s'),
},
{
Label: self.c.Tr.CommitMessage,
OnPress: func() error {
return self.copyCommitMessageToClipboard(commit)
},
Key: gocui.NewKeyRune('m'),
Key: menuKey('m'),
},
{
Label: self.c.Tr.CommitMessageBody,
@@ -179,28 +178,28 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e
OnPress: func() error {
return self.copyCommitMessageBodyToClipboard(commitMessageBody)
},
Key: gocui.NewKeyRune('b'),
Key: menuKey('b'),
},
{
Label: self.c.Tr.CommitURL,
OnPress: func() error {
return self.copyCommitURLToClipboard(commit)
},
Key: gocui.NewKeyRune('u'),
Key: menuKey('u'),
},
{
Label: self.c.Tr.CommitDiff,
OnPress: func() error {
return self.copyCommitDiffToClipboard(commit)
},
Key: gocui.NewKeyRune('d'),
Key: menuKey('d'),
},
{
Label: self.c.Tr.CommitAuthor,
OnPress: func() error {
return self.copyAuthorToClipboard(commit)
},
Key: gocui.NewKeyRune('a'),
Key: menuKey('a'),
},
}
@@ -209,7 +208,7 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e
OnPress: func() error {
return self.copyCommitTagsToClipboard(commit)
},
Key: gocui.NewKeyRune('t'),
Key: menuKey('t'),
}
if len(commit.Tags) == 0 {
+8 -9
View File
@@ -6,7 +6,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
@@ -102,7 +101,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
return self.afterMark(selectCurrentAfter, waitToReselect)
},
DisabledReason: singleItemIfNotBisecting,
Key: gocui.NewKeyRune('b'),
Key: menuKey('b'),
},
{
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, shortHashToMark, info.OldTerm()),
@@ -115,7 +114,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
return self.afterMark(selectCurrentAfter, waitToReselect)
},
DisabledReason: singleItemIfNotBisecting,
Key: gocui.NewKeyRune('g'),
Key: menuKey('g'),
},
{
Label: fmt.Sprintf(self.c.Tr.Bisect.SkipCurrent, shortHashToMark),
@@ -128,7 +127,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
return self.afterMark(selectCurrentAfter, waitToReselect)
},
DisabledReason: singleItemIfNotBisecting,
Key: gocui.NewKeyRune('s'),
Key: menuKey('s'),
},
}
if info.GetCurrentHash() != "" && info.GetCurrentHash() != commit.Hash() {
@@ -143,7 +142,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
return self.afterMark(selectCurrentAfter, waitToReselect)
},
DisabledReason: self.require(self.singleItemSelected())(),
Key: gocui.NewKeyRune('S'),
Key: menuKey('S'),
}))
}
menuItems = append(menuItems, lo.ToPtr(types.MenuItem{
@@ -151,7 +150,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
OnPress: func() error {
return self.c.Helpers().Bisect.Reset()
},
Key: gocui.NewKeyRune('r'),
Key: menuKey('r'),
}))
return self.c.Menu(types.CreateMenuOptions{
@@ -180,7 +179,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
return nil
},
DisabledReason: self.require(self.singleItemSelected())(),
Key: gocui.NewKeyRune('b'),
Key: menuKey('b'),
},
{
Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortHash(), info.OldTerm()),
@@ -198,7 +197,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
return nil
},
DisabledReason: self.require(self.singleItemSelected())(),
Key: gocui.NewKeyRune('g'),
Key: menuKey('g'),
},
{
Label: self.c.Tr.Bisect.ChooseTerms,
@@ -223,7 +222,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
})
return nil
},
Key: gocui.NewKeyRune('t'),
Key: menuKey('t'),
},
},
})
+8 -8
View File
@@ -300,7 +300,7 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc
)
viewDivergenceFromBaseBranchItem := &types.MenuItem{
LabelColumns: []string{label},
Key: gocui.NewKeyRune('b'),
Key: menuKey('b'),
OnPress: func() error {
branch := self.context().GetSelected()
if branch == nil {
@@ -333,7 +333,7 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc
})
return nil
},
Key: gocui.NewKeyRune('u'),
Key: menuKey('u'),
}
setUpstreamItem := &types.MenuItem{
@@ -358,7 +358,7 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc
return nil
})
},
Key: gocui.NewKeyRune('s'),
Key: menuKey('s'),
}
upstreamResetOptions := utils.ResolvePlaceholderString(
@@ -391,7 +391,7 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc
return nil
},
Tooltip: upstreamResetTooltip,
Key: gocui.NewKeyRune('g'),
Key: menuKey('g'),
}
upstreamRebaseItem := &types.MenuItem{
@@ -404,7 +404,7 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc
return nil
},
Tooltip: upstreamRebaseTooltip,
Key: gocui.NewKeyRune('r'),
Key: menuKey('r'),
}
if !selectedBranch.IsTrackingRemote() {
@@ -624,7 +624,7 @@ func (self *BranchesController) delete(branches []*models.Branch) error {
localDeleteItem := &types.MenuItem{
Label: lo.Ternary(len(branches) > 1, self.c.Tr.DeleteLocalBranches, self.c.Tr.DeleteLocalBranch),
Key: gocui.NewKeyRune('c'),
Key: menuKey('c'),
OnPress: func() error {
return self.localDelete(branches)
},
@@ -635,7 +635,7 @@ func (self *BranchesController) delete(branches []*models.Branch) error {
remoteDeleteItem := &types.MenuItem{
Label: lo.Ternary(len(branches) > 1, self.c.Tr.DeleteRemoteBranches, self.c.Tr.DeleteRemoteBranch),
Key: gocui.NewKeyRune('r'),
Key: menuKey('r'),
OnPress: func() error {
return self.remoteDelete(branches)
},
@@ -648,7 +648,7 @@ func (self *BranchesController) delete(branches []*models.Branch) error {
deleteBothItem := &types.MenuItem{
Label: lo.Ternary(len(branches) > 1, self.c.Tr.DeleteLocalAndRemoteBranches, self.c.Tr.DeleteLocalAndRemoteBranch),
Key: gocui.NewKeyRune('b'),
Key: menuKey('b'),
OnPress: func() error {
return self.localAndRemoteDelete(branches)
},
@@ -230,7 +230,7 @@ func (self *CommitFilesController) openCopyMenu() error {
return nil
},
DisabledReason: self.require(self.singleItemSelected())(),
Key: gocui.NewKeyRune('n'),
Key: menuKey('n'),
}
copyRelativePathItem := &types.MenuItem{
Label: self.c.Tr.CopyRelativeFilePath,
@@ -242,7 +242,7 @@ func (self *CommitFilesController) openCopyMenu() error {
return nil
},
DisabledReason: self.require(self.singleItemSelected())(),
Key: gocui.NewKeyRune('p'),
Key: menuKey('p'),
}
copyAbsolutePathItem := &types.MenuItem{
Label: self.c.Tr.CopyAbsoluteFilePath,
@@ -258,7 +258,7 @@ func (self *CommitFilesController) openCopyMenu() error {
return nil
},
DisabledReason: self.require(self.singleItemSelected())(),
Key: gocui.NewKeyRune('P'),
Key: menuKey('P'),
}
copyFileDiffItem := &types.MenuItem{
Label: self.c.Tr.CopySelectedDiff,
@@ -266,7 +266,7 @@ func (self *CommitFilesController) openCopyMenu() error {
return self.copyDiffToClipboard(node.GetPath(), self.c.Tr.FileDiffCopiedToast)
},
DisabledReason: self.require(self.singleItemSelected())(),
Key: gocui.NewKeyRune('s'),
Key: menuKey('s'),
}
copyAllDiff := &types.MenuItem{
Label: self.c.Tr.CopyAllFilesDiff,
@@ -274,7 +274,7 @@ func (self *CommitFilesController) openCopyMenu() error {
return self.copyDiffToClipboard(".", self.c.Tr.AllFilesDiffCopiedToast)
},
DisabledReason: self.require(self.itemsSelected())(),
Key: gocui.NewKeyRune('a'),
Key: menuKey('a'),
}
copyFileContentItem := &types.MenuItem{
Label: self.c.Tr.CopyFileContent,
@@ -295,7 +295,7 @@ func (self *CommitFilesController) openCopyMenu() error {
}
return nil
}))(),
Key: gocui.NewKeyRune('c'),
Key: menuKey('c'),
}
return self.c.Menu(types.CreateMenuOptions{
@@ -31,19 +31,19 @@ func (self *CustomPatchOptionsMenuAction) Call() error {
Label: self.c.Tr.ResetPatch,
Tooltip: self.c.Tr.ResetPatchTooltip,
OnPress: self.c.Helpers().PatchBuilding.Reset,
Key: gocui.NewKeyRune('c'),
Key: menuKey('c'),
},
{
Label: self.c.Tr.ApplyPatch,
Tooltip: self.c.Tr.ApplyPatchTooltip,
OnPress: func() error { return self.handleApplyPatch(false) },
Key: gocui.NewKeyRune('a'),
Key: menuKey('a'),
},
{
Label: self.c.Tr.ApplyPatchInReverse,
Tooltip: self.c.Tr.ApplyPatchInReverseTooltip,
OnPress: func() error { return self.handleApplyPatch(true) },
Key: gocui.NewKeyRune('r'),
Key: menuKey('r'),
},
}
@@ -53,25 +53,25 @@ func (self *CustomPatchOptionsMenuAction) Call() error {
Label: fmt.Sprintf(self.c.Tr.RemovePatchFromOriginalCommit, utils.ShortHash(self.c.Git().Patch.PatchBuilder.To)),
Tooltip: self.c.Tr.RemovePatchFromOriginalCommitTooltip,
OnPress: self.handleDeletePatchFromCommit,
Key: gocui.NewKeyRune('d'),
Key: menuKey('d'),
},
{
Label: self.c.Tr.MovePatchOutIntoIndex,
Tooltip: self.c.Tr.MovePatchOutIntoIndexTooltip,
OnPress: self.handleMovePatchIntoWorkingTree,
Key: gocui.NewKeyRune('i'),
Key: menuKey('i'),
},
{
Label: self.c.Tr.MovePatchIntoNewCommit,
Tooltip: self.c.Tr.MovePatchIntoNewCommitTooltip,
OnPress: self.handlePullPatchIntoNewCommit,
Key: gocui.NewKeyRune('n'),
Key: menuKey('n'),
},
{
Label: self.c.Tr.MovePatchIntoNewCommitBefore,
Tooltip: self.c.Tr.MovePatchIntoNewCommitBeforeTooltip,
OnPress: self.handlePullPatchIntoNewCommitBefore,
Key: gocui.NewKeyRune('N'),
Key: menuKey('N'),
},
}...)
@@ -93,7 +93,7 @@ func (self *CustomPatchOptionsMenuAction) Call() error {
Label: fmt.Sprintf(self.c.Tr.MovePatchToSelectedCommit, selectedCommit.Hash()),
Tooltip: self.c.Tr.MovePatchToSelectedCommitTooltip,
OnPress: self.handleMovePatchToSelectedCommit,
Key: gocui.NewKeyRune('m'),
Key: menuKey('m'),
DisabledReason: disabledReason,
},
}, menuItems[1:]...,
@@ -107,7 +107,7 @@ func (self *CustomPatchOptionsMenuAction) Call() error {
{
Label: self.c.Tr.CopyPatchToClipboard,
OnPress: func() error { return self.copyPatchToClipboard() },
Key: gocui.NewKeyRune('y'),
Key: menuKey('y'),
},
}...)
+20 -20
View File
@@ -671,14 +671,14 @@ func (self *FilesController) handleNonInlineConflict(file *models.File) error {
OnPress: func() error {
return handle(self.c.Git().WorkingTree.StageFile, self.c.Tr.Actions.ResolveConflictByKeepingFile)
},
Key: gocui.NewKeyRune('k'),
Key: menuKey('k'),
}
deleteItem := &types.MenuItem{
Label: self.c.Tr.MergeConflictDeleteFile,
OnPress: func() error {
return handle(self.c.Git().WorkingTree.RemoveConflictedFile, self.c.Tr.Actions.ResolveConflictByDeletingFile)
},
Key: gocui.NewKeyRune('d'),
Key: menuKey('d'),
}
items := []*types.MenuItem{}
switch file.ShortStatus {
@@ -856,7 +856,7 @@ func (self *FilesController) ignoreOrExcludeMenu(node *filetree.FileNode) error
}
return nil
},
Key: gocui.NewKeyRune('i'),
Key: menuKey('i'),
},
{
LabelColumns: []string{self.c.Tr.ExcludeFile},
@@ -866,7 +866,7 @@ func (self *FilesController) ignoreOrExcludeMenu(node *filetree.FileNode) error
}
return nil
},
Key: gocui.NewKeyRune('e'),
Key: menuKey('e'),
},
},
})
@@ -950,7 +950,7 @@ func (self *FilesController) handleStatusFilterPressed() error {
OnPress: func() error {
return self.setStatusFiltering(filetree.DisplayStaged)
},
Key: gocui.NewKeyRune('s'),
Key: menuKey('s'),
Widget: types.MakeMenuRadioButton(currentFilter == filetree.DisplayStaged),
},
{
@@ -958,7 +958,7 @@ func (self *FilesController) handleStatusFilterPressed() error {
OnPress: func() error {
return self.setStatusFiltering(filetree.DisplayUnstaged)
},
Key: gocui.NewKeyRune('u'),
Key: menuKey('u'),
Widget: types.MakeMenuRadioButton(currentFilter == filetree.DisplayUnstaged),
},
{
@@ -966,7 +966,7 @@ func (self *FilesController) handleStatusFilterPressed() error {
OnPress: func() error {
return self.setStatusFiltering(filetree.DisplayTracked)
},
Key: gocui.NewKeyRune('t'),
Key: menuKey('t'),
Widget: types.MakeMenuRadioButton(currentFilter == filetree.DisplayTracked),
},
{
@@ -974,7 +974,7 @@ func (self *FilesController) handleStatusFilterPressed() error {
OnPress: func() error {
return self.setStatusFiltering(filetree.DisplayUntracked)
},
Key: gocui.NewKeyRune('T'),
Key: menuKey('T'),
Widget: types.MakeMenuRadioButton(currentFilter == filetree.DisplayUntracked),
},
{
@@ -982,7 +982,7 @@ func (self *FilesController) handleStatusFilterPressed() error {
OnPress: func() error {
return self.setStatusFiltering(filetree.DisplayAll)
},
Key: gocui.NewKeyRune('r'),
Key: menuKey('r'),
Widget: types.MakeMenuRadioButton(currentFilter == filetree.DisplayAll),
},
},
@@ -1092,7 +1092,7 @@ func (self *FilesController) createStashMenu() error {
}
return self.handleStashSave(self.c.Git().Stash.Push, self.c.Tr.Actions.StashAllChanges)
},
Key: gocui.NewKeyRune('a'),
Key: menuKey('a'),
},
{
Label: self.c.Tr.StashAllChangesKeepIndex,
@@ -1103,14 +1103,14 @@ func (self *FilesController) createStashMenu() error {
// if there are no staged files it behaves the same as Stash.Save
return self.handleStashSave(self.c.Git().Stash.StashAndKeepIndex, self.c.Tr.Actions.StashAllChangesKeepIndex)
},
Key: gocui.NewKeyRune('i'),
Key: menuKey('i'),
},
{
Label: self.c.Tr.StashIncludeUntrackedChanges,
OnPress: func() error {
return self.handleStashSave(self.c.Git().Stash.StashIncludeUntrackedChanges, self.c.Tr.Actions.StashIncludeUntrackedChanges)
},
Key: gocui.NewKeyRune('U'),
Key: menuKey('U'),
},
{
Label: self.c.Tr.StashStagedChanges,
@@ -1121,7 +1121,7 @@ func (self *FilesController) createStashMenu() error {
}
return self.handleStashSave(self.c.Git().Stash.SaveStagedChanges, self.c.Tr.Actions.StashStagedChanges)
},
Key: gocui.NewKeyRune('s'),
Key: menuKey('s'),
},
{
Label: self.c.Tr.StashUnstagedChanges,
@@ -1135,7 +1135,7 @@ func (self *FilesController) createStashMenu() error {
// ordinary stash
return self.handleStashSave(self.c.Git().Stash.Push, self.c.Tr.Actions.StashUnstagedChanges)
},
Key: gocui.NewKeyRune('u'),
Key: menuKey('u'),
},
},
})
@@ -1182,7 +1182,7 @@ func (self *FilesController) openCopyMenu() error {
return nil
},
DisabledReason: self.require(self.singleItemSelected())(),
Key: gocui.NewKeyRune('n'),
Key: menuKey('n'),
}
copyRelativePathItem := &types.MenuItem{
Label: self.c.Tr.CopyRelativeFilePath,
@@ -1194,7 +1194,7 @@ func (self *FilesController) openCopyMenu() error {
return nil
},
DisabledReason: self.require(self.singleItemSelected())(),
Key: gocui.NewKeyRune('p'),
Key: menuKey('p'),
}
copyAbsolutePathItem := &types.MenuItem{
Label: self.c.Tr.CopyAbsoluteFilePath,
@@ -1210,7 +1210,7 @@ func (self *FilesController) openCopyMenu() error {
return nil
},
DisabledReason: self.require(self.singleItemSelected())(),
Key: gocui.NewKeyRune('P'),
Key: menuKey('P'),
}
copyFileDiffItem := &types.MenuItem{
Label: self.c.Tr.CopySelectedDiff,
@@ -1236,7 +1236,7 @@ func (self *FilesController) openCopyMenu() error {
return nil
},
))(),
Key: gocui.NewKeyRune('s'),
Key: menuKey('s'),
}
copyAllDiff := &types.MenuItem{
Label: self.c.Tr.CopyAllFilesDiff,
@@ -1261,7 +1261,7 @@ func (self *FilesController) openCopyMenu() error {
return nil
},
)(),
Key: gocui.NewKeyRune('a'),
Key: menuKey('a'),
}
return self.c.Menu(types.CreateMenuOptions{
@@ -1528,7 +1528,7 @@ func (self *FilesController) remove(selectedNodes []*filetree.FileNode) error {
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
return nil
},
Key: gocui.NewKeyRune('u'),
Key: menuKey('u'),
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.DiscardUnstagedTooltip,
map[string]string{
+4 -5
View File
@@ -5,7 +5,6 @@ import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@@ -83,22 +82,22 @@ func (self *GitFlowController) handleCreateGitFlowMenu(branch *models.Branch) er
{
Label: "start feature",
OnPress: startHandler("feature"),
Key: gocui.NewKeyRune('f'),
Key: menuKey('f'),
},
{
Label: "start hotfix",
OnPress: startHandler("hotfix"),
Key: gocui.NewKeyRune('h'),
Key: menuKey('h'),
},
{
Label: "start bugfix",
OnPress: startHandler("bugfix"),
Key: gocui.NewKeyRune('b'),
Key: menuKey('b'),
},
{
Label: "start release",
OnPress: startHandler("release"),
Key: gocui.NewKeyRune('r'),
Key: menuKey('r'),
},
},
})
@@ -228,7 +228,7 @@ func (self *CommitsHelper) OpenCommitMenu(suggestionFunc func(string) []*types.S
OnPress: func() error {
return self.SwitchToEditor()
},
Key: gocui.NewKeyRune('e'),
Key: menuKey('e'),
DisabledReason: disabledReasonForOpenInEditor,
},
{
@@ -236,14 +236,14 @@ func (self *CommitsHelper) OpenCommitMenu(suggestionFunc func(string) []*types.S
OnPress: func() error {
return self.addCoAuthor(suggestionFunc)
},
Key: gocui.NewKeyRune('c'),
Key: menuKey('c'),
},
{
Label: self.c.Tr.PasteCommitMessageFromClipboard,
OnPress: func() error {
return self.pasteCommitMessageFromClipboard()
},
Key: gocui.NewKeyRune('p'),
Key: menuKey('p'),
},
}
return self.c.Menu(types.CreateMenuOptions{
+11
View File
@@ -0,0 +1,11 @@
package helpers
import "github.com/jesseduffield/lazygit/pkg/gocui"
// menuKey is a shorthand for constructing a key value for a menu item from a single rune literal,
// avoiding the noise of `gocui.NewKeyRune('a')` at every call site. There is an intentionally
// identical helper in the controllers package so that callers in either package can use the
// unqualified form.
func menuKey(r rune) gocui.Key {
return gocui.NewKeyRune(r)
}
@@ -43,13 +43,13 @@ func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error {
}
options := []optionAndKey{
{option: REBASE_OPTION_CONTINUE, key: gocui.NewKeyRune('c')},
{option: REBASE_OPTION_ABORT, key: gocui.NewKeyRune('a')},
{option: REBASE_OPTION_CONTINUE, key: menuKey('c')},
{option: REBASE_OPTION_ABORT, key: menuKey('a')},
}
if self.c.Git().Status.WorkingTreeState().CanSkip() {
options = append(options, optionAndKey{
option: REBASE_OPTION_SKIP, key: gocui.NewKeyRune('s'),
option: REBASE_OPTION_SKIP, key: menuKey('s'),
})
}
@@ -198,7 +198,7 @@ func (self *MergeAndRebaseHelper) PromptForConflictHandling() error {
OnPress: func() error {
return self.genericMergeCommand(REBASE_OPTION_ABORT)
},
Key: gocui.NewKeyRune('a'),
Key: menuKey('a'),
},
},
HideCancel: true,
@@ -284,7 +284,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
Label: utils.ResolvePlaceholderString(self.c.Tr.SimpleRebase,
map[string]string{"ref": ref},
),
Key: gocui.NewKeyRune('s'),
Key: menuKey('s'),
DisabledReason: disabledReason,
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.RebaseBranch)
@@ -308,7 +308,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
Label: utils.ResolvePlaceholderString(self.c.Tr.InteractiveRebase,
map[string]string{"ref": ref},
),
Key: gocui.NewKeyRune('i'),
Key: menuKey('i'),
DisabledReason: disabledReason,
Tooltip: self.c.Tr.InteractiveRebaseTooltip,
OnPress: func() error {
@@ -334,7 +334,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
Label: utils.ResolvePlaceholderString(self.c.Tr.RebaseOntoBaseBranch,
map[string]string{"baseBranch": ShortBranchName(baseBranch)},
),
Key: gocui.NewKeyRune('b'),
Key: menuKey('b'),
DisabledReason: baseBranchDisabledReason,
Tooltip: self.c.Tr.RebaseOntoBaseBranchTooltip,
OnPress: func() error {
@@ -392,7 +392,7 @@ func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) e
firstRegularMergeItem = &types.MenuItem{
Label: self.c.Tr.RegularMergeFastForward,
OnPress: self.RegularMerge(refName, git_commands.MERGE_VARIANT_REGULAR),
Key: gocui.NewKeyRune('m'),
Key: menuKey('m'),
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.RegularMergeFastForwardTooltip,
map[string]string{
@@ -406,7 +406,7 @@ func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) e
secondRegularMergeItem = &types.MenuItem{
Label: self.c.Tr.RegularMergeNonFastForward,
OnPress: self.RegularMerge(refName, git_commands.MERGE_VARIANT_NON_FAST_FORWARD),
Key: gocui.NewKeyRune('n'),
Key: menuKey('n'),
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.RegularMergeNonFastForwardTooltip,
map[string]string{
@@ -419,7 +419,7 @@ func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) e
firstRegularMergeItem = &types.MenuItem{
Label: self.c.Tr.RegularMergeNonFastForward,
OnPress: self.RegularMerge(refName, git_commands.MERGE_VARIANT_REGULAR),
Key: gocui.NewKeyRune('m'),
Key: menuKey('m'),
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.RegularMergeNonFastForwardTooltip,
map[string]string{
@@ -432,7 +432,7 @@ func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) e
secondRegularMergeItem = &types.MenuItem{
Label: self.c.Tr.RegularMergeFastForward,
OnPress: self.RegularMerge(refName, git_commands.MERGE_VARIANT_FAST_FORWARD),
Key: gocui.NewKeyRune('f'),
Key: menuKey('f'),
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.RegularMergeFastForwardTooltip,
map[string]string{
@@ -464,7 +464,7 @@ func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) e
{
Label: self.c.Tr.SquashMergeUncommitted,
OnPress: self.SquashMergeUncommitted(refName),
Key: gocui.NewKeyRune('s'),
Key: menuKey('s'),
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.SquashMergeUncommittedTooltip,
map[string]string{
@@ -475,7 +475,7 @@ func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) e
{
Label: self.c.Tr.SquashMergeCommitted,
OnPress: self.SquashMergeCommitted(refName, checkedOutBranchName),
Key: gocui.NewKeyRune('S'),
Key: menuKey('S'),
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.SquashMergeCommittedTooltip,
map[string]string{
+9 -9
View File
@@ -222,9 +222,9 @@ func (self *RefsHelper) CreateSortOrderMenu(sortOptionsOrder []string, menuPromp
sortOrder string
}
availableSortOptions := map[string]sortMenuOption{
"recency": {label: self.c.Tr.SortByRecency, description: self.c.Tr.SortBasedOnReflog, key: gocui.NewKeyRune('r')},
"alphabetical": {label: self.c.Tr.SortAlphabetical, description: "--sort=refname", key: gocui.NewKeyRune('a')},
"date": {label: self.c.Tr.SortByDate, description: "--sort=-committerdate", key: gocui.NewKeyRune('d')},
"recency": {label: self.c.Tr.SortByRecency, description: self.c.Tr.SortBasedOnReflog, key: menuKey('r')},
"alphabetical": {label: self.c.Tr.SortAlphabetical, description: "--sort=refname", key: menuKey('a')},
"date": {label: self.c.Tr.SortByDate, description: "--sort=-committerdate", key: menuKey('d')},
}
sortOptions := make([]sortMenuOption, 0, len(sortOptionsOrder))
for _, key := range sortOptionsOrder {
@@ -265,9 +265,9 @@ func (self *RefsHelper) CreateGitResetMenu(name string, ref string) error {
}
strengths := []strengthWithKey{
// not i18'ing because it's git terminology
{strength: "mixed", label: "Mixed reset", key: gocui.NewKeyRune('m'), tooltip: self.c.Tr.ResetMixedTooltip},
{strength: "soft", label: "Soft reset", key: gocui.NewKeyRune('s'), tooltip: self.c.Tr.ResetSoftTooltip},
{strength: "hard", label: "Hard reset", key: gocui.NewKeyRune('h'), tooltip: self.c.Tr.ResetHardTooltip},
{strength: "mixed", label: "Mixed reset", key: menuKey('m'), tooltip: self.c.Tr.ResetMixedTooltip},
{strength: "soft", label: "Soft reset", key: menuKey('s'), tooltip: self.c.Tr.ResetSoftTooltip},
{strength: "hard", label: "Hard reset", key: menuKey('h'), tooltip: self.c.Tr.ResetHardTooltip},
}
menuItems := lo.Map(strengths, func(row strengthWithKey, _ int) *types.MenuItem {
@@ -312,7 +312,7 @@ func (self *RefsHelper) CreateCheckoutMenu(commit *models.Commit) error {
self.c.LogAction(self.c.Tr.Actions.CheckoutCommit)
return self.CheckoutRef(hash, types.CheckoutRefOptions{})
},
Key: gocui.NewKeyRune('d'),
Key: menuKey('d'),
},
}
@@ -320,7 +320,7 @@ func (self *RefsHelper) CreateCheckoutMenu(commit *models.Commit) error {
menuItems = append(menuItems, lo.Map(branches, func(branch *models.Branch, index int) *types.MenuItem {
var key gocui.Key
if index < 9 {
key = gocui.NewKeyRune(rune(index + 1 + '0')) // Convert 1-based index to key
key = menuKey(rune(index + 1 + '0')) // Convert 1-based index to key
}
return &types.MenuItem{
LabelColumns: []string{fmt.Sprintf(self.c.Tr.Actions.CheckoutBranchAtCommit, branch.Name)},
@@ -336,7 +336,7 @@ func (self *RefsHelper) CreateCheckoutMenu(commit *models.Commit) error {
LabelColumns: []string{self.c.Tr.Actions.CheckoutBranch},
OnPress: func() error { return nil },
DisabledReason: &types.DisabledReason{Text: self.c.Tr.NoBranchesFoundAtCommitTooltip},
Key: gocui.NewKeyRune('1'),
Key: menuKey('1'),
})
}
@@ -10,7 +10,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
@@ -383,7 +382,7 @@ func (self *WorkingTreeHelper) CreateMergeConflictMenu(selectedFilepaths []strin
OnPress: func() error {
return onMergeStrategySelected("--ours")
},
Key: gocui.NewKeyRune('c'),
Key: menuKey('c'),
},
{
LabelColumns: []string{
@@ -393,7 +392,7 @@ func (self *WorkingTreeHelper) CreateMergeConflictMenu(selectedFilepaths []strin
OnPress: func() error {
return onMergeStrategySelected("--theirs")
},
Key: gocui.NewKeyRune('i'),
Key: menuKey('i'),
},
{
LabelColumns: []string{
@@ -403,7 +402,7 @@ func (self *WorkingTreeHelper) CreateMergeConflictMenu(selectedFilepaths []strin
OnPress: func() error {
return onMergeStrategySelected("--union")
},
Key: gocui.NewKeyRune('b'),
Key: menuKey('b'),
},
{
LabelColumns: []string{
@@ -411,7 +410,7 @@ func (self *WorkingTreeHelper) CreateMergeConflictMenu(selectedFilepaths []strin
cmdColor.Sprint("git mergetool"),
},
OnPress: self.OpenMergeTool,
Key: gocui.NewKeyRune('m'),
Key: menuKey('m'),
},
},
})
@@ -361,7 +361,7 @@ func (self *LocalCommitsController) fixup(selectedCommits []*models.Commit, star
Items: []*types.MenuItem{
{
Label: self.c.Tr.Fixup,
Key: gocui.NewKeyRune('f'),
Key: menuKey('f'),
OnPress: func() error {
return self.c.WithWaitingStatus(self.c.Tr.FixingStatus, func(gocui.Task) error {
self.c.LogAction(self.c.Tr.Actions.FixupCommit)
@@ -372,7 +372,7 @@ func (self *LocalCommitsController) fixup(selectedCommits []*models.Commit, star
},
{
Label: self.c.Tr.FixupKeepMessage,
Key: gocui.NewKeyRune('c'),
Key: menuKey('c'),
OnPress: func() error {
return self.c.WithWaitingStatus(self.c.Tr.FixingStatus, func(gocui.Task) error {
self.c.LogAction(self.c.Tr.Actions.FixupCommitKeepMessage)
@@ -403,7 +403,7 @@ func (self *LocalCommitsController) setFixupMessage(commit *models.Commit) error
Items: []*types.MenuItem{
{
Label: self.c.Tr.FixupDiscardMessage,
Key: gocui.NewKeyRune('f'),
Key: menuKey('f'),
OnPress: func() error {
return self.updateTodosWithFlag(todo.Fixup, []*models.Commit{commit}, "")
},
@@ -411,7 +411,7 @@ func (self *LocalCommitsController) setFixupMessage(commit *models.Commit) error
},
{
Label: self.c.Tr.FixupKeepMessage,
Key: gocui.NewKeyRune('c'),
Key: menuKey('c'),
OnPress: func() error {
return self.updateTodosWithFlag(todo.Fixup, []*models.Commit{commit}, "-C")
},
@@ -1000,7 +1000,7 @@ func (self *LocalCommitsController) createFixupCommit(commit *models.Commit) err
Items: []*types.MenuItem{
{
Label: self.c.Tr.FixupMenu_Fixup,
Key: gocui.NewKeyRune('f'),
Key: menuKey('f'),
OnPress: func() error {
return self.c.Helpers().WorkingTree.WithEnsureCommittableFiles(func() error {
self.c.LogAction(self.c.Tr.Actions.CreateFixupCommit)
@@ -1024,7 +1024,7 @@ func (self *LocalCommitsController) createFixupCommit(commit *models.Commit) err
},
{
Label: self.c.Tr.FixupMenu_AmendWithChanges,
Key: gocui.NewKeyRune('a'),
Key: menuKey('a'),
OnPress: func() error {
return self.c.Helpers().WorkingTree.WithEnsureCommittableFiles(func() error {
return self.createAmendCommit(commit, true)
@@ -1035,7 +1035,7 @@ func (self *LocalCommitsController) createFixupCommit(commit *models.Commit) err
},
{
Label: self.c.Tr.FixupMenu_AmendWithoutChanges,
Key: gocui.NewKeyRune('r'),
Key: menuKey('r'),
OnPress: func() error { return self.createAmendCommit(commit, false) },
Tooltip: self.c.Tr.FixupMenu_AmendWithoutChangesTooltip,
},
@@ -1134,14 +1134,14 @@ func (self *LocalCommitsController) squashFixupCommits() error {
Label: self.c.Tr.SquashCommitsInCurrentBranch,
OnPress: self.squashAllFixupsInCurrentBranch,
DisabledReason: self.canFindCommitForSquashFixupsInCurrentBranch(),
Key: gocui.NewKeyRune('b'),
Key: menuKey('b'),
Tooltip: self.c.Tr.SquashCommitsInCurrentBranchTooltip,
},
{
Label: self.c.Tr.SquashCommitsAboveSelectedCommit,
OnPress: self.withItem(self.squashAllFixupsAboveSelectedCommit),
DisabledReason: self.singleItemSelected()(),
Key: gocui.NewKeyRune('a'),
Key: menuKey('a'),
Tooltip: self.c.Tr.SquashCommitsAboveSelectedTooltip,
},
},
+11
View File
@@ -0,0 +1,11 @@
package controllers
import "github.com/jesseduffield/lazygit/pkg/gocui"
// menuKey is a shorthand for constructing a key value for a menu item from a single rune literal,
// avoiding the noise of `gocui.NewKeyRune('a')` at every call site. There is an intentionally
// identical helper in the helpers package so that callers in either package can use the unqualified
// form.
func menuKey(r rune) gocui.Key {
return gocui.NewKeyRune(r)
}
+4 -4
View File
@@ -233,7 +233,7 @@ func (self *SubmodulesController) openBulkActionsMenu() error {
return nil
})
},
Key: gocui.NewKeyRune('i'),
Key: menuKey('i'),
},
{
LabelColumns: []string{self.c.Tr.BulkUpdateSubmodules, style.FgYellow.Sprint(self.c.Git().Submodule.BulkUpdateCmdObj().ToString())},
@@ -248,7 +248,7 @@ func (self *SubmodulesController) openBulkActionsMenu() error {
return nil
})
},
Key: gocui.NewKeyRune('u'),
Key: menuKey('u'),
},
{
LabelColumns: []string{self.c.Tr.BulkUpdateRecursiveSubmodules, style.FgYellow.Sprint(self.c.Git().Submodule.BulkUpdateRecursivelyCmdObj().ToString())},
@@ -263,7 +263,7 @@ func (self *SubmodulesController) openBulkActionsMenu() error {
return nil
})
},
Key: gocui.NewKeyRune('r'),
Key: menuKey('r'),
},
{
LabelColumns: []string{self.c.Tr.BulkDeinitSubmodules, style.FgRed.Sprint(self.c.Git().Submodule.BulkDeinitCmdObj().ToString())},
@@ -278,7 +278,7 @@ func (self *SubmodulesController) openBulkActionsMenu() error {
return nil
})
},
Key: gocui.NewKeyRune('d'),
Key: menuKey('d'),
},
},
})
+3 -3
View File
@@ -282,14 +282,14 @@ func (self *TagsController) delete(tag *models.Tag) error {
menuItems := []*types.MenuItem{
{
Label: self.c.Tr.DeleteLocalTag,
Key: gocui.NewKeyRune('c'),
Key: menuKey('c'),
OnPress: func() error {
return self.localDelete(tag)
},
},
{
Label: self.c.Tr.DeleteRemoteTag,
Key: gocui.NewKeyRune('r'),
Key: menuKey('r'),
OpensMenu: true,
OnPress: func() error {
return self.remoteDelete(tag)
@@ -297,7 +297,7 @@ func (self *TagsController) delete(tag *models.Tag) error {
},
{
Label: self.c.Tr.DeleteLocalAndRemoteTag,
Key: gocui.NewKeyRune('b'),
Key: menuKey('b'),
OpensMenu: true,
OnPress: func() error {
return self.localAndRemoteDelete(tag)
@@ -53,7 +53,7 @@ func (self *FilesController) createResetMenu() error {
})
return nil
},
Key: gocui.NewKeyRune('x'),
Key: menuKey('x'),
Tooltip: self.c.Tr.NukeDescription,
},
{
@@ -72,7 +72,7 @@ func (self *FilesController) createResetMenu() error {
)
return nil
},
Key: gocui.NewKeyRune('u'),
Key: menuKey('u'),
},
{
LabelColumns: []string{
@@ -90,7 +90,7 @@ func (self *FilesController) createResetMenu() error {
)
return nil
},
Key: gocui.NewKeyRune('c'),
Key: menuKey('c'),
},
{
LabelColumns: []string{
@@ -115,7 +115,7 @@ func (self *FilesController) createResetMenu() error {
)
return nil
},
Key: gocui.NewKeyRune('S'),
Key: menuKey('S'),
},
{
LabelColumns: []string{
@@ -133,7 +133,7 @@ func (self *FilesController) createResetMenu() error {
)
return nil
},
Key: gocui.NewKeyRune('s'),
Key: menuKey('s'),
},
{
LabelColumns: []string{
@@ -151,7 +151,7 @@ func (self *FilesController) createResetMenu() error {
)
return nil
},
Key: gocui.NewKeyRune('m'),
Key: menuKey('m'),
},
{
LabelColumns: []string{
@@ -176,7 +176,7 @@ func (self *FilesController) createResetMenu() error {
},
})
},
Key: gocui.NewKeyRune('h'),
Key: menuKey('h'),
},
}