1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

refactor to only have one context per view

This commit is contained in:
Jesse Duffield
2022-06-13 11:01:26 +10:00
parent 6dfef08efc
commit 524bf83a4a
372 changed files with 28866 additions and 6902 deletions

View File

@ -29,7 +29,7 @@ func (self *KeybindingCreator) call(customCommand config.CustomCommand, handler
return nil, formatContextNotProvidedError(customCommand)
}
viewName, contexts, err := self.getViewNameAndContexts(customCommand)
viewName, err := self.getViewNameAndContexts(customCommand)
if err != nil {
return nil, err
}
@ -41,7 +41,6 @@ func (self *KeybindingCreator) call(customCommand config.CustomCommand, handler
return &types.Binding{
ViewName: viewName,
Contexts: contexts,
Key: self.getKey(customCommand.Key),
Modifier: gocui.ModNone,
Handler: handler,
@ -49,22 +48,18 @@ func (self *KeybindingCreator) call(customCommand config.CustomCommand, handler
}, nil
}
func (self *KeybindingCreator) getViewNameAndContexts(customCommand config.CustomCommand) (string, []string, error) {
func (self *KeybindingCreator) getViewNameAndContexts(customCommand config.CustomCommand) (string, error) {
if customCommand.Context == "global" {
return "", nil, nil
return "", nil
}
ctx, ok := self.contextForContextKey(types.ContextKey(customCommand.Context))
if !ok {
return "", nil, formatUnknownContextError(customCommand)
return "", formatUnknownContextError(customCommand)
}
// here we assume that a given context will always belong to the same view.
// Currently this is a safe bet but it's by no means guaranteed in the long term
// and we might need to make some changes in the future to support it.
viewName := ctx.GetViewName()
contexts := []string{customCommand.Context}
return viewName, contexts, nil
return viewName, nil
}
func (self *KeybindingCreator) contextForContextKey(contextKey types.ContextKey) (types.Context, bool) {