diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-17 17:53:50 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-17 18:22:57 +1000 |
commit | 44d8b3e8f3a49da82c0c39950f3df1086e1a6551 (patch) | |
tree | d6c0002237d68c2f23d3297ebcaa9eb7e34bd20a /pkg/gui | |
parent | 4f4bb40ea689925c24b2663c3b642393c7c62fe8 (diff) |
allow overriding default confirm/escape keybindings
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/confirmation_panel.go | 24 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 10 | ||||
-rw-r--r-- | pkg/gui/menu_panel.go | 8 |
3 files changed, 28 insertions, 14 deletions
diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index 71fe20452..98a2a5fc6 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -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 { diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index e149dc66d..ffef99873 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -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, }, diff --git a/pkg/gui/menu_panel.go b/pkg/gui/menu_panel.go index 98f4a5f61..07c786ec3 100644 --- a/pkg/gui/menu_panel.go +++ b/pkg/gui/menu_panel.go @@ -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 { |