Skip to content

Commit ea174ec

Browse files
committed
Show context-specific labels for the global <esc> binding
WHen several modes are active at the same time, it isn't totally obvious which one will be cancelled first, so show this in the status bar.
1 parent 0f6cd4b commit ea174ec

File tree

4 files changed

+81
-5
lines changed

4 files changed

+81
-5
lines changed

pkg/gui/controllers/global_controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (self *GlobalController) GetKeybindings(opts types.KeybindingsOpts) []*type
118118
Key: opts.GetKey(opts.Config.Universal.Return),
119119
Modifier: gocui.ModNone,
120120
Handler: self.escape,
121-
Description: self.c.Tr.Cancel,
121+
DescriptionFunc: self.escapeDescription,
122122
GetDisabledReason: self.escapeEnabled,
123123
DisplayOnScreen: true,
124124
},
@@ -191,6 +191,10 @@ func (self *GlobalController) escape() error {
191191
return (&QuitActions{c: self.c}).Escape()
192192
}
193193

194+
func (self *GlobalController) escapeDescription() string {
195+
return (&QuitActions{c: self.c}).EscapeDescription()
196+
}
197+
194198
func (self *GlobalController) escapeEnabled() *types.DisabledReason {
195199
if (&QuitActions{c: self.c}).EscapeEnabled() {
196200
return nil

pkg/gui/controllers/helpers/mode_helper.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ func NewModeHelper(
3939
}
4040

4141
type ModeStatus struct {
42-
IsActive func() bool
43-
InfoLabel func() string
44-
Reset func() error
42+
IsActive func() bool
43+
InfoLabel func() string
44+
CancelLabel func() string
45+
Reset func() error
4546
}
4647

4748
func (self *ModeHelper) Statuses() []ModeStatus {
@@ -58,13 +59,19 @@ func (self *ModeHelper) Statuses() []ModeStatus {
5859
style.FgMagenta,
5960
)
6061
},
62+
CancelLabel: func() string {
63+
return self.c.Tr.CancelDiffingMode
64+
},
6165
Reset: self.diffHelper.ExitDiffMode,
6266
},
6367
{
6468
IsActive: self.c.Git().Patch.PatchBuilder.Active,
6569
InfoLabel: func() string {
6670
return self.withResetButton(self.c.Tr.BuildingPatch, style.FgYellow.SetBold())
6771
},
72+
CancelLabel: func() string {
73+
return self.c.Tr.ExitCustomPatchBuilder
74+
},
6875
Reset: self.patchBuildingHelper.Reset,
6976
},
7077
{
@@ -80,6 +87,9 @@ func (self *ModeHelper) Statuses() []ModeStatus {
8087
style.FgRed,
8188
)
8289
},
90+
CancelLabel: func() string {
91+
return self.c.Tr.ExitFilterMode
92+
},
8393
Reset: self.ExitFilterMode,
8494
},
8595
{
@@ -90,6 +100,9 @@ func (self *ModeHelper) Statuses() []ModeStatus {
90100
style.FgCyan,
91101
)
92102
},
103+
CancelLabel: func() string {
104+
return self.c.Tr.CancelMarkedBaseCommit
105+
},
93106
Reset: self.mergeAndRebaseHelper.ResetMarkedBaseCommit,
94107
},
95108
{
@@ -110,6 +123,9 @@ func (self *ModeHelper) Statuses() []ModeStatus {
110123
style.FgCyan,
111124
)
112125
},
126+
CancelLabel: func() string {
127+
return self.c.Tr.ResetCherryPickShort
128+
},
113129
Reset: self.cherryPickHelper.Reset,
114130
},
115131
{
@@ -122,6 +138,9 @@ func (self *ModeHelper) Statuses() []ModeStatus {
122138
workingTreeState.Title(self.c.Tr), style.FgYellow,
123139
)
124140
},
141+
CancelLabel: func() string {
142+
return fmt.Sprintf(self.c.Tr.AbortTitle, self.c.Git().Status.WorkingTreeState().CommandName())
143+
},
125144
Reset: self.mergeAndRebaseHelper.AbortMergeOrRebaseWithConfirm,
126145
},
127146
{
@@ -131,6 +150,9 @@ func (self *ModeHelper) Statuses() []ModeStatus {
131150
InfoLabel: func() string {
132151
return self.withResetButton(self.c.Tr.Bisect.Bisecting, style.FgGreen)
133152
},
153+
CancelLabel: func() string {
154+
return self.c.Tr.Actions.ResetBisect
155+
},
134156
Reset: self.bisectHelper.Reset,
135157
},
136158
}

