@@ -24,12 +24,12 @@ func NewKeybindingCreator(c *helpers.HelperCommon) *KeybindingCreator {
2424 }
2525}
2626
27- func (self * KeybindingCreator ) call (customCommand config.CustomCommand , handler func () error ) (* types.Binding , error ) {
27+ func (self * KeybindingCreator ) call (customCommand config.CustomCommand , handler func () error ) ([] * types.Binding , error ) {
2828 if customCommand .Context == "" {
2929 return nil , formatContextNotProvidedError (customCommand )
3030 }
3131
32- viewName , err := self .getViewNameAndContexts (customCommand )
32+ viewNames , err := self .getViewNamesAndContexts (customCommand )
3333 if err != nil {
3434 return nil , err
3535 }
@@ -39,27 +39,40 @@ func (self *KeybindingCreator) call(customCommand config.CustomCommand, handler
3939 description = customCommand .Command
4040 }
4141
42- return & types.Binding {
43- ViewName : viewName ,
44- Key : keybindings .GetKey (customCommand .Key ),
45- Modifier : gocui .ModNone ,
46- Handler : handler ,
47- Description : description ,
48- }, nil
42+ bindings := []* types.Binding {}
43+ for _ , viewName := range viewNames {
44+ bindings = append (bindings , & types.Binding {
45+ ViewName : viewName ,
46+ Key : keybindings .GetKey (customCommand .Key ),
47+ Modifier : gocui .ModNone ,
48+ Handler : handler ,
49+ Description : description ,
50+ })
51+ }
52+ return bindings , nil
4953}
5054
51- func (self * KeybindingCreator ) getViewNameAndContexts (customCommand config.CustomCommand ) (string , error ) {
55+ func (self * KeybindingCreator ) getViewNamesAndContexts (customCommand config.CustomCommand ) ([] string , error ) {
5256 if customCommand .Context == "global" {
53- return "" , nil
57+ return [] string {} , nil
5458 }
5559
56- ctx , ok := self .contextForContextKey (types .ContextKey (customCommand .Context ))
57- if ! ok {
58- return "" , formatUnknownContextError (customCommand )
60+ contexts := strings .Split (customCommand .Context , "," )
61+ contexts = lo .Map (contexts , func (context string , _ int ) string {
62+ return strings .TrimSpace (context )
63+ })
64+
65+ viewNames := []string {}
66+ for _ , context := range contexts {
67+ ctx , ok := self .contextForContextKey (types .ContextKey (context ))
68+ if ! ok {
69+ return []string {}, formatUnknownContextError (customCommand )
70+ }
71+
72+ viewNames = append (viewNames , ctx .GetViewName ())
5973 }
6074
61- viewName := ctx .GetViewName ()
62- return viewName , nil
75+ return viewNames , nil
6376}
6477
6578func (self * KeybindingCreator ) contextForContextKey (contextKey types.ContextKey ) (types.Context , bool ) {
0 commit comments