1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-26 05:37:18 +02:00
lazygit/pkg/gui/context.go

46 lines
1004 B
Go
Raw Normal View History

2019-02-16 21:01:17 +11:00
package gui
2019-11-10 16:33:31 +11:00
func (gui *Gui) changeContext(context string) error {
oldContext := gui.State.Context
if gui.State.Context == context {
2019-02-16 21:01:17 +11:00
return nil
}
2019-03-02 15:11:53 +11:00
contextMap := gui.GetContextMap()
2019-02-16 21:01:17 +11:00
2019-11-10 16:33:31 +11:00
oldBindings := contextMap[oldContext]
for _, binding := range oldBindings {
if err := gui.g.DeleteKeybinding(binding.ViewName, binding.Key, binding.Modifier); err != nil {
return err
}
}
2019-02-16 21:01:17 +11:00
2019-11-10 16:33:31 +11:00
bindings := contextMap[context]
2019-02-16 21:01:17 +11:00
for _, binding := range bindings {
2019-11-10 16:20:35 +11:00
if err := gui.g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, binding.Handler); err != nil {
2019-02-16 21:01:17 +11:00
return err
}
}
2019-11-10 16:33:31 +11:00
gui.State.Context = context
2019-11-10 16:20:35 +11:00
return nil
2019-02-16 21:01:17 +11:00
}
2019-11-10 16:33:31 +11:00
func (gui *Gui) setInitialContext() error {
2019-03-02 15:11:53 +11:00
contextMap := gui.GetContextMap()
2019-02-16 21:01:17 +11:00
2019-11-10 16:33:31 +11:00
initialContext := "normal"
2019-02-16 21:01:17 +11:00
2019-11-10 16:33:31 +11:00
bindings := contextMap[initialContext]
for _, binding := range bindings {
if err := gui.g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, binding.Handler); err != nil {
return err
2019-02-16 21:01:17 +11:00
}
}
2019-11-10 16:33:31 +11:00
gui.State.Context = initialContext
2019-02-16 21:01:17 +11:00
return nil
}