1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-04 03:48:07 +02:00

fixed keybinding display in merge_panel.go

This commit is contained in:
David Chen 2020-01-07 09:50:25 -08:00
parent 66c7672a0c
commit 529ba45cc7
3 changed files with 36 additions and 48 deletions

View File

@ -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 {

View File

@ -5,6 +5,7 @@ package gui
import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"math"
"os"
@ -242,6 +243,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"),

View File

@ -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)