mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-11-26 09:00:57 +02:00
rewrite some of menu panel logic
panel keybindings are now on top and global keybindings are below separated with empty newline
This commit is contained in:
parent
db2e2160a9
commit
ba6dedfb22
@ -74,27 +74,42 @@ func (gui *Gui) GetMaxKeyLength(bindings []Binding) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleMenu(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleMenu(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
var (
|
||||||
|
contentGlobal, contentPanel []string
|
||||||
|
bindingsGlobal, bindingsPanel []Binding
|
||||||
|
)
|
||||||
// clear keys slice, so we don't have ghost elements
|
// clear keys slice, so we don't have ghost elements
|
||||||
gui.State.Keys = gui.State.Keys[:0]
|
gui.State.Keys = gui.State.Keys[:0]
|
||||||
content := ""
|
|
||||||
current := ""
|
|
||||||
bindings := gui.GetKeybindings()
|
bindings := gui.GetKeybindings()
|
||||||
padWidth := gui.GetMaxKeyLength(bindings)
|
padWidth := gui.GetMaxKeyLength(bindings)
|
||||||
|
|
||||||
for _, binding := range bindings {
|
for _, binding := range bindings {
|
||||||
if key := gui.GetKey(binding); key != "" && (binding.ViewName == v.Name() || binding.ViewName == "") && binding.Description != "" {
|
key := gui.GetKey(binding)
|
||||||
if binding.ViewName != current {
|
if key != "" && binding.Description != "" {
|
||||||
content += "\n"
|
content := fmt.Sprintf("%s %s", utils.WithPadding(key, padWidth), binding.Description)
|
||||||
gui.State.Keys = append(gui.State.Keys, Binding{})
|
switch binding.ViewName {
|
||||||
current = binding.ViewName
|
case "":
|
||||||
|
contentGlobal = append(contentGlobal, content)
|
||||||
|
bindingsGlobal = append(bindingsGlobal, binding)
|
||||||
|
case v.Name():
|
||||||
|
contentPanel = append(contentPanel, content)
|
||||||
|
bindingsPanel = append(bindingsPanel, binding)
|
||||||
}
|
}
|
||||||
content += fmt.Sprintf("%s %s\n", utils.WithPadding(key, padWidth), binding.Description)
|
|
||||||
gui.State.Keys = append(gui.State.Keys, binding)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// append dummy element to have a separator between
|
||||||
|
// panel and global keybindings
|
||||||
|
contentPanel = append(contentPanel, "")
|
||||||
|
bindingsPanel = append(bindingsPanel, Binding{})
|
||||||
|
|
||||||
|
content := append(contentPanel, contentGlobal...)
|
||||||
|
gui.State.Keys = append(bindingsPanel, bindingsGlobal...)
|
||||||
|
// append newline at the end so the last line would be selectable
|
||||||
|
contentJoined := strings.Join(content, "\n") + "\n"
|
||||||
|
|
||||||
// y1-1 so there will not be an extra space at the end of panel
|
// y1-1 so there will not be an extra space at the end of panel
|
||||||
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(g, content)
|
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(g, contentJoined)
|
||||||
menuView, _ := g.SetView("menu", x0, y0, x1, y1-1, 0)
|
menuView, _ := g.SetView("menu", x0, y0, x1, y1-1, 0)
|
||||||
menuView.Title = strings.Title(gui.Tr.SLocalize("menu"))
|
menuView.Title = strings.Title(gui.Tr.SLocalize("menu"))
|
||||||
menuView.FgColor = gocui.ColorWhite
|
menuView.FgColor = gocui.ColorWhite
|
||||||
@ -103,7 +118,7 @@ func (gui *Gui) handleMenu(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprint(menuView, content)
|
fmt.Fprint(menuView, contentJoined)
|
||||||
|
|
||||||
g.Update(func(g *gocui.Gui) error {
|
g.Update(func(g *gocui.Gui) error {
|
||||||
_, err := g.SetViewOnTop("menu")
|
_, err := g.SetViewOnTop("menu")
|
||||||
|
Loading…
Reference in New Issue
Block a user