pkg/gui/controllers/quit_actions.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (self *QuitActions) confirmQuitDuringUpdate() error {
4848
}
4949

5050
func (self *QuitActions) Escape() error {
51-
// If you make changes to this function, be sure to update EscapeEnabled accordingly.
51+
// If you make changes to this function, be sure to update EscapeEnabled and EscapeDescription accordingly.
5252

5353
currentContext := self.c.Context().Current()
5454

@@ -130,3 +130,41 @@ func (self *QuitActions) EscapeEnabled() bool {
130130

131131
return false
132132
}
133+
134+
func (self *QuitActions) EscapeDescription() string {
135+
currentContext := self.c.Context().Current()
136+
137+
if listContext, ok := currentContext.(types.IListContext); ok {
138+
if listContext.GetList().IsSelectingRange() {
139+
return self.c.Tr.DismissRangeSelect
140+
}
141+
}
142+
143+
if ctx, ok := currentContext.(types.IFilterableContext); ok {
144+
if ctx.IsFiltering() {
145+
return self.c.Tr.ExitFilterMode
146+
}
147+
}
148+
149+
parentContext := currentContext.GetParentContext()
150+
if parentContext != nil {
151+
return self.c.Tr.ExitSubview
152+
}
153+
154+
for _, mode := range self.c.Helpers().Mode.Statuses() {
155+
if mode.IsActive() {
156+
return mode.CancelLabel()
157+
}
158+
}
159+
160+
repoPathStack := self.c.State().GetRepoPathStack()
161+
if !repoPathStack.IsEmpty() {
162+
return self.c.Tr.BackToParentRepo
163+
}
164+
165+
if self.c.UserConfig().QuitOnTopLevelReturn {
166+
return self.c.Tr.Quit
167+
}
168+
169+
return self.c.Tr.Cancel
170+
}

pkg/i18n/english.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ type TranslationSet struct {
601601
RenameBranchWarning string
602602
OpenKeybindingsMenu string
603603
ResetCherryPick string
604+
ResetCherryPickShort string
604605
NextTab string
605606
PrevTab string
606607
CantUndoWhileRebasing string
@@ -634,6 +635,7 @@ type TranslationSet struct {
634635
SwapDiff string
635636
ViewDiffingOptions string
636637
ViewDiffingOptionsTooltip string
638+
CancelDiffingMode string
637639
OpenCommandLogMenu string
638640
OpenCommandLogMenuTooltip string
639641
ShowingGitDiff string
@@ -671,6 +673,7 @@ type TranslationSet struct {
671673
SubmoduleStashAndReset string
672674
AndResetSubmodules string
673675
EnterSubmoduleTooltip string
676+
BackToParentRepo string
674677
Enter string
675678
CopySubmoduleNameToClipboard string
676679
RemoveSubmodule string
@@ -699,6 +702,7 @@ type TranslationSet struct {
699702
BulkSubmoduleOptions string
700703
RunningCommand string
701704
SubCommitsTitle string
705+
ExitSubview string
702706
SubmodulesTitle string
703707
NavigationTitle string
704708
SuggestionsCheatsheetTitle string
@@ -860,6 +864,7 @@ type TranslationSet struct {
860864
MarkedBaseCommitStatus string
861865
MarkAsBaseCommit string
862866
MarkAsBaseCommitTooltip string
867+
CancelMarkedBaseCommit string
863868
MarkedCommitMarker string
864869
FailedToOpenURL string
865870
InvalidLazygitEditURL string
@@ -869,6 +874,7 @@ type TranslationSet struct {
869874
QuickStartInteractiveRebaseTooltip string
870875
CannotQuickStartInteractiveRebase string
871876
ToggleRangeSelect string
877+
DismissRangeSelect string
872878
RangeSelectUp string
873879
RangeSelectDown string
874880
RangeSelectNotSupported string
@@ -1348,6 +1354,7 @@ func EnglishTranslationSet() *TranslationSet {
13481354
DiscardSelection: `Discard`,
13491355
DiscardSelectionTooltip: "When unstaged change is selected, discard the change using `git reset`. When staged change is selected, unstage the change.",
13501356
ToggleRangeSelect: "Toggle range select",
1357+
DismissRangeSelect: "Dismiss range select",
13511358
ToggleSelectHunk: "Toggle hunk selection",
13521359
SelectHunk: "Select hunks",
13531360
SelectLineByLine: "Select line-by-line",
@@ -1666,6 +1673,7 @@ func EnglishTranslationSet() *TranslationSet {
16661673
RenameBranchWarning: "This branch is tracking a remote. This action will only rename the local branch name, not the name of the remote branch. Continue?",
16671674
OpenKeybindingsMenu: "Open keybindings menu",
16681675
ResetCherryPick: "Reset copied (cherry-picked) commits selection",
1676+
ResetCherryPickShort: "Reset copied commits",
16691677
NextTab: "Next tab",
16701678
PrevTab: "Previous tab",
16711679
CantUndoWhileRebasing: "Can't undo while rebasing",
@@ -1699,6 +1707,7 @@ func EnglishTranslationSet() *TranslationSet {
16991707
SwapDiff: "Reverse diff direction",
17001708
ViewDiffingOptions: "View diffing options",
17011709
ViewDiffingOptionsTooltip: "View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction.",
1710+
CancelDiffingMode: "Cancel diffing mode",
17021711
// the actual view is the extras view which I intend to give more tabs in future but for now we'll only mention the command log part
17031712
OpenCommandLogMenu: "View command log options",
17041713
OpenCommandLogMenuTooltip: "View options for the command log e.g. show/hide the command log and focus the command log.",
@@ -1738,6 +1747,7 @@ func EnglishTranslationSet() *TranslationSet {
17381747
AndResetSubmodules: "And reset submodules",
17391748
Enter: "Enter",
17401749
EnterSubmoduleTooltip: "Enter submodule. After entering the submodule, you can press `{{.escape}}` to escape back to the parent repo.",
1750+
BackToParentRepo: "Back to parent repo",
17411751
CopySubmoduleNameToClipboard: "Copy submodule name to clipboard",
17421752
RemoveSubmodule: "Remove submodule",
17431753
RemoveSubmodulePrompt: "Are you sure you want to remove submodule '%s' and its corresponding directory? This is irreversible.",
@@ -1765,6 +1775,7 @@ func EnglishTranslationSet() *TranslationSet {
17651775
BulkSubmoduleOptions: "Bulk submodule options",
17661776
RunningCommand: "Running command",
17671777
SubCommitsTitle: "Sub-commits",
1778+
ExitSubview: "Exit subview",
17681779
SubmodulesTitle: "Submodules",
17691780
NavigationTitle: "List panel navigation",
17701781
SuggestionsCheatsheetTitle: "Suggestions",
@@ -1923,6 +1934,7 @@ func EnglishTranslationSet() *TranslationSet {
19231934
MarkedBaseCommitStatus: "Marked a base commit for rebase",
19241935
MarkAsBaseCommit: "Mark as base commit for rebase",
19251936
MarkAsBaseCommitTooltip: "Select a base commit for the next rebase. When you rebase onto a branch, only commits above the base commit will be brought across. This uses the `git rebase --onto` command.",
1937+
CancelMarkedBaseCommit: "Cancel marked base commit",
19261938
MarkedCommitMarker: "↑↑↑ Will rebase from here ↑↑↑",
19271939
FailedToOpenURL: "Failed to open URL %s\n\nError: %v",
19281940
InvalidLazygitEditURL: "Invalid lazygit-edit URL format: %s",

0 commit comments

Comments
 (0)