summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Chen <weichen2000121@gmail.com>2020-01-07 09:50:25 -0800
committerDavid Chen <weichen2000121@gmail.com>2020-01-07 09:50:25 -0800
commit529ba45cc74c9f777c0589fa85b4a5f3ee109402 (patch)
tree14dea64b3b3292f8093e4c184286564e9c8ee4c4
parent66c7672a0cda3fa95b49d5bb2b6a0d25b4631794 (diff)
fixed keybinding display in merge_panel.go
-rw-r--r--pkg/gui/keybindings.go74
-rw-r--r--pkg/gui/merge_panel.go8
-rw-r--r--pkg/gui/options_menu_panel.go2
3 files changed, 36 insertions, 48 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 50cec5afd..032281608 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -21,7 +21,7 @@ type Binding struct {
// GetDisplayStrings returns the display string of a file
func (b *Binding) GetDisplayStrings(isFocused bool) []string {
- return []string{b.GetKey(), b.Description}
+ return []string{GetKeyDisplay(b.Key), b.Description}
}
var keyMapReversed = map[gocui.Key]string{
@@ -43,10 +43,10 @@ var keyMapReversed = map[gocui.Key]string{
gocui.KeyEnd: "end",
gocui.KeyPgup: "pgup",
gocui.KeyPgdn: "pgdown",
- gocui.KeyArrowUp: "up",
- gocui.KeyArrowDown: "down",
- gocui.KeyArrowLeft: "left",
- gocui.KeyArrowRight: "right",
+ gocui.KeyArrowUp: "▲",
+ gocui.KeyArrowDown: "▼",
+ gocui.KeyArrowLeft: "◄",
+ gocui.KeyArrowRight: "►",
gocui.KeyTab: "tab", // ctrl+i
gocui.KeyEnter: "enter", // ctrl+m
gocui.KeyEsc: "esc", // ctrl+[, ctrl+3
@@ -83,48 +83,6 @@ var keyMapReversed = map[gocui.Key]string{
gocui.KeyCtrl8: "ctrl+8",
}
-// GetKey is a function.
-func (b *Binding) GetKey() string {
- key := 0
-
- switch b.Key.(type) {
- case rune:
- key = int(b.Key.(rune))
- case gocui.Key:
- value, ok := keyMapReversed[b.Key.(gocui.Key)]
- if ok {
- return value
- }
- key = int(b.Key.(gocui.Key))
- }
-
- // special keys
- switch key {
- case 27:
- return "esc"
- case 13:
- return "enter"
- case 32:
- return "space"
- case 65514:
- return "►"
- case 65515:
- return "◄"
- case 65517:
- return "▲"
- case 65516:
- return "▼"
- case 65508:
- return "PgUp"
- case 65507:
- return "PgDn"
- case 9:
- return "tab"
- }
-
- return string(key)
-}
-
var keymap = map[string]interface{}{
"<c-a>": gocui.KeyCtrlA,
"<c-b>": gocui.KeyCtrlB,
@@ -195,6 +153,28 @@ var keymap = map[string]interface{}{
"<right>": gocui.KeyArrowRight,
}
+func (gui *Gui) getKeyDisplay(name string) string {
+ key := gui.getKey(name)
+ return GetKeyDisplay(key)
+}
+
+func GetKeyDisplay(key interface{}) string {
+ keyInt := 0
+
+ switch key.(type) {
+ case rune:
+ keyInt = int(key.(rune))
+ case gocui.Key:
+ value, ok := keyMapReversed[key.(gocui.Key)]
+ if ok {
+ return value
+ }
+ keyInt = int(key.(gocui.Key))
+ }
+
+ return string(keyInt)
+}
+
func (gui *Gui) getKey(name string) interface{} {
key := gui.Config.GetUserConfig().GetString("keybinding." + name)
if len(key) > 1 {
diff --git a/pkg/gui/merge_panel.go b/pkg/gui/merge_panel.go
index 64c17e6b4..2084ee4f1 100644
--- a/pkg/gui/merge_panel.go
+++ b/pkg/gui/merge_panel.go
@@ -5,6 +5,7 @@ package gui
import (
"bufio"
"bytes"
+ "fmt"
"io/ioutil"
"math"
"os"
@@ -243,6 +244,13 @@ func (gui *Gui) scrollToConflict(g *gocui.Gui) error {
func (gui *Gui) renderMergeOptions() error {
return gui.renderOptionsMap(map[string]string{
+ fmt.Sprintf("%s %s", gui.getKeyDisplay("universal.prevItem"), gui.getKeyDisplay("universal.nextItem")): gui.Tr.SLocalize("selectHunk"),
+ fmt.Sprintf("%s %s", gui.getKeyDisplay("universal.prevBlock"), gui.getKeyDisplay("universal.nextBlock")): gui.Tr.SLocalize("navigateConflicts"),
+ gui.getKeyDisplay("universal.select"): gui.Tr.SLocalize("pickHunk"),
+ gui.getKeyDisplay("main.pickBothHunks"): gui.Tr.SLocalize("pickBothHunks"),
+ gui.getKeyDisplay("main.undo"): gui.Tr.SLocalize("undo"),
+ })
+ return gui.renderOptionsMap(map[string]string{
"↑ ↓": gui.Tr.SLocalize("selectHunk"),
"← →": gui.Tr.SLocalize("navigateConflicts"),
"space": gui.Tr.SLocalize("pickHunk"),
diff --git a/pkg/gui/options_menu_panel.go b/pkg/gui/options_menu_panel.go
index 85a25677e..51abb64bb 100644
--- a/pkg/gui/options_menu_panel.go
+++ b/pkg/gui/options_menu_panel.go
@@ -17,7 +17,7 @@ func (gui *Gui) getBindings(v *gocui.View) []*Binding {
bindings := gui.GetInitialKeybindings()
for _, binding := range bindings {
- if binding.GetKey() != "" && binding.Description != "" {
+ if GetKeyDisplay(binding.Key) != "" && binding.Description != "" {
switch binding.ViewName {
case "":
bindingsGlobal = append(bindingsGlobal, binding)