@@ -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 ) {
28- if customCommand .Context == "" {
27+ func (self * KeybindingCreator ) call (customCommand config.CustomCommand , handler func () error ) ([] * types.Binding , error ) {
28+ if customCommand .Contexts == nil || len ( customCommand . Contexts ) == 0 {
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,35 @@ 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 ) {
52- if customCommand .Context == "global" {
53- return "" , nil
55+ func (self * KeybindingCreator ) getViewNamesAndContexts (customCommand config.CustomCommand ) ([] string , error ) {
56+ if lo . Contains ( customCommand .Contexts , "global" ) {
57+ return [] string {} , nil
5458 }
5559
56- ctx , ok := self .contextForContextKey (types .ContextKey (customCommand .Context ))
57- if ! ok {
58- return "" , formatUnknownContextError (customCommand )
60+ viewNames := []string {}
61+ for _ , context := range customCommand .Contexts {
62+ ctx , ok := self .contextForContextKey (types .ContextKey (context ))
63+ if ! ok {
64+ return []string {}, formatUnknownContextError (customCommand )
65+ }
66+
67+ viewNames = append (viewNames , ctx .GetViewName ())
5968 }
6069
61- viewName := ctx .GetViewName ()
62- return viewName , nil
70+ return viewNames , nil
6371}
6472
6573func (self * KeybindingCreator ) contextForContextKey (contextKey types.ContextKey ) (types.Context , bool ) {
@@ -77,7 +85,7 @@ func formatUnknownContextError(customCommand config.CustomCommand) error {
7785 return string (key )
7886 })
7987
80- return fmt .Errorf ("Error when setting custom command keybindings: unknown context: %s. Key: %s, Command: %s.\n Permitted contexts: %s" , customCommand .Context , customCommand .Key , customCommand .Command , strings .Join (allContextKeyStrings , ", " ))
88+ return fmt .Errorf ("Error when setting custom command keybindings: unknown context: %s. Key: %s, Command: %s.\n Permitted contexts: %s" , strings . Join ( customCommand .Contexts , ", " ) , customCommand .Key , customCommand .Command , strings .Join (allContextKeyStrings , ", " ))
8189}
8290
8391func formatContextNotProvidedError (customCommand config.CustomCommand ) error {
0 commit comments