1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00

move keys slice to guiState struct

This commit is contained in:
Dawid Dziurla 2018-09-04 15:29:43 +02:00
parent 7b84c162f4
commit cbafadd48e
No known key found for this signature in database
GPG Key ID: 7B6D8368172E9B0B
2 changed files with 5 additions and 6 deletions

View File

@ -83,6 +83,7 @@ type guiState struct {
EditHistory *stack.Stack EditHistory *stack.Stack
Platform commands.Platform Platform commands.Platform
Updating bool Updating bool
Keys []Binding
} }
// NewGui builds a new gui handler // NewGui builds a new gui handler

View File

@ -8,16 +8,14 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
var keys []Binding
func (gui *Gui) handleHelpPress(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleHelpPress(g *gocui.Gui, v *gocui.View) error {
lineNumber := gui.getItemPosition(v) lineNumber := gui.getItemPosition(v)
if len(keys) > lineNumber { if len(gui.State.Keys) > lineNumber {
err := gui.handleHelpClose(g, v) err := gui.handleHelpClose(g, v)
if err != nil { if err != nil {
return err return err
} }
return keys[lineNumber].Handler(g, v) return gui.State.Keys[lineNumber].Handler(g, v)
} }
return nil return nil
} }
@ -74,7 +72,7 @@ func (gui *Gui) getMaxKeyLength(bindings []Binding) int {
func (gui *Gui) handleHelp(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleHelp(g *gocui.Gui, v *gocui.View) error {
// clear keys slice, so we don't have ghost elements // clear keys slice, so we don't have ghost elements
keys = keys[:0] gui.State.Keys = gui.State.Keys[:0]
content := "" content := ""
bindings := gui.GetKeybindings() bindings := gui.GetKeybindings()
padWidth := gui.getMaxKeyLength(bindings) padWidth := gui.getMaxKeyLength(bindings)
@ -82,7 +80,7 @@ func (gui *Gui) handleHelp(g *gocui.Gui, v *gocui.View) error {
for _, binding := range bindings { for _, binding := range bindings {
if key := gui.GetKey(binding); key != "" && binding.ViewName == v.Name() && binding.Description != "" { if key := gui.GetKey(binding); key != "" && binding.ViewName == v.Name() && binding.Description != "" {
content += fmt.Sprintf("%s %s\n", utils.WithPadding(key, padWidth), binding.Description) content += fmt.Sprintf("%s %s\n", utils.WithPadding(key, padWidth), binding.Description)
keys = append(keys, binding) gui.State.Keys = append(gui.State.Keys, binding)
} }
} }