Add return-alt1 to allow for a secondary Return key

This partially adds the feature back that was removed in #2495. This
allows specifing a secondary Return keybinding. In my personal setup I
use the `q` for this (and remove it as the default for Quit). Returning
is a very common operation in lazygit, and having to reach for the
Escape key all the time is annoying. There are cases where it's not
possible to use a regular letter as the Return keybinding, such as the
commit prompt.
This commit is contained in:
Jelte Fennema-Nio 2024-07-15 17:58:30 +02:00
parent f598da0df2
commit 9812d2fca4
12 changed files with 45 additions and 0 deletions

View file

@ -449,6 +449,8 @@ keybinding:
quit: q quit: q
quit-alt1: <c-c> quit-alt1: <c-c>
return: <esc> return: <esc>
# When set to a printable character, this will work for returning from non-prompt panels
return-alt1: null
quitWithoutChangingDirectory: Q quitWithoutChangingDirectory: Q
togglePanel: <tab> togglePanel: <tab>
prevItem: <up> prevItem: <up>

View file

@ -344,6 +344,7 @@ type KeybindingUniversalConfig struct {
Quit string `yaml:"quit"` Quit string `yaml:"quit"`
QuitAlt1 string `yaml:"quit-alt1"` QuitAlt1 string `yaml:"quit-alt1"`
Return string `yaml:"return"` Return string `yaml:"return"`
ReturnAlt1 string `yaml:"return-alt1"`
QuitWithoutChangingDirectory string `yaml:"quitWithoutChangingDirectory"` QuitWithoutChangingDirectory string `yaml:"quitWithoutChangingDirectory"`
TogglePanel string `yaml:"togglePanel"` TogglePanel string `yaml:"togglePanel"`
PrevItem string `yaml:"prevItem"` PrevItem string `yaml:"prevItem"`

View file

@ -31,6 +31,10 @@ func (self *CommitDescriptionController) GetKeybindings(opts types.KeybindingsOp
Key: opts.GetKey(opts.Config.Universal.Return), Key: opts.GetKey(opts.Config.Universal.Return),
Handler: self.close, Handler: self.close,
}, },
{
Key: opts.GetKey(opts.Config.Universal.ReturnAlt1),
Handler: self.close,
},
{ {
Key: opts.GetKey(opts.Config.Universal.ConfirmInEditor), Key: opts.GetKey(opts.Config.Universal.ConfirmInEditor),
Handler: self.confirm, Handler: self.confirm,

View file

@ -37,6 +37,10 @@ func (self *ConfirmationController) GetKeybindings(opts types.KeybindingsOpts) [
Description: self.c.Tr.CloseCancel, Description: self.c.Tr.CloseCancel,
DisplayOnScreen: true, DisplayOnScreen: true,
}, },
{
Key: opts.GetKey(opts.Config.Universal.ReturnAlt1),
Handler: func() error { return self.context().State.OnClose() },
},
{ {
Key: opts.GetKey(opts.Config.Universal.TogglePanel), Key: opts.GetKey(opts.Config.Universal.TogglePanel),
Handler: func() error { Handler: func() error {

View file

@ -119,6 +119,11 @@ func (self *GlobalController) GetKeybindings(opts types.KeybindingsOpts) []*type
Description: self.c.Tr.Cancel, Description: self.c.Tr.Cancel,
DisplayOnScreen: true, DisplayOnScreen: true,
}, },
{
Key: opts.GetKey(opts.Config.Universal.ReturnAlt1),
Modifier: gocui.ModNone,
Handler: self.escape,
},
{ {
Key: opts.GetKey(opts.Config.Universal.ToggleWhitespaceInDiffView), Key: opts.GetKey(opts.Config.Universal.ToggleWhitespaceInDiffView),
Handler: self.toggleWhitespace, Handler: self.toggleWhitespace,

View file

@ -50,6 +50,10 @@ func (self *MenuController) GetKeybindings(opts types.KeybindingsOpts) []*types.
Description: self.c.Tr.Close, Description: self.c.Tr.Close,
DisplayOnScreen: true, DisplayOnScreen: true,
}, },
{
Key: opts.GetKey(opts.Config.Universal.ReturnAlt1),
Handler: self.close,
},
} }
return bindings return bindings

View file

@ -123,6 +123,10 @@ func (self *MergeConflictsController) GetKeybindings(opts types.KeybindingsOpts)
Handler: self.Escape, Handler: self.Escape,
Description: self.c.Tr.ReturnToFilesPanel, Description: self.c.Tr.ReturnToFilesPanel,
}, },
{
Key: opts.GetKey(opts.Config.Universal.ReturnAlt1),
Handler: self.Escape,
},
} }
return bindings return bindings

View file

@ -47,6 +47,10 @@ func (self *PatchBuildingController) GetKeybindings(opts types.KeybindingsOpts)
Handler: self.Escape, Handler: self.Escape,
Description: self.c.Tr.ExitCustomPatchBuilder, Description: self.c.Tr.ExitCustomPatchBuilder,
}, },
{
Key: opts.GetKey(opts.Config.Universal.ReturnAlt1),
Handler: self.Escape,
},
} }
} }

View file

@ -33,6 +33,11 @@ func (self *SearchPromptController) GetKeybindings(opts types.KeybindingsOpts) [
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: self.cancel, Handler: self.cancel,
}, },
{
Key: opts.GetKey(opts.Config.Universal.ReturnAlt1),
Modifier: gocui.ModNone,
Handler: self.cancel,
},
{ {
Key: opts.GetKey(opts.Config.Universal.PrevItem), Key: opts.GetKey(opts.Config.Universal.PrevItem),
Modifier: gocui.ModNone, Modifier: gocui.ModNone,

View file

@ -43,6 +43,10 @@ func (self *SnakeController) GetKeybindings(opts types.KeybindingsOpts) []*types
Key: opts.GetKey(opts.Config.Universal.Return), Key: opts.GetKey(opts.Config.Universal.Return),
Handler: self.Escape, Handler: self.Escape,
}, },
{
Key: opts.GetKey(opts.Config.Universal.ReturnAlt1),
Handler: self.Escape,
},
} }
return bindings return bindings

View file

@ -70,6 +70,10 @@ func (self *StagingController) GetKeybindings(opts types.KeybindingsOpts) []*typ
Handler: self.Escape, Handler: self.Escape,
Description: self.c.Tr.ReturnToFilesPanel, Description: self.c.Tr.ReturnToFilesPanel,
}, },
{
Key: opts.GetKey(opts.Config.Universal.ReturnAlt1),
Handler: self.Escape,
},
{ {
Key: opts.GetKey(opts.Config.Universal.TogglePanel), Key: opts.GetKey(opts.Config.Universal.TogglePanel),
Handler: self.TogglePanel, Handler: self.TogglePanel,

View file

@ -39,6 +39,10 @@ func (self *SuggestionsController) GetKeybindings(opts types.KeybindingsOpts) []
Key: opts.GetKey(opts.Config.Universal.Return), Key: opts.GetKey(opts.Config.Universal.Return),
Handler: func() error { return self.context().State.OnClose() }, Handler: func() error { return self.context().State.OnClose() },
}, },
{
Key: opts.GetKey(opts.Config.Universal.ReturnAlt1),
Handler: func() error { return self.context().State.OnClose() },
},
{ {
Key: opts.GetKey(opts.Config.Universal.TogglePanel), Key: opts.GetKey(opts.Config.Universal.TogglePanel),
Handler: self.switchToConfirmation, Handler: self.switchToConfirmation,