mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-03 00:57:52 +02:00
480 - remove duplication by using a decorator
Also use a for loop to append the new keybindings
This commit is contained in:
committed by
Jesse Duffield
parent
ac5cbc1d2c
commit
3524f6baa9
@ -523,36 +523,6 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
Handler: gui.handleOpenOldCommitFile,
|
Handler: gui.handleOpenOldCommitFile,
|
||||||
Description: gui.Tr.SLocalize("openFile"),
|
Description: gui.Tr.SLocalize("openFile"),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
ViewName: "",
|
|
||||||
Key: '1',
|
|
||||||
Modifier: gocui.ModNone,
|
|
||||||
Handler: gui.goToStatus,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "",
|
|
||||||
Key: '2',
|
|
||||||
Modifier: gocui.ModNone,
|
|
||||||
Handler: gui.goToFiles,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "",
|
|
||||||
Key: '3',
|
|
||||||
Modifier: gocui.ModNone,
|
|
||||||
Handler: gui.goToBranches,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "",
|
|
||||||
Key: '4',
|
|
||||||
Modifier: gocui.ModNone,
|
|
||||||
Handler: gui.goToCommits,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: "",
|
|
||||||
Key: '5',
|
|
||||||
Modifier: gocui.ModNone,
|
|
||||||
Handler: gui.goToStash,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, viewName := range []string{"status", "branches", "files", "commits", "commitFiles", "stash", "menu"} {
|
for _, viewName := range []string{"status", "branches", "files", "commits", "commitFiles", "stash", "menu"} {
|
||||||
@ -565,6 +535,11 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
}...)
|
}...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Appends keybindings to jump to a particular sideView using numbers
|
||||||
|
for i, viewName := range []string{"status", "files", "branches", "commits", "stash"} {
|
||||||
|
bindings = append(bindings, &Binding{ViewName: "", Key: rune(i+1) + '0', Modifier: gocui.ModNone, Handler: gui.goToSideView(viewName)})
|
||||||
|
}
|
||||||
|
|
||||||
listPanelMap := map[string]struct {
|
listPanelMap := map[string]struct {
|
||||||
prevLine func(*gocui.Gui, *gocui.View) error
|
prevLine func(*gocui.Gui, *gocui.View) error
|
||||||
nextLine func(*gocui.Gui, *gocui.View) error
|
nextLine func(*gocui.Gui, *gocui.View) error
|
||||||
|
@ -139,44 +139,15 @@ func (gui *Gui) returnFocus(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return gui.switchFocus(g, v, previousView)
|
return gui.switchFocus(g, v, previousView)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) goToStatus(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) goToSideView(sideViewName string) func(g *gocui.Gui, v *gocui.View) error {
|
||||||
view, err := g.View("status")
|
return func(g *gocui.Gui, v *gocui.View) error {
|
||||||
if err != nil {
|
view, err := g.View(sideViewName)
|
||||||
gui.Log.Error(err)
|
if err != nil {
|
||||||
|
gui.Log.Error(err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return gui.switchFocus(g, nil, view)
|
||||||
}
|
}
|
||||||
return gui.switchFocus(g, nil, view)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) goToFiles(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
view, err := g.View("files")
|
|
||||||
if err != nil {
|
|
||||||
gui.Log.Error(err)
|
|
||||||
}
|
|
||||||
return gui.switchFocus(g, nil, view)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) goToBranches(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
view, err := g.View("branches")
|
|
||||||
if err != nil {
|
|
||||||
gui.Log.Error(err)
|
|
||||||
}
|
|
||||||
return gui.switchFocus(g, nil, view)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) goToCommits(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
view, err := g.View("commits")
|
|
||||||
if err != nil {
|
|
||||||
gui.Log.Error(err)
|
|
||||||
}
|
|
||||||
return gui.switchFocus(g, nil, view)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) goToStash(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
view, err := g.View("stash")
|
|
||||||
if err != nil {
|
|
||||||
gui.Log.Error(err)
|
|
||||||
}
|
|
||||||
return gui.switchFocus(g, nil, view)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// pass in oldView = nil if you don't want to be able to return to your old view
|
// pass in oldView = nil if you don't want to be able to return to your old view
|
||||||
|
Reference in New Issue
Block a user