mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-12 11:15:00 +02:00
move context specific keybindings into context file
This commit is contained in:
parent
c730271e09
commit
4f4df8f9cc
@ -411,3 +411,49 @@ func (gui *Gui) changeMainViewsContext(context string) {
|
|||||||
|
|
||||||
gui.State.MainContext = context
|
gui.State.MainContext = context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) getListContextKeyBindings() []*Binding {
|
||||||
|
bindings := make([]*Binding, 0)
|
||||||
|
|
||||||
|
for _, listContext := range gui.getListContexts() {
|
||||||
|
bindings = append(bindings, []*Binding{
|
||||||
|
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.prevItem-alt"), Modifier: gocui.ModNone, Handler: listContext.handlePrevLine},
|
||||||
|
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.prevItem"), Modifier: gocui.ModNone, Handler: listContext.handlePrevLine},
|
||||||
|
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gocui.MouseWheelUp, Modifier: gocui.ModNone, Handler: listContext.handlePrevLine},
|
||||||
|
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.nextItem-alt"), Modifier: gocui.ModNone, Handler: listContext.handleNextLine},
|
||||||
|
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.nextItem"), Modifier: gocui.ModNone, Handler: listContext.handleNextLine},
|
||||||
|
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.prevPage"), Modifier: gocui.ModNone, Handler: listContext.handlePrevPage, Description: gui.Tr.SLocalize("prevPage")},
|
||||||
|
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.nextPage"), Modifier: gocui.ModNone, Handler: listContext.handleNextPage, Description: gui.Tr.SLocalize("nextPage")},
|
||||||
|
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.gotoTop"), Modifier: gocui.ModNone, Handler: listContext.handleGotoTop, Description: gui.Tr.SLocalize("gotoTop")},
|
||||||
|
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: listContext.handleNextLine},
|
||||||
|
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gocui.MouseLeft, Modifier: gocui.ModNone, Handler: listContext.handleClick},
|
||||||
|
}...)
|
||||||
|
|
||||||
|
// the commits panel needs to lazyload things so it has a couple of its own handlers
|
||||||
|
openSearchHandler := gui.handleOpenSearch
|
||||||
|
gotoBottomHandler := listContext.handleGotoBottom
|
||||||
|
if listContext.ViewName == "commits" {
|
||||||
|
openSearchHandler = gui.handleOpenSearchForCommitsPanel
|
||||||
|
gotoBottomHandler = gui.handleGotoBottomForCommitsPanel
|
||||||
|
}
|
||||||
|
|
||||||
|
bindings = append(bindings, []*Binding{
|
||||||
|
{
|
||||||
|
ViewName: listContext.ViewName,
|
||||||
|
Contexts: []string{listContext.ContextKey},
|
||||||
|
Key: gui.getKey("universal.startSearch"),
|
||||||
|
Handler: openSearchHandler,
|
||||||
|
Description: gui.Tr.SLocalize("startSearch"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ViewName: listContext.ViewName,
|
||||||
|
Contexts: []string{listContext.ContextKey},
|
||||||
|
Key: gui.getKey("universal.gotoBottom"),
|
||||||
|
Handler: gotoBottomHandler,
|
||||||
|
Description: gui.Tr.SLocalize("gotoBottom"),
|
||||||
|
},
|
||||||
|
}...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return bindings
|
||||||
|
}
|
||||||
|
@ -1400,45 +1400,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
bindings = append(bindings, &Binding{ViewName: "", Key: rune(i+1) + '0', Modifier: gocui.ModNone, Handler: gui.goToSideWindow(window)})
|
bindings = append(bindings, &Binding{ViewName: "", Key: rune(i+1) + '0', Modifier: gocui.ModNone, Handler: gui.goToSideWindow(window)})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, listContext := range gui.getListContexts() {
|
bindings = append(bindings, gui.getListContextKeyBindings()...)
|
||||||
bindings = append(bindings, []*Binding{
|
|
||||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.prevItem-alt"), Modifier: gocui.ModNone, Handler: listContext.handlePrevLine},
|
|
||||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.prevItem"), Modifier: gocui.ModNone, Handler: listContext.handlePrevLine},
|
|
||||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gocui.MouseWheelUp, Modifier: gocui.ModNone, Handler: listContext.handlePrevLine},
|
|
||||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.nextItem-alt"), Modifier: gocui.ModNone, Handler: listContext.handleNextLine},
|
|
||||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.nextItem"), Modifier: gocui.ModNone, Handler: listContext.handleNextLine},
|
|
||||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.prevPage"), Modifier: gocui.ModNone, Handler: listContext.handlePrevPage, Description: gui.Tr.SLocalize("prevPage")},
|
|
||||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.nextPage"), Modifier: gocui.ModNone, Handler: listContext.handleNextPage, Description: gui.Tr.SLocalize("nextPage")},
|
|
||||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.gotoTop"), Modifier: gocui.ModNone, Handler: listContext.handleGotoTop, Description: gui.Tr.SLocalize("gotoTop")},
|
|
||||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: listContext.handleNextLine},
|
|
||||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gocui.MouseLeft, Modifier: gocui.ModNone, Handler: listContext.handleClick},
|
|
||||||
}...)
|
|
||||||
|
|
||||||
// the commits panel needs to lazyload things so it has a couple of its own handlers
|
|
||||||
openSearchHandler := gui.handleOpenSearch
|
|
||||||
gotoBottomHandler := listContext.handleGotoBottom
|
|
||||||
if listContext.ViewName == "commits" {
|
|
||||||
openSearchHandler = gui.handleOpenSearchForCommitsPanel
|
|
||||||
gotoBottomHandler = gui.handleGotoBottomForCommitsPanel
|
|
||||||
}
|
|
||||||
|
|
||||||
bindings = append(bindings, []*Binding{
|
|
||||||
{
|
|
||||||
ViewName: listContext.ViewName,
|
|
||||||
Contexts: []string{listContext.ContextKey},
|
|
||||||
Key: gui.getKey("universal.startSearch"),
|
|
||||||
Handler: openSearchHandler,
|
|
||||||
Description: gui.Tr.SLocalize("startSearch"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ViewName: listContext.ViewName,
|
|
||||||
Contexts: []string{listContext.ContextKey},
|
|
||||||
Key: gui.getKey("universal.gotoBottom"),
|
|
||||||
Handler: gotoBottomHandler,
|
|
||||||
Description: gui.Tr.SLocalize("gotoBottom"),
|
|
||||||
},
|
|
||||||
}...)
|
|
||||||
}
|
|
||||||
|
|
||||||
return bindings
|
return bindings
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user