mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-06 08:59:31 +02:00
allow overriding default confirm/escape keybindings
This commit is contained in:
@@ -81,6 +81,8 @@ Default path for the config file:
|
||||
optionMenu-alt1: '?' # show help menu
|
||||
select: '<space>'
|
||||
goInto: '<enter>'
|
||||
confirm: '<enter>'
|
||||
confirm-alt1: 'y'
|
||||
remove: 'd'
|
||||
new: 'n'
|
||||
edit: 'e'
|
||||
|
||||
@@ -309,6 +309,8 @@ keybinding:
|
||||
optionMenu-alt1: '?'
|
||||
select: '<space>'
|
||||
goInto: '<enter>'
|
||||
confirm: '<enter>'
|
||||
confirm-alt1: 'y'
|
||||
remove: 'd'
|
||||
new: 'n'
|
||||
edit: 'e'
|
||||
|
||||
@@ -104,8 +104,15 @@ func (gui *Gui) closeConfirmationPrompt(returnFocusOnClose bool) error {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
gui.g.DeleteKeybinding("confirmation", gocui.KeyEnter, gocui.ModNone)
|
||||
gui.g.DeleteKeybinding("confirmation", gocui.KeyEsc, gocui.ModNone)
|
||||
|
||||
for _, key := range gui.menuConfirmationKeys() {
|
||||
if err := gui.g.DeleteKeybinding("confirmation", key, gocui.ModNone); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
gui.g.DeleteKeybinding("confirmation", gui.getKey("universal.return"), gocui.ModNone)
|
||||
|
||||
return gui.g.DeleteView("confirmation")
|
||||
}
|
||||
|
||||
@@ -216,17 +223,20 @@ func (gui *Gui) setKeyBindings(opts createPopupPanelOpts) error {
|
||||
)
|
||||
|
||||
gui.renderString("options", actions)
|
||||
var onConfirm func(*gocui.Gui, *gocui.View) error
|
||||
if opts.handleConfirmPrompt != nil {
|
||||
if err := gui.g.SetKeybinding("confirmation", nil, gocui.KeyEnter, gocui.ModNone, gui.wrappedPromptConfirmationFunction(opts.handleConfirmPrompt, opts.returnFocusOnClose)); err != nil {
|
||||
return err
|
||||
}
|
||||
onConfirm = gui.wrappedPromptConfirmationFunction(opts.handleConfirmPrompt, opts.returnFocusOnClose)
|
||||
} else {
|
||||
if err := gui.g.SetKeybinding("confirmation", nil, gocui.KeyEnter, gocui.ModNone, gui.wrappedConfirmationFunction(opts.handleConfirm, opts.returnFocusOnClose)); err != nil {
|
||||
onConfirm = gui.wrappedConfirmationFunction(opts.handleConfirm, opts.returnFocusOnClose)
|
||||
}
|
||||
|
||||
for _, key := range gui.menuConfirmationKeys() {
|
||||
if err := gui.g.SetKeybinding("confirmation", nil, key, gocui.ModNone, onConfirm); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return gui.g.SetKeybinding("confirmation", nil, gocui.KeyEsc, gocui.ModNone, gui.wrappedConfirmationFunction(opts.handleClose, opts.returnFocusOnClose))
|
||||
return gui.g.SetKeybinding("confirmation", nil, gui.getKey("universal.return"), gocui.ModNone, gui.wrappedConfirmationFunction(opts.handleClose, opts.returnFocusOnClose))
|
||||
}
|
||||
|
||||
func (gui *Gui) createErrorPanel(message string) error {
|
||||
|
||||
@@ -831,25 +831,25 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
||||
},
|
||||
{
|
||||
ViewName: "commitMessage",
|
||||
Key: gocui.KeyEnter,
|
||||
Key: gui.getKey("universal.confirm"),
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: gui.handleCommitConfirm,
|
||||
},
|
||||
{
|
||||
ViewName: "commitMessage",
|
||||
Key: gocui.KeyEsc,
|
||||
Key: gui.getKey("universal.return"),
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: gui.handleCommitClose,
|
||||
},
|
||||
{
|
||||
ViewName: "credentials",
|
||||
Key: gocui.KeyEnter,
|
||||
Key: gui.getKey("universal.confirm"),
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: gui.handleSubmitCredential,
|
||||
},
|
||||
{
|
||||
ViewName: "credentials",
|
||||
Key: gocui.KeyEsc,
|
||||
Key: gui.getKey("universal.return"),
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: gui.handleCloseCredentialsView,
|
||||
},
|
||||
@@ -1355,7 +1355,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
||||
},
|
||||
{
|
||||
ViewName: "search",
|
||||
Key: gocui.KeyEnter,
|
||||
Key: gui.getKey("universal.confirm"),
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: gui.handleSearch,
|
||||
},
|
||||
|
||||
@@ -32,8 +32,12 @@ func (gui *Gui) renderMenuOptions() error {
|
||||
return gui.renderOptionsMap(optionsMap)
|
||||
}
|
||||
|
||||
func (gui *Gui) menuConfirmationKeys() []interface{} {
|
||||
return []interface{}{gui.getKey("universal.select"), gui.getKey("universal.confirm"), gui.getKey("universal.confirm-alt1")}
|
||||
}
|
||||
|
||||
func (gui *Gui) handleMenuClose(g *gocui.Gui, v *gocui.View) error {
|
||||
for _, key := range []gocui.Key{gocui.KeySpace, gocui.KeyEnter} {
|
||||
for _, key := range gui.menuConfirmationKeys() {
|
||||
if err := g.DeleteKeybinding("menu", key, gocui.ModNone); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -104,7 +108,7 @@ func (gui *Gui) createMenu(title string, items []*menuItem, createMenuOptions cr
|
||||
|
||||
gui.State.Panels.Menu.OnPress = wrappedHandlePress
|
||||
|
||||
for _, key := range []gocui.Key{gocui.KeySpace, gocui.KeyEnter, 'y'} {
|
||||
for _, key := range gui.menuConfirmationKeys() {
|
||||
_ = gui.g.DeleteKeybinding("menu", key, gocui.ModNone)
|
||||
|
||||
if err := gui.g.SetKeybinding("menu", nil, key, gocui.ModNone, wrappedHandlePress); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user