summaryrefslogtreecommitdiffstats
path: root/pkg/gui/keybindings.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-09-25 19:05:24 +1000
committerGitHub <noreply@github.com>2018-09-25 19:05:24 +1000
commit7164f372661794eedd749eb41cc1265c86110913 (patch)
tree39751808681b8908989443b278cd5e90aac97a52 /pkg/gui/keybindings.go
parent61f0801bd366e959437676ae72b2d9fe98c4b8af (diff)
parent80d6bbef8661932ee0a665961b44a681c811ac36 (diff)
Merge branch 'master' into feature/commit-amend
Diffstat (limited to 'pkg/gui/keybindings.go')
-rw-r--r--pkg/gui/keybindings.go44
1 files changed, 33 insertions, 11 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 3eb8785d2..44df7b686 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -1,7 +1,9 @@
package gui
-import "github.com/jesseduffield/gocui"
-import "strings"
+import (
+ "github.com/jesseduffield/gocui"
+ "strings"
+)
// Binding - a keybinding mapping a key and modifier to a handler. The keypress
// is only handled if the given view has focus, or handled globally if the view
@@ -15,8 +17,26 @@ type Binding struct {
Description string
}
-func (gui *Gui) GetKeybindings() []Binding {
- bindings := []Binding{
+// GetDisplayStrings returns the display string of a file
+func (b *Binding) GetDisplayStrings() []string {
+ return []string{b.GetKey(), b.Description}
+}
+
+func (b *Binding) GetKey() string {
+ r, ok := b.Key.(rune)
+ key := ""
+
+ if ok {
+ key = string(r)
+ } else if b.KeyReadable != "" {
+ key = b.KeyReadable
+ }
+
+ return key
+}
+
+func (gui *Gui) GetKeybindings() []*Binding {
+ bindings := []*Binding{
{
ViewName: "",
Key: 'q',
@@ -74,7 +94,7 @@ func (gui *Gui) GetKeybindings() []Binding {
ViewName: "",
Key: 'x',
Modifier: gocui.ModNone,
- Handler: gui.handleMenu,
+ Handler: gui.handleCreateOptionsMenu,
}, {
ViewName: "status",
Key: 'e',
@@ -94,6 +114,13 @@ func (gui *Gui) GetKeybindings() []Binding {
Handler: gui.handleCheckForUpdate,
Description: gui.Tr.SLocalize("checkForUpdate"),
}, {
+ ViewName: "status",
+ Key: 's',
+ Modifier: gocui.ModNone,
+ Handler: gui.handleCreateRecentReposMenu,
+ Description: gui.Tr.SLocalize("SwitchRepo"),
+ },
+ {
ViewName: "files",
Key: 'c',
Modifier: gocui.ModNone,
@@ -356,18 +383,13 @@ func (gui *Gui) GetKeybindings() []Binding {
Key: 'q',
Modifier: gocui.ModNone,
Handler: gui.handleMenuClose,
- }, {
- ViewName: "menu",
- Key: gocui.KeySpace,
- Modifier: gocui.ModNone,
- Handler: gui.handleMenuPress,
},
}
// Would make these keybindings global but that interferes with editing
// input in the confirmation panel
for _, viewName := range []string{"status", "files", "branches", "commits", "stash", "menu"} {
- bindings = append(bindings, []Binding{
+ bindings = append(bindings, []*Binding{
{ViewName: viewName, Key: gocui.KeyTab, Modifier: gocui.ModNone, Handler: gui.nextView},
{ViewName: viewName, Key: gocui.KeyArrowLeft, Modifier: gocui.ModNone, Handler: gui.previousView},
{ViewName: viewName, Key: gocui.KeyArrowRight, Modifier: gocui.ModNone, Handler: gui.nextView},